Ejemplo n.º 1
0
 /**
  * Allows a user to edit a workshop
  *
  */
 public function editAction()
 {
     $get = Zend_Registry::get('getFilter');
     if (!isset($get->workshopId)) {
         throw new Ot_Exception_Input('msg-error-workshopIdNotSet');
     }
     $workshop = new Workshop();
     $tag = new Tag();
     $we = new Workshop_Editor();
     $thisWorkshop = $workshop->find($get->workshopId);
     if (is_null($thisWorkshop)) {
         throw new Ot_Exception_Data('msg-error-noWorkshop');
     }
     if (!$this->_helper->hasAccess('edit-all-workshops') && !$we->isEditor($thisWorkshop->workshopId, Zend_Auth::getInstance()->getIdentity()->accountId)) {
         throw new Ot_Exception_Access('msg-error-noAccess');
     }
     $thisWorkshopArray = $thisWorkshop->toArray();
     $thisWorkshopArray['tags'] = array();
     $tags = $tag->getTagsForAttribute('workshopId', $thisWorkshop->workshopId);
     foreach ($tags as $t) {
         array_push($thisWorkshopArray['tags'], $t['name']);
     }
     $we = new Workshop_Editor();
     $where = $we->getAdapter()->quoteInto('workshopId = ?', $thisWorkshop->workshopId);
     $results = $we->fetchAll($where);
     $thisWorkshopArray['editors'] = array();
     foreach ($results as $r) {
         array_push($thisWorkshopArray['editors'], $r->accountId);
     }
     $form = $workshop->form($thisWorkshopArray);
     $messages = array();
     if ($this->_request->isPost()) {
         if ($form->isValid($_POST)) {
             $data = array('workshopId' => $thisWorkshop->workshopId, 'status' => $form->getValue('status'), 'title' => $form->getValue('title'), 'description' => $form->getValue('description'), 'prerequisites' => $form->getValue('prerequisites'));
             $workshop->update($data, null);
             if ($form->getValue('tags') != '') {
                 $tags = explode(',', $form->getValue('tags'));
                 $tag->setTagsForAttribute('workshopId', $thisWorkshop->workshopId, $tags);
             }
             $we->setEditorsForWorkshop($thisWorkshop->workshopId, $form->getValue('editors'));
             $logOptions = array('attributeName' => 'workshopId', 'attributeId' => $thisWorkshop->workshopId);
             $this->_helper->log(Zend_Log::INFO, 'Workshop was modified', $logOptions);
             $this->_helper->flashMessenger->addMessage('msg-info-workshopModified');
             if ($data['status'] == 'enabled') {
                 $workshop->index($thisWorkshop->workshopId);
             } else {
                 $workshop->deleteFromIndex($thisWorkshop->workshopId);
             }
             $this->_helper->redirector->gotoUrl('/workshop/index/details/?workshopId=' . $thisWorkshop->workshopId);
         } else {
             $messages[] = 'msg-error-formSubmitProblem';
         }
     }
     $this->view->headScript()->appendFile($this->view->baseUrl() . '/scripts/jquery.wysiwyg.js');
     $this->view->headScript()->appendFile($this->view->baseUrl() . '/scripts/jquery.autocomplete.js');
     $this->view->headLink()->appendStylesheet($this->view->baseUrl() . '/css/jquery.wysiwyg.css');
     $this->view->headLink()->appendStylesheet($this->view->baseUrl() . '/css/jquery.autocomplete.css');
     $this->_helper->pageTitle('workshop-index-edit:title');
     $this->view->form = $form;
     $this->view->messages = $messages;
 }