'title'); protected $_formDefaults = array('enabled' => 'y'); 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'))) { if (is_numeric($idCategory = Qs_Request::getGetValue('idCategory'))) { $this->dataObj->addFilter(array('idCategory' => $idCategory)); } } 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')); $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) { $options = $this->dataObj->getCategories4Select(); $form->addElement( 'select', 'idCategory', array( 'label' => 'Category', 'multiOptions' => array('' => 'Select Category') + (array) $options, 'required' => true ) ); $form->addElement('text', 'title', array('label' => 'Subject', 'required' => true)); $form->addElement('htmlEditor', 'description', array('label' => 'Summary/Description', 'required' => false)); $path = constant('WWW_PATH') . '/' . App_DirectorFile_AbstractObj::DIRECTOR_PATH; $fileTransferAdapter = new Qs_File_Transfer_Adapter_Db(); $fileTransferAdapter->setDefaultDestination($path); $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) ) ); $form->getElement('file')->setTransferAdapter($fileTransferAdapter); $downloadUrl = BASE_URL_LANGUAGE. '/' . CURRENT_PAGE_FINAL . '?action=download&id=' . $this->_getData('id'); $form->getElement('file')->setDownloadUrl($downloadUrl); $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->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', 'idCategory', array( 'multiOptions' => array('' => 'All Categories') + $categories, 'onchange' => 'this.form.submit()', ) ); } return $this; } protected function _doNew() { $form = $this->_getNewForm(); $defaults = array(); $defaults['idCategory'] = Qs_Request::getGetValue('idCategory'); $form->setDefaults($defaults); $this->_renderMainForm($form); return $this; } protected function _getCategorySectionFullAlias() { if (null === $this->_categorySectionFullAlias) { $this->_categorySectionFullAlias = Qs_SiteMap::findFirst( null, array('type' => 'DirectorFile_Category_Admin'), null, 'fullAlias' ); } return $this->_categorySectionFullAlias; } protected function _getDefaultLinks() { $params = array('action' => 'new'); if (is_numeric($idCategory = $this->dataObj->getFilter('idCategory'))) { $params['idCategory'] = $idCategory; } $links = array(); $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($idCategory) && $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'] = '#'; } $fullAlias = $this->_getCategorySectionFullAlias(); if (false !== $fullAlias) { $links[] = array('title' => 'Manage Categories', 'url' => $fullAlias); } return $links; } }