Exemplo n.º 1
0
 /**
  * Returns a collection given the query parameters
  *
  * @param string table
  * @param array filter
  * @param array sort
  * @param int start
  * @param int range
  * @return array
  */
 public function getCollection($table, $filters = NULL, array $sort = array(), $start = 0, $range = 0, $index = NULL)
 {
     //argument test
     Eden_Facebook_Error::i()->argument(1, 'string')->argument(2, 'string', 'array', 'null')->argument(4, 'numeric')->argument(5, 'numeric')->argument(6, 'numeric', 'null');
     //Argument 7 must be a number or null
     $results = $this->getRows($table, $filters, $sort, $start, $range, $index);
     $collection = Eden_Collection::i();
     if (is_null($results)) {
         return $collection;
     }
     if (!is_null($index)) {
         return $this->model($results);
     }
     return $collection->set($results);
 }
Exemplo n.º 2
0
 /**
  * Returns the results in a collection
  *
  * @return Eden_Facebook_Collection
  */
 public function getCollection($key = 'last')
 {
     $rows = $this->getRows($key);
     if (count($this->_group) == 1) {
         return Eden_Collection::i($rows);
     }
     foreach ($rows as $key => $collection) {
         $rows[$key] = Eden_Collection::i($collection['fql_result_set']);
     }
     return $rows;
 }
Exemplo n.º 3
0
if(!class_exists('Eden_Facebook_Fql')){class Eden_Facebook_Fql extends Eden_Class{const SELECT='Eden_Facebook_Select';const FQL_URL='https://graph.facebook.com/fql';protected $_queries=array();protected $_token=NULL;public static function i(){return self::_getMultiple(__CLASS__);}public function __construct($token){$this->_token=$token;}public function getCollection($table,$filters=NULL,array $sort=array(),$start=0,$range=0,$index=NULL){Eden_Facebook_Error::i()->argument(1,'string')->argument(2,'string','array','null')->argument(4,'numeric')->argument(5,'numeric')->argument(6,'numeric','null');$results=$this->getRows($table,$filters,$sort,$start,$range,$index);$collection=Eden_Collection::i();if(is_null($results)){return $collection;}if(!is_null($index)){return $this->model($results);}return $collection->set($results);}public function getModel($table,$name,$value){Eden_Facebook_Error::i()->argument(1,'string')->argument(2,'string')->argument(3,'string','numeric');$result=$this->getRow($table,$name,$value);$model=Eden_Model::i();if(is_null($result)){return $model;}return $model->set($result);}public function getRow($table,$name,$value){Eden_Facebook_Error::i()->argument(1,'string')->argument(2,'string')->argument(3,'string','numeric');$query=$this->select()->from($table)->where($name.'='.$value)->limit(0,1);$results=$this->query($query);return isset($results[0]) ? $results[0] : NULL;}public function getRows($table,$filters=NULL,array $sort=array(),$start=0,$range=0,$index=NULL){Eden_Facebook_Error::i()->argument(1,'string')->argument(2,'string','array','null')->argument(4,'numeric')->argument(5,'numeric')->argument(6,'numeric','null');$query=$this->select()->from($table);if(is_array($filters)){foreach($filters as $i=>$filter){if(!is_array($filter)){continue;}$format=array_shift($filter);$filters[$i]=vsprintf($format,$filter);}}if(!is_null($filters)){$query->where($filters);}if(!empty($sort)){foreach($sort as $key=>$value){if(is_string($key) && trim($key)){$query->sortBy($key,$value);}}}if($range){$query->limit($start,$range);}$results=$this->query($query);if(!is_null($index)){if(empty($results)){$results=NULL;}else{if($index==self::FIRST){$index=0;}if($index==self::LAST){$index=count($results)-1;}if(isset($results[$index])){$results=$results[$index];}else{$results=NULL;}}}return $results;}public function getRowsCount($table,$filters=NULL){Eden_Facebook_Error::i()->argument(1,'string')->argument(2,'string','array','null');$query=$this->select('COUNT(*) as count')->from($table);if(is_array($filters)){foreach($filters as $i=>$filter){if(!is_array($filter)){continue;}$format=array_shift($filter);$filters[$i]=vsprintf($format,$filter);}}if(!is_null($filters)){$query->where($filters);}$results=$this->query($query);if(isset($results[0]['count'])){return $results[0]['count'];}return false;}public function getQueries($index=NULL){if(is_null($index)){return $this->_queries;}if($index==self::FIRST){$index=0;}if($index==self::LAST){$index=count($this->_queries) - 1;}if(isset($this->_queries[$index])){return $this->_queries[$index];}return NULL;}public function query($query){Eden_Facebook_Error::i()->argument(1,'string','array',self::SELECT);if(!is_array($query)){$query=array('q'=>(string) $query);}else{foreach($query as $key=>$select){$query[$key]=(string) $select;}$query=array('q'=>json_encode($query));}$query['access_token']=$this->_token;$url=self::FQL_URL.'?'.http_build_query($query);$results=Eden_Curl::i()->setUrl($url)->setConnectTimeout(10)->setFollowLocation(true)->setTimeout(60)->verifyPeer(false)->setUserAgent(Eden_Facebook_Auth::USER_AGENT)->setHeaders('Expect')->getJsonResponse();$this->_queries[]=array( 'query'=>$query['q'],'results'=>$results);if(isset($results['error']['message'])){Eden_Facebook_Error::i($query['q'].$results['error']['message'])->trigger();}return $results['data'];}public function search(){return Eden_Facebook_Search::i($this);}public function select($select='*'){Eden_Facebook_Error::i()->argument(1,'string','array');return Eden_Facebook_Select::i($select);}}}