/** * function to update parent followers when adding a comment * with this user and referenced users from comment * @return void */ protected function updateParentFollowers() { $p =& $this->data; $posd = $this->parentObj->getSysData(); $newUserIds = array(); $posd['lastComment'] = array('user_id' => User::getId(), 'date' => Util\dateMysqlToISO('now')); $fu = empty($posd['fu']) ? array() : $posd['fu']; $uid = User::getId(); if (!in_array($uid, $fu)) { $newUserIds[] = intval($uid); } //analize comment text and get referenced users if (preg_match_all('/@([^@\\s,!\\?]+)/', $p['data']['_title'], $matches, PREG_SET_ORDER)) { foreach ($matches as $match) { $uid = DM\User::getIdByName($match[1]); if (is_numeric($uid) && !in_array($uid, $fu) && !in_array($uid, $newUserIds)) { $newUserIds[] = $uid; } } } //update only if new users added if (!empty($newUserIds)) { $fu = array_merge($fu, $newUserIds); $fu = Util\toNumericArray($fu); $posd['fu'] = array_unique($fu); } //always update sys_data to change lastComment date $this->parentObj->updateSysData($posd); }
/** * function to update parent followers when adding a comment * with this user and referenced users from comment * @return void */ protected function updateParentFollowers() { $p =& $this->data; $po = $this->getParentObject(); $posd = $po->getSysData(); $newUserIds = array(); $posd['lastComment'] = array('user_id' => User::getId(), 'date' => Util\dateMysqlToISO('now')); $wu = empty($posd['wu']) ? array() : $posd['wu']; $uid = User::getId(); if (!in_array($uid, $wu)) { $newUserIds[] = intval($uid); } //analize comment text and get referenced users $this->lastMentionedUserIds = Util\getReferencedUsers($p['data']['_title']); foreach ($this->lastMentionedUserIds as $uid) { if (!in_array($uid, $wu)) { $newUserIds[] = $uid; } } //update only if new users added if (!empty($newUserIds)) { $wu = array_merge($wu, $newUserIds); $wu = Util\toNumericArray($wu); $posd['wu'] = array_unique($wu); } //always update sys_data to change lastComment date $po->updateSysData($posd); }
public function getData($id = false) { $rez = array('success' => true); parent::getData($id); $preview = Objects::getPreview($this->id); $obj = Objects::getCachedObject($this->id); if (empty($obj)) { return $rez; } $data = $obj->getData(); if (!empty($preview)) { $rez['data'] = array('preview' => $preview); } if (!empty($data)) { if (!empty($data['pids'])) { $path = explode(',', $data['pids']); array_pop($path); $rez['data']['pids'] = $rez['data']['path'] = implode('/', $path); $arr = array(&$rez['data']); Search::setPaths($arr); } foreach ($data as $k => $v) { if (in_array($k, array('id', 'template_id', 'date_end', 'cid', 'uid', 'cdate', 'udate'))) { if (in_array($k, array('date', 'date_end', 'cdate', 'udate'))) { $v = Util\dateMysqlToISO($v); } $rez['data'][$k] = $v; //add ago udate text if (in_array($k, array('cdate', 'udate'))) { $rez['data'][$k . '_ago_text'] = Util\formatAgoTime($v); } } } $rez['data']['name'] = $obj->getName(); } $rez['data']['can'] = $obj->getActionFlags(); //set status info for tasks if not active if ($obj->getType() == 'task') { $d =& $rez['data']; $d['status'] = ''; switch ($obj->getStatus()) { case Objects\Task::$STATUS_ACTIVE: break; case Objects\Task::$STATUS_CLOSED: //just add title css class and continue with default $d['titleCls'] = 'task-completed'; // break; // break; default: $d['status'] = $obj->getStatusText(); $d['statusCls'] = $obj->getStatusCSSClass(); } } return $rez; }
public function getData($id = false) { $rez = array('success' => true, 'data' => array()); parent::getData($id); $obj = $this->getObjectClass(); if (!is_object($obj)) { return $rez; } $data = $obj->getData(); $rez['data'] = array_intersect_key($data, array('id' => 1, 'name' => 1, 'template_id' => 1, 'cid' => 1, 'cdate' => 1, 'uid' => 1, 'udate' => 1, 'dstatus' => 1, 'did' => 1, 'ddate' => 1, 'size' => 1)); $d =& $rez['data']; $pids = Util\toNumericArray($data['pids']); array_pop($pids); $d['pids'] = $d['path'] = implode('/', $pids); $arr = array(&$d); Search::setPaths($arr); $d['template_name'] = Objects::getName($d['template_id']); $sd = $obj->getSysData(); $userId = User::getId(); $d['subscription'] = 'ignore'; if (!empty($sd['fu']) && in_array($userId, $sd['fu'])) { $d['subscription'] = 'watch'; //follow } if (!empty($sd['wu']) && in_array($userId, $sd['wu'])) { $d['subscription'] = 'watch'; } $d['cid_text'] = User::getDisplayName($d['cid']); $d['cdate_ago_text'] = Util\formatAgoTime($d['cdate']); $d['cdate'] = Util\dateMysqlToISO($d['cdate']); $d['udate'] = Util\dateMysqlToISO($d['udate']); $d['uid_text'] = User::getDisplayName($d['uid']); $d['udate_ago_text'] = Util\formatAgoTime($d['udate']); if (!empty($d['dstatus'])) { $d['did_text'] = User::getDisplayName($d['did']); $d['ddate_text'] = Util\formatAgoTime($d['ddate']); } return $rez; }
public function getLastActionData() { $data = $this->getData(); $sysData = empty($data['sys_data']) ? $this->getSysData() : $data['sys_data']; $rez = array(); if (!empty($sysData['lastAction'])) { $rez = $sysData['lastAction']; } else { if (!empty($sysData['lastComment'])) { $rez = array('type' => 'comment', 'time' => $sysData['lastComment']['date'], 'users' => array($sysData['lastComment']['user_id'] => 0)); } if (!empty($data['udate']) && (empty($rez['time']) || $data['udate'] > $rez['time'])) { $rez = array('type' => 'update', 'time' => Util\dateMysqlToISO($data['udate']), 'users' => array($data['uid'] => 0)); } if (empty($rez['time'])) { $date = Util\dateMysqlToISO(empty($data['cdate']) ? 'now' : $data['cdate']); $rez = array('type' => 'create', 'time' => $date, 'users' => array($data['cid'] => 0)); } } return $rez; }
/** * get filtering query array * @param array &$p * @return array */ protected function getFilterQueryParam(&$p) { //by default filter deleted nodes $fq = array('dstatus:0'); if (!empty($p['dstatus'])) { $fq = array('dstatus:' . intval($p['dstatus'])); } //check if fq is set and add it to result if (!empty($p['fq'])) { if (!is_array($p['fq'])) { $p['fq'] = array($p['fq']); } $fq = array_merge($fq, $p['fq']); } //check system param $sysParam = 'system:[0 TO 1]'; if (isset($p['system'])) { if (is_numeric($p['system']) || preg_match('/^\\[\\d+ TO \\d+\\]$/', $p['system'])) { $sysParam = 'system:' . $p['system']; } } $fq[] = $sysParam; /* adding additional query filters */ //check securitySets param $ss = $this->getSecuritySetsParam($p); if (!empty($ss)) { $fq[] = $ss; } //check numeric params $params = array('pid' => 'pid', 'ids' => 'id', 'pids' => 'pids', 'templates' => 'template_id'); foreach ($params as $param => $fn) { if (!empty($p[$param])) { $ids = Util\toNumericArray($p[$param]); if (!empty($ids)) { $fq[] = $fn . ':(' . implode(' OR ', $ids) . ')'; } } } if (!empty($p['template_types'])) { $types = Util\toTrimmedArray($p['template_types']); $filteredTypes = array(); foreach ($types as $tt) { if (preg_match('/^[a-z]+$/i', $tt)) { $filteredTypes[] = $tt; } } if (!empty($filteredTypes)) { $fq[] = 'template_type:("' . implode('" OR "', $filteredTypes) . '")'; } } // $folderTemplates = Config::get('folder_templates'); // if (isset($p['folders']) && !empty($folderTemplates)) { // $fq[] = '!template_id:('.implode(' OR ', $folderTemplates).')'; // } if (!empty($p['dateStart'])) { $fq[] = 'date:[' . Util\dateMysqlToISO($p['dateStart']) . ' TO ' . (empty($p['dateEnd']) ? '*' : Util\dateMysqlToISO($p['dateEnd'])) . ']'; } return $fq; }