Пример #1
0
 public function viewAction()
 {
     $identity = Zend_Auth::getInstance()->getIdentity();
     $id = Zend_Filter::filterStatic($this->_getParam('id'), 'int');
     $exerciseId = Zend_Filter::filterStatic($this->_getParam('exerciseId'), 'int');
     $userId = Zend_Filter::filterStatic($this->_getParam('userId', $identity->id), 'int');
     $exercise = new Tri_Db_Table('exercise');
     $exerciseQuestion = new Tri_Db_Table('exercise_question');
     $exerciseNote = new Tri_Db_Table('exercise_note');
     $exerciseAnswer = new Tri_Db_Table('exercise_answer');
     if ($id) {
         $note = $exerciseNote->fetchRow(array('id = ?' => $id));
     } elseif ($exerciseId) {
         $note = $exerciseNote->fetchRow(array('exercise_id = ?' => $exerciseId, 'user_id = ?' => $userId), 'id DESC');
     }
     if ($note) {
         $row = $exercise->fetchRow(array('id = ?' => $note->exercise_id));
         if ($row) {
             $where = array('exercise_id = ?' => $row->id, 'status = ?' => 'active');
             $this->view->questions = $exerciseQuestion->fetchAll($where);
             $this->view->exercise = $row;
             $this->view->answers = $exerciseAnswer->fetchAll(array('exercise_note_id = ?' => $note->id));
             $this->view->note = $note;
             $whereNote = array('exercise_id = ?' => $note->exercise_id, 'id <> ?' => $note->id, 'user_id = ?' => $userId);
             $this->view->notes = $exerciseNote->fetchAll($whereNote, 'id DESC');
             $this->view->userId = $userId;
         } else {
             $this->view->message = 'there are no records';
         }
     } else {
         $this->view->message = 'there are no records';
     }
 }
Пример #2
0
 /**
  * Action send.
  *
  * @return void
  */
 public function sendAction()
 {
     $form = new Application_Form_Forgot();
     $tableUser = new Tri_Db_Table('user');
     $data = $this->_getAllParams();
     if ($form->isValid($data)) {
         $email = $this->_getParam('email');
         $user = $tableUser->fetchRow(array('email = ?' => $email));
         if (!$user->id) {
             $this->_helper->_flashMessenger->addMessage('user not avaliable');
             $this->_redirect('forgot/');
         }
         $this->view->name = $user->name;
         $this->view->url = $this->encryptUrl($user);
         $mail = new Zend_Mail(APP_CHARSET);
         $mail->setBodyHtml($this->view->render('forgot/mail.phtml'));
         $mail->setFrom(FROM_EMAIL, FROM_NAME);
         $mail->setSubject($this->view->translate('forgot'));
         $mail->addTo($user->email, $user->name);
         $mail->send();
         $this->_helper->_flashMessenger->addMessage('Success');
         $this->_redirect('forgot/');
     }
     $this->_helper->_flashMessenger->addMessage('Error');
     $this->_redirect('forgot/');
 }
Пример #3
0
 public function payAction()
 {
     $classroom = new Tri_Db_Table('classroom');
     $session = new Zend_Session_Namespace('data');
     $select = $classroom->select(true)->setIntegrityCheck(false)->join('course', 'course.id = classroom.course_id', 'course.name as cname')->where('classroom.id = ?', $session->classroom_id)->order('status');
     $this->view->data = $classroom->fetchRow($select);
 }
Пример #4
0
 public function validateAction()
 {
     $uniqueId = $this->_getParam('uniqueId');
     if ($uniqueId) {
         $certificate = new Tri_Db_Table('certificate');
         $select = $certificate->select(true)->setIntegrityCheck(false)->join('classroom', 'classroom.id = certificate.classroom_id', array())->join('course', 'course.id = classroom.course_id')->join('user', 'user.id = certificate.user_id', array('user.name as uname'))->where('unique_id = ?', $uniqueId);
         $this->view->data = $certificate->fetchRow($select);
     }
 }
Пример #5
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();
     }
 }
Пример #6
0
 /**
  * Remove question from exercise
  *
  * @param array $questionIds
  */
 public static function remove($questionIds)
 {
     if (count($questionIds)) {
         $question = new Tri_Db_Table('exercise_question');
         foreach ($questionIds as $questionId) {
             $row = $question->fetchRow(array('id = ?' => $questionId));
             $row->exercise_id = null;
             $row->save();
         }
     }
 }
Пример #7
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;
 }
Пример #8
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();
     }
 }
Пример #9
0
 private function _verifyPanel($in)
 {
     $session = new Zend_Session_Namespace('data');
     $table = new Tri_Db_Table('restriction_panel');
     $select = $table->select()->where('classroom_id = ?', $session->classroom_id)->where('content_id IN(?)', $in);
     $result = $table->fetchAll($select);
     $panelNote = new Tri_Db_Table('panel_note');
     if (count($result)) {
         foreach ($result as $rs) {
             $note = $panelNote->fetchRow(array('panel_id = ?' => $rs->panel_id))->note;
             if ($note < $rs->note) {
                 self::$restriction['has'] = true;
                 self::$restriction['content'] = "restriction content, note must have more than";
                 self::$restriction['value'] = $rs->note;
                 return false;
             }
             if ($note < $rs->note_restriction) {
                 self::_verifyTime($in);
             }
         }
     } else {
         self::_verifyTime($in);
     }
 }
Пример #10
0
 /**
  * Verify if class it's available
  *
  * @param int $id 
  * @return boolean
  */
 public static function isAvailable($id)
 {
     $classroom = new Tri_Db_Table('classroom');
     $classroomUser = new Tri_Db_Table('classroom_user');
     $row = $classroom->fetchRow(array('id = ?' => $id));
     if (!$row) {
         return false;
     }
     $select = $classroomUser->select(true)->columns(array('COUNT(0) as total'))->where('classroom_id = ?', $id);
     $total = $classroom->fetchRow($select)->total;
     if ($row->max_student > 0 && $row->max_student <= $total) {
         return false;
     }
     return true;
 }
Пример #11
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');
 }
Пример #12
0
 /**
  * Action matriculate
  *
  * @return void
  */
 public function rejectAction()
 {
     $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::REJECTED;
             $row->setFromArray($data);
             $id = $row->save();
             if ($id) {
                 $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']);
 }
Пример #13
0
 public function changeAction()
 {
     $userId = Zend_Filter::filterStatic($this->_getParam('userId'), 'int');
     $status = $this->_getParam('status');
     $classroomUser = new Tri_Db_Table('classroom_user');
     $session = new Zend_Session_Namespace('data');
     $where = array('classroom_id = ?' => $session->classroom_id, 'user_id = ?' => $userId);
     $row = $classroomUser->fetchRow($where);
     if ($row) {
         $row->status = $status;
         $row->save();
     }
     $this->_helper->_flashMessenger->addMessage('Success');
     $this->_redirect('/panel');
 }
Пример #14
0
 public function listUserAction()
 {
     $id = Zend_filter::filterStatic($this->_getParam('id'), 'int');
     $classroom = new Tri_Db_Table('classroom');
     $classroomUser = new Tri_Db_Table('classroom_user');
     $select = $classroomUser->select(true)->setIntegrityCheck(false)->join('user', 'classroom_user.user_id = user.id')->where('classroom_user.classroom_id = ?', $id)->order('name');
     $this->view->data = $classroomUser->fetchAll($select);
     $select = $classroom->select(true)->setIntegrityCheck(false)->join('course', 'course.id = classroom.course_id', 'course.name as cname')->where('classroom.id = ?', $id)->order('status');
     $this->view->classroom = $classroom->fetchRow($select);
     $this->view->id = $id;
 }