/** * Method used to get the list of changes made against a specific issue. * * @param integer $iss_id The issue ID * @param string $order_by The order to sort the history * @return array The list of changes */ public static function getListing($iss_id, $order_by = 'DESC') { $order_by = DB_Helper::orderBy($order_by); $stmt = "SELECT\n *\n FROM\n {{%issue_history}},\n {{%history_type}}\n WHERE\n htt_id = his_htt_id AND\n his_is_hidden != 1 AND\n his_iss_id=? AND\n his_min_role <= ?\n ORDER BY\n his_id {$order_by}"; $params = array($iss_id, Auth::getCurrentRole()); try { $res = DB_Helper::getInstance()->getAll($stmt, $params); } catch (DbException $e) { return ''; } foreach ($res as &$row) { $row['his_summary'] = Misc::processTokens(ev_gettext($row['his_summary']), $row['his_context']); } return $res; }
/** * Method used to get the list of emails to be displayed in the * grid layout. * * @param array $options The search parameters * @param integer $current_row The current page number * @param integer $max The maximum number of rows per page * @return array The list of issues to be displayed */ public static function getEmailListing($options, $current_row = 0, $max = 5) { $prj_id = Auth::getCurrentProject(); if ($max == 'ALL') { $max = 9999999; } $start = $current_row * $max; $stmt = 'SELECT sup_id, sup_ema_id, sup_iss_id, sup_customer_id, sup_from, sup_date, sup_to, sup_subject, sup_has_attachment FROM ( {{%support_email}}, {{%email_account}}'; if (!empty($options['keywords'])) { $stmt .= ', {{%support_email_body}} '; } $stmt .= ' ) LEFT JOIN {{%issue}} ON sup_iss_id = iss_id'; $stmt .= self::buildWhereClause($options); $stmt .= ' ORDER BY ' . Misc::escapeString($options['sort_by']) . ' ' . DB_Helper::orderBy($options['sort_order']); $total_rows = Pager::getTotalRows($stmt); $stmt .= ' LIMIT ' . Misc::escapeInteger($max) . ' OFFSET ' . Misc::escapeInteger($start); try { $res = DB_Helper::getInstance()->getAll($stmt); } catch (DbException $e) { return array('list' => '', 'info' => ''); } if (count($res) < 1 && $current_row > 0) { // if there are no results, and the page is not the first page reset page to one and reload results Auth::redirect("emails.php?pagerRow=0&rows={$max}"); } if (CRM::hasCustomerIntegration($prj_id)) { $crm = CRM::getInstance($prj_id); $customer_ids = array(); foreach ($res as $row) { if (!empty($row['sup_customer_id']) && !in_array($row['sup_customer_id'], $customer_ids)) { $customer_ids[] = $row['sup_customer_id']; } } if (count($customer_ids) > 0) { $company_titles = $crm->getCustomerTitles($customer_ids); } } foreach ($res as &$row) { $row['sup_subject'] = Mime_Helper::fixEncoding($row['sup_subject']); $row['sup_from'] = implode(', ', Mail_Helper::getName($row['sup_from'], true)); if (empty($row['sup_to']) && !empty($row['sup_iss_id'])) { $row['sup_to'] = 'Notification List'; } else { $to = Mail_Helper::getName($row['sup_to']); // Ignore unformattable headers if (!Misc::isError($to)) { $row['sup_to'] = Mime_Helper::fixEncoding($to); } } if (CRM::hasCustomerIntegration($prj_id)) { // FIXME: $company_titles maybe used uninitialied $row['customer_title'] = $company_titles[$row['sup_customer_id']]; } } $total_pages = ceil($total_rows / $max); $last_page = $total_pages - 1; return array('list' => $res, 'info' => array('current_page' => $current_row, 'start_offset' => $start, 'end_offset' => $start + count($res), 'total_rows' => $total_rows, 'total_pages' => $total_pages, 'previous_page' => $current_row == 0 ? '-1' : $current_row - 1, 'next_page' => $current_row == $last_page ? '-1' : $current_row + 1, 'last_page' => $last_page)); }