static function &getTicketCount($foradmin = true, $current_handler_only = false) { $key = 0; if ($foradmin) { $key += 1; } if ($current_handler_only) { $key += 2; } if (empty(self::$counts)) { self::$counts = array(); } if (!array_key_exists($key, self::$counts)) { $db = JFactory::getDBO(); $query = "SELECT count( * ) AS count, ticket_status_id FROM #__fss_ticket_ticket as t WHERE 1 "; $query .= " AND " . SupportUsers::getAdminWhere(); if ($foradmin) { $query .= " AND " . SupportSource::admin_list_sql(); } else { $query .= " AND " . SupportSource::user_list_sql(); } if ($current_handler_only) { $query .= " AND admin_id = " . JFactory::getUser()->id; } $query .= " GROUP BY ticket_status_id"; $db->setQuery($query); $rows = $db->loadAssocList(); $out = array(); FSS_Ticket_Helper::GetStatusList(); foreach (FSS_Ticket_Helper::$status_list as $status) { $out[$status->id] = 0; } if (count($rows) > 0) { foreach ($rows as $row) { $out[$row['ticket_status_id']] = $row['count']; } } // work out counts for allopen, closed, all, archived $archived = FSS_Ticket_Helper::GetStatusID("def_archive"); $out['archived'] = 0; if (array_key_exists($archived, $out)) { $out['archived'] = $out[$archived]; } $allopen = FSS_Ticket_Helper::GetStatusIDs("is_closed", true); $out['allopen'] = 0; foreach ($allopen as $id) { if (array_key_exists($id, $out)) { $out['allopen'] += $out[$id]; } } $allclosed = FSS_Ticket_Helper::GetClosedStatus(); $out['allclosed'] = 0; foreach ($allclosed as $id) { if (array_key_exists($id, $out)) { $out['allclosed'] += $out[$id]; } } $all = FSS_Ticket_Helper::GetStatusIDs("def_archive", true); $out['all'] = 0; foreach ($all as $id) { if (array_key_exists($id, $out)) { $out['all'] += $out[$id]; } } self::$counts[$key] = $out; } return self::$counts[$key]; }
function &getTicketCount() { $user = JFactory::getUser(); $userid = $user->get('id'); if (empty(self::$ticket_counts)) { self::$ticket_counts = array(); } if (array_key_exists($userid, self::$ticket_counts)) { $this->_counts = self::$ticket_counts[$userid]; return $this->_counts; } $uidlist = $this->getUIDS($userid); $tidlist = $this->getTIDS($userid); $db = JFactory::getDBO(); $query = "SELECT count( * ) AS count, ticket_status_id FROM #__fss_ticket_ticket WHERE (user_id IN (" . implode(", ", $uidlist) . ") OR id IN ( " . implode(", ", $tidlist) . ")) "; $query .= " AND " . SupportSource::user_list_sql(); $query .= " GROUP BY ticket_status_id"; $db->setQuery($query); $rows = $db->loadAssocList(); $out = array(); FSS_Ticket_Helper::GetStatusList(); foreach (FSS_Ticket_Helper::$status_list as $status) { $out[$status->id] = 0; } if (count($rows) > 0) { foreach ($rows as $row) { $out[$row['ticket_status_id']] = $row['count']; } } // work out counts for allopen, closed, all, archived $archived = FSS_Ticket_Helper::GetStatusID("def_archive"); if (array_key_exists($archived, $out)) { $out['archived'] = $out[$archived]; } else { $out['archived'] = 0; } $allopen = FSS_Ticket_Helper::GetStatusIDs("is_closed", true); $out['open'] = 0; foreach ($allopen as $id) { if (array_key_exists($id, $out)) { $out['open'] += $out[$id]; } } $allclosed = FSS_Ticket_Helper::GetClosedStatus(); $out['closed'] = 0; foreach ($allclosed as $id) { if (array_key_exists($id, $out)) { $out['closed'] += $out[$id]; } } $all = FSS_Ticket_Helper::GetStatusIDs("def_archive"); $out['all'] = 0; foreach ($rows as $row) { if ($row['ticket_status_id'] != $all) { $out['all'] += $row['count']; } } $this->_counts = $out; self::$ticket_counts[$userid] = $out; return $this->_counts; }