/** * create thesauri * @return void */ protected function createThesauri($pid, &$th, $prefix) { $o = new \CB\Objects\Object(); foreach ($th as $k => &$v) { //create $k folder under pid echo "creating '{$k}' .. "; $id = $o->create(array('id' => null, 'pid' => $pid, 'template_id' => BBM::$cfg['folderTemplateId'], 'name' => $k, 'data' => array('_title' => $k))); $this->thesauriIds[$prefix . $k] = array('id' => $id); echo "ok\n"; if (Util\isAssocArray($v)) { //subfolders $this->createThesauri($id, $v, $prefix . $k . '/'); } else { //create thesauri items $i = 1; foreach ($v as $item) { $o->create(array('id' => null, 'pid' => $id, 'template_id' => BBM::$cfg['thesauriTemplateId'], 'name' => $item, 'data' => array("en" => $item, "iconCls" => "icon-tag-small", "visible" => 1, "order" => $i++))); } } } }
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; }
/** * test CRUD (temp: for one record) for future create data providers * @dataProvider objectsProvider */ public function testObjectCRUD($data) { // try to add one folder to root tree $obj = new \CB\Objects\Object(); // first create object $data['id'] = $obj->create($data); $this->assertTrue($data['id'] > 0, ' Error on Object create'); // second read created object $obj->load($data['id']); $read_data = $obj->getData(); $this->assertArraySubset($data, $read_data, false, ' readed data: ' . print_r($read_data, true)); // third update created object $data['name'] = $data['name'] . ' (updated)'; $data['data']['_title'] = $data['data']['_title'] . ' (updated)'; $obj->update($data); $obj->load($data['id']); $read_data = $obj->getData(); $this->assertArraySubset($data, $read_data, false, ' error on updated object data '); // four delete object $obj->delete(false); $obj->delete(true); $obj->load($data['id']); $read_data = $obj->getData(); $this->assertTrue(empty($read_data['id']), 'error delete object data'); }
public static function deleteObject($id) { $file = new \CB\Objects\Object($id); $file->delete(); \CB\Solr\Client::runCron(); }
/** * transfer config options to tree * @return void */ protected function syncConfigToTree() { $o = new \CB\Objects\Object(); $co = new \CB\Objects\Config(); $recs = DM\Config::readAll(); foreach ($recs as $r) { //detect option type $type = ''; switch ($r['param']) { case 'default_event_template': case 'default_file_template': case 'default_folder_template': case 'default_task_template': $type = 'int'; break; case 'default_language': case 'languages': case 'project_name_en': case 'project_name_ru': $type = 'varchar'; break; case 'folder_templates': case 'max_files_version_count': case 'templateIcons': $type = 'text'; break; case 'facet_configs': case 'js': case 'maintenance_cfg': case 'node_facets': case 'rootNode': case 'object_type_plugins': case 'treeNodes': $type = 'json'; break; case 'responsible_party': case 'responsible_party_default': case 'task_categories': case 'maintenance_mode': continue; default: if (is_numeric($r['value'])) { $type = 'int'; } else { $type = 'text'; } } if (empty($type)) { continue; } $childs = array(); if ($r['param'] == 'folder_templates') { $r['value'] .= ',' . $this->templateIds["Config json option"]; DM\Config::update($r); } if ($r['param'] == 'treeNodes') { $childs = Util\toJSONArray($r['value']); $r['value'] = ''; DM\Config::update($r); } $pid = $o->create(array('id' => null, 'pid' => $this->cfg['configFolderId'], 'template_id' => $this->templateIds["Config {$type} option"], 'name' => $r['param'], 'data' => array('_title' => $r['param'], 'value' => $r['value']))); $i = 1; foreach ($childs as $k => $v) { $co->create(array('id' => null, 'pid' => $pid, 'template_id' => $this->templateIds["Config {$type} option"], 'name' => $k, 'data' => array('_title' => $k, 'value' => json_encode($v, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT), 'order' => $i++))); } } //add menu rule for Menus folder $pid = Objects::getChildId($this->systemFolderId, 'Menus'); $tempalteIds = DM\Templates::getIdsByType('menu'); $o->create(array('id' => null, 'pid' => $pid, 'template_id' => $tempalteIds[0], 'name' => 'Create config options rule', 'data' => array('_title' => 'Create config options rule', 'node_ids' => $this->cfg['configFolderId'], 'menu' => $this->templateIds['Config int option'] . ',' . $this->templateIds['Config varchar option'] . ',' . $this->templateIds['Config text option'] . ',' . $this->templateIds['Config json option']))); }
/** * transfer menu rules to tree * @return void */ protected function convertMenuRulesToTree() { $o = new \CB\Objects\Object(); $res = DB\dbQuery('SELECT * FROM menu') or die(DB\dbQueryError()); while ($r = $res->fetch_assoc()) { // $menu = Util\toTrimmedArray($r['menu'], ','); //replace splitters $r['menu'] = str_replace('-', $this->templateIds['- Menu separator -'], $r['menu']); $o->create(array('id' => null, 'pid' => $this->cfg['menusFolderId'], 'template_id' => $this->templateIds['Menu rule'], 'name' => '#' . $r['id'], 'data' => array('_title' => '#' . $r['id'], 'node_ids' => $r['node_ids'], 'template_ids' => $r['node_template_ids'], 'user_group_ids' => $r['user_group_ids'], 'menu' => $r['menu']))); } $res->close(); //add menu rule for Menus folder $o->create(array('id' => null, 'pid' => $this->cfg['menusFolderId'], 'template_id' => $this->templateIds['Menu rule'], 'name' => 'Create menu rules in this folder', 'data' => array('_title' => 'Create menu rules in this folder', 'node_ids' => $this->cfg['menusFolderId'], 'menu' => $this->templateIds['Menu rule']))); }
/** * get search params for given request params * @param array &$rp * @return array */ protected function getSearchParams(&$rp) { $rez = array(); // creating search object $so = new \CB\Objects\Object(); if (!empty($rp['search']['template_id'])) { // searching from a search form $so->setData($rp['search']); } else { // should/will be reviewed for saved searches $searchId = $this->lastNode->id; if (!empty($rp['search']['id']) && is_numeric($rp['search']['id'])) { $searchId = $rp['search']['id']; } // executing a saved search $so->load($searchId); } $t = $so->getTemplate(); $td = $t->getData(); // if we have a router defined in config of the search template then try to prepare search params wit it // otherwise use default search method // if (empty($td['cfg']['router'])) { $rez = $t->getData()['cfg']; @($rez['template_id'] = $so->getData()['template_id']); if (empty($rez['fq'])) { $rez['fq'] = array(); } $ld = $so->getLinearData(); foreach ($ld as $v) { $condition = $this->adjustCondition($t->getField($v['name']), $v); if (!empty($condition)) { $rez['fq'][] = $condition; } } // } else { if (!empty($td['cfg']['router'])) { $a = explode('.', $td['cfg']['router']); $class = str_replace('_', '\\', $a[0]); $class = new $class(); $rez = $class->{$a[1]}($rp, $rez); } return $rez; }
); $object = new \CB\Objects\Object(); //you can create the object by passing params to create method: $objectId = $object->create($newObjectData); //or by setting data an then call create $newObjectData['pid'] = $objectId; $newObjectData['id'] = null; $object->setData($newObjectData); $objectId2 = $object->create(); //loading and updating an object $object->load($objectId); $objectData = $object->getData(); $objectData['name'] = 'Renamed object'; $objectData['data']['_title'] = 'Renamed object'; // you can setData and then call update or just call update with data param $object->setData($objectData); $object->update(); // delete method will be available with next commit // It will have a param to just mark the object as deleted in tree or completely delete object from database // index in solr \CB\Solr\Client::runCron(); /**/ $object = new \CB\Objects\Object(2197); $object->load(2197);