<?php
class AccessInfo extends AppModel
{
	var $name='AccessInfo'; 	
	
	
	public function saveAccessInfo($formData){
		
		$error = "";
		
		$form["id"] = trim($formData["id"]);
		$form["unique_url"] = trim($formData["unique_url"]);
		$form["access_time"] = date('Y-m-d H:i:s');
		
		$fileds = array('id','unique_url','access_time');
		
		$data["AccessInfo"] = $form;
		if(!empty($form["id"]) && !empty($form["unique_url"])){
            if(!$this->save($data,false,$fileds)){
                $error = "22";
            }
        }else{
            $error = "23";
        }

		return $error;
	}
	
	public function getExpiredExpenses($month,$type=1){
        $type_value = $type==1?"months":"days";
		date_default_timezone_set("UTC");
		$range = date('Y-m-d H:i:s', strtotime("-{$month} {$type_value}"));
		$result =  $this->find('all', 
						array(
						'conditions' => array('AccessInfo.access_time < ' => $range
						)
				));
		return $result;
	}
	
	public function deleteAllExpiredExpenses($deleteList){
		$result =  $this->deleteAll( 
				array(array('id' => $deleteList))
					 );
		
		return $result;
	}
	 
}