public function getContentItems()
 {
     $p =& $this->requestParams;
     $folderTemplates = \CB\Config::get('folder_templates');
     $p['fl'] = 'id,system,path,name,case,date,date_end,size,cid,oid,cdate,uid,udate,template_id,acl_count,cls,status,task_status,dstatus';
     if (@$p['from'] == 'tree') {
         $p['templates'] = $folderTemplates;
     }
     if (is_numeric($this->lastNode->id)) {
         $p['pid'] = $pid;
     }
     $p['dstatus'] = 1;
     $p['fq'] = $this->fq;
     $s = new \CB\Search();
     $rez = $s->query($p);
     if (!empty($rez['data'])) {
         for ($i = 0; $i < sizeof($rez['data']); $i++) {
             $d =& $rez['data'][$i];
             $res = DB\dbQuery('SELECT cfg
                   , (SELECT 1
                      FROM tree
                      WHERE pid = $1' . (@$p['from'] == 'tree' ? ' AND `template_id` IN (0' . implode(',', $folderTemplates) . ')' : '') . ' LIMIT 1) has_childs
                 FROM tree
                 WHERE id = $1', $d['id']) or die(DB\dbQueryError());
             if ($r = $res->fetch_assoc()) {
                 $d['cfg'] = Util\toJSONArray($r['cfg']);
                 $d['has_childs'] = !empty($r['has_childs']);
             }
             $res->close();
         }
     }
     return $rez;
 }
Beispiel #2
0
 /**
  * query method with all params description
  * @param array $p
  *
  *         <will add here all params detailed description>
  *
  * @return json array with a subarray "data" that list all nodes
  */
 public function query($p)
 {
     $search = new \CB\Search();
     $rez = $search->query($p);
     $rez['success'] = true;
     return $rez;
 }
Beispiel #3
0
 public function getContentItems()
 {
     $p =& $this->requestParams;
     $folderTemplates = \CB\Config::get('folder_templates');
     $p['fl'] = 'id,system,path,name,case,date,date_end,size,cid,oid,cdate,uid,udate,template_id,acl_count,cls,status,task_status,dstatus';
     if (@$p['from'] == 'tree') {
         $p['templates'] = $folderTemplates;
     }
     if (is_numeric($this->lastNode->id)) {
         $p['pid'] = $pid;
     }
     $p['dstatus'] = 1;
     $p['fq'] = $this->fq;
     $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)) {
                 $d['cfg'] = $r['cfg'];
                 $r = DM\Tree::getChildCount($d['id'], @$p['from'] == 'tree' ? $folderTemplates : false);
                 $d['has_childs'] = !empty($r[$d['id']]);
             }
         }
     }
     return $rez;
 }
Beispiel #4
0
 private function getGraphNodes($id)
 {
     $acceptTemplates = Util\toNumericArray(\CB\getOption('action_templates'));
     if (empty($acceptTemplates)) {
         return null;
     }
     $p = array('templates' => $acceptTemplates, 'template_types' => array('object'), 'pids' => $id, 'fl' => 'id,name,date,template_id', 'sort' => 'date');
     $s = new \CB\Search();
     $srez = $s->query($p);
     unset($s);
     return $srez['data'];
 }
Beispiel #5
0
 /**
  *  returns SOLR results: nodeId children
  *  @param  [type] $id [description]
  *  @return [type]     [description]
  */
 public static function solrGetChildren($id, $fileId = null)
 {
     $s = new \CB\Search();
     $query = 'pid: ' . $id;
     // fetch only a single file
     if (@$fileId) {
         $query = 'id: ' . $fileId;
     }
     $params = array('fl' => 'id, name, template_id, date, cdate, uid, udate, size', 'fq' => array('dstatus: 0', 'system: [0 TO 1]'), 'sort' => 'sort_name asc');
     $data = $s->search($query, 0, 1000, $params);
     return $data;
 }
 protected function getChildrenTasks()
 {
     $p = $this->requestParams;
     if (@$p['from'] == 'tree') {
         return array();
     }
     $p['fq'] = $this->fq;
     $p['fq'][] = 'task_u_assignee:' . $_SESSION['user']['id'];
     $p['fq'][] = 'task_status:[0 TO 2]';
     $s = new \CB\Search();
     $rez = $s->query($p);
     $rez['view'] = 'calendar';
     return $rez;
 }
Beispiel #7
0
 public function getData($id = false)
 {
     $rez = array('success' => true, 'data' => array());
     if (empty(parent::getData($id))) {
         return $rez;
     }
     $params = array('pid' => $this->id, 'fq' => array('(template_type:file) OR (target_type:file)'), 'fl' => 'id,pid,name,template_id,size,cdate', 'sort' => 'cdate', 'dir' => 'desc');
     $s = new \CB\Search();
     $sr = $s->query($params);
     foreach ($sr['data'] as $d) {
         $d['ago_text'] = Util\formatAgoTime($d['cdate']);
         $rez['data'][] = $d;
     }
     return $rez;
 }
Beispiel #8
0
 protected function createDefaultFilter()
 {
     parent::createDefaultFilter();
     $programs = array();
     //filter only programs where current user is manager
     $s = new \CB\Search();
     $sr = $s->query(array('fl' => 'id', 'fq' => array('template_id:24484', 'user_ids:' . $_SESSION['user']['id'])));
     if (empty($sr['data'])) {
         $this->fq[] = 'id:0';
     } else {
         foreach ($sr['data'] as $pr) {
             $programs[] = $pr['id'];
         }
         // $this->fq[] = 'category_id:('.implode(' OR ', $programs).')';
     }
 }
Beispiel #9
0
 protected function getRootNodes()
 {
     $fq = $this->fq;
     $s = new \CB\Search();
     if (@$this->requestParams['from'] == 'tree') {
         $sr = $s->query(array('rows' => 0, 'fq' => $fq, 'facet' => true, 'facet.field' => array('{!ex=template_id key=template_id}template_id')));
         $rez = array('data' => array());
         if (!empty($sr['facets']->facet_fields->{'template_id'})) {
             foreach ($sr['facets']->facet_fields->{'template_id'} as $template_id => $count) {
                 $rez['data'][] = array('name' => $this->getName($template_id) . ' (' . $count . ')', 'id' => $this->getId($template_id), 'iconCls' => $this->iconCls, 'has_childs' => true);
             }
         }
         return $rez;
     }
     $sr = $s->query(array('fq' => $fq));
     return $sr;
 }
Beispiel #10
0
 public function getData($id = false)
 {
     $rez = array('success' => true);
     if (empty(parent::getData($id))) {
         return $rez;
     }
     $params = array('pid' => $this->id, 'fq' => array('(template_type:task) OR (target_type:task)'), 'fl' => 'id,pid,name,template_id,date,date_end,cid,cdate,status', 'sort' => 'cdate', 'dir' => 'desc');
     $s = new \CB\Search();
     $sr = $s->query($params);
     foreach ($sr['data'] as $d) {
         $d['ago_text'] = @Util\formatDateTimePeriod($d['date'], null, @$_SESSION['user']['cfg']['timezone']);
         $d['user'] = User::getDisplayName($d['cid'], true);
         \CB\Tasks::setTaskActionFlags($d);
         $rez['data'][] = $d;
     }
     return $rez;
 }
Beispiel #11
0
 public function getData($id = false)
 {
     $rez = array('success' => true);
     if (empty(parent::getData($id))) {
         return $rez;
     }
     $params = array('pid' => $this->id, 'fq' => array('(template_type:object) OR (target_type:object)'), 'fl' => 'id,pid,name,template_id,cdate,cid', 'sort' => 'cdate', 'dir' => 'desc');
     $folderTemplates = \CB\Config::get('folder_templates');
     if (!empty($folderTemplates)) {
         $params['fq'][] = '!template_id:(' . implode(' OR ', Util\toNumericArray($folderTemplates)) . ')';
     }
     $s = new \CB\Search();
     $sr = $s->query($params);
     foreach ($sr['data'] as $d) {
         $d['ago_text'] = Util\formatAgoTime($d['cdate']);
         $d['user'] = @User::getDisplayName($d['cid']);
         $rez['data'][] = $d;
     }
     return $rez;
 }
Beispiel #12
0
 protected function getRootNodes()
 {
     $fq = $this->fq;
     $rez = array('data' => array());
     //filter only programs where current user is manager
     $s = new \CB\Search();
     $sr = $s->query(array('fl' => 'id', 'fq' => array('template_id:24484', 'user_ids:' . $_SESSION['user']['id'])));
     $programs = array();
     if (empty($sr['data'])) {
         return $rez;
     } else {
         foreach ($sr['data'] as $pr) {
             $programs[] = $pr['id'];
         }
         // $fq = 'category_id:('.implode(' OR ', $programs).')';
     }
     // $sr = $s->query(
     //     array(
     //         'rows' => 0
     //         ,'fq' => $fq
     //         ,'facet' => true
     //         ,'facet.field' => array(
     //             '{!ex=category_id key=category_id}category_id'
     //         )
     //     )
     // );
     // if (!empty($sr['facets']->facet_fields->{'category_id'})) {
     //     foreach ($sr['facets']->facet_fields->{'category_id'} as $program_id => $count) {
     //         if (!in_array($program_id, $programs)) {
     //             continue;
     //         }
     //         $rez['data'][] = array(
     //             'name' => $this->getName($program_id)
     //             ,'id' => $this->getId($program_id)
     //             ,'iconCls' => 'i-building'
     //             ,'has_childs' => true
     //         );
     //     }
     // }
     return $rez;
 }
Beispiel #13
0
 public function getChildren(&$pathArray, $requestParams)
 {
     $rez = array();
     $this->path = $pathArray;
     $this->lastNode = @$pathArray[sizeof($pathArray) - 1];
     $this->requestParams = $requestParams;
     if (!$this->acceptedPath($pathArray, $requestParams)) {
         return;
     }
     $p = $this->getSearchParams($requestParams);
     //view is detected earlier by Browser class
     if (!empty($requestParams['view'])) {
         $p['view'] = $requestParams['view'];
     }
     //facets are obtained by browser class before collecting children
     unset($p['facets']);
     $p = array_merge($requestParams, $p);
     $s = new \CB\Search();
     $rez = $s->query($p);
     return $rez;
 }
Beispiel #14
0
 public static function getNodeContent($id, $myPath, $onlyFileId = null)
 {
     $s = new \CB\Search();
     $query = 'pid:' . $id;
     $params = array('fl' => 'id,name,template_id,date,cdate,udate,size', 'fq' => array('dstatus:0', 'system:[0 TO 1]'), 'sort' => 'sort_name asc');
     if (is_array($onlyFileId)) {
         $params['fq'][] = 'id:(' . implode(' OR ', $onlyFileId) . ')';
     }
     $data = $s->search($query, 0, 9999, $params);
     $fileIds = array();
     $array = array();
     foreach ($data->response->docs as $item) {
         $el = array('id' => $item->id, 'name' => $item->name, 'template_id' => $item->template_id, 'size' => $item->size, 'cdate' => $item->cdate, 'udate' => $item->udate, 'path' => $myPath . DIRECTORY_SEPARATOR . $item->name);
         if ($item->template_id != \CB\Config::get('default_file_template')) {
             $el['path'] = $myPath . DIRECTORY_SEPARATOR . $item->name;
         } else {
             $fileIds[] = $el['id'];
         }
         $array[$el['id']] = $el;
     }
     /* select additional info required for files */
     if (!empty($fileIds)) {
         $res = \CB\DB\dbQuery('SELECT
                 f.id
                 ,CONCAT(c.path, \'/\', f.content_id) `content_path`
                 ,c.md5
                 ,c.type
             FROM files f
             LEFT JOIN files_content c ON f.content_id = c.id
             WHERE f.id in (' . implode(',', $fileIds) . ')') or die(DB\dbQueryError());
         while ($r = $res->fetch_assoc()) {
             $array[$r['id']] = array_merge($array[$r['id']], $r);
         }
         $res->close();
     }
     return $array;
 }
Beispiel #15
0
 protected function getAssigneeTasks()
 {
     $p = $this->requestParams;
     $p['fq'] = $this->fq;
     $p['fq'][] = 'cid:' . User::getId();
     $p['fq'][] = 'task_status:[1 TO 2]';
     $user_id = substr($this->lastNode->id, 3);
     $p['fq'][] = 'task_u_ongoing:' . $user_id;
     $s = new \CB\Search();
     $sr = $s->query($p);
     return $sr;
 }
Beispiel #16
0
 protected function getCases()
 {
     $s = new \CB\Search();
     $rez = $s->query(array('fq' => $this->fq));
     return $rez;
 }
 protected function getTasks()
 {
     $fq = $this->fq;
     $s = new \CB\Search();
     $sr = $s->query(array('fq' => $fq));
     return $sr;
 }
Beispiel #18
0
 /**
  * add attachment links below the comments body
  * @param  array reference $rez
  * @return void
  */
 protected static function addAttachmentLinks(&$rez)
 {
     //collect comment ids
     $ids = array();
     foreach ($rez['data'] as $d) {
         $ids[] = $d['id'];
     }
     if (empty($ids)) {
         return;
     }
     //select files for all loaded comments using a single solr request
     $params = array('system' => '[0 TO 2]', 'fq' => array('pid:(' . implode(' OR ', $ids) . ')', 'template_type:"file"'), 'fl' => 'id,pid,name,template_id', 'sort' => 'pid,cdate', 'rows' => 50, 'dir' => 'asc');
     $s = new \CB\Search();
     $sr = $s->query($params);
     $files = array();
     $fileIds = array();
     $fileTypes = array();
     foreach ($sr['data'] as $d) {
         $files[$d['pid']][] = $d;
         $fileIds[] = $d['id'];
     }
     //get file types
     if (!empty($fileIds)) {
         $fileTypes = DM\Files::getTypes($fileIds);
     }
     foreach ($rez['data'] as &$d) {
         if (empty($files[$d['id']])) {
             continue;
         }
         $links = array();
         foreach ($files[$d['id']] as $f) {
             $f['type'] = @$fileTypes[$f['id']];
             $links[] = static::getFileLink($f);
         }
         $d['files'] = '<ul class="comment-attachments"><li>' . implode('</li><li>', $links) . '</li></ul>';
     }
 }
Beispiel #19
0
 protected function getDepth1()
 {
     $rez = array();
     $users = array();
     $office = new \CB\Objects\Object($this->office_id);
     $od = $office->load();
     if (empty($od['data']['security_group'])) {
         return $rez;
     }
     $res = DB\dbQuery('SELECT
             ug.id
             ,ug.name
             ,ug.first_name
             ,ug.last_name
             ,ug.sex
         FROM
         `users_groups_association` uga
         JOIN users_groups ug ON uga.user_id = ug.id
         WHERE uga.`group_id` = $1
         ORDER BY ug.first_name, ug.last_name, ug.name', $od['data']['security_group']);
     while ($r = $res->fetch_assoc()) {
         $name = trim($r['first_name'] . ' ' . $r['last_name']);
         if (empty($name)) {
             $name = $r['name'];
         }
         $users[$r['id']] = array('id' => $this->getId($r['id']), 'name' => $name, 'iconCls' => 'icon-user-' . $r['sex'], 'has_childs' => true);
     }
     $res->close();
     $fq = $this->fq;
     $s = new \CB\Search();
     if (@$this->requestParams['from'] == 'tree') {
         $rez['data'] = array_values($users);
         return $rez;
     }
     $sr = $s->query(array('fq' => $fq));
     return $sr;
 }
Beispiel #20
0
 /**
  * @dataProvider searchDataProvider
  */
 public function testSearch($search)
 {
     $src = new \CB\Search();
     $this->assertTrue(is_numeric($src->ping()));
     $src_response = $src->search('test', 0, 10, []);
     $this->assertEquals('OK', $src_response->getHttpStatusMessage(), $src_response->getHttpStatusMessage());
     $result = Helpers::getIncludeContents(\CB\DOC_ROOT . 'remote/router.php', ['postdata' => $search['postdata']]);
     $result = json_decode($result, true);
     $this->assertArraySubset(json_decode($search['expected_response'], true), $result, false, ' Result:' . print_r($result, true) . PHP_EOL . ' Expected:' . print_r(json_decode($search['expected_response'], true), true));
 }
Beispiel #21
0
 /**
  * add attachment links below the comments body
  * @param  array reference $rez
  * @return void
  */
 protected static function addAttachmentLinks(&$rez)
 {
     //collect comment ids
     $ids = array();
     foreach ($rez['data'] as $d) {
         $ids[] = $d['id'];
     }
     if (empty($ids)) {
         return;
     }
     //select files for all loaded comments using a single solr request
     $params = array('system' => '[0 TO 2]', 'fq' => array('pid:(' . implode(' OR ', $ids) . ')', 'template_type:"file"'), 'fl' => 'id,pid,name,template_id', 'sort' => 'pid,cdate', 'rows' => 50, 'dir' => 'asc');
     $s = new \CB\Search();
     $sr = $s->query($params);
     $files = array();
     $fileIds = array();
     $fileTypes = array();
     foreach ($sr['data'] as $d) {
         $files[$d['pid']][] = $d;
         $fileIds[] = $d['id'];
     }
     //get file types from db
     if (!empty($fileIds)) {
         $res = DB\dbQuery('SELECT f.id, c.`type`
             FROM files f
             JOIN files_content c
                 ON f.content_id = c.id
             WHERE f.id in (' . implode(',', $fileIds) . ')') or die(DB\dbQueryError());
         while ($r = $res->fetch_assoc()) {
             $fileTypes[$r['id']] = $r['type'];
         }
         $res->close();
     }
     foreach ($rez['data'] as &$d) {
         if (empty($files[$d['id']])) {
             continue;
         }
         $links = array();
         foreach ($files[$d['id']] as $f) {
             $f['type'] = @$fileTypes[$f['id']];
             $links[] = static::getFileLink($f);
         }
         $d['files'] = '<ul class="comment-attachments"><li>' . implode('</li><li>', $links) . '</li></ul>';
     }
 }