コード例 #1
0
ファイル: Admin.php プロジェクト: kalburgimanjunath/system
 public function getManualFilters($table)
 {
     $query = false;
     $session = $this->getSession($table);
     $keys = $this->getSetVar($session, 'manual_key', 'manual_key');
     $types = Admin_Lines::getOptions();
     $operators = $this->getSetVar($session, 'manual_operator', 'manual_operator');
     $values = $this->getSetVar($session, 'manual_value', 'manual_value');
     for ($i = 0; $i < count($keys); $i++) {
         if ($keys[$i] == '' || $values[$i] == '') {
             continue;
         }
         switch ($types[$keys[$i]]) {
             case 'number':
                 $values[$i] = floatval($values[$i]);
                 break;
             case 'date':
                 if (Zend_Date::isDate($values[$i], 'yyyy-MM-dd hh:mm:ss')) {
                     $values[$i] = new MongoDate((new Zend_Date($values[$i], null, new Zend_Locale('he_IL')))->getTimestamp());
                 } else {
                     continue 2;
                 }
             default:
                 break;
         }
         // TODO: decoupling to config of fields
         switch ($operators[$i]) {
             case 'starts_with':
                 $operators[$i] = '$regex';
                 $values[$i] = "^{$values[$i]}";
                 break;
             case 'ends_with':
                 $operators[$i] = '$regex';
                 $values[$i] = "{$values[$i]}\$";
                 break;
             case 'like':
                 $operators[$i] = '$regex';
                 $values[$i] = "{$values[$i]}";
                 break;
             case 'lt':
                 $operators[$i] = '$lt';
                 break;
             case 'lte':
                 $operators[$i] = '$lte';
                 break;
             case 'gt':
                 $operators[$i] = '$gt';
                 break;
             case 'gte':
                 $operators[$i] = '$gte';
                 break;
             case 'ne':
                 $operators[$i] = '$ne';
                 break;
             case 'equals':
                 $operators[$i] = '$in';
                 $values[$i] = array($values[$i]);
                 break;
             default:
                 break;
         }
         $query[$keys[$i]][$operators[$i]] = $values[$i];
     }
     return $query;
 }
コード例 #2
0
ファイル: Admin.php プロジェクト: ngchie/system
 public function getManualFilters($table)
 {
     $query = false;
     $session = $this->getSession($table);
     $keys = $this->getSetVar($session, 'manual_key', 'manual_key');
     if ($this->model instanceof LinesModel) {
         $advanced_options = Admin_Lines::getOptions();
     } else {
         if ($this->model instanceof BalancesModel) {
             // TODO: make refactoring of the advanced options for each page (lines, balances, etc)
             $advanced_options = array($keys[0] => array('type' => 'number', 'display' => 'usage'));
         } else {
             if ($this->model instanceof EventsModel) {
                 $avanced_options = array($keys[0] => array('type' => 'text'));
             } else {
                 return $query;
             }
         }
     }
     $operators = $this->getSetVar($session, 'manual_operator', 'manual_operator');
     $values = $this->getSetVar($session, 'manual_value', 'manual_value');
     settype($operators, 'array');
     settype($values, 'array');
     for ($i = 0; $i < count($keys); $i++) {
         if ($keys[$i] == '' || $values[$i] == '') {
             continue;
         }
         switch ($advanced_options[$keys[$i]]['type']) {
             case 'number':
                 $values[$i] = floatval($values[$i]);
                 break;
             case 'date':
                 if (Zend_Date::isDate($values[$i], 'yyyy-MM-dd hh:mm:ss')) {
                     $values[$i] = new MongoDate((new Zend_Date($values[$i], null, new Zend_Locale('he_IL')))->getTimestamp());
                 } else {
                     continue 2;
                 }
             default:
                 break;
         }
         if (isset($advanced_options[$keys[$i]]['case'])) {
             $values[$i] = Admin_Table::convertValueByCaseType($values[$i], $advanced_options[$keys[$i]]['case']);
         }
         // TODO: decoupling to config of fields
         switch ($operators[$i]) {
             case 'starts_with':
                 $operators[$i] = '$regex';
                 $values[$i] = "^{$values[$i]}";
                 break;
             case 'ends_with':
                 $operators[$i] = '$regex';
                 $values[$i] = "{$values[$i]}\$";
                 break;
             case 'like':
                 $operators[$i] = '$regex';
                 $values[$i] = "{$values[$i]}";
                 break;
             case 'lt':
                 $operators[$i] = '$lt';
                 break;
             case 'lte':
                 $operators[$i] = '$lte';
                 break;
             case 'gt':
                 $operators[$i] = '$gt';
                 break;
             case 'gte':
                 $operators[$i] = '$gte';
                 break;
             case 'ne':
                 $operators[$i] = '$ne';
                 break;
             case 'equals':
                 $operators[$i] = '$in';
                 $values[$i] = array($values[$i]);
                 break;
             default:
                 break;
         }
         if ($advanced_options[$keys[$i]]['type'] == 'dbref') {
             $collection = Billrun_Factory::db()->{$advanced_options[$keys[$i]]['collection'] . "Collection"}();
             $pre_query[$advanced_options[$keys[$i]]['collection_key']][$operators[$i]] = $values[$i];
             $cursor = $collection->query($pre_query);
             $values[$i] = array();
             foreach ($cursor as $entity) {
                 $values[$i][] = $entity->createRef($collection);
             }
             $operators[$i] = '$in';
         }
         $query[$keys[$i]][$operators[$i]] = $values[$i];
     }
     return $query;
 }