public function indexAction() { $roomModel = new RoomModel(); $roomList = $roomModel->getRoomList(); $this->view->roomList = $roomList; $this->view->pageName = "index"; $this->render('home/index'); }
/** * @param $lesson_id * @return array */ public static function getAllByLessonId($lesson_id) { $lesson_id = abs(intval($lesson_id)); /** @var PDO $db */ $db = Registry::get('db'); $result = array(); $sth = $db->query("\r\n SELECT t1.* FROM " . RoomModel::TABLE . " as t1\r\n JOIN " . RoomModel::RELATION_TABLE . " as t2 USING(" . RoomModel::PRIMARY_KEY . ")\r\n JOIN " . LessonModel::TABLE . " as t3 USING(" . LessonModel::PRIMARY_KEY . ")\r\n WHERE t3." . LessonModel::PRIMARY_KEY . " = '{$lesson_id}'\r\n "); while ($data = $sth->fetch(PDO::FETCH_ASSOC)) { $room = new RoomModel(); $room->unpack($data); $result[] = $room->toArray(); } return $result; }
public function quitAction() { $rid = trim($_POST['rid']); $roomModel = new RoomModel(); $room = $roomModel->getRoomById($rid); $userlist = json_decode($room['user_list'], true); $userlist = $userlist ? $userlist : array(); if (!isset($userlist[$this->uid])) { $this->echoJson(true, $rid); } else { $res = $roomModel->removeUser($rid, $userlist, $this->uid); if ($res) { $this->echoJson(true, $rid); } else { $this->echoJson(false, "db fail"); } } }
public function indexAction() { $roomId = trim($_GET['room_id']); if (!$roomId) { $this->errorPage(); } $roomModel = new RoomModel(); $roomInfo = $roomModel->getRoomById($roomId); if (!$roomInfo) { $this->errorPage(); } $userlist = json_decode($roomInfo['user_list'], true); $userlist = $userlist ? $userlist : array(); $this->view->isJoined = in_array($this->uid, $userlist); $roomInfo['user_list'] = $userlist; $this->view->room = $roomInfo; $this->view->pageName = "room"; $config = Kiss_Registry::get("config"); $this->view->wsHost = $config->gochannel_url; $this->render('room/index'); }
/** * @param string|int $teacher_name * @param string $cond * @return array * @throws ApiException */ public static function getAllByTeacherNameOrTeacherId($teacher_name, $cond = "") { $result = array(); //hide some properties $hideFilter = array('group_id' => true); Registry::set('LessonModelHideFilter', $hideFilter); $teacher_name = urldecode(trim($teacher_name)); /** @var PDO $db */ $db = Registry::get('db'); $teacher_id = $db->query("\r\n SELECT teacher_id FROM " . TeacherModel::TABLE . "\r\n WHERE (teacher_name = " . $db->quote($teacher_name) . " OR teacher_id = " . $db->quote($teacher_name) . ")\r\n ")->fetchColumn(); $count = 0; if ($teacher_id) { $count = $db->query("\r\n SELECT COUNT(*) FROM " . LessonModel::TABLE . " AS t1\r\n JOIN " . TeacherModel::RELATION_TABLE . " as t2 USING(" . LessonModel::PRIMARY_KEY . ")\r\n WHERE t2." . TeacherModel::PRIMARY_KEY . " = '" . abs(intval($teacher_id)) . "' {$cond}\r\n ")->fetchColumn(); } if ($count > 0) { $query = $db->query("\r\n SELECT *\r\n FROM " . LessonModel::TABLE . " AS t1\r\n JOIN " . TeacherModel::RELATION_TABLE . " as t2 USING(" . LessonModel::PRIMARY_KEY . ")\r\n WHERE t2." . TeacherModel::PRIMARY_KEY . " = '" . abs(intval($teacher_id)) . "' {$cond}\r\n GROUP BY t1.day_number,t1.lesson_number,t1.lesson_week\r\n ORDER BY t1.lesson_week,t1.day_number,t1.lesson_number ASC\r\n "); while ($data = $query->fetch(PDO::FETCH_ASSOC)) { $lessonModel = new LessonModel(); $lessonModel->unpack($data); //$lessonModel->teachers = TeacherModel::getAllByLessonId($lessonModel->lesson_id); //load rooms $lessonModel->rooms = RoomModel::getAllByLessonId($lessonModel->lesson_id); //load groups $q = $db->query("\r\n SELECT t1.* FROM " . GroupModel::TABLE . " as t1\r\n JOIN " . LessonModel::TABLE . " as t2 USING(" . GroupModel::PRIMARY_KEY . ")\r\n WHERE t2.day_number = '" . $lessonModel->day_number . "'\r\n AND t2.lesson_number = '" . $lessonModel->lesson_number . "'\r\n AND t2.teacher_name = " . $db->quote($lessonModel->teacher_name) . "\r\n AND t2.lesson_week = '" . $lessonModel->lesson_week . "'\r\n "); $groupsRes = array(); while ($groupsData = $q->fetch(PDO::FETCH_ASSOC)) { $group = new GroupModel(); $group->unpack($groupsData); $groupsRes[] = $group->toArray(); } $m = $lessonModel->toArray(); $m["groups"] = $groupsRes; $result[] = $m; } } else { throw new ApiException("Lessons not found"); } return $result; }