Exemplo n.º 1
0
 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];
 }