/** * method to analize grouping params and add group column to result * @param array $p search params * @return void */ protected function analizeGrouping(&$p) { if (empty($p['result']['view']['group']['property'])) { return; } //sync grouping sort direction with sorting if same column $result =& $p['result']; $view =& $result['view']; $group =& $view['group']; if (!empty($view['sort'])) { if (@$group['property'] == $view['sort']['property']) { $group['direction'] = $view['sort']['direction']; } else { $group['direction'] = 'ASC'; } } //end of sync $field = $group['property']; $data =& $p['result']['data']; $count = sizeof($data); for ($i = 0; $i < $count; $i++) { $d =& $data[$i]; $v = @$d[$field]; switch ($field) { case 'cid': case 'uid': case 'oid': if (empty($v)) { $d['group'] = ''; $d['groupText'] = 'none'; } else { $d['group'] = $v; $d['groupText'] = User::getDisplayName($d[$field]); } break; case 'date': case 'date_end': case 'cdate': case 'udate': case 'ddate': case 'task_d_closed': if (empty($v)) { $d['group'] = 'empty'; $d['groupText'] = 'empty'; } else { $d['group'] = substr($v, 0, 7) . '-01T00:00:00Z'; $d['groupText'] = Util\formatMysqlDate($d['group'], 'Y, F'); } break; case 'size': if (empty($v)) { $d['group'] = 'up to 1 MB'; } else { $t = Util\formatFileSize($v); $d['size'] .= ' - ' . $t; $t = explode(' ', $t); if (@$t[1] == 'KB' || $t[0] <= 1) { $t = 1; } else { $q = floor($t[0] / 10) * 10; $t = $t[0] > $q ? $q + 10 : $q; } $d['size'] .= ' - ' . $t; $d['group'] = $t < 1 ? 'up to 1 MB' : 'up to ' . $t . ' MB'; } break; default: if (empty($d[$field])) { $d['group'] = 'empty'; } else { //split values by comma and duplicate records if multivalued $values = is_array($d[$field]) ? $d[$field] : explode(',', $d[$field]); $d['group'] = trim(array_shift($values)); for ($j = 0; $j < sizeof($values); $j++) { $newRecord = $d; $newRecord['group'] = trim($values[$j]); array_push($data, $newRecord); } } } } }
/** * 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; }
/** * formats a value for display according to it's field definition * @param array | int $field array of field properties or field id * @param variant $value field value to be formated * @param boolean $html default true - format for html, otherwise format for text display * @return varchar formated value */ public static function formatValueForDisplay($field, $value, $html = true) { $cacheVarName = ''; if (is_numeric($field)) { $field = $this->data->fields[$field]; } //condition is specified for values from search templates $condition = null; if (is_array($value)) { if (isset($value['cond'])) { $condition = Template::formatConditionForDisplay($field, $value['cond'], $html) . ' '; } if (isset($value['value'])) { $value = $value['value']; } else { $value = null; } } //we'll cache scalar by default, but will exclude textual fields $cacheValue = is_scalar($value); if ($cacheValue) { $fid = empty($field['id']) ? $field['name'] : $field['id']; $cacheVarName = 'dv' . $html . '_' . $fid . '_' . $value; //check if value is in cache and return if (Cache::exist($cacheVarName)) { return Cache::get($cacheVarName); } } /*check if field is not rezerved field for usernames (cid, oid, uid, did)*/ if (!empty($field['name']) && in_array($field['name'], array('cid', 'oid', 'uid', 'did'))) { $value = Util\toNumericArray($value); for ($i = 0; $i < sizeof($value); $i++) { $value[$i] = User::getDisplayName($value[$i]); } $value = implode(', ', $value); } else { switch ($field['type']) { case 'boolean': case 'checkbox': $value = empty($value) ? '' : ($value < 0 ? L\get('no') : L\get('yes')); break; case '_sex': switch ($value) { case 'm': $value = L\get('male'); break; case 'f': $value = L\get('female'); break; default: $value = ''; } break; case '_language': @($value = @\CB\Config::get('language_settings')[\CB\Config::get('languages')[$value - 1]][0]); break; case 'combo': case '_objects': if (empty($value)) { $value = ''; break; } $ids = Util\toNumericArray($value); if (empty($ids)) { if (empty($field['cfg']['source']) || !is_array($field['cfg']['source'])) { $value = ''; } break; } $value = array(); if (in_array(@$field['cfg']['source'], array('users', 'groups', 'usersgroups'))) { $udp = UsersGroups::getDisplayData($ids); foreach ($ids as $id) { if (empty($udp[$id])) { continue; } $r =& $udp[$id]; $label = @htmlspecialchars(Util\coalesce($r['title'], $r['name']), ENT_COMPAT); if ($html) { switch (@$field['cfg']['renderer']) { case 'listGreenIcons': $label = '<li class="icon-padding icon-element">' . $label . '</li>'; break; // case 'listObjIcons': // case 'listObjIcons': default: $icon = empty($r['iconCls']) ? 'icon-none' : $r['iconCls']; $label = '<li class="icon-padding ' . $icon . '">' . $label . '</li>'; break; } } $value[] = $label; } } else { $objects = \CB\Objects::getCachedObjects($ids); foreach ($ids as $id) { if (empty($objects[$id])) { continue; } $obj =& $objects[$id]; $d = $obj->getData(); $label = $obj->getHtmlSafeName(); $pids = $d['pids']; if ($html && !empty($pids)) { $pids = str_replace(',', '/', $pids); $linkType = empty($field['cfg']['linkType']) ? '' : 'link-type-' . $field['cfg']['linkType']; $label = '<a class="click ' . $linkType . '" template_id="' . $d['template_id'] . '" path="' . $pids . '" nid="' . $id . '">' . $label . '</a>'; } switch (@$field['cfg']['renderer']) { case 'listGreenIcons': $value[] = $html ? '<li class="icon-padding icon-element">' . $label . '</li>' : $label; break; // case 'listObjIcons': // case 'listObjIcons': default: $icon = \CB\Browser::getIcon($d); if (empty($icon)) { $icon = 'icon-none'; } $value[] = $html ? '<li class="icon-padding ' . $icon . '">' . $label . '</li>' : $label; break; } } } $value = $html ? '<ul class="clean">' . implode('', $value) . '</ul>' : implode(', ', $value); break; case '_fieldTypesCombo': $value = L\get(@static::$fieldTypeNames[$value]); break; case 'date': $value = Util\formatMysqlDate(Util\dateISOToMysql($value)); break; case 'datetime': $value = Util\UTCTimeToUserTimezone($value); break; case 'time': if (empty($value)) { continue; } $format = empty($field['format']) ? 'H:i' : $field['format']; if (is_numeric($value)) { $s = $value % 60; $value = floor($value / 60); $m = $value % 60; $value = floor($value / 60); if (strlen($value) < 2) { $value = '0' . $value; } if (strlen($m) < 2) { $m = '0' . $m; } $value .= ':' . $m; if (!empty($s)) { if (strlen($s) < 2) { $s = '0' . $s; } $value .= ':' . $s; } } else { $date = \DateTime::createFromFormat($format, $value); if (is_object($date)) { $value = $date->format($format); } } break; case 'html': $cacheValue = false; // $value = trim(strip_tags($value)); // $value = nl2br($value); break; case 'varchar': case 'memo': case 'text': $cacheValue = false; $renderers = ''; if (!empty($field['cfg']['linkRenderers'])) { $renderers = $field['cfg']['linkRenderers']; } elseif (!empty($field['cfg']['text_renderer'])) { $renderers = $field['cfg']['text_renderer']; } $value = empty($renderers) ? nl2br(htmlspecialchars($value, ENT_COMPAT)) : nl2br(Comment::processAndFormatMessage($value), $renderers); break; default: if (is_array($value)) { $cacheValue = false; $value = Util\jsonEncode($value); } else { $value = htmlspecialchars($value, ENT_COMPAT); } } } if ($cacheValue) { Cache::set($cacheVarName, $condition . $value); } return $condition . $value; }