public function testCategory() { $category = new Category(); $category->setDomain('http://do.main')->setTitle('News')->setDomain('https://www.example.com'); $this->assertEquals('News', $category->getTitle()); $this->assertEquals('https://www.example.com', $category->getDomain()); }
public function create($title, $content, $idAuthor) { $category = new Category($this->db); try { $category->setTitle($title); $category->setContent($content); $category->setIdAuthor($idAuthor); } catch (Exception $e) { $errors = $e->getMessage(); echo $errors; } if (!isset($err)) { $title = $this->db->quote($category->getTitle()); $content = $this->db->quote($category->getContent()); $idAuthor = $category->getIdAuthor(); $query = 'INSERT INTO category(title, content, idAuthor) VALUE (' . $title . ',' . $content . ',' . $idAuthor . ')'; } $res = $this->db->exec($query); if ($res) { $id = $this->db->lastInsertId(); if ($id) { return $this->findById($id); } else { throw new Exception('Database error'); } } else { throw new Exception($errors); } }
/** * Метод добавления новой категории * @param Category $category - категория * @return bool - категория добавлена/не добавлена */ public function create($category) { $db = DataBase::getInstance(); $connection = $db->connect(); $sql = "INSERT INTO " . self::TABLE_NAME . " (title) VALUES (:title)"; $stmt = $connection->prepare($sql); $result = $stmt->execute(array('title' => $category->getTitle())); $db->close(); return $result; }
/** * Add a subcategory to the internal lists */ function addSubcategoryObject(Category $cat, $sortkey, $pageLength) { global $wgRequest; $title = $cat->getTitle(); if ($wgRequest->getCheck('notree')) { return parent::addSubcategoryObject($cat, $sortkey, $pageLength); } $tree = $this->getCategoryTree(); $this->children[] = $tree->renderNodeInfo($title, $cat); $this->children_start_char[] = $this->getSubcategorySortChar($title, $sortkey); }
public function testSetGetTitle() { // Arrange $c = new Category(); $c->setTitle('drinks'); $expectedResult = 'drinks'; // Act $result = $c->getTitle(); // Assert $this->assertEquals($result, $expectedResult); }
/** * Method used to bulk update a list of issues * * @return boolean */ public static function bulkUpdate() { // check if user performing this chance has the proper role if (Auth::getCurrentRole() < User::ROLE_MANAGER) { return -1; } $items = (array) $_POST['item']; $new_status_id = (int) $_POST['status']; $new_release_id = (int) $_POST['release']; $new_priority_id = (int) $_POST['priority']; $new_category_id = (int) $_POST['category']; foreach ($items as $issue_id) { $issue_id = (int) $issue_id; if (!self::canAccess($issue_id, Auth::getUserID())) { continue; } if (self::getProjectID($issue_id) != Auth::getCurrentProject()) { // make sure issue is not in another project continue; } $issue_details = self::getDetails($issue_id); $updated_fields = array(); // update assignment if (count(@$_POST['users']) > 0) { $users = (array) $_POST['users']; // get who this issue is currently assigned too $stmt = 'SELECT isu_usr_id, usr_full_name FROM {{%issue_user}}, {{%user}} WHERE isu_usr_id = usr_id AND isu_iss_id = ?'; try { $current_assignees = DB_Helper::getInstance()->getPair($stmt, array($issue_id)); } catch (DbException $e) { return -1; } foreach ($current_assignees as $usr_id => $usr_name) { if (!in_array($usr_id, $users)) { self::deleteUserAssociation($issue_id, $usr_id, false); } } $new_user_names = array(); $new_assignees = array(); foreach ($users as $usr_id) { $usr_id = (int) $usr_id; $new_user_names[$usr_id] = User::getFullName($usr_id); // check if the issue is already assigned to this person $stmt = 'SELECT COUNT(*) AS total FROM {{%issue_user}} WHERE isu_iss_id=? AND isu_usr_id=?'; $total = DB_Helper::getInstance()->getOne($stmt, array($issue_id, $usr_id)); if ($total > 0) { continue; } else { $new_assignees[] = $usr_id; // add the assignment self::addUserAssociation(Auth::getUserID(), $issue_id, $usr_id, false); Notification::subscribeUser(Auth::getUserID(), $issue_id, $usr_id, Notification::getAllActions()); } } $prj_id = Auth::getCurrentProject(); $usr_ids = self::getAssignedUserIDs($issue_id); Workflow::handleAssignmentChange($prj_id, $issue_id, Auth::getUserID(), $issue_details, $usr_ids, false); Notification::notifyNewAssignment($new_assignees, $issue_id); $updated_fields['Assignment'] = History::formatChanges(implode(', ', $current_assignees), implode(', ', $new_user_names)); } // update status if ($new_status_id) { $old_status_id = self::getStatusID($issue_id); $res = self::setStatus($issue_id, $new_status_id, false); if ($res == 1) { $updated_fields['Status'] = History::formatChanges(Status::getStatusTitle($old_status_id), Status::getStatusTitle($new_status_id)); } } // update release if ($new_release_id) { $old_release_id = self::getRelease($issue_id); $res = self::setRelease($issue_id, $new_release_id); if ($res == 1) { $updated_fields['Release'] = History::formatChanges(Release::getTitle($old_release_id), Release::getTitle($new_release_id)); } } // update priority if ($new_priority_id) { $old_priority_id = self::getPriority($issue_id); $res = self::setPriority($issue_id, $new_priority_id); if ($res == 1) { $updated_fields['Priority'] = History::formatChanges(Priority::getTitle($old_priority_id), Priority::getTitle($new_priority_id)); } } // update category if ($new_category_id) { $old_category_id = self::getCategory($issue_id); $res = self::setCategory($issue_id, $new_category_id); if ($res == 1) { $updated_fields['Category'] = History::formatChanges(Category::getTitle($old_category_id), Category::getTitle($new_category_id)); } } if (count($updated_fields) > 0) { // log the changes $changes = ''; $k = 0; foreach ($updated_fields as $key => $value) { if ($k > 0) { $changes .= '; '; } $changes .= "{$key}: {$value}"; $k++; } $usr_id = Auth::getUserID(); History::add($issue_id, $usr_id, 'issue_bulk_updated', 'Issue updated ({changes}) by {user}', array('changes' => $changes, 'user' => User::getFullName(Auth::getUserID()))); } // close if request if (isset($_REQUEST['closed_status']) && !empty($_REQUEST['closed_status'])) { self::close(Auth::getUserID(), $issue_id, true, 0, $_REQUEST['closed_status'], $_REQUEST['closed_message'], $_REQUEST['notification_list']); } } return true; }
/** * Add a subcategory to the internal lists, using a Category object * @param Category $cat * @param string $sortkey * @param int $pageLength */ function addSubcategoryObject(Category $cat, $sortkey, $pageLength) { // Subcategory; strip the 'Category' namespace from the link text. $title = $cat->getTitle(); $this->children[] = $this->generateLink('subcat', $title, $title->isRedirect(), htmlspecialchars($title->getText())); $this->children_start_char[] = $this->getSubcategorySortChar($cat->getTitle(), $sortkey); }
function __construct($options) { $this->options = $options; if (isset($this->options['lang'])) { $this->locale = $this->options['lang']; } else { $this->locale = getOption('locale'); } $this->locale_xml = strtr($this->locale, '_', '-'); if (isset($this->options['sortdir'])) { $this->sortdirection = strtolower($this->options['sortdir']) != 'asc'; } else { $this->sortdirection = true; } if (isset($this->options['sortorder'])) { $this->sortorder = $this->options['sortorder']; } else { $this->sortorder = NULL; } switch ($this->feedtype) { case 'comments': if (isset($this->options['type'])) { $this->commentfeedtype = $this->options['type']; } else { $this->commentfeedtype = 'all'; } if (isset($this->options['id'])) { $this->id = (int) $this->options['id']; } break; case 'gallery': if (isset($this->options['albumsmode'])) { $this->mode = 'albums'; } if (isset($this->options['folder'])) { $this->albumfolder = $this->options['folder']; $this->collection = true; } else { if (isset($this->options['albumname'])) { $this->albumfolder = $this->options['albumname']; $this->collection = false; } else { $this->collection = false; } } if (is_null($this->sortorder)) { if ($this->mode == "albums") { $this->sortorder = getOption($this->feed . "_sortorder_albums"); } else { $this->sortorder = getOption($this->feed . "_sortorder"); } } break; case 'news': if ($this->sortorder == 'latest') { $this->sortorder = NULL; } if (isset($this->options['category'])) { $this->catlink = $this->options['category']; $catobj = new Category($this->catlink); $this->cattitle = $catobj->getTitle(); $this->newsoption = 'category'; } else { $this->catlink = ''; $this->cattitle = ''; $this->newsoption = 'news'; } break; case 'pages': break; case 'null': //we just want the class instantiated return; } if (isset($this->options['itemnumber'])) { $this->itemnumber = (int) $this->options['itemnumber']; } else { $this->itemnumber = getOption($this->feed . '_items'); } }
<?php if (!path()) { draw_page('Поваренная книга программиста', dview('index_content', main_categories())); } elseif (is_category_path(path()) && is_category_exists(path())) { is_need_cache(true); $category = new Category(path()); keywords($category->keywords()); draw_page($category->getTitle(), dview('one_category', $category)); } elseif (is_example_path(path()) && is_example_exists(path())) { is_need_cache(true); $example = new Example(path()); keywords($example->keywords()); draw_page($example->prop('desc'), view('path_block', ['id' => $example->id()]) . view('one_example', ['data' => $example, 'show_link' => true])); } else { show_404(); }
function __construct(Category $category) { parent::__construct($category->getTitle(), RequestContext::getMain()); $this->limit = self::LIMIT; # BAC-265 $this->items = []; $this->count = 0; }
$res = Issue::clearDuplicateStatus($HTTP_GET_VARS["iss_id"]); $tpl->assign("clear_duplicate_result", $res); } elseif (@$HTTP_GET_VARS["cat"] == "delete_phone") { $res = Phone_Support::remove($HTTP_GET_VARS["id"]); $tpl->assign("delete_phone_result", $res); } elseif (@$HTTP_GET_VARS["cat"] == "new_status") { // XXX: need to call the workflow api in the following function? $res = Issue::setStatus($HTTP_GET_VARS["iss_id"], $HTTP_GET_VARS["new_sta_id"], true); if ($res == 1) { History::add($HTTP_GET_VARS["iss_id"], $usr_id, History::getTypeID('status_changed'), "Issue manually set to status '" . Status::getStatusTitle($HTTP_GET_VARS["new_sta_id"]) . "' by " . User::getFullName($usr_id)); } $tpl->assign("new_status_result", $res); } elseif (@$HTTP_GET_VARS["cat"] == "new_category") { $res = Issue::setCategory($HTTP_GET_VARS["iss_id"], $HTTP_GET_VARS["iss_prc_id"], true); if ($res == 1) { History::add($HTTP_GET_VARS["iss_id"], $usr_id, History::getTypeID('status_changed'), "Issue manually set to category '" . Category::getTitle($HTTP_GET_VARS["iss_prc_id"]) . "' by " . User::getFullName($usr_id)); } $tpl->assign("new_status_result", $res); } elseif (@$HTTP_GET_VARS["cat"] == "new_project") { $res = Issue::setProject($HTTP_GET_VARS["iss_id"], $HTTP_GET_VARS["iss_prj_id"], true); if ($res == 1) { History::add($HTTP_GET_VARS["iss_id"], $usr_id, History::getTypeID('status_changed'), "Issue manually set to project '" . Project::getName($HTTP_GET_VARS["iss_prj_id"]) . "' by " . User::getFullName($usr_id)); } $tpl->assign("new_status_result", $res); } elseif (@$HTTP_GET_VARS['cat'] == 'authorize_reply') { $res = Authorized_Replier::addUser($HTTP_GET_VARS["iss_id"], $usr_id); $tpl->assign('authorize_reply_result', $res); } elseif (@$HTTP_GET_VARS['cat'] == 'remove_quarantine') { if (Auth::getCurrentRole() > User::getRoleID('Developer')) { $res = Issue::setQuarantine($HTTP_GET_VARS['iss_id'], 0); $tpl->assign('remove_quarantine_result', $res);
/** * Method used to send a diff-style notification email to the issue * subscribers about updates to its attributes. * * @param integer $issue_id The issue ID * @param array $old The old issue details * @param array $new The new issue details * @param array $updated_custom_fields An array of the custom fields that were changed. */ public static function notifyIssueUpdated($issue_id, $old, $new, $updated_custom_fields) { $prj_id = Issue::getProjectID($issue_id); $diffs = array(); if (@$new['keep_assignments'] == 'no') { if (empty($new['assignments'])) { $new['assignments'] = array(); } $assign_diff = Misc::arrayDiff($old['assigned_users'], $new['assignments']); if (count($assign_diff) > 0) { $diffs[] = '-' . ev_gettext('Assignment List') . ': ' . $old['assignments']; @($diffs[] = '+' . ev_gettext('Assignment List') . ': ' . implode(', ', User::getFullName($new['assignments']))); } } if (isset($new['expected_resolution_date']) && @$old['iss_expected_resolution_date'] != $new['expected_resolution_date']) { $diffs[] = '-' . ev_gettext('Expected Resolution Date') . ': ' . $old['iss_expected_resolution_date']; $diffs[] = '+' . ev_gettext('Expected Resolution Date') . ': ' . $new['expected_resolution_date']; } if (isset($new['category']) && $old['iss_prc_id'] != $new['category']) { $diffs[] = '-' . ev_gettext('Category') . ': ' . Category::getTitle($old['iss_prc_id']); $diffs[] = '+' . ev_gettext('Category') . ': ' . Category::getTitle($new['category']); } if (isset($new['release']) && $old['iss_pre_id'] != $new['release']) { $diffs[] = '-' . ev_gettext('Release') . ': ' . Release::getTitle($old['iss_pre_id']); $diffs[] = '+' . ev_gettext('Release') . ': ' . Release::getTitle($new['release']); } if (isset($new['priority']) && $old['iss_pri_id'] != $new['priority']) { $diffs[] = '-' . ev_gettext('Priority') . ': ' . Priority::getTitle($old['iss_pri_id']); $diffs[] = '+' . ev_gettext('Priority') . ': ' . Priority::getTitle($new['priority']); } if (isset($new['severity']) && $old['iss_sev_id'] != $new['severity']) { $diffs[] = '-' . ev_gettext('Severity') . ': ' . Severity::getTitle($old['iss_sev_id']); $diffs[] = '+' . ev_gettext('Severity') . ': ' . Severity::getTitle($new['severity']); } if (isset($new['status']) && $old['iss_sta_id'] != $new['status']) { $diffs[] = '-' . ev_gettext('Status') . ': ' . Status::getStatusTitle($old['iss_sta_id']); $diffs[] = '+' . ev_gettext('Status') . ': ' . Status::getStatusTitle($new['status']); } if (isset($new['resolution']) && $old['iss_res_id'] != $new['resolution']) { $diffs[] = '-' . ev_gettext('Resolution') . ': ' . Resolution::getTitle($old['iss_res_id']); $diffs[] = '+' . ev_gettext('Resolution') . ': ' . Resolution::getTitle($new['resolution']); } if (isset($new['estimated_dev_time']) && $old['iss_dev_time'] != $new['estimated_dev_time']) { $diffs[] = '-' . ev_gettext('Estimated Dev. Time') . ': ' . Misc::getFormattedTime($old['iss_dev_time'] * 60); $diffs[] = '+' . ev_gettext('Estimated Dev. Time') . ': ' . Misc::getFormattedTime($new['estimated_dev_time'] * 60); } if (isset($new['summary']) && $old['iss_summary'] != $new['summary']) { $diffs[] = '-' . ev_gettext('Summary') . ': ' . $old['iss_summary']; $diffs[] = '+' . ev_gettext('Summary') . ': ' . $new['summary']; } if (isset($new['percent_complete']) && $old['iss_original_percent_complete'] != $new['percent_complete']) { $diffs[] = '-' . ev_gettext('Percent complete') . ': ' . $old['iss_original_percent_complete']; $diffs[] = '+' . ev_gettext('Percent complete') . ': ' . $new['percent_complete']; } if (isset($new['description']) && $old['iss_description'] != $new['description']) { $old['iss_description'] = explode("\n", $old['iss_original_description']); $new['description'] = explode("\n", $new['description']); $diff = new Text_Diff($old['iss_description'], $new['description']); $renderer = new Text_Diff_Renderer_unified(); $desc_diff = explode("\n", trim($renderer->render($diff))); $diffs[] = 'Description:'; foreach ($desc_diff as $diff) { $diffs[] = $diff; } } $data = Issue::getDetails($issue_id); $data['diffs'] = implode("\n", $diffs); $data['updated_by'] = User::getFullName(Auth::getUserID()); $all_emails = array(); $role_emails = array(User::ROLE_VIEWER => array(), User::ROLE_REPORTER => array(), User::ROLE_CUSTOMER => array(), User::ROLE_USER => array(), User::ROLE_DEVELOPER => array(), User::ROLE_MANAGER => array(), User::ROLE_ADMINISTRATOR => array()); $users = self::getUsersByIssue($issue_id, 'updated'); foreach ($users as $user) { if (empty($user['sub_usr_id'])) { $email = $user['sub_email']; // non users are treated as "Viewers" for permission checks $role = User::ROLE_VIEWER; } else { $prefs = Prefs::get($user['sub_usr_id']); if (Auth::getUserID() == $user['sub_usr_id'] && (empty($prefs['receive_copy_of_own_action'][$prj_id]) || $prefs['receive_copy_of_own_action'][$prj_id] == false)) { continue; } $email = User::getFromHeader($user['sub_usr_id']); $role = $user['pru_role']; } // now add it to the list of emails if (!empty($email) && !in_array($email, $all_emails)) { $all_emails[] = $email; $role_emails[$role][] = $email; } } // get additional email addresses to notify $additional_emails = Workflow::getAdditionalEmailAddresses($prj_id, $issue_id, 'issue_updated', array('old' => $old, 'new' => $new)); $data['custom_field_diffs'] = implode("\n", Custom_Field::formatUpdatesToDiffs($updated_custom_fields, User::ROLE_VIEWER)); foreach ($additional_emails as $email) { if (!in_array($email, $all_emails)) { $role_emails[User::ROLE_VIEWER][] = $email; } } // send email to each role separately due to custom field restrictions foreach ($role_emails as $role => $emails) { if (count($emails) > 0) { $data['custom_field_diffs'] = implode("\n", Custom_Field::formatUpdatesToDiffs($updated_custom_fields, $role)); if (!empty($data['custom_field_diffs']) || !empty($data['diffs'])) { self::notifySubscribers($issue_id, $emails, 'updated', $data, ev_gettext('Updated'), false); } } } }
function printLatestNewsCustom($number = 5, $category = '', $showdate = true, $showcontent = true, $contentlength = 70, $showcat = true) { global $_zp_gallery, $_zp_current_article; $latest = getLatestNews($number, $category); echo "\n<div id=\"latestnews-spotlight\">\n"; $count = ""; foreach ($latest as $item) { $count++; $category = ""; $categories = ""; $obj = newArticle($item['titlelink']); $title = htmlspecialchars($obj->getTitle()); $link = getNewsURL($item['titlelink']); $count2 = 0; $category = $obj->getCategories(); foreach ($category as $cat) { $catobj = new Category($cat['titlelink']); $count2++; if ($count2 != 1) { $categories = $categories . "; "; } $categories = $categories . $catobj->getTitle(); } $content = strip_tags($obj->getContent()); $date = zpFormattedDate(getOption('date_format'), strtotime($item['date'])); $type = 'news'; echo "<div>"; echo "<h3><a href=\"" . $link . "\" title=\"" . strip_tags(htmlspecialchars($title, ENT_QUOTES)) . "\">" . htmlspecialchars($title) . "</a></h3>\n"; echo "<div class=\"newsarticlecredit\">\n"; echo "<span class=\"latestnews-date\">" . $date . "</span>\n"; echo "<span class=\"latestnews-cats\">| Posted in " . $categories . "</span>\n"; echo "</div>\n"; echo "<p class=\"latestnews-desc\">" . html_encode(getContentShorten($content, $contentlength, '(...)', null, null)) . "</p>\n"; echo "</div>\n"; if ($count == $number) { break; } } echo "</div>\n"; }
/** * Method used to get the list of reminder conditions to be displayed in the * administration section. * * @access public * @param integer $rma_id The reminder action ID * @return array The list of reminder conditions */ function getAdminList($rma_id) { $stmt = "SELECT\n rlc_id,\n rlc_value,\n rlc_comparison_rmf_id,\n rmf_title,\n rmo_title\n FROM\n " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "reminder_level_condition,\n " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "reminder_field,\n " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "reminder_operator\n WHERE\n rlc_rmf_id=rmf_id AND\n rlc_rmo_id=rmo_id AND\n rlc_rma_id=" . Misc::escapeInteger($rma_id) . "\n ORDER BY\n rlc_id ASC"; $res = $GLOBALS["db_api"]->dbh->getAll($stmt, DB_FETCHMODE_ASSOC); if (PEAR::isError($res)) { Error_Handler::logError(array($res->getMessage(), $res->getDebugInfo()), __FILE__, __LINE__); return array(); } else { for ($i = 0; $i < count($res); $i++) { if (!empty($res[$i]['rlc_comparison_rmf_id'])) { $res[$i]['rlc_value'] = 'Field: ' . Reminder_Condition::getFieldTitle($res[$i]['rlc_comparison_rmf_id']); } elseif (strtolower($res[$i]['rmf_title']) == 'status') { $res[$i]['rlc_value'] = Status::getStatusTitle($res[$i]['rlc_value']); } elseif (strtolower($res[$i]['rmf_title']) == 'category') { $res[$i]['rlc_value'] = Category::getTitle($res[$i]['rlc_value']); } elseif (strtoupper($res[$i]['rlc_value']) != 'NULL') { $res[$i]['rlc_value'] .= ' hours'; } } return $res; } }
/** * Method used to get the list of reminder conditions to be displayed in the * administration section. * * @param integer $rma_id The reminder action ID * @return array The list of reminder conditions */ public static function getAdminList($rma_id) { $stmt = 'SELECT rlc_id, rlc_value, rlc_comparison_rmf_id, rmf_title, rmo_title FROM {{%reminder_level_condition}}, {{%reminder_field}}, {{%reminder_operator}} WHERE rlc_rmf_id=rmf_id AND rlc_rmo_id=rmo_id AND rlc_rma_id=? ORDER BY rlc_id ASC'; try { $res = DB_Helper::getInstance()->getAll($stmt, array($rma_id)); } catch (DbException $e) { return array(); } foreach ($res as &$row) { if (!empty($row['rlc_comparison_rmf_id'])) { $row['rlc_value'] = ev_gettext('Field') . ': ' . self::getFieldTitle($row['rlc_comparison_rmf_id']); } elseif (strtolower($row['rmf_title']) == 'status') { $row['rlc_value'] = Status::getStatusTitle($row['rlc_value']); } elseif (strtolower($row['rmf_title']) == 'category') { $row['rlc_value'] = Category::getTitle($row['rlc_value']); } elseif (strtolower($row['rmf_title']) == 'group' || strtolower($row['rmf_title']) == 'active group') { $row['rlc_value'] = Group::getName($row['rlc_value']); } elseif (strtoupper($row['rlc_value']) != 'NULL') { $row['rlc_value'] .= ' ' . ev_gettext('hours'); } } return $res; }
/** * Method used to send a diff-style notification email to the issue * subscribers about updates to its attributes. * * @access public * @param integer $issue_id The issue ID * @param array $old The old issue details * @param array $new The new issue details */ function notifyIssueUpdated($issue_id, $old, $new) { $diffs = array(); if (@$new["keep_assignments"] == "no") { if (empty($new['assignments'])) { $new['assignments'] = array(); } $assign_diff = Misc::arrayDiff($old['assigned_users'], $new['assignments']); if (count($assign_diff) > 0) { $diffs[] = '-Assignment List: ' . $old['assignments']; @($diffs[] = '+Assignment List: ' . implode(', ', User::getFullName($new['assignments']))); } } if (@$old['iss_expected_resolution_date'] != $new['expected_resolution_date']) { $diffs[] = '-Expected Resolution Date: ' . $old['iss_expected_resolution_date']; $diffs[] = '+Expected Resolution Date: ' . $new['expected_resolution_date']; } if ($old["iss_prc_id"] != $new["category"]) { $diffs[] = '-Category: ' . Category::getTitle($old["iss_prc_id"]); $diffs[] = '+Category: ' . Category::getTitle($new["category"]); } if (@$new["keep"] == "no" && $old["iss_pre_id"] != $new["release"]) { $diffs[] = '-Release: ' . Release::getTitle($old["iss_pre_id"]); $diffs[] = '+Release: ' . Release::getTitle($new["release"]); } if ($old["iss_pri_id"] != $new["priority"]) { $diffs[] = '-Priority: ' . Priority::getTitle($old["iss_pri_id"]); $diffs[] = '+Priority: ' . Priority::getTitle($new["priority"]); } if ($old["iss_sta_id"] != $new["status"]) { $diffs[] = '-Status: ' . Status::getStatusTitle($old["iss_sta_id"]); $diffs[] = '+Status: ' . Status::getStatusTitle($new["status"]); } if ($old["iss_res_id"] != $new["resolution"]) { $diffs[] = '-Resolution: ' . Resolution::getTitle($old["iss_res_id"]); $diffs[] = '+Resolution: ' . Resolution::getTitle($new["resolution"]); } if ($old["iss_dev_time"] != $new["estimated_dev_time"]) { $diffs[] = '-Estimated Dev. Time: ' . Misc::getFormattedTime($old["iss_dev_time"] * 60); $diffs[] = '+Estimated Dev. Time: ' . Misc::getFormattedTime($new["estimated_dev_time"] * 60); } if ($old["iss_summary"] != $new["summary"]) { $diffs[] = '-Summary: ' . $old['iss_summary']; $diffs[] = '+Summary: ' . $new['summary']; } if ($old["iss_description"] != $new["description"]) { // need real diff engine here include_once 'Text_Diff/Diff.php'; include_once 'Text_Diff/Diff/Renderer.php'; include_once 'Text_Diff/Diff/Renderer/unified.php'; $old['iss_description'] = explode("\n", $old['iss_description']); $new['description'] = explode("\n", $new['description']); $diff =& new Text_Diff($old["iss_description"], $new["description"]); $renderer =& new Text_Diff_Renderer_unified(); $desc_diff = explode("\n", trim($renderer->render($diff))); $diffs[] = 'Description:'; for ($i = 0; $i < count($desc_diff); $i++) { $diffs[] = $desc_diff[$i]; } } $emails = array(); $users = Notification::getUsersByIssue($issue_id, 'updated'); $user_emails = Project::getUserEmailAssocList(Issue::getProjectID($issue_id), 'active', User::getRoleID('Customer')); $user_emails = array_map('strtolower', $user_emails); for ($i = 0; $i < count($users); $i++) { if (empty($users[$i]["sub_usr_id"])) { $email = $users[$i]["sub_email"]; } else { $email = User::getFromHeader($users[$i]["sub_usr_id"]); } // now add it to the list of emails if (!empty($email) && !in_array($email, $emails)) { $emails[] = $email; } } $data = Notification::getIssueDetails($issue_id); $data['diffs'] = implode("\n", $diffs); $data['updated_by'] = User::getFullName(Auth::getUserID()); Notification::notifySubscribers($issue_id, $emails, 'updated', $data, 'Updated', FALSE); }
/** * Generates the specialized headers for an email. * * @access public * @param integer $issue_id The issue ID * @param string $type The type of message this is * @param string $headers The existing headers of this message. * @param integer $sender_usr_id The id of the user sending this email. * @return array An array of specialized headers */ function getSpecializedHeaders($issue_id, $type, $headers, $sender_usr_id) { $new_headers = array(); if (!empty($issue_id)) { $prj_id = Issue::getProjectID($issue_id); if (count(Group::getAssocList($prj_id)) > 0) { // group issue is currently assigned too $new_headers['X-Eventum-Group-Issue'] = Group::getName(Issue::getGroupID($issue_id)); // group of whoever is sending this message. if (empty($sender_usr_id)) { $new_headers['X-Eventum-Group-Replier'] = $new_headers['X-Eventum-Group-Issue']; } else { $new_headers['X-Eventum-Group-Replier'] = Group::getName(User::getGroupID($sender_usr_id)); } // group of current assignee $assignees = Issue::getAssignedUserIDs($issue_id); if (empty($assignees[0])) { $new_headers['X-Eventum-Group-Assignee'] = ''; } else { $new_headers['X-Eventum-Group-Assignee'] = @Group::getName(User::getGroupID($assignees[0])); } } if (Customer::hasCustomerIntegration($prj_id)) { if (empty($support_levels)) { $support_levels = Customer::getSupportLevelAssocList($prj_id); } $customer_id = Issue::getCustomerID($issue_id); if (!empty($customer_id)) { $customer_details = Customer::getDetails($prj_id, $customer_id); $new_headers['X-Eventum-Customer'] = $customer_details['customer_name']; } if (count($support_levels) > 0) { $new_headers['X-Eventum-Level'] = $support_levels[Customer::getSupportLevelID($prj_id, $customer_id)]; } } $new_headers['X-Eventum-Category'] = Category::getTitle(Issue::getCategory($issue_id)); $new_headers['X-Eventum-Project'] = Project::getName($prj_id); } $new_headers['X-Eventum-Type'] = $type; return $new_headers; }
/** * Method used to bulk update a list of issues * * @access public * @return boolean */ function bulkUpdate() { global $HTTP_POST_VARS; // check if user performing this chance has the proper role if (Auth::getCurrentRole() < User::getRoleID('Manager')) { return -1; } $items = Misc::escapeInteger($HTTP_POST_VARS['item']); $new_status_id = Misc::escapeInteger($_POST['status']); $new_release_id = Misc::escapeInteger($_POST['release']); $new_priority_id = Misc::escapeInteger($_POST['priority']); $new_category_id = Misc::escapeInteger($_POST['category']); $new_project_id = Misc::escapeInteger($_POST['project']); for ($i = 0; $i < count($items); $i++) { if (!Issue::canAccess($items[$i], Auth::getUserID())) { continue; } elseif (Issue::getProjectID($HTTP_POST_VARS['item'][$i]) != Auth::getCurrentProject()) { // make sure issue is not in another project continue; } $updated_fields = array(); // update assignment if (count(@$HTTP_POST_VARS['users']) > 0) { $users = Misc::escapeInteger($HTTP_POST_VARS['users']); // get who this issue is currently assigned too $stmt = "SELECT\n isu_usr_id,\n CONCAT(en_firstname,' ', en_lastname) as usr_full_name\n FROM\n " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "issue_user,\n " . ETEL_USER_TABLE_NOSUB . "\n WHERE\n isu_usr_id = en_ID AND\n isu_iss_id = " . $items[$i]; $current_assignees = $GLOBALS["db_api"]->dbh->getAssoc($stmt); if (PEAR::isError($current_assignees)) { Error_Handler::logError(array($current_assignees->getMessage(), $current_assignees->getDebugInfo()), __FILE__, __LINE__); return -1; } foreach ($current_assignees as $usr_id => $usr_name) { if (!in_array($usr_id, $users)) { Issue::deleteUserAssociation($items[$i], $usr_id, false); } } $new_user_names = array(); $new_assignees = array(); foreach ($users as $usr_id) { $new_user_names[$usr_id] = User::getFullName($usr_id); // check if the issue is already assigned to this person $stmt = "SELECT\n COUNT(*) AS total\n FROM\n " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "issue_user\n WHERE\n isu_iss_id=" . $items[$i] . " AND\n isu_usr_id=" . $usr_id; $total = $GLOBALS["db_api"]->dbh->getOne($stmt); if ($total > 0) { continue; } else { $new_assignees[] = $usr_id; // add the assignment Issue::addUserAssociation(Auth::getUserID(), $items[$i], $usr_id, false); Notification::subscribeUser(Auth::getUserID(), $items[$i], $usr_id, Notification::getAllActions()); Workflow::handleAssignment(Auth::getCurrentProject(), $items[$i], Auth::getUserID()); } } Notification::notifyNewAssignment($new_assignees, $items[$i]); $updated_fields['Assignment'] = History::formatChanges(join(', ', $current_assignees), join(', ', $new_user_names)); } // update status if (!empty($new_status_id)) { $old_status_id = Issue::getStatusID($items[$i]); $res = Issue::setStatus($items[$i], $new_status_id, false); if ($res == 1) { $updated_fields['Status'] = History::formatChanges(Status::getStatusTitle($old_status_id), Status::getStatusTitle($new_status_id)); } } // update release if (!empty($new_release_id)) { $old_release_id = Issue::getRelease($items[$i]); $res = Issue::setRelease($items[$i], $new_release_id); if ($res == 1) { $updated_fields['Release'] = History::formatChanges(Release::getTitle($old_release_id), Release::getTitle($new_release_id)); } } // update priority if (!empty($new_priority_id)) { $old_priority_id = Issue::getPriority($items[$i]); $res = Issue::setPriority($items[$i], $new_priority_id); if ($res == 1) { $updated_fields['Priority'] = History::formatChanges(Priority::getTitle($old_priority_id), Priority::getTitle($new_priority_id)); } } // update category if (!empty($new_category_id)) { $old_category_id = Issue::getCategory($items[$i]); $res = Issue::setCategory($items[$i], $new_category_id); if ($res == 1) { $updated_fields['Category'] = History::formatChanges(Category::getTitle($old_category_id), Category::getTitle($new_category_id)); } } // update project if (!empty($new_project_id)) { $old_project_id = Issue::getProjectID($items[$i]); $res = Issue::setProject($items[$i], $new_project_id); if ($res == 1) { $updated_fields['Project'] = History::formatChanges(Category::getTitle($old_project_id), Category::getTitle($new_project_id)); } } if (count($updated_fields) > 0) { // log the changes $changes = ''; $k = 0; foreach ($updated_fields as $key => $value) { if ($k > 0) { $changes .= "; "; } $changes .= "{$key}: {$value}"; $k++; } History::add($items[$i], Auth::getUserID(), History::getTypeID('issue_bulk_updated'), "Issue updated ({$changes}) by " . User::getFullName(Auth::getUserID())); } } return true; }
/** * Prints the categories of current article as a unordered html list WITHOUT links * * @param string $separator A separator to be shown between the category names if you choose to style the list inline */ function jqm_printNewsCategories($separator = '', $class = '') { $categories = getNewsCategories(); $catcount = count($categories); if ($catcount != 0) { echo "<ul class=\"{$class}\">\n"; $count = 0; foreach ($categories as $cat) { $count++; $catobj = new Category($cat['titlelink']); if ($count >= $catcount) { $separator = ""; } echo "<li>" . $catobj->getTitle() . "</li>\n"; } echo "</ul>\n"; } }
/** * Generates the specialized headers for an email. * * @param integer $issue_id The issue ID * @param string $type The type of message this is * @param string $headers The existing headers of this message. * @param integer $sender_usr_id The id of the user sending this email. * @return array An array of specialized headers */ public static function getSpecializedHeaders($issue_id, $type, $headers, $sender_usr_id) { $new_headers = array(); if (!empty($issue_id)) { $prj_id = Issue::getProjectID($issue_id); if (count(Group::getAssocList($prj_id)) > 0) { // group issue is currently assigned too $new_headers['X-Eventum-Group-Issue'] = Group::getName(Issue::getGroupID($issue_id)); // group of whoever is sending this message. if (empty($sender_usr_id)) { $new_headers['X-Eventum-Group-Replier'] = $new_headers['X-Eventum-Group-Issue']; } else { $new_headers['X-Eventum-Group-Replier'] = Group::getName(User::getGroupID($sender_usr_id)); } // group of current assignee $assignees = Issue::getAssignedUserIDs($issue_id); if (empty($assignees[0])) { $new_headers['X-Eventum-Group-Assignee'] = ''; } else { $new_headers['X-Eventum-Group-Assignee'] = @Group::getName(User::getGroupID($assignees[0])); } } if (CRM::hasCustomerIntegration($prj_id)) { $crm = CRM::getInstance($prj_id); try { $customer = $crm->getCustomer(Issue::getCustomerID($issue_id)); $new_headers['X-Eventum-Customer'] = $customer->getName(); } catch (CustomerNotFoundException $e) { } try { $contract = $crm->getContract(Issue::getContractID($issue_id)); $support_level = $contract->getSupportLevel(); if (is_object($support_level)) { $new_headers['X-Eventum-Level'] = $support_level->getName(); } } catch (ContractNotFoundException $e) { } } // add assignee header $new_headers['X-Eventum-Assignee'] = implode(',', User::getEmail(Issue::getAssignedUserIDs($issue_id))); $new_headers['X-Eventum-Category'] = Category::getTitle(Issue::getCategory($issue_id)); $new_headers['X-Eventum-Project'] = Project::getName($prj_id); $new_headers['X-Eventum-Priority'] = Priority::getTitle(Issue::getPriority($issue_id)); // handle custom fields $cf_values = Custom_Field::getValuesByIssue($prj_id, $issue_id); $cf_titles = Custom_Field::getFieldsToBeListed($prj_id); foreach ($cf_values as $fld_id => $values) { // skip empty titles // TODO: why they are empty? if (!isset($cf_titles[$fld_id])) { continue; } // skip empty values if (empty($values)) { continue; } $cf_value = implode(', ', (array) $values); // value could be empty after multivalued field join if (empty($cf_value)) { continue; } // convert spaces for header fields $cf_title = str_replace(' ', '_', $cf_titles[$fld_id]); $new_headers['X-Eventum-CustomField-' . $cf_title] = $cf_value; } } $new_headers['X-Eventum-Type'] = $type; return $new_headers; }
function __construct(Category $category) { parent::__construct($category->getTitle(), RequestContext::getMain()); //get all the members in the category $this->limit = null; $this->items = array(); $this->count = 0; }
/** * Add a subcategory to the internal lists, using a Category object * @param $cat Category * @param $sortkey * @param $pageLength */ function addSubcategoryObject(Category $cat, $sortkey, $pageLength) { // Subcategory; strip the 'Category' namespace from the link text. $title = $cat->getTitle(); $link = Linker::link($title, htmlspecialchars($title->getText())); if ($title->isRedirect()) { // This didn't used to add redirect-in-category, but might // as well be consistent with the rest of the sections // on a category page. $link = '<span class="redirect-in-category">' . $link . '</span>'; } $this->children[] = $link; $this->children_start_char[] = $this->getSubcategorySortChar($cat->getTitle(), $sortkey); }
/** * Method used to send a diff-style notification email to the issue * subscribers about updates to its attributes. * * @param integer $issue_id The issue ID * @param array $old The old issue details * @param array $new The new issue details */ public static function notifyIssueUpdated($issue_id, $old, $new) { $prj_id = Issue::getProjectID($issue_id); $diffs = array(); if (@$new['keep_assignments'] == 'no') { if (empty($new['assignments'])) { $new['assignments'] = array(); } $assign_diff = Misc::arrayDiff($old['assigned_users'], $new['assignments']); if (count($assign_diff) > 0) { $diffs[] = '-' . ev_gettext('Assignment List') . ': ' . $old['assignments']; @($diffs[] = '+' . ev_gettext('Assignment List') . ': ' . implode(', ', User::getFullName($new['assignments']))); } } if (isset($new['expected_resolution_date']) && @$old['iss_expected_resolution_date'] != $new['expected_resolution_date']) { $diffs[] = '-' . ev_gettext('Expected Resolution Date') . ': ' . $old['iss_expected_resolution_date']; $diffs[] = '+' . ev_gettext('Expected Resolution Date') . ': ' . $new['expected_resolution_date']; } if (isset($new['category']) && $old['iss_prc_id'] != $new['category']) { $diffs[] = '-' . ev_gettext('Category') . ': ' . Category::getTitle($old['iss_prc_id']); $diffs[] = '+' . ev_gettext('Category') . ': ' . Category::getTitle($new['category']); } if (isset($new['release']) && $old['iss_pre_id'] != $new['release']) { $diffs[] = '-' . ev_gettext('Release') . ': ' . Release::getTitle($old['iss_pre_id']); $diffs[] = '+' . ev_gettext('Release') . ': ' . Release::getTitle($new['release']); } if (isset($new['priority']) && $old['iss_pri_id'] != $new['priority']) { $diffs[] = '-' . ev_gettext('Priority') . ': ' . Priority::getTitle($old['iss_pri_id']); $diffs[] = '+' . ev_gettext('Priority') . ': ' . Priority::getTitle($new['priority']); } if (isset($new['severity']) && $old['iss_sev_id'] != $new['severity']) { $diffs[] = '-' . ev_gettext('Severity') . ': ' . Severity::getTitle($old['iss_sev_id']); $diffs[] = '+' . ev_gettext('Severity') . ': ' . Severity::getTitle($new['severity']); } if (isset($new['status']) && $old['iss_sta_id'] != $new['status']) { $diffs[] = '-' . ev_gettext('Status') . ': ' . Status::getStatusTitle($old['iss_sta_id']); $diffs[] = '+' . ev_gettext('Status') . ': ' . Status::getStatusTitle($new['status']); } if (isset($new['resolution']) && $old['iss_res_id'] != $new['resolution']) { $diffs[] = '-' . ev_gettext('Resolution') . ': ' . Resolution::getTitle($old['iss_res_id']); $diffs[] = '+' . ev_gettext('Resolution') . ': ' . Resolution::getTitle($new['resolution']); } if (isset($new['estimated_dev_time']) && $old['iss_dev_time'] != $new['estimated_dev_time']) { $diffs[] = '-' . ev_gettext('Estimated Dev. Time') . ': ' . Misc::getFormattedTime($old['iss_dev_time'] * 60); $diffs[] = '+' . ev_gettext('Estimated Dev. Time') . ': ' . Misc::getFormattedTime($new['estimated_dev_time'] * 60); } if (isset($new['summary']) && $old['iss_summary'] != $new['summary']) { $diffs[] = '-' . ev_gettext('Summary') . ': ' . $old['iss_summary']; $diffs[] = '+' . ev_gettext('Summary') . ': ' . $new['summary']; } if (isset($new['percent_complete']) && $old['iss_original_percent_complete'] != $new['percent_complete']) { $diffs[] = '-' . ev_gettext('Percent complete') . ': ' . $old['iss_original_percent_complete']; $diffs[] = '+' . ev_gettext('Percent complete') . ': ' . $new['percent_complete']; } if (isset($new['description']) && $old['iss_description'] != $new['description']) { $old['iss_description'] = explode("\n", $old['iss_original_description']); $new['description'] = explode("\n", $new['description']); $diff = new Text_Diff($old['iss_description'], $new['description']); $renderer = new Text_Diff_Renderer_unified(); $desc_diff = explode("\n", trim($renderer->render($diff))); $diffs[] = 'Description:'; foreach ($desc_diff as $diff) { $diffs[] = $diff; } } $emails = array(); $users = self::getUsersByIssue($issue_id, 'updated'); $user_emails = Project::getUserEmailAssocList(Issue::getProjectID($issue_id), 'active', User::getRoleID('Customer')); // FIXME: $user_emails unused $user_emails = array_map(function ($s) { return strtolower($s); }, $user_emails); foreach ($users as $user) { if (empty($user['sub_usr_id'])) { $email = $user['sub_email']; } else { $prefs = Prefs::get($user['sub_usr_id']); if (Auth::getUserID() == $user['sub_usr_id'] && (empty($prefs['receive_copy_of_own_action'][$prj_id]) || $prefs['receive_copy_of_own_action'][$prj_id] == false)) { continue; } $email = User::getFromHeader($user['sub_usr_id']); } // now add it to the list of emails if (!empty($email) && !in_array($email, $emails)) { $emails[] = $email; } } // get additional email addresses to notify $emails = array_merge($emails, Workflow::getAdditionalEmailAddresses($prj_id, $issue_id, 'issue_updated', array('old' => $old, 'new' => $new))); $data = Issue::getDetails($issue_id); $data['diffs'] = implode("\n", $diffs); $data['updated_by'] = User::getFullName(Auth::getUserID()); self::notifySubscribers($issue_id, $emails, 'updated', $data, ev_gettext('Updated'), false); }