public static function getProperties($id) { $rez = array('success' => true, 'data' => array()); if (!is_numeric($id)) { return $rez; } $rez['menu'] = Browser\CreateMenu::getMenuForPath($id); $file = new Objects\File($id); $rez['data'] = $file->load(); $d =& $rez['data']; $d['path'] = str_replace(',', '/', $d['path']); $t = strtotime($d['cdate']); $dateFormat = getOption('long_date_format'); $timeFormat = getOption('time_format'); $d['ago_date'] = date($dateFormat, $t) . ' ' . L\get('at') . ' ' . date($timeFormat, $t); $d['ago_date'] = Util\translateMonths($d['ago_date']); $d['ago_text'] = Util\formatAgoTime($d['cdate']); if (!empty($d['versions'])) { foreach ($d['versions'] as &$r) { $r['template_id'] = $rez['data']['template_id']; $t = strtotime($r['cdate']); $r['ago_date'] = date($dateFormat, $t) . ' ' . L\get('at') . ' ' . date($timeFormat, $t); $r['ago_date'] = Util\translateMonths($r['ago_date']); $r['ago_text'] = Util\formatAgoTime($r['cdate']); } } return $rez; }
/** * get create menu for current node * @param array $rp request params * @return varchar menu config string */ public function getCreateMenu(&$rp) { return Browser\CreateMenu::getMenuForPath($this->id); }
/** * 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; }
/** * add a template for a given tree node * @param int $nodeId * @param int $templateId */ public static function addTemplateForNode($nodeId, $templateId) { $menuId = null; $menu = ''; $res = DB\dbQuery('SELECT id, menu FROM menu WHERE node_ids = $1', $nodeId) or die(DB\dbQueryError()); if ($r = $res->fetch_assoc()) { $menuId = $r['id']; $menu = $r['menu']; } $res->close(); if (strpos(',' . $menu . ',', ',' . $templateId . ',') === false) { if (!empty($menu)) { $menu .= ','; } $menu .= $templateId; } CreateMenu::replaceMenuForNode($menuId, $nodeId, $menu); }