'title'); protected $_formDefaults = array('enabled' => 'y'); protected $_categorySectionUrl; protected $_actions = array('list', 'cancel', 'new', 'insert', 'edit', 'update', 'delete', 'changeOption', /*'reorder', 'updateOrder',*/ 'back', 'download'); protected $_allowedExtensions = array('.pdf', '.txt', '.doc', '.docx', '.xls', '.xlsx', '.ppt', '.pptx', '.odt', '.ods', '.odp', '.png', '.jpg', '.jpeg'); protected function _initAction() { parent::_initAction(); if (in_array($this->_action, array('reorder', 'updateOrder'))) { $categoryId = Qs_Request::getGetValue('categoryId'); if (is_numeric($categoryId)) { $this->dataObj->addFilter(array('categoryId' => $categoryId)); } } return $this; } protected function _bindListColumns(Qs_ViewController_List $list) { $list->addColumn('no', 'no'); $list->addColumn('text', 'category', array('orderBy' => 'category')); $list->addColumn('text', 'title', array('title' => 'Subject', 'orderBy' => 'title')); $list->addColumn('description', 'description', array('title' => 'Summary')); $list->addColumn('file', 'file', array('title' => 'Document', 'params' => array('name' => 'file'))); $list->addColumn( 'link_enum', 'enabled', array( 'title' => 'Show', 'orderBy' => 'enabled', 'values' => array('n' => 'No', 'y' => 'Yes'), ) ); $list->addColumn('options', 'options'); return $this; } protected function _bindFormFields(Qs_Form $form) { $form->addElement( 'select', 'categoryId', array( 'label' => 'Category', 'multiOptions' => array('' => 'Select Category') + (array) $this->dataObj->getCategories4Select(), 'required' => true, ) ); $form->addElement('text', 'title', array('label' => 'Subject', 'required' => true)); $form->addElement('htmlEditor', 'description', array('label' => 'Summary')); $form->addElement( 'extendedFile', 'file', array( 'label' => 'File', 'required' => true, 'description' => 'Please note there is a file limit of 10MB ' . 'and allowed formats are: ' . implode(', ', $this->_allowedExtensions) ) ); $extensions = array(); foreach ($this->_allowedExtensions as $ext) { $extensions[] = trim($ext, '.'); } $extensionValidator = new Zend_Validate_File_Extension($extensions); $extensionValidator->setMessage("File format is not allowed.", Zend_Validate_File_Extension::FALSE_EXTENSION); $form->getElement('file')->addValidator($extensionValidator); $sizeValidator = new Zend_Validate_File_Size(array('max' => '10MB')); $sizeValidator->setMessage( "Maximum allowed file size is '%max%' but '%size%' detected", Zend_Validate_File_Size::TOO_BIG ); $form->getElement('file')->addValidator($sizeValidator); $form->addElement( 'checkbox', 'enabled', array( 'description' => 'Show on user end', 'checkedValue' => 'y', 'uncheckedValue' => 'n', 'checked' => 'y', ) ); $form->getElement('enabled')->getDecorator('Description') ->setTag('label') ->setOption('for', $form->enabled->getId()); return $this; } protected function _bindFilterFields($form) { parent::_bindFilterFields($form); $categories = $this->dataObj->getCategories4Select(); if (count($categories) > 1) { $form->addElement( 'select', 'categoryId', array( 'multiOptions' => array('' => 'All Categories') + $categories, 'onchange' => 'this.form.submit()', ) ); } return $this; } protected function _doNew() { $form = $this->_getNewForm(); $defaults = array(); $defaults['categoryId'] = Qs_Request::getGetValue('categoryId'); $form->setDefaults($defaults); $this->_renderMainForm($form); return $this; } protected function _getCategorySectionUrl() { if (null === $this->_categorySectionUrl) { $this->_categorySectionFullAlias = Qs_SiteMap::findFirst( null, array('type' => 'SchoolResource_Category_Admin'), null, 'url' ); } return $this->_categorySectionFullAlias; } protected function _getDefaultLinks() { $categoryId = $this->dataObj->getFilter('categoryId'); $links = array(); $params = array(); if (is_numeric($categoryId)) { $params['categoryId'] = $categoryId; } $params['action'] = 'new'; $links[] = array('title' => 'Add New ' . $this->dataObj->itemName, 'url' => $this->url($params)); $params['action'] = 'reorder'; $links['reorder'] = array('title' => 'Reorder ' . $this->dataObj->itemsName, 'url' => $this->url($params)); if (!is_numeric($categoryId) && $this->dataObj->getCategoriesCount() > 1) { $links['reorder']['attribs'] = array( 'class' => 'warning', 'onclick' => "alert('Please select one of the categories in the \"Search\" drop down above " . "to reorder its items.'); return false" ); $links['reorder']['url'] = '#'; } $url = $this->_getCategorySectionUrl(); if (false !== $url) { $links[] = array('title' => 'Manage Categories', 'url' => $url); } return $links; } }