예제 #1
0
 /**
  * 读取全部项目列表
  *
  * @author young
  * @name 读取全部项目列表
  * @version 2013.11.07 young
  */
 public function indexAction()
 {
     $query = array();
     $isSystem = filter_var($this->params()->fromQuery('isSystem', ''), FILTER_VALIDATE_BOOLEAN);
     $search = $this->params()->fromQuery('query', null);
     if ($search != null) {
         $search = myMongoRegex($search);
         $searchQuery = array('$or' => array(array('name' => $search), array('sn' => $search), array('desc' => $search)));
         $query['$and'][] = $searchQuery;
     }
     $query['$and'][] = array('isSystem' => $isSystem);
     if (!$_SESSION['acl']['admin']) {
         $query['$and'][] = array('_id' => array('$in' => myMongoId($_SESSION['acl']['project'])));
     }
     return $this->findAll(IDATABASE_PROJECTS, $query);
 }
예제 #2
0
 /**
  * 读取指定项目内的全部集合列表
  * 支持专家模式和普通模式显示,对于一些说明表和关系表,请在定义时,定义为普通模式
  *
  * @author young
  * @name 读取指定项目内的全部集合列表
  * @version 2014.01.21 young
  */
 public function indexAction()
 {
     $search = trim($this->params()->fromQuery('query', ''));
     $action = trim($this->params()->fromQuery('action', ''));
     $plugin_id = $this->_plugin_id;
     $sort = array('orderBy' => 1, '_id' => -1);
     $query = array();
     $query['$and'][] = array('project_id' => $this->_project_id);
     if ($action !== 'all') {
         $query['$and'][] = array('plugin_id' => $plugin_id);
     }
     if ($search != '') {
         $search = myMongoRegex($search);
         $query['$and'][] = array('$or' => array(array('name' => $search), array('alias' => $search)));
     }
     $isProfessional = isset($_SESSION['account']['isProfessional']) ? $_SESSION['account']['isProfessional'] : false;
     if ($isProfessional === false) {
         $query['$and'][] = array('isProfessional' => false);
     }
     if (!$_SESSION['acl']['admin']) {
         $query['$and'][] = array('_id' => array('$in' => myMongoId($_SESSION['acl']['collection'])));
     }
     $datas = array();
     $cursor = $this->_collection->find($query);
     $cursor->sort($sort);
     while ($cursor->hasNext()) {
         $row = $cursor->getNext();
         $row['locked'] = false;
         $lockInfo = $this->_lock->count(array('project_id' => $this->_project_id, 'collection_id' => myMongoId($row['_id']), 'active' => true));
         if ($lockInfo > 0) {
             $row['locked'] = true;
         }
         // 判断当前集合是否默认数据集合,如果是显示正确的集合
         if ($this->_plugin_data->isDefault(myMongoId($row['_id']))) {
             $row['defaultSourceData'] = true;
         } else {
             $row['defaultSourceData'] = false;
         }
         $datas[] = $row;
     }
     return $this->rst($datas, $cursor->count(), true);
 }
예제 #3
0
 /**
  * 读取全部项目列表
  *
  * @author young
  * @name 读取全部项目列表
  * @version 2013.11.07 young
  */
 public function indexAction()
 {
     $query = array();
     $isSystem = filter_var($this->params()->fromQuery('isSystem', ''), FILTER_VALIDATE_BOOLEAN);
     $search = $this->params()->fromQuery('query', null);
     $start = intval($this->params()->fromQuery('start', 0));
     $limit = intval($this->params()->fromQuery('limit', 10));
     if ($search != null) {
         $search = myMongoRegex($search);
         $searchQuery = array('$or' => array(array('name' => $search), array('sn' => $search), array('desc' => $search)));
         $query['$and'][] = $searchQuery;
     }
     $query['$and'][] = array('isSystem' => $isSystem);
     if (!$_SESSION['acl']['admin']) {
         $query['$and'][] = array('_id' => array('$in' => myMongoId($_SESSION['acl']['project'])));
     }
     $cursor = $this->_project->find($query);
     $total = $cursor->count();
     $cursor->sort(array('_id' => -1));
     $cursor->skip($start);
     $cursor->limit($limit);
     return $this->rst(iterator_to_array($cursor, false), $total, true);
 }
예제 #4
0
 /**
  * 处理检索条件
  */
 private function searchCondition()
 {
     $query = array();
     // 扩展两个系统默认参数加入查询条件
     $this->_schema['post'] = array_merge($this->_schema['post'], array('__CREATE_TIME__' => array('type' => 'datefield'), '__MODIFY_TIME__' => array('type' => 'datefield')));
     foreach ($this->_schema['post'] as $field => $detail) {
         $subQuery = array();
         $not = false;
         $exact = false;
         if (isset($_REQUEST['exclusive__' . $field]) && filter_var($_REQUEST['exclusive__' . $field], FILTER_VALIDATE_BOOLEAN)) {
             $not = true;
         }
         if (isset($_REQUEST['exactMatch__' . $field]) && filter_var($_REQUEST['exactMatch__' . $field], FILTER_VALIDATE_BOOLEAN)) {
             $exact = true;
         }
         if (!empty($detail['rshCollection'])) {
             $exact = true;
         }
         if (isset($_REQUEST[$field])) {
             if (is_array($_REQUEST[$field]) && trim(join('', $_REQUEST[$field])) == '') {
                 continue;
             }
             if (!is_array($_REQUEST[$field]) && trim($_REQUEST[$field]) == '') {
                 continue;
             }
             switch ($detail['type']) {
                 case 'numberfield':
                     if (is_array($_REQUEST[$field])) {
                         $min = trim($_REQUEST[$field]['min']);
                         $max = trim($_REQUEST[$field]['max']);
                         $min = preg_match("/^[0-9]+\\.[0-9]+\$/", $min) ? floatval($min) : intval($min);
                         $max = preg_match("/^[0-9]+\\.[0-9]+\$/", $max) ? floatval($max) : intval($max);
                         if ($min === $max) {
                             if ($not) {
                                 $subQuery[$field]['$ne'] = $min;
                             } else {
                                 $subQuery[$field] = $min;
                             }
                         } else {
                             if ($not) {
                                 if (!empty($min)) {
                                     $subQuery['$or'][][$field]['$lte'] = $min;
                                 }
                                 if (!empty($max)) {
                                     $subQuery['$or'][][$field]['$gte'] = $max;
                                 }
                             } else {
                                 if (!empty($min)) {
                                     $subQuery[$field]['$gte'] = $min;
                                 }
                                 if (!empty($max)) {
                                     $subQuery[$field]['$lte'] = $max;
                                 }
                             }
                         }
                     } else {
                         $value = preg_match("/^[0-9]+\\.[0-9]+\$/", $_REQUEST[$field]) ? floatval($_REQUEST[$field]) : intval($_REQUEST[$field]);
                         if ($not) {
                             $subQuery[$field]['$ne'] = $value;
                         } else {
                             $subQuery[$field] = $value;
                         }
                     }
                     break;
                 case 'datefield':
                     $start = trim($_REQUEST[$field]['start']);
                     $end = trim($_REQUEST[$field]['end']);
                     $start = preg_match("/^[0-9]+\$/", $start) ? new \MongoDate(intval($start)) : new \MongoDate(strtotime($start));
                     $end = preg_match("/^[0-9]+\$/", $end) ? new \MongoDate(intval($end)) : new \MongoDate(strtotime($end));
                     if ($not) {
                         if (!empty($start)) {
                             $subQuery['$or'][][$field]['$lte'] = $start;
                         }
                         if (!empty($end)) {
                             $subQuery['$or'][][$field]['$gte'] = $end;
                         }
                     } else {
                         if (!empty($start)) {
                             $subQuery[$field]['$gte'] = $start;
                         }
                         if (!empty($end)) {
                             $subQuery[$field]['$lte'] = $end;
                         }
                     }
                     break;
                 case '2dfield':
                     $lng = floatval(trim($_REQUEST[$field]['lng']));
                     $lat = floatval(trim($_REQUEST[$field]['lat']));
                     $distance = !empty($_REQUEST[$field]['distance']) ? floatval($_REQUEST[$field]['distance']) : 10;
                     $subQuery = array('$near' => array($lng, $lat), '$maxDistance' => $distance / 111.12);
                     break;
                 case 'boolfield':
                     $subQuery[$field] = filter_var(trim($_REQUEST[$field]), FILTER_VALIDATE_BOOLEAN);
                     break;
                 case 'arrayfield':
                     $rshCollection = $detail['rshCollection'];
                     if (!empty($rshCollection)) {
                         $rowType = $this->_rshCollection[$rshCollection]['rshCollectionValueFieldType'];
                         if ($not) {
                             $subQuery[$field]['$ne'] = formatData($_REQUEST[$field], $rowType, $field);
                         } else {
                             $subQuery[$field] = formatData($_REQUEST[$field], $rowType, $field);
                         }
                     }
                     break;
                 default:
                     if ($not) {
                         $subQuery[$field]['$ne'] = trim($_REQUEST[$field]);
                     } else {
                         $subQuery[$field] = $exact ? trim($_REQUEST[$field]) : myMongoRegex($_REQUEST[$field]);
                     }
                     break;
             }
             $query['$and'][] = $subQuery;
         }
     }
     if (empty($query['$and'])) {
         return array();
     }
     return $query;
 }
예제 #5
0
 /**
  * 处理检索条件
  */
 private function searchCondition()
 {
     $query = array();
     // 扩展两个系统默认参数加入查询条件
     $this->_schema['post'] = array_merge($this->_schema['post'], array('__CREATE_TIME__' => array('type' => 'datefield'), '__MODIFY_TIME__' => array('type' => 'datefield'), '__ID__' => array('type' => 'textfield')));
     foreach ($this->_schema['post'] as $field => $detail) {
         $subQuery = array();
         $not = false;
         $exact = false;
         if (in_array(strtolower($field), $this->_filter)) {
             continue;
         }
         if (isset($_REQUEST['exclusive__' . $field]) && filter_var($_REQUEST['exclusive__' . $field], FILTER_VALIDATE_BOOLEAN)) {
             $not = true;
         }
         if (isset($_REQUEST['exactMatch__' . $field]) && filter_var($_REQUEST['exactMatch__' . $field], FILTER_VALIDATE_BOOLEAN)) {
             $exact = true;
         }
         if (!empty($detail['rshCollection'])) {
             $exact = true;
         }
         if (isset($_REQUEST[$field])) {
             if (is_array($_REQUEST[$field]) && trim(join('', $_REQUEST[$field])) == '') {
                 continue;
             }
             if (!is_array($_REQUEST[$field]) && trim($_REQUEST[$field]) == '') {
                 continue;
             }
             switch ($detail['type']) {
                 case 'numberfield':
                     if (is_array($_REQUEST[$field])) {
                         $min = isset($_REQUEST[$field]['min']) ? trim($_REQUEST[$field]['min']) : '';
                         $max = isset($_REQUEST[$field]['max']) ? trim($_REQUEST[$field]['max']) : '';
                         $min = preg_match("/^[0-9]+\\.[0-9]+\$/", $min) ? floatval($min) : intval($min);
                         $max = preg_match("/^[0-9]+\\.[0-9]+\$/", $max) ? floatval($max) : intval($max);
                         if ($min === $max) {
                             if ($not) {
                                 $subQuery[$field]['$ne'] = $min;
                             } else {
                                 $subQuery[$field] = $min;
                             }
                         } else {
                             if ($not) {
                                 if (!empty($min)) {
                                     $subQuery['$or'][][$field]['$lte'] = $min;
                                 }
                                 if (!empty($max)) {
                                     $subQuery['$or'][][$field]['$gte'] = $max;
                                 }
                             } else {
                                 if (!empty($min)) {
                                     $subQuery[$field]['$gte'] = $min;
                                 }
                                 if (!empty($max)) {
                                     $subQuery[$field]['$lte'] = $max;
                                 }
                             }
                         }
                     } else {
                         $value = preg_match("/^[0-9]+\\.[0-9]+\$/", $_REQUEST[$field]) ? floatval($_REQUEST[$field]) : intval($_REQUEST[$field]);
                         if ($not) {
                             $subQuery[$field]['$ne'] = $value;
                         } else {
                             $subQuery[$field] = $value;
                         }
                     }
                     break;
                 case 'datefield':
                     $start = isset($_REQUEST[$field]['start']) ? trim($_REQUEST[$field]['start']) : null;
                     $end = isset($_REQUEST[$field]['end']) ? trim($_REQUEST[$field]['end']) : null;
                     if (!empty($start)) {
                         $start = preg_match("/^[0-9]+\$/", $start) ? new \MongoDate(intval($start)) : new \MongoDate(strtotime($start));
                     }
                     if (!empty($end)) {
                         $end = preg_match("/^[0-9]+\$/", $end) ? new \MongoDate(intval($end)) : new \MongoDate(strtotime($end));
                     }
                     if ($not) {
                         if (!empty($start)) {
                             $subQuery['$or'][][$field]['$lte'] = $start;
                         }
                         if (!empty($end)) {
                             $subQuery['$or'][][$field]['$gte'] = $end;
                         }
                     } else {
                         if (!empty($start)) {
                             $subQuery[$field]['$gte'] = $start;
                         }
                         if (!empty($end)) {
                             $subQuery[$field]['$lte'] = $end;
                         }
                     }
                     break;
                 case '2dfield':
                     // $lng = floatval(trim($_REQUEST[$field]['lng']));
                     // $lat = floatval(trim($_REQUEST[$field]['lat']));
                     // $distance = ! empty($_REQUEST[$field]['distance']) ? floatval($_REQUEST[$field]['distance']) : 10;
                     // $subQuery[$field] = array(
                     // '$near' => array(
                     // $lng,
                     // $lat
                     // ),
                     // '$maxDistance' => $distance / 111.12
                     // );
                     // // 在mognodb2.5.5以前,无法支持$and查询故如果进行地理位置信息检索,则强制其他检索条件失效。
                     // // 迁移到2.6以后,请注释掉该部分代码
                     // $geoQuery = array();
                     // $geoQuery[$field] = array(
                     // '$near' => array(
                     // $lng,
                     // $lat
                     // ),
                     // '$maxDistance' => $distance / 111.12
                     // );
                     // return $geoQuery;
                     break;
                 case 'boolfield':
                     $subQuery[$field] = filter_var(trim($_REQUEST[$field]), FILTER_VALIDATE_BOOLEAN);
                     break;
                 case 'arrayfield':
                     $rshCollection = $detail['rshCollection'];
                     if (!empty($rshCollection)) {
                         $rowType = $this->_rshCollection[$rshCollection]['rshCollectionValueFieldType'];
                         if ($not) {
                             $subQuery[$field]['$ne'] = formatData($_REQUEST[$field], $rowType, $field);
                         } else {
                             $subQuery[$field] = formatData($_REQUEST[$field], $rowType, $field);
                         }
                     }
                     break;
                 default:
                     if ($field == '__ID__') {
                         if ($not) {
                             $subQuery["_id"]['$ne'] = new \MongoId($_REQUEST[$field]);
                         } else {
                             $subQuery["_id"] = new \MongoId($_REQUEST[$field]);
                         }
                     } else {
                         if ($not) {
                             $subQuery[$field]['$ne'] = trim($_REQUEST[$field]);
                         } else {
                             $subQuery[$field] = $exact ? trim($_REQUEST[$field]) : myMongoRegex($_REQUEST[$field]);
                         }
                     }
                     break;
             }
             if (!empty($subQuery)) {
                 $query['$and'][] = $subQuery;
             }
         }
     }
     if (empty($query['$and'])) {
         return array();
     }
     return $query;
 }