getConfig('userType')); } protected function _isReviewer() { return (App_Application_Document_Obj::USER_TYPE_REVIEWER == $this->getConfig('userType')); } protected function _initAction() { $dataObj = $this->_getDataObj(); $userId = null; switch ($this->getConfig('userType')) { case App_Application_Document_Obj::USER_TYPE_APPLICANT: $userId = App_Application_User_Auth::getInstance()->getData('id'); break; case App_Application_Document_Obj::USER_TYPE_REVIEWER: if (1 != count($this->getRestParams())) { $this->_doc->display404(); return $this; } $userId = $this->getRestParam(0); if (!$dataObj->idAllowedApplication($userId, App_Application_Reviewer_Auth::getInstance()->getData('id'))) { $this->_doc->display404(); return $this; } $this->_hasFilter = true; $this->_filterQueryDescriptionFormat = 'Search will be done by "Document Name" or "Document Description".'; $dataObj->setHasFilter(true); $dataObj->setFilterFields(array('title', 'description')); break; default: throw new Exception('Unknown user type'); } $dataObj->setApplicationUserId($userId); $dataObj->setUserType($this->getConfig('userType')); self::createDocumentsSymlinks($userId); parent::_initAction(); if ($this->_action === 'upload') { if ($this->_isApplicant() && ($documentTypeId = Qs_Request::getGetValue('documentTypeId')) && ($documentType = $dataObj->getDocumentTypeById($documentTypeId)) ) { $this->_formDefaults = $documentType; foreach ($this->_formDefaults as $item => &$value) { $value = $value == '' ? '-' : $value; } $this->_formDefaults['documentTypeId'] = $documentTypeId; $this->_formDefaults['applicationUserId'] = $dataObj->getApplicationUserId(); } else { $this->_doc->display404(); } } return $this; } public function preDispatch(&$items) { parent::_initAction(); if ($this->_action != 'list') { foreach ($items as $index => $item) { if ($item['type'] == 'HtmlBlock_') { unset($items[$index]); } if ($item['type'] == 'Application_DeadlineNotice_') { unset($items[$index]); } } } return $this; } /** * @param int|int[] $userId * @return bool */ static public function createDocumentsSymlinks($userId) { if (!$userId) { return false; } if (!is_array($userId)) { $userId = array($userId); } $documentObj = new App_Application_Document_Obj(); $documentPath = constant('WWW_PATH') . '/' . App_Application_Document_Obj::DOCUMENT_PATH; $documentAccessPath = constant('WWW_PATH') . '/' . App_Application_Document_Obj::DOCUMENT_ACCESS_PATH . '/' . session_id(); foreach ($userId as $id) { $documents = $documentObj->getDocumentsByUserId($id); if ($documents && !is_dir($documentAccessPath)) { mkdir($documentAccessPath); } foreach ($documents as $document) { if (file_exists($documentPath . '/' . $document) && !file_exists($documentAccessPath . '/' . $document)) { symlink($documentPath . '/' . $document, $documentAccessPath . '/' . $document); } } } return true; } protected function _addListItem($list = null, $template = 'list.tpl') { if (null == $list) { $list = $this->list; } $list->documentUploadUrl = $this->url(array('action' => 'upload')); $list->documentEditUrl = $this->url(array('action' => 'edit')); return parent::_addListItem($list, $template); } /** * @param Qs_ViewController_List $list * * @return $this */ protected function _bindListColumns($list) { parent::_bindListColumns($list); if ($this->_isApplicant()) { $list->addColumn('uploads', 'uploads', array('title' => 'Upload', 'attribs' => 'class=text-center')); } if ($this->_isReviewer()) { $this->_bindReviewerListColumns($list); } return $this; } protected function _updatePageHeader(array $data) { $title = 'Upload Document - ' . $data['title']; $this->_doc->setHeader($title); $this->_doc->setTitle($title); return $this; } protected function _doList() { if (App_Application_Document_Obj::USER_TYPE_REVIEWER == $this->_getDataObj()->getUserType()) { $this->_doc->appendHeader(' - ' . $this->_getDataObj()->getApplicationUserData('schoolName')); } return parent::_doList(); } protected function _doUpload() { parent::_doNew(); $this->_updatePageHeader($this->getFormDefaults()); return $this; } protected function _doEdit() { parent::_doEdit(); $this->_updatePageHeader($this->_getDataObj()->getData()); return $this; } protected function _doUpdate() { parent::_doUpdate(); $this->_updatePageHeader($this->_getDataObj()->getData()); return $this; } protected function _getEditForm() { $form = parent::_getEditForm(); $this->_setStaticValues($form); return $form; } protected function _getNewForm() { $form = parent::_getNewForm(); $this->_setStaticValues($form); return $form; } protected function _setStaticValues(Qs_Form $form) { if ('POST' == $_SERVER['REQUEST_METHOD'] && ($documentTypeId = Qs_Request::getPostValue('documentTypeId'))) { $documentType = $this->_getDataObj()->getDocumentTypeById($documentTypeId); $form->getElement('title')->setValue($documentType['title']); $form->getElement('description')->setValue($documentType['description']); } return $this; } protected function _bindFormFields(Qs_Form $form) { $form->addElement('static', 'title', array('label' => 'Document Name')); $form->addElement('static', 'description', array('label' => 'Description')); $form->addElement('hidden', 'documentTypeId'); $form->addElement('hidden', 'applicationUserId'); $form->addElement( 'extendedFile', 'file', array( 'label' => 'File', 'destination' => constant('WWW_PATH') . '/' . App_Application_Document_Obj::DOCUMENT_PATH, 'downloadUrl' => constant('BASE_URL') . '/' . App_Application_Document_Obj::DOCUMENT_ACCESS_PATH . '/' . session_id() . '/' . $this->_getDataObj()->getData('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); return $this; } protected function _bindFormButtons($form) { parent::_bindFormButtons($form); $form->getElement('btnSubmit')->setLabel('Upload'); return $this; } public function fillConfigForm($form) { $form->addElement( 'select', 'userType', array( 'label' => 'User Type', 'multiOptions' => array( App_Application_Document_Obj::USER_TYPE_APPLICANT => 'Applicant', App_Application_Document_Obj::USER_TYPE_REVIEWER => 'Reviewer' ), ) ); return $this; } /** * @param Qs_Form $form * * @return $this|App_Application_Document_View */ protected function _bindFilterFields($form) { parent::_bindFilterFields($form); $form->addElement( 'select', 'status', array( 'label' => 'Filter By Document Status:', 'multiOptions' => array( '' => 'All Documents', App_Application_Document_Obj::STATUS_AWAITING_REVIEW => 'Awaiting Review', App_Application_Document_Obj::STATUS_REVIEW_COMPLETED => 'Review Completed', ) ) ); return $this; } }