示例#1
0
 /**
  * The function to add a new workshop to the system.
  *
  */
 public function addAction()
 {
     $workshop = new Workshop();
     $tag = new Tag();
     $we = new Workshop_Editor();
     $form = $workshop->form();
     $messages = array();
     if ($this->_request->isPost()) {
         if ($form->isValid($_POST)) {
             $data = array('status' => $form->getValue('status'), 'title' => $form->getValue('title'), 'description' => $form->getValue('description'), 'prerequisites' => $form->getValue('prerequisites'), 'categoryId' => $form->getValue('categoryId'));
             $workshopId = $workshop->insert($data);
             if ($form->getValue('tags') != '') {
                 $tags = explode(',', $form->getValue('tags'));
                 $tag->setTagsForAttribute('workshopId', $workshopId, $tags);
             }
             $we->setEditorsForWorkshop($workshopId, $form->getValue('editors'));
             $logOptions = array('attributeName' => 'workshopId', 'attributeId' => $workshopId);
             $this->_helper->log(Zend_Log::INFO, 'Workshop was added', $logOptions);
             $this->_helper->flashMessenger->addMessage('msg-info-workshopAdded');
             if ($data['status'] == 'enabled') {
                 $workshop->index($workshopId);
             }
             $this->_helper->redirector->gotoUrl('/workshop/index/details/?workshopId=' . $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-add:title');
     $this->view->form = $form;
     $this->view->messages = $messages;
 }
示例#2
0
 public function newAction()
 {
     $this->form->removeElement(Workshop::COL_ID);
     $table = new Workshop();
     $request = $this->getRequest();
     $insertValues = $request->getParams();
     $wsNamespace = new Zend_Session_Namespace('workshop');
     if ($request->isPost()) {
         if ($this->getRequest()->getParam('save') != null) {
             //save Button clicked
             if ($this->form->isValid($insertValues)) {
                 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->insert($data);
                     $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/new';
                 $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
         // Get part_id and part_role
         $auth = Zend_Auth::getInstance();
         $storage = $auth->getStorage();
         $constUserId = User::COL_ID;
         $userId = $storage->read()->{$constUserId};
         $constUsername = User::COL_USERNAME;
         $username = $storage->read()->{$constUsername};
         $this->form->isValidPartial(array(Workshop::COL_USER_ID => $userId, User::COL_USERNAME => $username));
         $guid = new Ble422_Guid();
         $wsNamespace->Token = $guid->__toString();
         $this->form->getElement('Token')->setValue($guid->__toString());
     }
 }