/**
  * 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;
 }
Exemple #2
0
 public function updateAction()
 {
     $table = new Workshop();
     $request = $this->getRequest();
     $updateValues = $request->getParams();
     $wsNamespace = new Zend_Session_Namespace('workshop');
     //$this->view->WORK_ID = $updateValues[Workshop::COL_ID];
     $workId = intval($this->getRequest()->getParam(Workshop::COL_ID));
     $this->view->WORK_ID = $workId;
     //if user is not actual workshop manager, redirect
     if (!AuthQuery::getUserId() == Default_SimpleQuery::getWsManagerUserId($workId)) {
         $this->redirectTo('list', 'search', 'workshop');
         return;
     }
     if ($request->isPost()) {
         if ($this->getRequest()->getParam('save') != null) {
             //save Button clicked
             if ($this->form->isValid($updateValues)) {
                 if ($this->form->getValue('Token') == $wsNamespace->Token) {
                     $data = array(Workshop::COL_NAME => $this->form->getValue(Workshop::COL_NAME), Workshop::COL_LOCATION => $this->form->getValue(Workshop::COL_LOCATION), Workshop::COL_START_DATE => $this->form->getValue(Workshop::COL_START_DATE), Workshop::COL_END_DATE => $this->form->getValue(Workshop::COL_END_DATE), Workshop::COL_HOST_ORGANISATION => $this->form->getValue(Workshop::COL_HOST_ORGANISATION), Workshop::COL_USER_ID => $this->form->getValue(Workshop::COL_USER_ID));
                     $table->update($data, Workshop::COL_ID . " = '" . $this->form->getValue(Workshop::COL_ID) . "'");
                     $wsNamespace->unsetAll();
                     $this->redirectTo();
                 } else {
                     $this->form->reset();
                     $this->render('outOfDate');
                 }
             }
         } else {
             if ($this->getRequest()->getParam('setManager') != null) {
                 // new ws manager button clicked
                 $wsNamespace->formValues = $this->getRequest()->getParams();
                 $defaultNamespace = new Zend_Session_Namespace('default');
                 $defaultNamespace->callingAction = 'workshop/edit/update';
                 $defaultNamespace->callingActionId = $request->getParam(Workshop::COL_ID);
                 $this->redirectTo('index', 'search', 'user');
             } else {
                 // new ws manager has choosen and is loading
                 $userTable = new User();
                 $userResult = $userTable->find($this->getRequest()->getParam(Workshop::COL_USER_ID))->current();
                 if ($userResult != null) {
                     $userArray = $userResult->toArray();
                 } else {
                     $userArray = array(Workshop::COL_USER_ID => null, User::COL_USERNAME => 'not valid');
                 }
                 $valueArray = $wsNamespace->formValues;
                 $valueArray[Workshop::COL_USER_ID] = $userArray[Workshop::COL_USER_ID];
                 $valueArray[User::COL_USERNAME] = $userArray[User::COL_USERNAME];
                 $this->form->isValid($valueArray);
                 if ($this->form->getValue('Token') == null) {
                     $guid = new Ble422_guid();
                     $wsNamespace->Token = $guid->__toString();
                     $this->form->getElement('Token')->setValue($guid->__toString());
                 }
             }
         }
     } else {
         // first call load form with default values
         $rowset = $table->find($request->getParam(Workshop::COL_ID))->current();
         if ($rowset != null) {
             $this->form->setValues($rowset->toArray());
         }
         $this->form->setAction(Zend_Controller_Front::getInstance()->getBaseUrl() . "/workshop/edit/update");
         // Get part_id and part_role
         $userTable = new User();
         $userResult = $userTable->find($this->form->getValue(Workshop::COL_USER_ID))->current();
         if ($userResult != null) {
             $userArray = $userResult->toArray();
         } else {
             $userArray = array(Workshop::COL_USER_ID => null, User::COL_USERNAME => 'not valid');
         }
         $this->form->isValidPartial(array(Workshop::COL_USER_ID => $userArray[User::COL_ID], User::COL_USERNAME => $userArray[User::COL_USERNAME]));
         $guid = new Ble422_Guid();
         $wsNamespace->Token = $guid->__toString();
         $this->form->getElement('Token')->setValue($guid->__toString());
     }
 }