Example #1
0
 public function onSolrQuery(&$p)
 {
     $result =& $p['result'];
     $data =& $result['data'];
     $ip =& $p['inputParams'];
     $view =& $ip['view'];
     $facets =& $ip['facets'];
     $coloring = empty($view['coloring']) ? array() : Util\toTrimmedArray($view['coloring']);
     $view['coloring'] = $coloring;
     // detect active coloring facet
     $coloringField = $this->getActiveColoringField($p);
     $activeFacetClass = null;
     $types = array();
     foreach ($coloring as $facetAlias) {
         if (!empty($facets[$facetAlias]->field)) {
             $types[] = $facets[$facetAlias]->field;
             if ($coloringField == $facets[$facetAlias]->field) {
                 $activeFacetClass =& $facets[$facetAlias];
             }
         }
     }
     $result['view']['coloring'] = $types;
     $coloringItems = array();
     if (!empty($activeFacetClass)) {
         $cf = $activeFacetClass->getClientData(array('colors' => true));
         $result['facets'][$activeFacetClass->field] = $cf;
         $coloringItems = $cf['items'];
     }
     $rez = array();
     foreach ($data as $r) {
         $fv = empty($r[$coloringField]) ? array() : Util\toNumericArray($r[$coloringField]);
         if (empty($fv)) {
             $r['cls'] = 'user-color-' . $r['cid'];
             $rez[] = $r;
         } else {
             foreach ($fv as $v) {
                 if (!empty($coloringItems[$v])) {
                     $c = $coloringItems[$v];
                     if (!empty($c['cls'])) {
                         $r['cls'] = $c['cls'];
                     }
                     if (!empty($c['color'])) {
                         $r['style'] = 'background-color: ' . $c['color'];
                     }
                 }
                 $rez[] = $r;
             }
         }
     }
     $result['data'] = $rez;
 }
Example #2
0
 /**
  * get sort options from config
  * @param  string $defaultDirection default direction to use if not specified in config
  * @param  string $defaultType      default type to use if not specified in config
  * @return array  | null
  */
 protected function getSortParams($defaultDirection = 'asc', $defaultType = 'asString')
 {
     $rez = null;
     $cfg =& $this->config;
     if (!empty($cfg['sort'])) {
         if (is_array($cfg['sort'])) {
             $rez = $cfg['sort'];
             if (empty($rez['direction'])) {
                 $rez['direction'] = $defaultDirection;
             }
             if (empty($rez['type'])) {
                 $rez['type'] = $defaultType;
             }
         } else {
             $parts = Util\toTrimmedArray($cfg['sort'], ' ');
             $rez = array('property' => $parts[0], 'direction' => empty($parts[1]) ? $defaultDirection : $parts[1], 'type' => empty($parts[2]) ? $defaultType : $parts[2]);
         }
     }
     return $rez;
 }
Example #3
0
 /**
  * analize sort param and replace sort fields if needed
  * @return void
  */
 protected function replaceSortFields()
 {
     if (!empty($this->params['sort'])) {
         $sort = Util\toTrimmedArray($this->params['sort']);
         foreach ($sort as $k => $el) {
             list($f, $s) = explode(' ', $el);
             if (!empty($this->replaceSortFields[$f])) {
                 $sort[$k] = $this->replaceSortFields[$f] . ' ' . $s;
             }
         }
         $this->params['sort'] = implode(', ', $sort);
     }
 }
Example #4
0
 /**
  * process a message:
  *     - replace urls with links
  *     - replace object references with links
  * @param varchar $message
  */
 public static function processAndFormatMessage($message, $replacements = 'user,object,url')
 {
     if (empty($message)) {
         return $message;
     }
     $replacements = Util\toTrimmedArray($replacements);
     // replace urls with links
     if (in_array('url', $replacements)) {
         $message = \Kwi\UrlLinker::getInstance()->linkUrlsAndEscapeHtml($message);
     }
     //replace object references with links
     if (in_array('object', $replacements) && preg_match_all('/(.?)#(\\d+)(.?)/', $message, $matches, PREG_SET_ORDER)) {
         foreach ($matches as $match) {
             // check if not a html code
             if ($match[1] == '&' && $match[3] == ';') {
                 continue;
             }
             $templateId = Objects::getTemplateId($match[2]);
             $name = Objects::getName($match[2]);
             $name = strlen($name) > 30 ? mb_substr($name, 0, 30) . '…' : $name;
             $message = str_replace($match[0], $match[1] . '<a class="click obj-ref" itemid="' . $match[2] . '" templateid= "' . $templateId . '" title="' . $name . '"' . '>#' . $match[2] . '</a>' . $match[3], $message);
         }
     }
     //replace users with their names
     if (in_array('user', $replacements) && preg_match_all('/@([\\w\\.\\-]+[\\w])/', $message, $matches, PREG_SET_ORDER)) {
         foreach ($matches as $match) {
             $userId = DM\User::getIdByName($match[1]);
             if (is_numeric($userId)) {
                 $userName = $match[1];
                 $message = str_replace($match[0], '<span class="cDB user-ref" title="' . User::getDisplayName($userId) . '">@' . $userName . '</span>', $message);
             }
         }
     }
     return $message;
 }
Example #5
0
 /**
  * get user id by email
  * @param  varchar $email
  * @return int     | null
  */
 public static function getIdByEmail($email)
 {
     $rez = null;
     $res = DB\dbQuery('SELECT id
             ,email
         FROM users_groups
         WHERE email LIKE $1
             AND enabled = 1
             AND did IS NULL', "%{$email}%") or die(DB\dbQueryError());
     while (($r = $res->fetch_assoc()) && empty($rez)) {
         $mails = Util\toTrimmedArray($r['email']);
         for ($i = 0; $i < sizeof($mails); $i++) {
             if (mb_strtolower($mails[$i]) == $email) {
                 $rez = $r['id'];
             }
         }
     }
     $res->close();
     return $rez;
 }
Example #6
0
 public function getLookupValues($fields, &$resultingTemplateField = null)
 {
     $rez = array();
     $fields = Util\toTrimmedArray($fields, '.');
     $objects = array(&$this);
     do {
         $fn = array_shift($fields);
         $values = array();
         foreach ($objects as &$o) {
             $tpl = $o->getTemplate();
             $tf = $tpl->getField($fn);
             if (!empty($tf)) {
                 $resultingTemplateField = $tf;
                 $v = $o->getFieldValue($fn);
                 if (!empty($v)) {
                     $values = array_merge($values, $v);
                 }
             }
         }
         $objects = array();
         foreach ($values as $v) {
             $v = is_array($v) ? @$v['value'] : $v;
             $v = Util\toNumericArray($v);
             foreach ($v as $id) {
                 $objects[] = \CB\Objects::getCachedObject($id);
             }
         }
         $rez = $values;
     } while (!empty($fields) && !empty($tf['type']) && $tf['type'] == '_objects');
     return $rez;
 }