Beispiel #1
0
 public function init()
 {
     //parent::init();
     $this->addDecorators(array('FormElements'));
     $fields = Engine_Api::_()->getApi('core', 'fields')->getFieldsMeta($this->_type);
     foreach ($fields as $field) {
         if (!$field->search || !$field->alias) {
             continue;
         }
         $key = $field->alias;
         // Hack for birthday type fields
         $params = $field->getElementParams($this->_type, array('required' => false));
         // Range type fields
         if ($field->type == 'date' || $field->type == 'birthdate' || $field->type == 'float') {
             $subform = new Engine_Form(array('description' => $params['options']['label'], 'elementsBelongTo' => $key, 'decorators' => array('FormElements', array('Description', array('placement' => 'PREPEND', 'tag' => 'label', 'class' => 'form-label')), array('HtmlTag', array('tag' => 'div', 'class' => 'integer_field form-wrapper integer_field_unselected', 'id' => 'integer-wrapper')))));
             //Engine_Form::enableForm($subform);
             unset($params['options']['label']);
             $params['options']['decorators'] = array('ViewHelper', array('HtmlTag', array('tag' => 'div', 'class' => 'form-element')));
             $subform->addElement($params['type'], 'min', $params['options']);
             $subform->addElement($params['type'], 'max', $params['options']);
             $this->addSubForm($subform, $key);
         } else {
             $this->addElement($params['type'], $key, $params['options']);
         }
         $element = $this->getElement($key);
     }
     $this->addElement('Button', 'done', array('label' => 'Search', 'type' => 'submit'));
 }
 public function widgetAction()
 {
     // Render by widget name
     $mod = $this->_getParam('mod');
     $name = $this->_getParam('name');
     if (null === $name) {
         throw new Exception('no widget found with name: ' . $name);
     }
     if (null !== $mod) {
         $name = $mod . '.' . $name;
     }
     $contentInfoRaw = $this->getContentAreas();
     $contentInfo = array();
     foreach ($contentInfoRaw as $info) {
         $contentInfo[$info['name']] = $info;
     }
     // It has a form specified in content manifest
     if (!empty($contentInfo[$name]['adminForm'])) {
         if (is_string($contentInfo[$name]['adminForm'])) {
             // Core_Form_Admin_Widget_*
             $formClass = $contentInfo[$name]['adminForm'];
             Engine_Loader::loadClass($formClass);
             $this->view->form = $form = new $formClass();
         } else {
             if (is_array($contentInfo[$name]['adminForm'])) {
                 $this->view->form = $form = new Engine_Form($contentInfo[$name]['adminForm']);
             } else {
                 throw new Core_Model_Exception('Unable to load admin form class');
             }
         }
         // Try to set title if missing
         if (!$form->getTitle()) {
             $form->setTitle('Editing: ' . $contentInfo[$name]['title']);
         }
         // Try to set description if missing
         if (!$form->getDescription()) {
             $form->setDescription('placeholder');
         }
         $form->setAttrib('class', 'global_form_popup ' . $form->getAttrib('class'));
         // Add title element
         if (!$form->getElement('title')) {
             $form->addElement('Text', 'title', array('label' => 'Title', 'order' => -100));
         }
         // Add mobile element?
         if (!$form->getElement('nomobile')) {
             $form->addElement('Select', 'nomobile', array('label' => 'Hide on mobile site?', 'order' => 100000 - 5, 'multiOptions' => array('1' => 'Yes, do not display on mobile site.', '0' => 'No, display on mobile site.'), 'value' => '0'));
         }
         if (!empty($contentInfo[$name]['isPaginated']) && !$form->getElement('itemCountPerPage')) {
             $form->addElement('Text', 'itemCountPerPage', array('label' => 'Count', 'description' => '(number of items to show)', 'validators' => array(array('Int', true), array('GreaterThan', true, array(0))), 'order' => 1000000 - 1));
         }
         // Add submit button
         if (!$form->getElement('submit') && !$form->getElement('execute')) {
             $form->addElement('Button', 'execute', array('label' => 'Save Changes', 'type' => 'submit', 'ignore' => true, 'decorators' => array('ViewHelper'), 'order' => 1000000));
         }
         // Add name
         $form->addElement('Hidden', 'name', array('value' => $name, 'order' => 1000010));
         if (!$form->getElement('cancel')) {
             $form->addElement('Cancel', 'cancel', array('label' => 'cancel', 'link' => true, 'prependText' => ' or ', 'onclick' => 'parent.Smoothbox.close();', 'ignore' => true, 'decorators' => array('ViewHelper'), 'order' => 1000001));
         }
         if (!$form->getDisplayGroup('buttons')) {
             $submitName = $form->getElement('execute') ? 'execute' : 'submit';
             $form->addDisplayGroup(array($submitName, 'cancel'), 'buttons', array('order' => 1000002));
         }
         // Force method and action
         $form->setMethod('post')->setAction($_SERVER['REQUEST_URI']);
         if ($this->getRequest()->isPost() && $form->isValid($this->getRequest()->getPost())) {
             $this->view->values = $form->getValues();
             $this->view->form = null;
         }
         return;
     }
     // Try to render admin page
     if (!empty($contentInfo[$name])) {
         try {
             $structure = array('type' => 'widget', 'name' => $name, 'request' => $this->getRequest(), 'action' => 'admin', 'throwExceptions' => true);
             // Create element (with structure)
             $element = new Engine_Content_Element_Container(array('elements' => array($structure), 'decorators' => array('Children')));
             $content = $element->render();
             $this->getResponse()->setBody($content);
             $this->_helper->viewRenderer->setNoRender(true);
             return;
         } catch (Exception $e) {
         }
     }
     // Just render default editing form
     $this->view->form = $form = new Engine_Form(array('title' => $contentInfo[$name]['title'], 'description' => 'placeholder', 'method' => 'post', 'action' => $_SERVER['REQUEST_URI'], 'class' => 'global_form_popup', 'elements' => array(array('Text', 'title', array('label' => 'Title')), array('Button', 'submit', array('label' => 'Save', 'type' => 'submit', 'decorators' => array('ViewHelper'), 'ignore' => true, 'order' => 1501)), array('Hidden', 'name', array('value' => $name)), array('Cancel', 'cancel', array('label' => 'cancel', 'link' => true, 'prependText' => ' or ', 'onclick' => 'parent.Smoothbox.close();', 'ignore' => true, 'decorators' => array('ViewHelper'), 'order' => 1502))), 'displaygroups' => array('buttons' => array('name' => 'buttons', 'elements' => array('submit', 'cancel'), 'options' => array('order' => 1500)))));
     if (!empty($contentInfo[$name]['isPaginated'])) {
         $form->addElement('Text', 'itemCountPerPage', array('label' => 'Count', 'description' => '(number of items to show)', 'validators' => array(array('Int', true), array('GreaterThan', true, array(0)))));
     }
     if ($this->getRequest()->isPost() && $form->isValid($this->getRequest()->getPost())) {
         $this->view->values = $form->getValues();
         $this->view->form = null;
     } else {
         $form->populate($this->_getAllParams());
     }
 }
Beispiel #3
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.');
 }