Exemplo n.º 1
0
 protected function deleteCustomData($permanent)
 {
     if ($permanent) {
         $d =& $this->data['data'];
         DM\Config::delete(DM\Config::toId($d['_title'], 'param'));
     }
     parent::deleteCustomData($permanent);
 }
Exemplo n.º 2
0
 /**
  * update objects custom data
  * @return boolean
  */
 protected function updateCustomData()
 {
     parent::updateCustomData();
     /* saving template data to templates and templates_structure tables */
     $p =& $this->data;
     $data = $this->collectCustomModelData();
     $data['template_id'] = $this->detectParentTemplate();
     DM\TemplatesStructure::update($data);
 }
Exemplo n.º 3
0
 /**
  * update comment
  * @param  array   $p optional properties. If not specified then $this-data is used
  * @return boolean
  */
 public function update($p = false)
 {
     //disable default log from parent Object class
     //we'll set comments add as comment action for parent
     Config::setFlag('disableActivityLog', true);
     $rez = parent::update($p);
     Config::setFlag('disableActivityLog', false);
     $p =& $this->data;
     $this->logAction('comment_update', array('new' => Objects::getCachedObject($p['pid']), 'comment' => $p['data']['_title']));
     return $rez;
 }
Exemplo n.º 4
0
 /**
  * update objects custom data
  * @return boolean
  */
 protected function updateCustomData()
 {
     parent::updateCustomData();
     /* saving template data to templates and templates_structure tables */
     $data = $this->collectCustomModelData();
     unset($data['id']);
     if (!empty($data)) {
         $data['id'] = $this->id;
         DM\Templates::update($data);
     }
 }
Exemplo n.º 5
0
 /**
  * update objects custom data
  * @return boolean
  */
 protected function updateCustomData()
 {
     parent::updateCustomData();
     /* saving template data to templates and templates_structure tables */
     $p =& $this->data;
     $data = $this->collectCustomModelData();
     $data['id'] = $this->id;
     $data['template_id'] = $this->detectParentTemplate();
     DM\TemplatesStructure::update($data);
     if ($this->isSolrConfigUpdated()) {
         $tpl = \CB\Objects::getCachedObject($data['template_id']);
         $tpl->setSysDataProperty('solrConfigUpdated', true);
     }
 }
Exemplo n.º 6
0
 /**
  * update objects custom data
  * @return boolean
  */
 protected function updateCustomData()
 {
     parent::updateCustomData();
     /* saving template data to templates and templates_structure tables */
     $p =& $this->data;
     $saveFields = array('template_id');
     $saveValues = array($this->id, $this->detectParentTemplate());
     $params = array('template_id = $2');
     $i = 3;
     $dataParams = $this->getParamsFromData();
     foreach ($dataParams as $k => $v) {
         $saveFields[] = $k;
         $saveValues[] = $v;
         $params[] = "`{$k}` = \${$i}";
         $i++;
     }
     if (!empty($saveFields)) {
         DB\dbQuery('UPDATE templates_structure
             SET ' . implode(',', $params) . '
             WHERE id = $1', $saveValues) or die(DB\dbQueryError());
     }
 }
Exemplo n.º 7
0
 /**
  * method to collect solr data from object data
  * according to template fields configuration
  * and store it in sys_data onder "solr" property
  * @return void
  */
 protected function collectSolrData()
 {
     parent::collectSolrData();
     $sd =& $this->data['sys_data']['solr'];
     $r = DM\Files::getSolrData($this->id);
     if (!empty($r)) {
         $sd['size'] = $r['size'];
         $sd['versions'] = intval($r['versions']);
     }
 }
Exemplo n.º 8
0
 /**
  * method to collect solr data from object data
  * according to template fields configuration
  * and store it in sys_data onder "solr" property
  * @return void
  */
 protected function collectSolrData()
 {
     parent::collectSolrData();
     $sd =& $this->data['sys_data']['solr'];
     $sd['target_type'] = Objects::getType($this->data['target_id']);
 }
Exemplo n.º 9
0
 /**
  * generate html preview for a task
  * @param  int   $id task id
  * @return array
  */
 public function getPreviewBlocks()
 {
     $pb = parent::getPreviewBlocks();
     $data = $this->getData();
     $sd =& $data['sys_data'];
     $template = $this->getTemplate();
     $actionsLine = 'Actions<hr />';
     $dateLines = '';
     $ownerRow = '';
     $assigneeRow = '';
     $contentRow = '';
     //create actions line
     $flags = $this->getActionFlags();
     $actions = array();
     if (!empty($flags['complete'])) {
         $actions[] = '<a action="complete" class="task-action ib-done">' . L\get('Complete') . '</a>';
     }
     if (!empty($flags['close'])) {
         $actions[] = '<a action="close" class="task-action ib-done-all">' . L\get('Close') . '</a>';
     }
     if (!empty($flags['reopen'])) {
         $actions[] = '<a action="reopen" class="task-action ib-repeat">' . L\get('Reopen') . '</a>';
     }
     $actionsLine = '<div class="task-actions">' . implode(' ', $actions) . '</div>';
     //create date and status row
     $ed = $this->getEndDate();
     $status = $this->getStatus();
     if (!empty($ed)) {
         $endDate = Util\formatTaskTime($ed, !$sd['task_allday']);
         // $endDate = empty($sd['task_allday'])
         //     ? Util\formatDateTimePeriod($ed, null, @$_SESSION['user']['cfg']['timezone'])
         //     : Util\formatDatePeriod($ed, null, @$_SESSION['user']['cfg']['timezone']);
         $dateLines = '<tr><td class="prop-key">' . L\get('Due') . ':</td><td>' . $endDate . '</td></tr>';
         // $dateLine .= '<div class="date">' . $endDate . '</div>';
     }
     if (!empty($sd['task_d_closed'])) {
         $dateLines .= '<tr><td class="prop-key">' . L\get('Completed') . ':</td><td>' . Util\formatAgoTime($sd['task_d_closed']) . '</td></tr>';
     }
     //create owner row
     $v = $this->getOwner();
     if (!empty($v)) {
         $cn = User::getDisplayName($v);
         $cdt = Util\formatAgoTime($data['cdate']);
         $cd = Util\formatDateTimePeriod($data['cdate'], null, @$_SESSION['user']['cfg']['timezone']);
         $ownerRow = '<tr><td class="prop-key">' . L\get('Owner') . ':</td><td>' . '<table class="prop-val people"><tbody>' . '<tr><td class="user"><img class="photo32" src="photo/' . $v . '.jpg?32=' . User::getPhotoParam($v) . '" style="width:32px; height: 32px" alt="' . $cn . '" title="' . $cn . '"></td>' . '<td><b>' . $cn . '</b><p class="gr">' . L\get('Created') . ': ' . '<span class="dttm" title="' . $cd . '">' . $cdt . '</span></p></td></tr></tbody></table>' . '</td></tr>';
     }
     //create assignee row
     $v = $this->getFieldValue('assigned', 0);
     if (!empty($v['value'])) {
         $isOwner = $this->isOwner();
         $assigneeRow .= '<tr><td class="prop-key">' . L\get('TaskAssigned') . ':</td><td><table class="prop-val people"><tbody>';
         $v = Util\toNumericArray($v['value']);
         $dateFormat = \CB\getOption('long_date_format') . ' H:i:s';
         foreach ($v as $id) {
             $un = User::getDisplayName($id);
             $completed = $this->getUserStatus($id) == static::$USERSTATUS_DONE;
             $flags = $this->getActionFlags($id);
             $cdt = '';
             //completed date title
             $dateText = '';
             if ($completed && !empty($sd['task_u_d_closed'][$id])) {
                 $cdt = Util\formatMysqlDate($sd['task_u_d_closed'][$id], $dateFormat);
                 $dateText = ': ' . Util\formatAgoTime($sd['task_u_d_closed'][$id]);
             }
             $assigneeRow .= '<tr><td class="user"><div style="position: relative">' . '<img class="photo32" src="photo/' . $id . '.jpg?32=' . User::getPhotoParam($id) . '" style="width:32px; height: 32px" alt="' . $un . '" title="' . $un . '">' . ($completed ? '<img class="done icon icon-tick-circle" src="/css/i/s.gif" />' : "") . '</div></td><td><b>' . $un . '</b>' . '<p class="gr" title="' . $cdt . '">' . ($completed ? L\get('Completed') . $dateText . ($isOwner ? ' <a class="bt task-action click" action="markincomplete" uid="' . $id . '">' . L\get('revoke') . '</a>' : '') : L\get('waitingForAction') . ($isOwner ? ' <a class="bt task-action click" action="markcomplete" uid="' . $id . '">' . L\get('complete') . '</a>' : '')) . '</p></td></tr>';
         }
         $assigneeRow .= '</tbody></table></td></tr>';
     }
     //create description row
     $v = $this->getFieldValue('description', 0);
     if (!empty($v['value'])) {
         $tf = $template->getField('description');
         $v = $template->formatValueForDisplay($tf, $v);
         $contentRow = '<tr><td class="prop-val" colspan="2">' . $v . '</td></tr>';
     }
     //insert rows
     $p = $pb[0];
     $pos = strrpos($p, '<tbody>');
     $p = substr($p, $pos + 7);
     $pos = strrpos($p, '</tbody>');
     if ($pos !== false) {
         $p = substr($p, 0, $pos);
     }
     $pb[0] = $actionsLine . '<table class="obj-preview"><tbody>' . $dateLines . $p . $ownerRow . $assigneeRow . $contentRow . '<tbody></table>';
     return $pb;
 }
Exemplo n.º 10
0
 /**
  * get the list of objects referenced inside another object
  * @param  array | int $p params
  * @return json        response
  */
 public static function getAssociatedObjects($p)
 {
     $data = array();
     if (is_numeric($p)) {
         $p = array('id' => $p);
     }
     if (empty($p['id']) && empty($p['template_id'])) {
         return array('success' => true, 'data' => $data, 's' => '1');
     }
     $ids = array();
     $template = null;
     if (!empty($p['id'])) {
         // SECURITY: check if current user has at least read access to this case
         if (!Security::canRead($p['id'])) {
             throw new \Exception(L\get('Access_denied'));
         }
         /* select distinct associated case ids from the case */
         $obj = new Objects\Object($p['id']);
         $obj->load();
         $template = $obj->getTemplate();
         $linearData = $obj->getLinearData();
         foreach ($linearData as $f) {
             $tf = $template->getField($f['name']);
             if ($tf['type'] == '_objects') {
                 $a = Util\toIntArray(@$f['value']);
                 $ids = array_merge($ids, $a);
             }
         }
     } else {
         $template = new Objects\Template($p['template_id']);
         $template->load();
     }
     if (!empty($p['data']) && is_array($p['data'])) {
         foreach ($p['data'] as $key => $value) {
             $a = Util\toIntArray($value);
             $ids = array_merge($ids, $a);
         }
     }
     if ($template) {
         $templateData = $template->getData();
         foreach ($templateData['fields'] as $field) {
             if (!empty($field['cfg']['value'])) {
                 $a = Util\toIntArray($field['cfg']['value']);
                 $ids = array_merge($ids, $a);
             }
         }
     }
     $ids = array_unique($ids);
     if (empty($ids)) {
         return array('success' => true, 'data' => array());
     }
     /* end of select distinct case ids from the case */
     $data = Search::getObjects($ids, 'id,template_id,name,date,status:task_status');
     $data = array_values($data);
     return array('success' => true, 'data' => $data);
 }
Exemplo n.º 11
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;
 }
Exemplo n.º 12
0
 /**
  * update objects custom data
  * @return boolean
  */
 protected function updateCustomData()
 {
     parent::updateCustomData();
     /* saving template data to templates and templates_structure tables */
     $p =& $this->data;
     $saveFields = array();
     $saveValues = array($this->id);
     $params = array();
     $i = 2;
     foreach ($this->tableFields as $fieldName) {
         $field = null;
         if (!empty($this->template)) {
             $field = $this->template->getField($fieldName);
         }
         if (isset($p[$fieldName]) && $fieldName !== 'id') {
             $value = $p[$fieldName];
             $value = is_scalar($value) || is_null($value) ? $value : Util\jsonEncode($value);
             $saveFields[] = $fieldName;
             $saveValues[] = $value;
             $params[] = "`{$fieldName}` = \${$i}";
             $i++;
         } elseif (!empty($field)) {
             $value = @$this->getFieldValue($fieldName, 0)['value'];
             $value = is_scalar($value) || is_null($value) ? $value : Util\jsonEncode($value);
             $saveFields[] = $fieldName;
             $saveValues[] = $value;
             $params[] = "`{$fieldName}` = \${$i}";
             $i++;
         } else {
             // this if should be removed after complete migration to language abreviation titles
             if (in_array($fieldName, array('l1', 'l2', 'l3', 'l4'))) {
                 $lang = @\CB\Config::get('languages')[$fieldName[1] - 1];
                 if (!empty($lang)) {
                     $value = @$this->getFieldValue($lang, 0)['value'];
                     $saveFields[] = $fieldName;
                     $saveValues[] = $value;
                     $params[] = "`{$fieldName}` = \${$i}";
                     $i++;
                 }
             }
         }
     }
     if (!empty($saveFields)) {
         DB\dbQuery('UPDATE templates
             SET ' . implode(',', $params) . '
             WHERE id = $1', $saveValues) or die(DB\dbQueryError());
     }
     $this->saveFields();
 }
Exemplo n.º 13
0
 /**
  * method to collect solr data from object data
  * according to template fields configuration
  * and store it in sys_data onder "solr" property
  * @return void
  */
 protected function collectSolrData()
 {
     parent::collectSolrData();
     $sd =& $this->data['sys_data']['solr'];
     $res = DB\dbQuery('SELECT c.size
         ,(SELECT count(*)
             FROM files_versions
             WHERE file_id = f.id
         ) `versions`
         FROM files f
         LEFT JOIN files_content c
             ON f.content_id = c.id
         WHERE f.id = $1', $this->id) or die(DB\dbQueryError());
     if ($r = $res->fetch_assoc()) {
         $sd['size'] = $r['size'];
         $sd['versions'] = intval($r['versions']);
     }
     $res->close();
 }