Beispiel #1
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();
                 }
             }
         }
     }
 }
Beispiel #2
0
 private function _verifyTime($in)
 {
     $session = new Zend_Session_Namespace('data');
     $table = new Tri_Db_Table('restriction_time');
     $select = $table->select()->where('classroom_id = ?', $session->classroom_id)->where('content_id IN(?)', $in);
     $result = $table->fetchAll($select);
     if (count($result)) {
         foreach ($result as $rs) {
             $started = (double) preg_replace('/[^0-9]/', '', $rs->begin);
             $finished = (double) preg_replace('/[^0-9]/', '', $rs->end);
             $today = (double) date('Ymd');
             if ($started > $today) {
                 self::$restriction['has'] = true;
                 self::$restriction['content'] = "restricted content, access after";
                 self::$restriction['value'] = $rs->begin;
                 return false;
             }
             if ($finished < $today) {
                 self::$restriction['has'] = true;
                 self::$restriction['content'] = "content expired since the";
                 self::$restriction['value'] = $rs->end;
                 return false;
             }
         }
     }
 }
 public function indexAction()
 {
     $id = Zend_Filter::filterStatic($this->_getParam('id'), 'int');
     $userId = Zend_Filter::filterStatic($this->_getParam('userId'), 'int');
     $page = Zend_Filter::filterStatic($this->_getParam('page'), 'int');
     $session = new Zend_Session_Namespace('data');
     $table = new Tri_Db_Table('message');
     $form = new Chat_Form_Message();
     $classroomUser = new Tri_Db_Table('classroom_user');
     $select = $table->select(true)->setIntegrityCheck(false)->join('user', 'message.sender = user.id', array('name', 'image'))->order('id DESC');
     if (!$userId) {
         $userId = Zend_Auth::getInstance()->getIdentity()->id;
     }
     $form->populate(array('receiver' => $userId));
     $select->where('receiver = ?', $userId);
     if ($id) {
         $table = new Tri_Db_Table('message');
         $row = $table->find($id)->current();
         if ($row) {
             $form->populate($row->toArray());
         }
     }
     $tableUser = new Tri_Db_Table('user');
     $user = $tableUser->find($userId)->current();
     $selectUser = $classroomUser->select(true)->setIntegrityCheck(false)->join('user', 'classroom_user.user_id = user.id')->where('classroom_user.classroom_id = ?', $session->classroom_id)->order('name');
     $this->view->users = $classroomUser->fetchAll($selectUser);
     $paginator = new Tri_Paginator($select, $page);
     $this->view->data = $paginator->getResult();
     $this->view->form = $form;
     $this->view->userId = $userId;
     $this->view->userName = $user->name;
     $this->view->userImage = $user->image;
 }
 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';
     }
 }
Beispiel #5
0
 /**
  * (non-PHPdoc)
  * @see Zend_Controller_Action#init()
  */
 public function init()
 {
     if (!Zend_Auth::getInstance()->getIdentity()) {
         $page = new Tri_Db_Table('page');
         $this->view->pages = $page->fetchAll("status = 'active'", 'position');
     }
 }
 public function formAction()
 {
     $session = new Zend_Session_Namespace('data');
     $table = new Tri_Db_Table('panel');
     $where = array('classroom_id = ?' => $session->classroom_id);
     $this->view->data = $table->fetchAll($where);
 }
 public function indexAction()
 {
     $id = Zend_Filter::filterStatic($this->_getParam('id'), 'int');
     $session = new Zend_Session_Namespace('data');
     $content = new Tri_Db_Table('content');
     if ($id) {
         $this->view->id = $id;
         $where = $content->select()->from('content', array('id', 'title', 'content_id'))->where('course_id = ?', $session->course_id)->where('content_id = ?', $id)->order(array('position', 'id'));
         $this->view->data = $content->fetchAll($where)->toArray();
     } else {
         $where = $content->select()->from('content', array('id', 'title', 'content_id'))->where('course_id = ?', $session->course_id)->where('content_id IS NULL')->order(array('position', 'id'));
         $this->view->data = $content->fetchAll($where)->toArray();
     }
     $this->view->save = Zend_Filter::filterStatic($this->_getParam('save'), 'int');
     if (!$this->_hasParam('layout')) {
         $this->_helper->layout->disableLayout();
     }
 }
Beispiel #8
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');
     }
 }
 public function indexAction()
 {
     $calendar = new Tri_Db_Table('calendar');
     $id = Zend_Filter::filterStatic($this->_getParam('id'), 'int');
     $where = array('classroom_id IS NULL');
     if ($id) {
         $where = array('classroom_id = ?' => $id);
     }
     $where['end IS NULL OR end > ?'] = date('Y-m-d');
     $this->view->data = $calendar->fetchAll($where, 'begin');
 }
 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);
     }
 }
Beispiel #11
0
 /**
  * Get all timeline registers by user registry classroom
  *
  * @param array $courses
  * @param int $page
  * @return Zend_Db_Rowset
  */
 public static function getByClassroom($courses, $page)
 {
     if ($courses) {
         foreach ($courses as $course) {
             $ids[] = $course['classroom_id'];
         }
     } else {
         $ids = array(0);
     }
     $table = new Tri_Db_Table('timeline');
     $select = $table->select(true)->setIntegrityCheck(false)->join('user', 'user.id = user_id', array('user.id as uid', 'user.name', 'user.image', 'user.role'))->join('classroom', 'classroom.id = classroom_id', array())->join('course', 'course.id = course_id', array('course.name as cname'))->where('classroom_id IN(?)', $ids)->order('id DESC')->limit(10, $page - 1);
     return $table->fetchAll($select);
 }
Beispiel #12
0
 public static function getByClassroom($courses)
 {
     if ($courses) {
         foreach ($courses as $course) {
             $ids[] = $course['classroom_id'];
         }
     } else {
         $ids = array(0);
     }
     $calendar = new Tri_Db_Table('calendar');
     $where = array();
     $where['end IS NULL OR end > ?'] = date('Y-m-d');
     $where['classroom_id IS NULL OR classroom_id IN(?)'] = $ids;
     return $calendar->fetchAll($where);
 }
Beispiel #13
0
 /**
  * Action index.
  *
  * @return void
  */
 public function indexAction()
 {
     $course = new Tri_Db_Table('course');
     $calendar = new Tri_Db_Table('calendar');
     $page = Zend_Filter::filterStatic($this->_getParam('page'), 'int');
     $form = new Application_Form_Login();
     $select = $course->select()->where('status = ?', 'active')->order(array('name', 'category'));
     $where = array('classroom_id IS NULL', 'end IS NULL OR end > ?' => date('Y-m-d'));
     $this->view->calendar = $calendar->fetchAll($where, 'begin', 10);
     $this->view->form = $form;
     $this->view->user = Zend_Auth::getInstance()->getIdentity();
     $paginator = new Tri_Paginator($select, $page);
     $this->view->courses = $paginator->getResult();
     $this->view->newUserToGuest = Tri_Config::get('tri_new_user_to_guest');
     $this->_helper->layout->setLayout('layout');
 }
Beispiel #14
0
 /**
  * Fetch all content and organize
  *
  * @param integer $disciplineId
  * @param integer $contentId
  * @param array $data
  * @param integer $level
  * @return array
  */
 public static function fetchAllOrganize($courseId, $contentId = null, $data = null, $level = 0)
 {
     $table = new Tri_Db_Table('content');
     $select = $table->select()->from('content', array("id", "title"))->where("course_id = ?", $courseId)->order(array("position", "id"));
     if ($contentId) {
         $select->where('content_id = ?', $contentId);
     } else {
         $select->where('content_id IS NULL');
     }
     $rowset = $table->fetchAll($select)->toArray();
     if (count($rowset)) {
         foreach ($rowset as $row) {
             $row['level'] = $level;
             $data[] = $row;
             $data = self::fetchAllOrganize($courseId, $row['id'], $data, $level + 1);
         }
     }
     return $data;
 }
Beispiel #15
0
 public function indexAction()
 {
     $table = new Tri_Db_Table('activity_text');
     $activity = new Tri_Db_Table('activity');
     $id = Zend_Filter::filterStatic($this->_getParam('id'), 'int');
     $textId = Zend_Filter::filterStatic($this->_getParam('textId'), 'int');
     $authId = Zend_Auth::getInstance()->getIdentity()->id;
     $userId = Zend_Filter::filterStatic($this->_getParam('userId', $authId), 'int');
     $form = new Activity_Form_Text();
     if (!$id) {
         $this->_redirect('activity');
     }
     $select = $table->select(true)->setIntegrityCheck(false)->join('user', 'user.id = sender', array('user.id as uid', 'user.name', 'user.image', 'user.role'))->where('activity_id = ?', $id)->order('id DESC')->limit(6);
     if (Zend_Auth::getInstance()->getIdentity()->role == 'student') {
         $select->where('user_id = ?', $authId);
     } else {
         $select->where('(user_id = ?', $authId)->orWhere('user_id = ?)', $userId);
     }
     $data = $table->fetchAll($select);
     $populate = array('activity_id' => $id, 'user_id' => $userId);
     $current = null;
     if (count($data) && !$textId) {
         $current = current(current($data));
         $populate['description'] = $current['description'];
     } elseif ($textId) {
         $current = $table->find($textId)->current();
         $populate['description'] = $current->description;
     }
     if (Zend_Auth::getInstance()->getIdentity()->role == 'student' && !$this->_hasParam('nav')) {
         if ($current && ($current['status'] == 'final' || $current['status'] == 'close')) {
             $this->_redirect('activity/text/view/status/' . $current['status']);
         }
     }
     $form->populate($populate);
     $this->view->data = $data;
     $this->view->parent = $activity->find($id)->current();
     $this->view->form = $form;
     $this->view->id = $id;
     $this->view->userId = $userId;
 }
Beispiel #16
0
 public function addMultipleText($questionId = null)
 {
     $table = new Tri_Db_Table('exercise_question');
     $validators = $table->getValidators();
     $filters = $table->getFilters();
     $statusOptions = array('active' => 'active', 'inactive' => 'inactive');
     $multiple = new Tri_Form_Element_MultiText('option');
     $multiple->setLabel('Options')->setAttrib('cols', 60)->setAttrib('rows', 4);
     if ($questionId) {
         $option = new Tri_Db_Table('exercise_option');
         $options = $option->fetchAll(array('exercise_question_id = ?' => $questionId));
         if (count($options)) {
             foreach ($options as $value) {
                 if ($value->status == 'right') {
                     $multiple->setAttrib('checked', (int) $value->id);
                 }
                 $multiple->addMultiOption($value->id, $value->description);
             }
         } else {
             $multiple->setAttrib('checked', 0);
             $multiple->setMultiOptions(array('', '' => '', ' ' => ''));
         }
     } else {
         $multiple->setAttrib('checked', 0);
         $multiple->setMultiOptions(array('', '' => '', ' ' => ''));
     }
     if (!$statusOptions || isset($statusOptions[''])) {
         $status = new Zend_Form_Element_Text('status');
     } else {
         $statusOptions = array_unique($statusOptions);
         $status = new Zend_Form_Element_Select('status');
         $status->addMultiOptions(array('' => '[select]') + $statusOptions)->setRegisterInArrayValidator(false);
     }
     $note = new Zend_Form_Element_Text('note');
     $note->setLabel('Note')->addValidators($validators['note'])->addFilters($filters['note']);
     $status->setLabel('Status')->addValidators($validators['status'])->addFilters($filters['status']);
     $this->addElement($multiple)->addElement($note)->addElement($status)->addElement('submit', 'Save');
 }
 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;
 }
Beispiel #18
0
 /**
  * Get all possible classroom
  *
  * @param int $userId
  * @return array
  */
 public static function getFinalizedByUser($userId)
 {
     $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')->where('certificate.user_id = ?', $userId);
     return $certificate->fetchAll($select);
 }
 /**
  * Get all courses it's available to selection process
  *
  * @param int $selection_process_id
  * @return array
  */
 public static function getCourses($selection_process_id)
 {
     $selectionProcessClassroom = new Tri_Db_Table('selection_process_classroom');
     $select = $selectionProcessClassroom->select()->setIntegrityCheck(false)->from(array('p' => 'selection_process_classroom'), array())->join(array('c' => 'classroom'), "p.classroom_id = c.id", array())->join(array('co' => 'course'), 'c.course_id = co.id', array('id', 'name'))->where('p.selection_process_id = ?', $selection_process_id);
     return $selectionProcessClassroom->fetchAll($select);
 }