コード例 #1
0
ファイル: Fulltext.php プロジェクト: schpill/thin
 public function prepare($text)
 {
     $slugs = explode(' ', Inflector::slug($text, ' '));
     if (count($slugs)) {
         $collection = array();
         foreach ($slugs as $slug) {
             if (strlen($slug) > 1) {
                 if (!Arrays::in($slug, $collection)) {
                     array_push($collection, $slug);
                 }
             }
         }
         asort($collection);
     }
     return $collection;
 }
コード例 #2
0
ファイル: Mongonode.php プロジェクト: schpill/thin
 private function search($condition = null, $results = array(), $populate = true)
 {
     self::$queries++;
     $collection = array();
     $condition = repl('NOT LIKE', 'NOTLIKE', $condition);
     $condition = repl('NOT IN', 'NOTIN', $condition);
     list($field, $op, $value) = explode(' ', $condition, 3);
     $indexes = $this->indexes();
     $fulltextes = $this->fulltextes();
     if (true === Arrays::in($field, $indexes)) {
         $ids = $this->searchIndexes($field, $op, $value);
         if (count($ids)) {
             foreach ($ids as $id) {
                 array_push($collection, $this->find($id, false));
             }
             if (true === $populate) {
                 $this->results = $collection;
             }
             return $collection;
         }
     }
     if ($op == 'LIKE' && Arrays::in($field, $fulltextes)) {
         $ids = $this->searchFulltextes($field, Inflector::slug($value, ' '));
         if (count($ids)) {
             foreach ($ids as $id) {
                 array_push($collection, $this->find($id, false));
             }
             if (true === $populate) {
                 $this->results = $collection;
             }
             return $collection;
         }
     }
     $datas = !count($results) ? $this->all(true) : $results;
     if (empty($condition)) {
         return $datas;
     }
     $keyCache = sha1('eavRDB_search_' . $condition . serialize($datas) . $this->entity);
     $cached = $this->cached($keyCache);
     if (empty($cached)) {
         if (count($datas)) {
             if (strstr($field, '.')) {
                 list($table, $field) = explode('.', $field, 2);
                 if ($table != $this->entity) {
                     $fkFields = isAke($this->joins, $table);
                     if (!empty($fkFields)) {
                         $db = new self($table);
                         list($entityField, $fkField) = Arrays::first($fkFields);
                         $fkField = empty($fkField) ? 'id' : $fkField;
                         foreach ($datas as $tab) {
                             if (!empty($tab)) {
                                 $joinVal = isAke($tab, $entityField, null);
                                 if (strlen($joinVal)) {
                                     $foreignDatas = $db->where("{$fkField} = {$joinVal}")->exec();
                                     foreach ($foreignDatas as $foreignTab) {
                                         if (!empty($foreignTab)) {
                                             $val = isAke($foreignTab, $field, null);
                                             if (strlen($val)) {
                                                 $val = repl('|', ' ', $val);
                                                 $check = $this->compare($val, $op, $value);
                                             } else {
                                                 $check = 'null' == $value ? true : false;
                                             }
                                             if (true === $check) {
                                                 array_push($collection, $tab);
                                             }
                                         }
                                     }
                                 } else {
                                     throw new Exception("The field {$entityField} has no value and must be not nulled.");
                                 }
                             }
                         }
                     } else {
                         throw new Exception("The table {$table} is not correctly joined.");
                     }
                 } else {
                     $condition = repl($this->entity . '.', '', $condition);
                     return $this->search($condition, $results, $populate);
                 }
             } else {
                 foreach ($datas as $tab) {
                     if (!empty($tab)) {
                         $val = isAke($tab, $field, null);
                         if (strlen($val)) {
                             $val = repl('|', ' ', $val);
                             $check = $this->compare($val, $op, $value);
                         } else {
                             $check = 'null' == $value ? true : false;
                         }
                         if (true === $check) {
                             array_push($collection, $tab);
                         }
                     }
                 }
                 $this->cached($keyCache, $collection);
             }
         }
     } else {
         $collection = $cached;
     }
     if (true === $populate) {
         $this->results = $collection;
     }
     return $collection;
 }
コード例 #3
0
ファイル: View.php プロジェクト: schpill/thin
 public function compile($code)
 {
     $v = $this;
     $e = function ($_) use($v) {
         return $v->show($_);
     };
     $slug = function ($str) {
         return Inflector::slug($str);
     };
     eval(' ?>' . $code . '<?php ');
 }