public function getTemplatesStructure() { $rez = array('success' => true, 'data' => array()); $tc = Templates\SingletonCollection::getInstance(); $tc->loadAll(); foreach ($tc->templates as $id => $t) { $td = $t->getData(); $tt = $td['type']; $fields = $t->getFields(); foreach ($fields as $f) { if ($f['type'] == '_auto_title' && empty($td['title_template'])) { $f['type'] = 'varchar'; } if ($f['type'] == 'geoPoint' && empty($f['cfg']['validator'])) { $f['cfg']['validator'] = 'geoPoint'; } if ($f['pid'] == $id) { $f['pid'] = null; } //unset server side functions to not be visible on lcient if (!empty($f['cfg']['source']['fn'])) { unset($f['cfg']['source']['fn']); } //set default search conditions: // - varchar: contains // - objects & multiValued: Contains Any // - object & singleValued: Equal // - other fieldTypes: equal if ($tt == 'search' && empty($f['cfg']['cond'])) { switch ($f['type']) { case 'varchar': $f['cfg']['cond'] = 'contain'; break; case '_objects': $f['cfg']['cond'] = empty($f['cfg']['multiValued']) ? '=' : '<='; break; default: $f['cfg']['cond'] = '='; } } // If multiValued=True for Objects field, the default editor=form + default: "renderer": "listObjIcons" if (!empty($f['cfg']['multiValued'])) { if (!isset($f['cfg']['editor'])) { $f['cfg']['editor'] = 'form'; } if (!isset($f['cfg']['renderer'])) { $f['cfg']['renderer'] = 'listObjIcons'; } } $rez['data'][$id][] = $f; } } return $rez; }
public function getData($id = false) { $rez = parent::getData($id); $template = \CB\Templates\SingletonCollection::getInstance()->getTemplate($rez['data']['template_id']); $noTemplateFields = empty($template->getData()['fields']); if (empty($rez['data']['preview']) && $noTemplateFields) { unset($rez['data']); } else { $preview = implode('', $rez['data']['preview']); if (empty($preview) && $noTemplateFields) { unset($rez['data']); } } return $rez; }
/** * create an object * @param array $p params * @return json responce */ public function create($p) { $pid = empty($p['pid']) ? @$p['path'] : $p['pid']; if (empty($pid)) { throw new \Exception(L\get('Access_denied')); } if (empty($p['pid']) || !is_numeric($p['pid'])) { $p['pid'] = Path::detectRealTargetId($pid); } //security check moved inside objects class $template = \CB\Templates\SingletonCollection::getInstance()->getTemplate($p['template_id']); $templateData = $template->getData(); $object = $this->getCustomClassByType($templateData['type']); //prepare params if (empty($p['name'])) { $p['name'] = $template->getName(); } $p['name'] = $this->getAvailableName($p['pid'], $p['name']); $id = $object->create($p); Solr\Client::runCron(); $rez = $this->load(array('id' => $id)); $rez['data']['isNew'] = true; return $rez; }
/** * update tree nodes into solr * * @param string[] $p { * @type boolean $all if true then all nodes will be updated into solr, * otherwise - only the nodes marked as updated will be reindexed in solr * @type int[] $id id or array of object ids to update * * @type varchar $cron_id when this function is called by a cron then cron_id should be passed * * @type boolean $nolimit if true then no limit will be applied to maximum indexed nodes * (default 2000) * } */ public function updateTree($p = array()) { /* connect to solr service */ $this->connect(); $eventParams = array('class' => &$this, 'params' => &$p); $this->folderTemplates = \CB\Config::get('folder_templates'); \CB\fireEvent('onBeforeSolrUpdate', $eventParams); /** @type int the last processed document id */ $lastId = 0; $indexedDocsCount = 0; $all = !empty($p['all']); $nolimit = !empty($p['nolimit']); /* prepeare where condition for sql depending on incomming params */ $where = '(t.updated > 0) AND (t.draft = 0) AND (t.id > $1)'; if ($all) { $this->deleteByQuery('*:*'); $where = '(t.id > $1) AND (t.draft = 0) '; \CB\Templates\SingletonCollection::getInstance()->loadAll(); } elseif (!empty($p['id'])) { $ids = \CB\Util\toNumericArray($p['id']); $where = '(t.id in (0' . implode(',', $ids) . ') ) and (t.id > $1)'; } $sql = 'SELECT t.id ,t.pid ,ti.pids ,ti.case_id ,ti.acl_count ,ti.security_set_id ,t.name ,t.system ,t.template_id ,t.target_id ,t.size ,DATE_FORMAT(t.`date`, \'%Y-%m-%dT%H:%i:%sZ\') `date` ,DATE_FORMAT(t.`date_end`, \'%Y-%m-%dT%H:%i:%sZ\') `date_end` ,t.oid ,t.cid ,DATE_FORMAT(t.cdate, \'%Y-%m-%dT%H:%i:%sZ\') `cdate` ,t.uid ,DATE_FORMAT(t.udate, \'%Y-%m-%dT%H:%i:%sZ\') `udate` ,t.did ,DATE_FORMAT(t.ddate, \'%Y-%m-%dT%H:%i:%sZ\') `ddate` ,t.dstatus ,t.updated ,o.sys_data FROM tree t LEFT JOIN tree_info ti ON t.id = ti.id LEFT JOIN objects o ON o.id = t.id where ' . $where . ' ORDER BY t.id LIMIT 500'; $docs = true; while (!empty($docs) && ($nolimit || $indexedDocsCount < 2000)) { $docs = array(); $res = DB\dbQuery($sql, $lastId) or die(DB\dbQueryError()); while ($r = $res->fetch_assoc()) { $lastId = $r['id']; /* process full object update only if: - updated = 1 - specific ids are specified - if $all parameter is true */ if ($all || !empty($p['id']) || $r['updated'] & 1) { $r['sys_data'] = Util\toJsonArray($r['sys_data']); $this->prepareDBRecord($r); $docs[$r['id']] = $r; } $this->updateCronLastActionTime(@$p['cron_id']); } $res->close(); if (!empty($docs)) { //append file contents for files to content field $this->appendFileContents($docs); $this->addDocuments($docs); /* reset updated flag into database for processed documents */ DB\dbQuery('UPDATE tree ,tree_info SET tree.updated = 0 ,tree_info.updated = 0 WHERE tree.id in (' . implode(',', array_keys($docs)) . ') AND tree_info.id = tree.id') or die(DB\dbQueryError()); $this->updateCronLastActionTime(@$p['cron_id']); $this->commit(); $indexedDocsCount += sizeof($docs); } } $this->updateTreeInfo($p); \CB\fireEvent('onSolrUpdate', $eventParams); }
/** * get object template property * * @return array object properties */ public function getTemplate() { if (empty($this->template) && $this->loadTemplate && !empty($this->data['template_id'])) { $this->template = \CB\Templates\SingletonCollection::getInstance()->getTemplate($this->data['template_id']); } return $this->template; }
/** * method to collect all node ids needed for rendering of loaded data set * @param array &$result containing recxords in 'data' property * @return void */ protected function warmUpNodes(&$result) { $d =& $result['data']; $requiredIds = array(); $paths = array(); foreach ($d as &$rec) { if (!empty($rec['id'])) { $requiredIds[$rec['id']] = 1; } //add shorcut targets if (!empty($rec['target_id'])) { $requiredIds[$rec['target_id']] = 1; } //add path ids if (isset($rec['path']) && !isset($paths[$rec['path']])) { $path = Util\toNumericArray($rec['path'], '/'); if (!empty($path)) { $paths[$rec['path']] = $path; foreach ($path as $id) { $requiredIds[$id] = 1; } } } } $requiredIds = array_keys($requiredIds); //preload templates Templates\SingletonCollection::getInstance()->loadAll(); //preload all users display data //now there objects should be loaded in bulk before firing event //because DisplayColumns analizes each object from result Objects::getCachedObjects($requiredIds); $requiredIds = array(); $eventParams = array('inputParams' => &$this->inputParams, 'params' => &$this->params, 'data' => &$d, 'requiredIds' => &$requiredIds); \CB\fireEvent('solrQueryWarmUp', $eventParams); return $requiredIds; }
/** * get data for defined plugins to be displayed in properties panel for selected object * @param array $p remote properties containing object id * @return ext direct responce */ public function getPluginsData($p) { $id = @$p['id']; $templateId = @$p['template_id']; $template = null; $templateData = null; $objectPlugins = null; $rez = array('success' => false, 'data' => array()); if (empty($id) && empty($templateId) || !is_numeric($id) && !is_numeric($templateId)) { return $rez; } if (is_numeric($id)) { if (!$this->idExists($id)) { return $rez; } if (!Security::canRead($id)) { throw new \Exception(L\get('Access_denied')); } $rez['menu'] = Browser\CreateMenu::getMenuForPath($id); /* now we'll try to detect plugins config that could be found in following places: 1. in config of the template for the given object, named object_plugins 2. in core config, property object_type_plugins (config definitions per available template type values: object, case, task etc) 3. a generic config, named default_object_plugins, could be defined in core config */ $o = $this->getCachedObject($id); if (!empty($o)) { $template = $o->getTemplate(); if (!empty($template)) { $templateData = $template->getData(); } } } else { $id = null; $templates = Templates\SingletonCollection::getInstance(); $templateData = $templates->getTemplate($templateId)->getData(); } $from = empty($p['from']) ? '' : $p['from']; if (!empty($from)) { if (isset($templateData['cfg']['object_plugins'])) { $op = $templateData['cfg']['object_plugins']; if (!empty($op[$from])) { $objectPlugins = $op[$from]; } else { //check if config has only numeric keys, i.e. plugins specified directly (without a category) if (!Util\isAssocArray($op)) { $objectPlugins = $op; } else { $objectPlugins = Config::getObjectTypePluginsConfig(@$templateData['type'], $from); } } } } if (empty($objectPlugins)) { if (!empty($templateData['cfg']['object_plugins'])) { $objectPlugins = $templateData['cfg']['object_plugins']; } else { $objectPlugins = Config::getObjectTypePluginsConfig($templateData['type'], $from); } } $rez['success'] = true; if (empty($objectPlugins)) { return $rez; } foreach ($objectPlugins as $pluginName) { $class = '\\CB\\Objects\\Plugins\\' . ucfirst($pluginName); $pClass = new $class($id); $prez = $pClass->getData(); $rez['data'][$pluginName] = $prez; } return $rez; }
/** * runs script for updating solr data for current template items * @param int $templateId * @return json responce */ public function updateSolrData($templateId) { $rez = array('success' => true); $tc = Templates\SingletonCollection::getInstance(); $tpl = $tc->getTemplate($templateId); $d = $tpl->getData(); if (!empty($d['sys_data']['solrConfigUpdated'])) { $cmd = 'php -f ' . BIN_DIR . 'update_solr_prepared_data.php -- ' . '-c ' . Config::get('core_name') . ' -a -t ' . $templateId . ' &'; shell_exec($cmd); $tpl->setSysDataProperty('solrConfigUpdated'); } }
/** * detect object icon by analizing it's data * * object data could have set a custom iconCls in cfg property of the data, * otherwise the icon is determined from it's template * TODO: think about shortcuts * @param array $data object data * @return varchar iconCls */ public static function getIcon(&$data) { if (!empty($data['cfg']) && !empty($data['cfg']['iconCls'])) { return $data['cfg']['iconCls']; } if (empty($data['template_id'])) { return 'icon-none'; } $templates = Templates\SingletonCollection::getInstance(); $templateData = $templates->getTemplate($data['template_id'])->getData(); if (!empty($templateData['iconCls'])) { return $templateData['iconCls']; } switch ($templateData['type']) { case 'object': if (in_array($data['template_id'], Config::get('folder_templates'))) { return 'icon-folder'; } break; case 2: return 'icon-shortcut'; //case break; case 'file': return Files::getIcon($data['name']); break; case 'task': if (@$d['status'] == 3) { return 'icon-task-completed'; } return 'icon-task'; //task break; case 'email': return 'icon-mail'; //Message (email) break; } return 'icon-none'; }