예제 #1
0
 public function testDeleteByQuery()
 {
     $this->solr->deleteByQuery('*:*');
     $search = new Search();
     $rez = $search->query(array('rows' => 0));
     $this->assertTrue($rez['total'] == 0, 'Delete all by query didnt clear the solr instance.');
 }
예제 #2
0
파일: Dbnode.php 프로젝트: sebbie42/casebox
 public function getChildren(&$pathArray, $requestParams)
 {
     $pid = null;
     /* should start with path check and see if child request is for a real db node*/
     if (empty($pathArray)) {
         if (empty($requestParams['query'])) {
             return;
         }
     } else {
         $lastNode = @$pathArray[sizeof($pathArray) - 1];
         if ($lastNode instanceof Dbnode || get_class($lastNode) == 'CB\\TreeNode\\Base') {
             $pid = $lastNode->id;
         } else {
             //we are under another node type
             $cfg = $lastNode->getConfig();
             if (!empty($cfg['realNodeId']) && $lastNode instanceof RealSubnode) {
                 $pid = $cfg['realNodeId'];
             } else {
                 return array();
             }
         }
     }
     if (empty($pid)) {
         return array();
     }
     /* end of check */
     $p =& $requestParams;
     $folderTemplates = \CB\Config::get('folder_templates');
     $p['fl'] = 'id,pid,system,path,name,case_id,date,date_end,size,cid,' . 'oid,cdate,uid,udate,template_id,acl_count,cls,status,task_status,versions,' . 'comment_user_id,comment_date';
     if (empty($p['showFoldersContent'])) {
         $p['templates'] = $folderTemplates;
     }
     if (empty($p['descendants'])) {
         $p['pid'] = $pid;
     } else {
         $p['pids'] = $pid;
     }
     $s = new \CB\Search();
     $rez = $s->query($p);
     if (!empty($rez['data'])) {
         for ($i = 0; $i < sizeof($rez['data']); $i++) {
             $d =& $rez['data'][$i];
             $r = DM\Tree::read($d['id']);
             if (!empty($r['cfg']) && $p['from'] == 'tree') {
                 if (isset($r['cfg']['loaded'])) {
                     $d['loaded'] = $r['cfg']['loaded'];
                 }
                 if (isset($r['cfg']['expanded'])) {
                     $d['expanded'] = $r['cfg']['expanded'];
                 }
                 if (isset($r['cfg']['leaf'])) {
                     $d['leaf'] = $r['cfg']['leaf'];
                 }
             }
         }
         \CB\Tasks::setTasksActionFlags($rez['data']);
     }
     return $rez;
 }
예제 #3
0
파일: Query.php 프로젝트: sebbie42/casebox
 /**
  * getChildNodes description
  * @return json responce
  */
 protected function getChildNodes()
 {
     $p = $this->requestParams;
     unset($p['facets']);
     $fq = empty($this->config['fq']) ? array() : $this->config['fq'];
     $this->replaceFilterVars($fq);
     $p['fq'] = $fq;
     $s = new \CB\Search();
     $rez = $s->query($p);
     return $rez;
 }
예제 #4
0
 protected static function getMenuRules()
 {
     $rez = Cache::get('CreateMenuRules', array());
     if (!empty($rez)) {
         return $rez;
     }
     $s = new Search();
     $ids = array();
     $sr = $s->query(array('fl' => 'id', 'template_types' => 'menu', 'skipSecurity' => true));
     foreach ($sr['data'] as $r) {
         $ids[] = $r['id'];
     }
     $arr = Objects::getCachedObjects($ids);
     foreach ($arr as $o) {
         $d = $o->getData()['data'];
         $rez[] = array('nids' => empty($d['node_ids']) ? array() : Util\toNumericArray($d['node_ids']), 'ntids' => empty($d['template_ids']) ? array() : Util\toNumericArray($d['template_ids']), 'ugids' => empty($d['user_group_ids']) ? array() : Util\toNumericArray($d['user_group_ids']), 'menu' => $d['menu']);
     }
     Cache::set('CreateMenuRules', $rez);
     return $rez;
 }
예제 #5
0
 /**
  * get items
  * @return json responce
  */
 protected function getItems()
 {
     $rez = array('data' => array());
     $p = $this->requestParams;
     $fq = empty($this->config['fq']) ? array() : $this->config['fq'];
     $p['fq'] = array_merge($fq, $this->getParentNodeFilters());
     $this->replaceFilterVars($p['fq']);
     $s = new \CB\Search();
     $rez = $s->query($p);
     return $rez;
 }
예제 #6
0
 public function getGroupItems()
 {
     $params = $this->requestParams;
     $params['fq'] = $this->fq;
     switch ($this->lastNode->id) {
         case 'commented':
             $params['fq'][] = 'comment_user_id: [* TO *]';
             $params['strictSort'] = 'comment_date desc';
             break;
         case 'modified':
             $params['fq'][] = 'uid: [* TO *]';
             $params['strictSort'] = 'udate desc';
             break;
         case 'added':
             $params['fq'][] = 'cid: [* TO *]';
             $params['strictSort'] = 'cdate desc';
             break;
     }
     $s = new \CB\Search();
     $rez = $s->query($params);
     return $rez;
 }
예제 #7
0
 /**
  * return records for an objects field based on its config
  * @param  array $p
  * @return json  repsponce
  */
 public function getObjectsForField($p)
 {
     // ,"scope": 'tree' //project, parent, self, $node_id
     // ,"field": <field_name> //for field type
     // ,"descendants": true
     // /* filter used for objects */
     // ,+"tags": []
     // ,+"types": []
     // ,+"templates": []
     // ,"templateGroups": []
     //,+query - user query
     //unset restricted query params from user input
     unset($p['fq']);
     $fieldConfig = array();
     // get field config from database
     if (!empty($p['fieldId']) && is_numeric($p['fieldId'])) {
         $res = DB\dbQuery('SELECT cfg FROM templates_structure WHERE id = $1', $p['fieldId']) or die(DB\dbQueryError());
         if ($r = $res->fetch_assoc()) {
             $fieldConfig = Util\jsonDecode($r['cfg']);
             //set "fq" param from database (dont trust user imput)
             if (!empty($fieldConfig['fq'])) {
                 $p['fq'] = $fieldConfig['fq'];
             }
         }
         $res->close();
     }
     if (!empty($p['source'])) {
         if (is_array($p['source'])) {
             // a custom source
             $rez = array();
             if (empty($p['fieldId'])) {
                 return $rez;
             }
             //get custom method from config
             if (empty($fieldConfig['source']['fn'])) {
                 return $rez;
             }
             $method = explode('.', $fieldConfig['source']['fn']);
             $class = new $method[0]();
             $rez = $class->{$method}[1]($p);
             if (!empty($rez)) {
                 return $rez;
             }
         }
         switch ($p['source']) {
             case 'field':
                 $ids = array();
                 switch ($p['scope']) {
                     case 'project':
                         $ids = $this->getCaseId(Path::detectRealTargetId($p['path']));
                         break;
                     case 'parent':
                         $ids = Path::detectRealTargetId($p['path']);
                         break;
                     default:
                         if (empty($p['pidValue']) || empty($p['field'])) {
                             break 2;
                         }
                         $ids = $p['pidValue'];
                 }
                 $ids = Util\toNumericArray($ids);
                 if (empty($ids)) {
                     break;
                 }
                 /*get distinct target field values for selected objects in parent field */
                 $obj = new Objects\Object();
                 $values = array();
                 foreach ($ids as $id) {
                     $obj->load($id);
                     $fv = $obj->getFieldValue($p['field'], 0);
                     $fv = Util\toNumericArray(@$fv['value']);
                     $values = array_merge($values, $fv);
                 }
                 $values = array_unique($values);
                 if (empty($values)) {
                     return array('success' => true, 'data' => array());
                 }
                 $p['ids'] = $values;
                 break;
         }
     }
     $pids = false;
     if (!empty($fieldConfig['scope'])) {
         $scope = $fieldConfig['scope'];
         switch ($scope) {
             case 'project':
                 /* limiting pid to project. If not in a project then to parent directory */
                 if (!empty($p['objectId']) && is_numeric($p['objectId'])) {
                     $pids = $this->getCaseId($p['objectId']);
                 } elseif (!empty($p['path'])) {
                     $pids = $this->getCaseId(Path::detectRealTargetId($p['path']));
                 }
                 break;
             case 'parent':
                 if (!empty($p['objectId']) && is_numeric($p['objectId'])) {
                     $p['pids'] = $this->getPid($p['objectId']);
                 } elseif (!empty($p['path'])) {
                     $pids = Path::detectRealTargetId($p['path']);
                 }
                 break;
             case 'self':
                 if (!empty($p['objectId']) && is_numeric($p['objectId'])) {
                     $p['pids'] = $p['objectId'];
                 } elseif (!empty($p['path'])) {
                     $pids = Path::detectRealTargetId($p['path']);
                 }
                 break;
             case 'variable':
                 $pids = empty($p['pidValue']) ? Path::detectRealTargetId($p['path']) : Util\toNumericArray($p['pidValue']);
                 break;
             default:
                 $pids = Util\toNumericArray($scope);
                 break;
         }
     }
     if (!empty($pids)) {
         if (empty($p['descendants'])) {
             $p['pid'] = $pids;
         } elseif (@$p['source'] !== 'field') {
             $p['pids'] = $pids;
         }
     }
     $p['fl'] = 'id,name,type,template_id,status';
     if (!empty($p['fields'])) {
         if (!is_array($p['fields'])) {
             $p['fields'] = explode(',', $p['fields']);
         }
         for ($i = 0; $i < sizeof($p['fields']); $i++) {
             $fieldName = trim($p['fields'][$i]);
             if ($fieldName == 'project') {
                 $fieldName = 'case';
             }
             if (in_array($fieldName, array('date', 'path', 'case', 'size', 'cid', 'oid', 'cdate', 'udate'))) {
                 $p['fl'] .= ',' . $fieldName;
             }
         }
     }
     //increase number of returned items
     if (empty($p['rows'])) {
         $p['rows'] = 50;
     }
     $search = new Search();
     // temporary: Don't use permissions for Objects fields
     // it can be later reinforced per field in config
     $p['skipSecurity'] = true;
     $rez = $search->query($p);
     foreach ($rez['data'] as &$doc) {
         $res = DB\dbQuery('SELECT cfg
             FROM tree
             WHERE id = $1 AND
                 cfg IS NOT NULL', $doc['id']) or die(DB\dbQueryError());
         if ($r = $res->fetch_assoc()) {
             if (!empty($r['cfg'])) {
                 $cfg = Util\toJSONArray($r['cfg']);
                 if (!empty($cfg['iconCls'])) {
                     $doc['iconCls'] = $cfg['iconCls'];
                 }
             }
         }
         $res->close();
     }
     if (empty($rez['DC'])) {
         $rez['DC'] = array('name' => array('solr_column_name' => "name", 'idx' => 0));
     }
     return $rez;
 }
예제 #8
0
 /**
  * method to get multiple object properties from solr
  * Multilanguage plugin works also
  *
  * @param  array | string $ids
  * @param  string         $fieldList
  * @return array          associative array of properties per id
  */
 public static function getObjects($ids, $fieldList = 'id,name')
 {
     $rez = array();
     $ids = Util\toNumericArray($ids);
     if (!empty($ids)) {
         $chunks = array_chunk($ids, 200);
         //execute search
         try {
             foreach ($chunks as $chunk) {
                 $params = array('fl' => $fieldList, 'facet' => false, 'skipSecurity' => true, 'fq' => array('id:(' . implode(' OR ', $chunk) . ')'));
                 $search = new Search();
                 $sr = $search->query($params);
                 if (!empty($sr['data'])) {
                     foreach ($sr['data'] as &$d) {
                         $rez[$d['id']] = $d;
                     }
                 }
             }
         } catch (\Exception $e) {
             throw new \Exception("An error occured in getObjects: \n\n {$e->__toString()}");
         }
     }
     return $rez;
 }
예제 #9
0
 protected function getCases()
 {
     $fq = $this->fq;
     $parent = $this->lastNode->parent;
     switch ($parent->id) {
         case 4:
             //all my cases
             $fq[] = '(role_ids2:' . $this->user_id . ' OR role_ids3:' . $this->user_id . ')';
             break;
         default:
             $fq[] = 'role_ids' . $parent->id . ':' . $this->user_id;
     }
     $fq[] = 'status:' . $this->lastNode->id;
     $s = new \CB\Search();
     $rez = $s->query(array('fq' => $fq));
     return $rez;
 }