public function index()
 {
     $queue = ContentNotifierQueue::get_unnotified();
     if ($queue->exists()) {
         $count = $queue->count();
         $e = Injector::inst()->create('ContentNotifierEmail')->setRecords($queue)->send();
         echo "Sent {$count} notifications\n";
     } else {
         echo "No queued notifications\n";
     }
 }
 public function send()
 {
     if (!$this->records) {
         $this->setRecords(ContentNotifierQueue::get_unnotified());
     }
     ContentNotifierExtension::disable_filtering();
     $total = $this->records->count();
     $grouped = GroupedList::create($this->records->limit($this->config()->items_limit))->GroupedBy('Category');
     $this->emailer->populateTemplate(array('Headline' => $this->config()->headline, 'GroupedItems' => $grouped, 'Total' => $total, 'Link' => Controller::join_links(Director::absoluteBaseURL(), 'admin', 'content-notifications')));
     $this->emailer->send();
     foreach ($this->records as $record) {
         $record->HasNotified = true;
         $record->write();
     }
     ContentNotifierExtension::enable_filtering(true);
 }
 public function run($request)
 {
     $action = $request->getVar('action');
     $count = 0;
     switch ($action) {
         case "all":
             $count = ContentNotifierQueue::get()->count();
             ContentNotifierQueue::get()->removeAll();
             break;
         case "approved":
             foreach (ContentNotifierQueue::get() as $q) {
                 if ($rec = $q->getRecord()) {
                     if ($rec->ContentNotifierApproved) {
                         $q->delete();
                         $count++;
                     }
                 }
             }
             break;
         case "denied":
             foreach (ContentNotifierQueue::get() as $q) {
                 if ($rec = $q->getRecord()) {
                     if (!$rec->ContentNotifierApproved) {
                         $q->delete();
                         $count++;
                     }
                 }
             }
             break;
         case "orphaned":
             foreach (ContentNotifierQueue::get() as $q) {
                 if (!$q->getRecord()) {
                     $q->delete();
                     $count++;
                 }
             }
             break;
         default:
             die("Please specify an 'action' parameter ('all','approved','denied', or 'orphaned') in the request");
             break;
     }
     die("Deleted {$count} records from the content notifier queue.");
 }
 public function getQueue($event = null)
 {
     $list = ContentNotifierQueue::get()->filter(array('RecordClass' => $this->owner->class, 'RecordID' => $this->owner->ID ?: 0));
     if ($event) {
         $list = $list->filter('Event', $event);
     }
     return $list->first();
 }