コード例 #1
0
 public function saveAction()
 {
     $form = new Exercise_Form_Question();
     $table = new Tri_Db_Table('exercise_question');
     $option = new Tri_Db_Table('exercise_option');
     $session = new Zend_Session_Namespace('data');
     $allData = $this->_getAllParams();
     $form->addMultipleText();
     if ($form->isValid($allData)) {
         $data = $form->getValues();
         if (isset($data['id']) && $data['id']) {
             $row = $table->find($data['id'])->current();
             $row->setFromArray($data);
             $id = $row->save();
         } else {
             unset($data['id']);
             if (isset($session->exercise_id) && $session->exercise_id) {
                 $exerciseId = $data['exercise_id'] = $session->exercise_id;
             }
             $row = $table->createRow($data);
             $id = $row->save();
         }
         if (count($allData['option'])) {
             foreach ($allData['option'] as $key => $value) {
                 $status = "wrong";
                 if ($allData['right_option'] == $key) {
                     $status = "right";
                 }
                 if ($value) {
                     if (isset($allData['id_option'][$key]) && $allData['id_option'][$key] != 0) {
                         $row = $option->find($allData['id_option'][$key])->current();
                         $row->setFromArray(array('description' => $value, 'status' => $status));
                         $row->save();
                     } else {
                         $data = array('description' => $value, 'exercise_question_id' => $id, 'status' => $status);
                         $row = $option->createRow($data);
                         $row->save();
                     }
                 } else {
                     if (isset($allData['id_option'][$key]) && $allData['id_option'][$key] != 0) {
                         $option->find($allData['id_option'][$key])->current()->delete();
                     }
                 }
             }
         }
         $this->_helper->_flashMessenger->addMessage('Success');
         $this->_redirect('exercise/question/index/id/' . $exerciseId);
     }
     $this->view->messages = array('Error');
     $this->getResponse()->prepend('messages', $this->view->render('message.phtml'));
     $this->view->form = $form;
     $this->render('form');
 }
コード例 #2
0
 public function saveAction()
 {
     $form = new Faq_Form_Faq();
     $table = new Tri_Db_Table('faq');
     $session = new Zend_Session_Namespace('data');
     $data = $this->_getAllParams();
     if ($form->isValid($data)) {
         $data = $form->getValues();
         $data['user_id'] = Zend_Auth::getInstance()->getIdentity()->id;
         $data['classroom_id'] = $session->classroom_id;
         if (isset($data['id']) && $data['id']) {
             $row = $table->find($data['id'])->current();
             $row->setFromArray($data);
             $id = $row->save();
         } else {
             unset($data['id']);
             $row = $table->createRow($data);
             $id = $row->save();
             Application_Model_Timeline::save('created a new FAQ', $data['question']);
         }
         $this->_helper->_flashMessenger->addMessage('Success');
         $this->_redirect('faq/index/form/id/' . $id);
     }
     $this->_helper->_flashMessenger->addMessage('Error');
     $this->view->form = $form;
     $this->render('form');
 }
コード例 #3
0
 public function saveAction()
 {
     $form = new Activity_Form_Text();
     $table = new Tri_Db_Table('activity_text');
     $session = new Zend_Session_Namespace('data');
     $data = $this->_getAllParams();
     $statusList = array('openButton' => 'open', 'finalize' => 'final');
     if (Zend_Auth::getInstance()->getIdentity()->role == 'student') {
         $statusList['sendCorrection'] = 'close';
         $statusList['saveDraft'] = 'open';
     }
     if ($form->isValid($data)) {
         $data = $form->getValues();
         $data['sender'] = Zend_Auth::getInstance()->getIdentity()->id;
         $data['status'] = $statusList[$data['status']];
         $row = $table->createRow($data);
         $id = $row->save();
         if (isset($data['note']) && $data['note']) {
             Panel_Model_Panel::addNote($row->user_id, 'activity', $data['activity_id'], $data['note']);
         }
         $this->_helper->_flashMessenger->addMessage('Success');
         $this->_redirect('activity/text/index/id/' . $data['activity_id'] . '/textId/' . $id . '/userId/' . $data['user_id']);
     }
     $activity = new Tri_Db_Table('activity');
     $this->view->parent = $activity->find($data['activity_id'])->current();
     $this->view->messages = array('Error');
     $this->view->form = $form;
     $this->render('index');
 }
コード例 #4
0
 public function saveAction()
 {
     $form = new Notepad_Form_Notepad();
     $table = new Tri_Db_Table('notepad');
     $session = new Zend_Session_Namespace('data');
     $data = $this->_getAllParams();
     if ($form->isValid($data)) {
         $data = $form->getValues();
         $data['user_id'] = Zend_Auth::getInstance()->getIdentity()->id;
         $data['classroom_id'] = $session->classroom_id;
         if (isset($data['id']) && $data['id']) {
             $row = $table->find($data['id'])->current();
             $row->setFromArray($data);
             $id = $row->save();
         } else {
             unset($data['id']);
             $row = $table->createRow($data);
             $id = $row->save();
         }
         $this->_helper->_flashMessenger->addMessage('Success');
         $this->_redirect('notepad/index/index/');
     }
     $this->view->messages = array('Error');
     $this->view->form = $form;
     $this->render('index');
 }
コード例 #5
0
 public function saveAction()
 {
     $form = new Calendar_Form_Form();
     $table = new Tri_Db_Table('calendar');
     $data = $this->_getAllParams();
     if ($form->isValid($data)) {
         $data = $form->getValues();
         $data['user_id'] = Zend_Auth::getInstance()->getIdentity()->id;
         if (!$data['classroom_id']) {
             unset($data['classroom_id']);
         }
         if (isset($data['id']) && $data['id']) {
             $row = $table->find($data['id'])->current();
             $row->setFromArray($data);
         } else {
             unset($data['id']);
             $row = $table->createRow($data);
         }
         $id = $row->save();
         $this->_helper->_flashMessenger->addMessage('Success');
         $this->_redirect('calendar/index/form/id/' . $id);
     }
     $this->_helper->_flashMessenger->addMessage('Error');
     $this->view->form = $form;
     $this->render('form');
 }
コード例 #6
0
 public function saveAction()
 {
     $form = new Admin_Form_Classroom();
     $table = new Tri_Db_Table('classroom');
     $data = $this->_getAllParams();
     if ($form->isValid($data)) {
         $data = $form->getValues();
         $data['user_id'] = Zend_Auth::getInstance()->getIdentity()->id;
         if (!$data['amount']) {
             unset($data['amount']);
         }
         if (!$data['responsible']) {
             unset($data['responsible']);
         }
         if (isset($data['id']) && $data['id']) {
             $row = $table->find($data['id'])->current();
             $row->setFromArray($data);
             $id = $row->save();
         } else {
             unset($data['id']);
             $row = $table->createRow($data);
             $id = $row->save();
         }
         $this->_helper->_flashMessenger->addMessage('Success');
         $this->_redirect('admin/classroom/');
     }
     $this->view->messages = array('Error');
     $this->view->form = $form;
     $this->render('form');
 }
コード例 #7
0
 public function viewAction()
 {
     $id = Zend_Filter::filterStatic($this->_getParam('id'), 'int');
     if ($id) {
         $course = new Tri_Db_Table('course');
         $classroom = new Tri_Db_Table('classroom');
         $this->view->data = $course->find($id)->current();
         $where = array('course_id = ?' => $id, 'status = ?' => 'open', 'end >= ? OR end IS NULL' => date('Y-m-d'));
         $this->view->classroom = $classroom->fetchAll($where, 'begin');
         $this->view->selectionProcess = SelectionProcess_Model_SelectionProcess::getAvailableProcessByCourse($id);
     }
 }
コード例 #8
0
 public function saveAction()
 {
     $data = $_POST['position'];
     $id = Zend_Filter::filterStatic($this->_getParam('id'), 'int');
     $content = new Tri_Db_Table('content');
     $i = 1;
     foreach ($data as $key => $val) {
         $row = $content->find($key)->current();
         $row->position = $i;
         $row->save();
         $i++;
     }
     $this->_helper->_flashMessenger->addMessage('Success');
     $this->_redirect('/content/organizer/index/id/' . $id);
 }
コード例 #9
0
 public function viewAction()
 {
     $id = Zend_Filter::filterStatic($this->_getParam('id'), 'int');
     $string = $this->_getParam('string');
     $session = new Zend_Session_Namespace('data');
     $restriction = Content_Model_Restriction::verify($id);
     if (empty($restriction['has'])) {
         $table = new Tri_Db_Table('content');
         $contentAccess = new Tri_Db_Table('content_access');
         $this->view->data = $table->find($id)->current();
         $data['content_id'] = $id;
         $data['user_id'] = Zend_Auth::getInstance()->getIdentity()->id;
         $data['classroom_id'] = $session->classroom_id;
         $contentAccess->createRow($data)->save();
     } else {
         $this->view->restriction = $this->view->translate($restriction['content']) . " " . $restriction['value'];
     }
 }
コード例 #10
0
 public function liveAction()
 {
     $id = Zend_Filter::filterStatic($this->_getParam('id'), 'int');
     $chat = new Tri_Db_Table('chat_room');
     $table = new Tri_Db_Table('chat_room_message');
     $data = array('user_id' => Zend_Auth::getInstance()->getIdentity()->id, 'chat_room_id' => $id, 'status' => 'logged');
     $table->createRow($data)->save();
     $this->view->data = $chat->find($id)->current();
     $select = $table->select(true)->setIntegrityCheck(false)->join('user', 'user.id = user_id', array('name'))->where('chat_room_id = ?', $id)->where('chat_room_message.status = ?', 'message')->order('id');
     $this->view->stream = $table->fetchAll($select, 'id DESC');
     $select = $table->select(true)->setIntegrityCheck(false)->join('user', 'user.id = user_id', array('name', 'role'))->where('chat_room_id = ?', $id)->where('chat_room_message.status = ?', 'logged')->where('chat_room_message.created > SYSDATE() - INTERVAL 5 MINUTE')->order('name')->group('user.id');
     $this->view->users = $table->fetchAll($select);
     $this->view->id = $id;
     if ($this->_hasParam('interval')) {
         $this->view->interval = $this->_hasParam('interval');
         $this->render('stream');
     }
 }
コード例 #11
0
 public function saveAction()
 {
     $form = new Content_Form_Template();
     $table = new Tri_Db_Table('content_template');
     $data = $this->_getAllParams();
     if ($form->isValid($data)) {
         $data = $form->getValues();
         if (isset($data['id']) && $data['id']) {
             $row = $table->find($data['id'])->current();
             $row->setFromArray($data);
             $id = $row->save();
         } else {
             unset($data['id']);
             $row = $table->createRow($data);
             $id = $row->save();
         }
         $this->_helper->_flashMessenger->addMessage('Success');
         $this->_redirect('content/template/form/id/' . $id);
     }
     $this->view->messages = array('Error');
     $this->view->form = $form;
     $this->render('form');
 }
コード例 #12
0
 /**
  * @access public
  * @return void
  * @final
  */
 public function saveAction()
 {
     $form = new Content_Form_Composer();
     $table = new Tri_Db_Table('content');
     $data = $this->_getAllParams();
     $session = new Zend_Session_Namespace('data');
     if ($form->isValid($data)) {
         $data = $form->getValues();
         $data['course_id'] = $session->course_id;
         if (!$data['content_id']) {
             unset($data['content_id']);
         }
         if (isset($data['id']) && $data['id']) {
             $row = $table->find($data['id'])->current();
             $row->setFromArray($data);
             $id = $row->save();
         } else {
             unset($data['id']);
             $row = $table->createRow($data);
             $id = $row->save();
         }
         $session = new Zend_Session_Namespace('data');
         unset($session->contents);
         $this->_helper->_flashMessenger->addMessage('Success');
         $this->_redirect('/content/composer/index/id/' . $id);
     }
     $this->view->messages = array('Error');
     $this->view->form = $form;
     $this->render('form');
 }
コード例 #13
0
 /**
  * Action save.
  *
  * @return void
  */
 public function saveAction()
 {
     $messages = array();
     $isValidEmail = true;
     $session = new Zend_Session_Namespace('data');
     $form = new Application_Form_User();
     $table = new Tri_Db_Table('user');
     $data = $this->_getAllParams();
     if ($data['email'] && (!isset($data['id']) || !$data['id'])) {
         $row = $table->fetchRow(array('email = ?' => $data['email']));
         if ($row) {
             $isValidEmail = false;
             $messages[] = 'Email existing';
         }
     }
     if (!isset($data['id']) || !$data['id']) {
         $form->getElement('password')->setAllowEmpty(false);
     }
     if ($form->isValid($data) && $isValidEmail) {
         if (!$form->image->receive()) {
             $messages[] = 'Image fail';
         }
         $data = $form->getValues();
         if (!$form->image->getValue()) {
             unset($data['image']);
         }
         if (!$data['password']) {
             unset($data['password']);
         }
         if (isset($data['id']) && $data['id'] && Zend_Auth::getInstance()->hasIdentity()) {
             $row = $table->find($data['id'])->current();
             $row->setFromArray($data);
             $id = $row->save();
         } else {
             unset($data['id']);
             $row = $table->createRow($data);
             $id = $row->save();
             $session->attempt = 0;
             $data['password'] = $this->_getParam('password');
             $this->view->data = $data;
             $mail = new Zend_Mail(APP_CHARSET);
             $mail->setBodyHtml($this->view->render('user/welcome.phtml'));
             $mail->setSubject($this->view->translate('Welcome'));
             $mail->addTo($data['email'], $data['name']);
             $mail->send();
             $result = $this->login($data['email'], $data['password']);
             if ($result->isValid()) {
                 if ($session->url) {
                     $this->_helper->_flashMessenger->addMessage('Success');
                     $url = $session->url;
                     $session->url = null;
                     $this->_redirect($url);
                 }
             }
         }
         $this->_helper->_flashMessenger->addMessage('Success');
         $identity = Zend_Auth::getInstance()->getIdentity();
         if ($identity->id == $id) {
             $this->_redirect('user/edit');
         }
         if ($identity->role == 'institution') {
             $this->_redirect('user');
         }
         $this->_redirect('dashboard');
     }
     $messages[] = 'Error';
     $this->view->messages = $messages;
     $this->view->form = $form;
     $this->render('form');
 }
コード例 #14
0
 /**
  * Action pre register
  *
  * @return void
  */
 public function preRegisterAction()
 {
     $user_id = Zend_Auth::getInstance()->getIdentity()->id;
     $selectionProcess = Zend_Filter::filterStatic($this->_getParam('selection_process_id'), 'int');
     $result = SelectionProcess_Model_SelectionProcess::verifyUserPermission($user_id, $selectionProcess);
     if (false === $result) {
         $this->_helper->_flashMessenger->addMessage('Error pre-register');
         $this->_redirect('index');
     }
     $course = Zend_Filter::filterStatic($this->_getParam('course'), 'int');
     $form = new SelectionProcess_Form_PreRegister();
     $table = new Tri_Db_Table('selection_process_user');
     $courseTable = new Tri_Db_Table('course');
     $data = $this->_getAllParams();
     $data['user_id'] = Zend_Auth::getInstance()->getIdentity()->id;
     if ($this->getRequest()->isPost()) {
         if ($form->isValid($data)) {
             $data = $form->getValues();
             $row = $table->createRow($data);
             if ($row->save()) {
                 $this->_helper->_flashMessenger->addMessage('Success');
                 $this->_redirect('dashboard/');
             }
         }
     }
     $this->view->course = $courseTable->find($course)->current();
     $form->populate($data);
     $this->view->form = $form;
 }
コード例 #15
0
 /**
  * Action save
  *
  * @return void
  */
 public function saveAction()
 {
     $form = new Admin_Form_Course();
     $table = new Tri_Db_Table('course');
     $data = $this->_getAllParams();
     if ($form->isValid($data)) {
         if (!$form->image->receive()) {
             $this->_helper->_flashMessenger->addMessage('Image fail');
         }
         $data = $form->getValues();
         if (!$form->image->getValue()) {
             unset($data['image']);
         }
         if (!$data['responsible']) {
             unset($data['responsible']);
         }
         $data['user_id'] = Zend_Auth::getInstance()->getIdentity()->id;
         if (isset($data['id']) && $data['id']) {
             $row = $table->find($data['id'])->current();
             $row->setFromArray($data);
             $id = $row->save();
         } else {
             unset($data['id']);
             $classroom = new Zend_Db_Table('classroom');
             $row = $table->createRow($data);
             $id = $row->save();
             $responsible = null;
             if (isset($data['responsible'])) {
                 $responsible = $data['responsible'];
             }
             $data = array('course_id' => $id, 'responsible' => $responsible, 'name' => 'Open ' . $data['name'], 'begin' => date('Y-m-d'));
             $row = $classroom->createRow($data);
             $row->save();
         }
         $this->_helper->_flashMessenger->addMessage('Success');
         $this->_redirect('admin/course/form/id/' . $id);
     }
     $this->_helper->_flashMessenger->addMessage('Error');
     $this->view->form = $form;
     $this->render('form');
 }
コード例 #16
0
 /**
  * Action recovery.
  *
  * @return void
  */
 public function saveAction()
 {
     $tableUser = new Tri_Db_Table('user');
     $form = new Application_Form_Recovery();
     $data = $this->_getAllParams();
     if ($form->isValid($data)) {
         $data = $form->getValues();
         $row = $tableUser->find($data['id'])->current();
         $row->setFromArray($data);
         $id = $row->save();
         if (!empty($id)) {
             $this->_helper->_flashMessenger->addMessage('Success');
         } else {
             $this->_helper->_flashMessenger->addMessage('Error');
         }
         $this->_redirect('/');
     }
     $messages = $form->getMessages();
     if (!empty($messages['password']['notMatch'])) {
         $this->_helper->_flashMessenger->addMessage($messages['password']['notMatch']);
     } else {
         $this->_helper->_flashMessenger->addMessage('Error');
     }
     $this->_redirect('/');
 }