コード例 #1
0
ファイル: ModelQuery.php プロジェクト: ekowabaka/ntentan
 public function __call($method, $args)
 {
     if (preg_match("/(sort)(?<dir>Ascending|Descending)?(?<by>By)(?<field>[a-zA-Z]*)/", $method, $matches)) {
         if ($matches['dir'] == 'Ascending') {
             $dir = 'ASC';
         } elseif ($matches['dir'] == 'Descending') {
             $dir = 'DESC';
         }
         $this->sortBy(Ntentan::deCamelize($matches['field']), $dir);
     } elseif (preg_match("/(sort)(?<dir>Ascending|Descending)?(?<sub_module>[a-zA-Z]*)(?<sub_by>By)(?<field>[a-zA-Z]*)/", $method, $matches)) {
         if ($matches['dir'] == 'Ascending') {
             $dir = 'ASC';
         } elseif ($matches['dir'] == 'Descending') {
             $dir = 'DESC';
         }
         $this->getParams[$matches['sub_module'] . "_sort"][] = Ntentan::deCamelize($matches['field']) . " {$dir}";
     }
     return $this;
 }
コード例 #2
0
ファイル: Model.php プロジェクト: ekowabaka/ntentan
 public function __call($method, $arguments)
 {
     //@todo Convert all these if conditions into one huge regular expression
     if (preg_match("/(get)((?<just>Just)?(?<type>First|All|Count|[0-9]+)?((With)(?<field>[a-zA-Z0-9]+))?)?/", $method, $matches)) {
         $field = Ntentan::deCamelize($matches['field']);
         $type = strtolower($matches['type'] == '' ? 'all' : $matches['type']);
         $conditions = array();
         foreach ($arguments as $argument) {
             if (is_array($argument)) {
                 $params = $argument;
                 break;
             } else {
                 $conditions[$this->route . "." . $field] = $argument;
             }
         }
         if (count($conditions) > 0) {
             $params["conditions"] = is_array($params['conditions']) ? array_merge($conditions, $params['conditions']) : $conditions;
         }
         if ($matches['just'] == 'Just') {
             $params["fetch_related"] = false;
             $params["fetch_belongs_to"] = false;
         } else {
             if (!isset($params["fetch_related"])) {
                 $params["fetch_related"] = true;
             }
             if (!isset($params["fetch_belongs_to"])) {
                 $params["fetch_belongs_to"] = true;
             }
         }
         if (isset($params['limit'])) {
             $type = $params['limit'];
         }
         return $this->get($type, $params);
     }
     throw new MethodNotFoundException($method);
 }