Report/SendEventErrors.php
[Pman.Admin] / Report / SendEventErrors.php
index 05d6e83..41c458e 100644 (file)
@@ -14,6 +14,13 @@ class Pman_Admin_Report_SendEventErrors extends Pman_Roo
             'min' => 1,
             'max' => 1,
         ),
+        'exclude' => array(
+            'desc' => 'list of actions to exclude from report',
+            'short' => 'e',
+            'default' => '',
+            'min' => 1,
+            'max' => 1,
+        ),
     );
     
     function getAuth()
@@ -37,15 +44,34 @@ class Pman_Admin_Report_SendEventErrors extends Pman_Roo
         
         PEAR::setErrorHandling(PEAR_ERROR_CALLBACK, array($this, 'onPearError'));
         
-        print_R($this->opts);exit;
-        
-        if(empty($this->opts->group)){
+        if(empty($this->opts['group'])){
             $this->jerr('Missing group - try add [-t {group name}]');
         }
         
-        $rcpts = DB_DataObject::factory('groups')->lookupMembers("{$this->opts->group}",'email');
+        $rcpts = DB_DataObject::factory('groups')->lookupMembers("{$this->opts['group']}",'email');
+        
+        if(empty($rcpts)){
+            $this->jerr("{$this->opts['group']} does not has any memeber");
+        }
+        
+        $events = DB_DataObject::factory('Events');
+        $events->selectAdd();
+        $events->selectAdd("
+            DISTINCT(Events.action) AS action,
+            COUNT(Events.id) AS total
+        ");
+        
+        $events->whereAdd("Events.event_when > NOW() - INTERVAL 1 DAY");
+        
+        if(!empty($this->opts['exclude'])){
+            $exclude = array_unique(array_filter(array_map('trim', explode(',', $this->opts['exclude']))));
+            print_r($exclude);exit;
+        }
+        
+        $events->groupBy('Events.action');
+        $events->orderBy('Events.action ASC');
         
-        print_R($rcpts);exit;
+        print_r($events->fetchAll('action', 'total'));exit;
         
         $this->jok("Done");