Exemple #1
0
 public function notificationsAction()
 {
     $user = Engine_Api::_()->core()->getSubject();
     // Build the different notification types
     $modules = Engine_Api::_()->getDbtable('modules', 'core')->getModulesAssoc();
     $notificationTypes = Engine_Api::_()->getDbtable('notificationTypes', 'activity')->getNotificationTypes();
     $notificationSettings = Engine_Api::_()->getDbtable('notificationSettings', 'activity')->getEnabledNotifications($user);
     $notificationTypesAssoc = array();
     $notificationSettingsAssoc = array();
     foreach ($notificationTypes as $type) {
         if (in_array($type->module, array('core', 'activity', 'fields', 'authorization', 'messages', 'user'))) {
             $elementName = 'general';
             $category = 'General';
         } else {
             if (isset($modules[$type->module])) {
                 $elementName = preg_replace('/[^a-zA-Z0-9]+/', '-', $type->module);
                 $category = $modules[$type->module]->title;
             } else {
                 $elementName = 'misc';
                 $category = 'Misc';
             }
         }
         $notificationTypesAssoc[$elementName]['category'] = $category;
         $notificationTypesAssoc[$elementName]['types'][$type->type] = 'ACTIVITY_TYPE_' . strtoupper($type->type);
         if (in_array($type->type, $notificationSettings)) {
             $notificationSettingsAssoc[$elementName][] = $type->type;
         }
     }
     ksort($notificationTypesAssoc);
     $notificationTypesAssoc = array_filter(array_merge(array('general' => array(), 'misc' => array()), $notificationTypesAssoc));
     // Make form
     $this->view->form = $form = new Engine_Form(array('title' => 'Notification Settings', 'description' => 'Which of the these do you want to receive email alerts about?'));
     foreach ($notificationTypesAssoc as $elementName => $info) {
         $form->addElement('MultiCheckbox', $elementName, array('label' => $info['category'], 'multiOptions' => $info['types'], 'value' => (array) @$notificationSettingsAssoc[$elementName]));
     }
     $form->addElement('Button', 'execute', array('label' => 'Save Changes', 'type' => 'submit'));
     // Check method
     if (!$this->getRequest()->isPost()) {
         return;
     }
     if (!$form->isValid($this->getRequest()->getPost())) {
         return;
     }
     // Process
     $values = array();
     foreach ($form->getValues() as $key => $value) {
         if (!is_array($value)) {
             continue;
         }
         foreach ($value as $skey => $svalue) {
             if (!isset($notificationTypesAssoc[$key]['types'][$svalue])) {
                 continue;
             }
             $values[] = $svalue;
         }
     }
     // Set notification setting
     Engine_Api::_()->getDbtable('notificationSettings', 'activity')->setEnabledNotifications($user, $values);
     $form->addNotice('Your changes have been saved.');
 }
 public function notificationsAction()
 {
     error_reporting(E_ALL);
     ini_set('display_errors', TRUE);
     // Build the different notification types
     $modules = Engine_Api::_()->getDbtable('modules', 'core')->getModulesAssoc();
     $notificationTypes = Engine_Api::_()->getDbtable('notificationTypes', 'activity')->getNotificationTypes();
     $notificationSettings = Engine_Api::_()->getDbtable('notificationTypes', 'activity')->getDefaultNotifications();
     $notificationTypesAssoc = array();
     $notificationSettingsAssoc = array();
     foreach ($notificationTypes as $type) {
         if (in_array($type->module, array('core', 'activity', 'fields', 'authorization', 'messages', 'user'))) {
             $elementName = 'general';
             $category = 'General';
         } else {
             if (isset($modules[$type->module])) {
                 $elementName = preg_replace('/[^a-zA-Z0-9]+/', '-', $type->module);
                 $category = $modules[$type->module]->title;
             } else {
                 $elementName = 'misc';
                 $category = 'Misc';
             }
         }
         $notificationTypesAssoc[$elementName]['category'] = $category;
         $notificationTypesAssoc[$elementName]['types'][$type->type] = 'ACTIVITY_TYPE_' . strtoupper($type->type);
         if (in_array($type->type, $notificationSettings)) {
             $notificationSettingsAssoc[$elementName][] = $type->type;
         }
     }
     ksort($notificationTypesAssoc);
     $notificationTypesAssoc = array_filter(array_merge(array('general' => array(), 'misc' => array()), $notificationTypesAssoc));
     $this->view->form = $form = new Engine_Form(array('title' => 'Default Email Notifications', 'description' => 'This page allows you to specify the default email notifications for new users.'));
     foreach ($notificationTypesAssoc as $elementName => $info) {
         $form->addElement('MultiCheckbox', $elementName, array('label' => $info['category'], 'multiOptions' => $info['types'], 'value' => (array) @$notificationSettingsAssoc[$elementName]));
     }
     // init submit
     $form->addElement('Button', 'submit', array('label' => 'Save Changes', 'type' => 'submit', 'ignore' => true));
     // Check method
     if (!$this->getRequest()->isPost()) {
         return;
     }
     if (!$form->isValid($this->getRequest()->getPost())) {
         return;
     }
     $values = array();
     foreach ($form->getValues() as $key => $value) {
         if (!is_array($value)) {
             continue;
         }
         foreach ($value as $skey => $svalue) {
             if (!isset($notificationTypesAssoc[$key]['types'][$svalue])) {
                 continue;
             }
             $values[] = $svalue;
         }
     }
     Engine_Api::_()->getDbtable('notificationTypes', 'activity')->setDefaultNotifications($values);
     $form->addNotice('Your changes have been saved.');
 }