Пример #1
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');
 }
Пример #2
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');
 }
Пример #3
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');
 }
Пример #4
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');
 }
Пример #5
0
 public function saveAction()
 {
     if ($this->_request->isPost()) {
         $exerciseNote = new Tri_Db_Table('exercise_note');
         $exerciseAnswer = new Tri_Db_Table('exercise_answer');
         $panelNote = new Tri_Db_Table('panel_note');
         $identity = Zend_Auth::getInstance()->getIdentity();
         $params = $this->_getAllParams();
         $data = array();
         $note = $exerciseNote->fetchRow(array('user_id = ?' => $identity->id), 'id DESC');
         if (isset($params['option'])) {
             foreach ($params['option'] as $option) {
                 $data['exercise_note_id'] = $note->id;
                 $data['exercise_option_id'] = $option;
                 $exerciseAnswer->createRow($data)->save();
             }
         }
         $note->note = Exercise_Model_Reply::sumNote($note->id);
         $note->save();
         Panel_Model_Panel::addNote($identity->id, 'exercise', $note->exercise_id, $note->note);
         $this->_redirect('/exercise/reply/view/id/' . $note->id);
     } else {
         $this->_helper->_flashMessenger->addMessage('Error');
         $this->_redirect('/exercise');
     }
 }
Пример #6
0
 /**
  * Associate question to exercise
  * If no previous associate duplicate and associate
  *
  * @param integer $exerciseId
  * @param array $questionIds
  */
 public static function associate($exerciseId, $questionIds)
 {
     if (count($questionIds)) {
         $question = new Tri_Db_Table('exercise_question');
         $optionTable = new Tri_Db_Table('exercise_option');
         foreach ($questionIds as $position => $questionId) {
             $row = $question->fetchRow(array('id = ?' => $questionId));
             if ($row) {
                 $row->position = $position;
                 if ($row->exercise_id != $exerciseId) {
                     $data = $row->toArray();
                     if (!$row->exercise_id) {
                         $data['parent_id'] = $data['id'];
                     }
                     $data['exercise_id'] = $exerciseId;
                     unset($data['id']);
                     $id = $question->createRow($data)->save();
                     $options = $optionTable->fetchAll(array('exercise_question_id = ?' => $questionId));
                     foreach ($options as $option) {
                         $data = $option->toArray();
                         unset($data['id']);
                         $data['exercise_question_id'] = $id;
                         $optionTable->createRow($data)->save();
                     }
                 } else {
                     $row->save();
                 }
             }
         }
     }
 }
Пример #7
0
 public function saveNoteAction()
 {
     $data = $this->_getAllParams();
     $panelNote = new Tri_Db_Table('panel_note');
     $panelNote->delete(array('panel_id = ?' => $data['panel_id'], 'user_id = ?' => $data['user_id']));
     $panelNote->createRow($data)->save();
     exit('ok');
 }
Пример #8
0
 /**
  * Create initial content
  *
  * @param integer $courseId
  */
 public static function createInitialContent($courseId)
 {
     $data = array();
     $data['course_id'] = $courseId;
     $data['title'] = "Introdução";
     $data['description'] = "Bem vindo ao curso!";
     $table = new Tri_Db_Table('content');
     $table->createRow($data)->save();
 }
Пример #9
0
 /**
  *
  * @param string $type
  * @param integer $id
  * @param integer $note
  */
 public static function addNote($userId, $type, $id, $note)
 {
     $session = new Zend_Session_Namespace('data');
     $panel = new Tri_Db_Table('panel');
     $row = $panel->fetchRow(array('type = ?' => $type, 'item_id = ?' => $id, 'classroom_id = ?' => $session->classroom_id));
     if ($row) {
         $panelNote = new Tri_Db_Table('panel_note');
         $panelNote->delete(array('panel_id = ?' => $row->id, 'user_id = ?' => $userId));
         $panelNote->createRow(array('panel_id' => $row->id, 'user_id' => $userId, 'note' => $note))->save();
     }
 }
Пример #10
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');
 }
Пример #11
0
 /**
  * Save timeline
  *
  * @param string $description 
  * @param string $postInfo 
  * @return void
  */
 public static function save($description, $postInfo = null)
 {
     $timeline = new Tri_Db_Table('timeline');
     $session = new Zend_Session_Namespace('data');
     $translate = Zend_Registry::get('Zend_Translate');
     $userId = Zend_Auth::getInstance()->getIdentity()->id;
     if ($postInfo) {
         $postInfo = ' - ' . $postInfo;
     }
     if (isset($session->classroom_id) && $userId) {
         $data = array('user_id' => $userId, 'classroom_id' => $session->classroom_id, 'description' => $translate->_($description) . $postInfo);
         $timeline->createRow($data)->save();
     }
 }
Пример #12
0
 public static function set($name, $data, $encoded = false)
 {
     $table = new Tri_Db_Table('configuration');
     $where = array('name = ?' => $name);
     $row = $table->fetchRow($where);
     if (!$row) {
         $row = $table->createRow();
     }
     if ($encoded) {
         $data = Zend_Json::encode($data);
     }
     self::$_data[$name] = $row->value = $data;
     $row->save();
     return $row->value;
 }
Пример #13
0
 /**
  * Emit certificate
  *
  * @param integer $userId
  * @param integer $classroomId
  */
 public static function emit($userId, $classroomId)
 {
     $classroom = new Tri_Db_Table('classroom');
     $row = $classroom->fetchRow(array('id = ?' => $classroomId));
     if ($row) {
         $classroomUser = new Tri_Db_Table('classroom_user');
         $certificate = new Tri_Db_Table('certificate');
         $uniqueId = uniqid();
         $where = array('classroom_id = ?' => $classroomId, 'user_id = ?' => $userId);
         $update = $classroomUser->fetchRow($where);
         $update->status = 'approved';
         $update->save();
         $data = array('classroom_id' => $classroomId, 'user_id' => $userId, 'unique_id' => $uniqueId, 'begin' => $row->begin, 'end' => date('Y-m-d'));
         $certificate->createRow($data)->save();
     }
 }
Пример #14
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'];
     }
 }
Пример #15
0
 public function saveAction()
 {
     $form = new Content_Form_File();
     $table = new Tri_Db_Table('content_file');
     $data = $this->_getAllParams();
     if ($form->isValid($data)) {
         if (!$form->location->receive()) {
             $this->_helper->_flashMessenger->addMessage('File fail');
         }
         $data = $form->getValues();
         $data['user_id'] = Zend_Auth::getInstance()->getIdentity()->id;
         $row = $table->createRow($data);
         $id = $row->save();
     } else {
         $this->_response->prepend('messages', $this->view->translate('Error'));
         $this->view->form = $form;
         $this->render('form');
     }
 }
Пример #16
0
 public function saveAction()
 {
     $form = new File_Form_File();
     $table = new Tri_Db_Table('file');
     $session = new Zend_Session_Namespace('data');
     $data = $this->_getAllParams();
     if ($form->isValid($data)) {
         if (!$form->location->receive()) {
             $this->_helper->_flashMessenger->addMessage('File fail');
         }
         $data = $form->getValues();
         $data['user_id'] = Zend_Auth::getInstance()->getIdentity()->id;
         $data['classroom_id'] = $session->classroom_id;
         $row = $table->createRow($data);
         $id = $row->save();
         Application_Model_Timeline::save('saved a new file', $data['name']);
     } else {
         $this->_response->prepend('messages', $this->view->translate('Error'));
         $this->view->form = $form;
         $this->render('form');
     }
 }
Пример #17
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');
 }
Пример #18
0
 public function matriculateAction()
 {
     $id = Zend_filter::filterStatic($this->_getParam('id'), 'int');
     if ($this->_hasParam('userId')) {
         $classroomUser = new Tri_Db_Table('classroom_user');
         $data['user_id'] = $this->_getParam('userId');
         $data['classroom_id'] = $id;
         $classroomUser->createRow($data)->save();
         $this->_helper->_flashMessenger->addMessage('Success');
         $this->_redirect('admin/classroom/list-user/id/' . $id);
     }
     $table = new Zend_Db_Table('user');
     $select = $table->select()->order('id DESC');
     $paginator = new Tri_Paginator($select, 1);
     $this->view->data = $paginator->getResult();
     $this->view->id = $id;
 }
Пример #19
0
 public function liveSaveAction()
 {
     $id = Zend_Filter::filterStatic($this->_getParam('id'), 'int');
     $description = Zend_Filter::filterStatic($this->_getParam('description'), 'striptags');
     $table = new Tri_Db_Table('chat_room_message');
     $data = array('user_id' => Zend_Auth::getInstance()->getIdentity()->id, 'chat_room_id' => $id, 'description' => $description, 'status' => 'message');
     $table->createRow($data)->save();
     $this->_redirect('chat/room/live/interval/true/id/' . $id);
 }
Пример #20
0
 public function registerAction()
 {
     $session = new Zend_Session_Namespace('data');
     $classroomUser = new Tri_Db_Table('classroom_user');
     $data['user_id'] = Zend_Auth::getInstance()->getIdentity()->id;
     $data['classroom_id'] = $session->classroom_id;
     try {
         $classroomUser->createRow($data)->save();
         $this->_helper->_flashMessenger->addMessage('Success');
     } catch (Exception $e) {
         $this->_helper->_flashMessenger->addMessage('Student already registered in this class');
     }
     $this->_redirect('/dashboard');
 }
Пример #21
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');
 }
Пример #22
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');
 }
Пример #23
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');
 }
Пример #24
0
 /**
  * Action matriculate
  *
  * @return void
  */
 public function matriculateAction()
 {
     $post = $this->_getAllParams();
     if (count($post['interested'])) {
         $table = new Tri_Db_Table('selection_process_user');
         foreach ($post['interested'] as $interested) {
             $i = explode('-', $interested);
             //Alter status of the interested to ACCEPTS
             $where['selection_process_id = ?'] = $i[0];
             $where['classroom_id = ?'] = $i[1];
             $where['user_id = ?'] = $i[2];
             $row = $table->fetchRow($where);
             $data['status'] = SelectionProcess_Model_SelectionProcess::ACCEPTS;
             $row->setFromArray($data);
             $id = $row->save();
             if (!$id) {
                 $this->_helper->_flashMessenger->addMessage('Error');
                 $this->_redirect('selection-process/index/list-pre-registration/id/' . $post['id']);
             }
             //Save new student in classroom_user
             $tableClassRoom = new Tri_Db_Table('classroom_user');
             $classroom['classroom_id'] = $i[1];
             $classroom['user_id'] = $i[2];
             $classroom['status'] = Application_Model_Classroom::REGISTERED;
             $rowClass = $tableClassRoom->createRow($classroom);
             $result = $rowClass->save();
             if ($result) {
                 $this->_helper->_flashMessenger->addMessage('Success');
                 $this->_redirect('selection-process/index/list-pre-registration/id/' . $post['id']);
             }
         }
     }
     $this->_helper->_flashMessenger->addMessage('Error');
     $this->_redirect('selection-process/index/list-pre-registration/id/' . $post['id']);
 }