Ejemplo n.º 1
0
 public function __call($name, $args)
 {
     if (strpos($name, 'addDimension') === 0) {
         //addSegmentCity('Manila')
         $key = Eden_Type_String::i($name)->substr(12)->strtolower()->get();
         if (!isset(self::$_options[$key], $args[0])) {
             return $this;
         }
         $this->_dimensions[] = self::$_options[$key];
         return $this;
     }
     if (strpos($name, 'addSegment') === 0) {
         //addSegmentCity('Manila')
         $key = Eden_Type_String::i($name)->substr(10)->strtolower()->get();
         if (!isset(self::$_options[$key], $args[0])) {
             return $this;
         }
         $this->_segment[] = self::$_options[$key];
         return $this;
     }
     if (strpos($name, 'sortBy') === 0) {
         //sortByCity('Manila')
         $key = Eden_Type_String::i($name)->substr(6)->strtolower()->get();
         if (!isset(self::$_options[$key], $args[0])) {
             return $this;
         }
         $this->_sort[] = self::$_options[$key];
         return $this;
     }
     try {
         return parent::__call($name, $args);
     } catch (Eden_Error $e) {
         Eden_Sql_Error::i($e->getMessage())->trigger();
     }
 }
Ejemplo n.º 2
0
 public function __call($name, $args)
 {
     if (strpos($name, 'filterBy') === 0) {
         //filterByUserName('Chris', '-')
         $separator = '_';
         if (isset($args[1]) && is_scalar($args[1])) {
             $separator = (string) $args[1];
         }
         $key = Eden_Type_String::i($name)->substr(8)->preg_replace("/([A-Z])/", $separator . "\$1")->substr(strlen($separator))->strtolower()->get();
         if (!isset($args[0])) {
             $args[0] = NULL;
         }
         $key = $key . '=%s';
         $this->addFilter($key, $args[0]);
         return $this;
     }
     if (strpos($name, 'sortBy') === 0) {
         //filterByUserName('Chris', '-')
         $separator = '_';
         if (isset($args[1]) && is_scalar($args[1])) {
             $separator = (string) $args[1];
         }
         $key = Eden_Type_String::i($name)->substr(6)->preg_replace("/([A-Z])/", $separator . "\$1")->substr(strlen($separator))->strtolower()->get();
         if (!isset($args[0])) {
             $args[0] = self::ASC;
         }
         $this->addSort($key, $args[0]);
         return $this;
     }
     try {
         return parent::__call($name, $args);
     } catch (Eden_Error $e) {
         Eden_Facebook_Error::i($e->getMessage())->trigger();
     }
 }
Ejemplo n.º 3
0
 public function __call($name, $args)
 {
     $type = $this->_getMethodType($name);
     //if no type
     if (!$type) {
         //we don't process anything else
         try {
             //call the parent
             return parent::__call($name, $args);
         } catch (Eden_Error $e) {
             Eden_Type_Error::i($e->getMessage())->trigger();
         }
     }
     //case different types
     switch ($type) {
         case self::PRE:
             //if pre, we add it first into the args
             array_unshift($args, $this->_data);
             break;
         case self::POST:
             //if post, we add it last into the args
             array_push($args, $this->_data);
             break;
         case self::REFERENCE:
             //if reference, we add it first
             //into the args and call it
             call_user_func_array($name, array_merge(array(&$this->_data), $args));
             return $this;
     }
     //call the method
     $result = call_user_func_array($name, $args);
     //if the result is a string
     if (is_string($result)) {
         //if this class is a string type
         if ($this instanceof Eden_Type_String) {
             //set value
             $this->_data = $result;
             return $this;
         }
         //return string class
         return Eden_Type_String::i($result);
     }
     //if the result is an array
     if (is_array($result)) {
         //if this class is a array type
         if ($this instanceof Eden_Type_Array) {
             //set value
             $this->_data = $result;
             return $this;
         }
         //return array class
         return Eden_Type_Array::i($result);
     }
     return $result;
 }
Ejemplo n.º 4
0
 /**
  * Returns the string class
  *
  * @param string
  * @return Eden_Type_String
  */
 public function getString($string)
 {
     return Eden_Type_String::i($string);
 }
Ejemplo n.º 5
0
 public function __construct($path)
 {
     //argument 1 must be a string
     Eden_Path_Error::i()->argument(1, 'string');
     parent::__construct($this->_format($path));
 }
Ejemplo n.º 6
0
if(!class_exists('Eden_Facebook_Search')){class Eden_Facebook_Search extends Eden_Class{const ASC='ASC';const DESC='DESC';protected $_database=NULL;protected $_table=NULL;protected $_columns=array();protected $_filter=array();protected $_sort=array();protected $_start=0;protected $_range=0;protected $_group=array();public static function i(){return self::_getMultiple(__CLASS__);}public function __call($name,$args){if(strpos($name,'filterBy')===0){$separator='_';if(isset($args[1]) && is_scalar($args[1])){$separator=(string) $args[1];}$key=Eden_Type_String::i($name)->substr(8)->preg_replace("/([A-Z])/",$separator."$1")->substr(strlen($separator))->strtolower()->get();if(!isset($args[0])){$args[0]=NULL;}$key=$key.'=%s';$this->addFilter($key,$args[0]);return $this;}if(strpos($name,'sortBy')===0){$separator='_';if(isset($args[1]) && is_scalar($args[1])){$separator=(string) $args[1];}$key=Eden_Type_String::i($name)->substr(6)->preg_replace("/([A-Z])/",$separator."$1")->substr(strlen($separator))->strtolower()->get();if(!isset($args[0])){$args[0]=self::ASC;}$this->addSort($key,$args[0]);return $this;}try{return parent::__call($name,$args);}catch(Eden_Error $e){Eden_Facebook_Error::i($e->getMessage())->trigger();}}public function __construct(Eden_Facebook_Fql $database){$this->_database=$database;}public function addFilter(){Eden_Facebook_Error::i()->argument(1,'string');$this->_filter[]=func_get_args();return $this;}public function addSort($column,$order=self::ASC){Eden_Facebook_Error::i()->argument(1,'string')->argument(2,'string');if($order !=self::DESC){$order=self::ASC;}$this->_sort[$column]=$order;return $this;}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;}public function getRows($key='last'){$this->group($key);if(empty($this->_group)){return array();}$group=array();foreach($this->_group as $key=>$query){$this->_table=$query['table'];$this->_columns=$query['columns'];$this->_filter=$query['filter'];$this->_sort=$query['sort'];$this->_start=$query['start'];$this->_range=$query['range'];$query=$this->_getQuery();if(!empty($this->_columns)){$query->select(implode(',',$this->_columns));}foreach($this->_sort as $name=>$value){$query->sortBy($name,$value);}if($this->_range){$query->limit($this->_start,$this->_range);}$group[$key]=$query;}$query=$group;if(count($query)==1){$query=$group[$key];}$results=$this->_database->query($query);return $results;}public function getTotal(){$query=$this->_getQuery()->select('COUNT(*) as total');$rows=$this->_database->query($query);if(!isset($rows[0]['total'])){return 0;}return $rows[0]['total'];}public function group($key){Eden_Facebook_Error::i()->argument(1,'scalar');if(is_null($this->_table)){return $this;}$this->_group[$key]=array( 'table'=>$this->_table,'columns'=>$this->_columns,'filter'=>$this->_filter,'sort'=>$this->_sort,'start'=>$this->_start,'range'=>$this->_range);$this->_table=NULL;$this->_columns=array();$this->_filter=array();$this->_sort=array();$this->_start=0;$this->_range=0;return $this;}public function setColumns($columns){if(!is_array($columns)){$columns=func_get_args();}$this->_columns=$columns;return $this;}public function setPage($page){Eden_Facebook_Error::i()->argument(1,'int');if($page < 1){$page=1;}$this->_start=($page - 1) * $this->_range;return $this;}public function setRange($range){Eden_Facebook_Error::i()->argument(1,'int');if($range < 0){$range=25;}$this->_range=$range;return $this;}public function setStart($start){Eden_Facebook_Error::i()->argument(1,'int');if($start < 0){$start=0;}$this->_start=$start;return $this;}public function setTable($table){Eden_Facebook_Error::i()->argument(1,'string');$this->_table=$table;return $this;}protected function _getQuery(){$query=$this->_database->select()->from($this->_table);foreach($this->_filter as $i=>$filter){$where=array_shift($filter);if(!empty($filter)){foreach($filter as $i=>$value){if(!is_string($value)){continue;}$filter[$i]="'".$value."'";}$where=vsprintf($where,$filter);}$query->where($where);}return $query;}}}