Example #1
0
 public function listAll()
 {
     $toReturn = array();
     $teachers = User::where('role', 'teacher')->get()->toArray();
     $toReturn['dormitory'] = dormitories::get()->toArray();
     $toReturn['subject'] = array();
     $subjects = subject::get();
     foreach ($subjects as $value) {
         $toReturn['subject'][$value->id] = $value->subjectTitle;
     }
     $toReturn['classes'] = array();
     $classes = \DB::table('classes')->leftJoin('dormitories', 'dormitories.id', '=', 'classes.dormitoryId')->select('classes.id as id', 'classes.className as className', 'classes.classTeacher as classTeacher', 'classes.classSubjects as classSubjects', 'dormitories.id as dormitory', 'dormitories.dormitory as dormitoryName')->where('classAcademicYear', $this->panelInit->selectAcYear)->get();
     $toReturn['teachers'] = array();
     while (list($teacherKey, $teacherValue) = each($teachers)) {
         $toReturn['teachers'][$teacherValue['id']] = $teacherValue;
     }
     while (list($key, $class) = each($classes)) {
         $toReturn['classes'][$key] = $class;
         $toReturn['classes'][$key]->classSubjects = json_decode($toReturn['classes'][$key]->classSubjects);
         if ($toReturn['classes'][$key]->classTeacher != "") {
             $toReturn['classes'][$key]->classTeacher = json_decode($toReturn['classes'][$key]->classTeacher, true);
             if (is_array($toReturn['classes'][$key]->classTeacher)) {
                 while (list($teacherKey, $teacherID) = each($toReturn['classes'][$key]->classTeacher)) {
                     if (isset($toReturn['teachers'][$teacherID]['fullName'])) {
                         $toReturn['classes'][$key]->classTeacher[$teacherKey] = $toReturn['teachers'][$teacherID]['fullName'];
                     } else {
                         unset($toReturn['classes'][$key]->classTeacher[$teacherKey]);
                     }
                 }
                 $toReturn['classes'][$key]->classTeacher = implode($toReturn['classes'][$key]->classTeacher, ", ");
             }
         }
     }
     return $toReturn;
 }
 public function listAll()
 {
     $toReturn = array();
     $toReturn['classes'] = classes::where('classAcademicYear', $this->panelInit->selectAcYear)->get()->toArray();
     $classesArray = array();
     while (list(, $class) = each($toReturn['classes'])) {
         $classesArray[$class['id']] = array("classTitle" => $class['className'], "subjects" => json_decode($class['classSubjects']));
     }
     if ($this->data['users']->role == "teacher") {
         $subjects = subject::where('teacherId', $this->data['users']->id)->get()->toArray();
     } else {
         $subjects = subject::get()->toArray();
     }
     $subjectArray = array();
     while (list(, $subject) = each($subjects)) {
         $subjectArray[$subject['id']] = $subject['subjectTitle'];
     }
     $toReturn['onlineExams'] = array();
     $onlineExams = new onlineExams();
     if ($this->data['users']->role == "teacher") {
         $onlineExams = $onlineExams->where('examTeacher', $this->data['users']->id);
     }
     if ($this->data['users']->role == "student") {
         $onlineExams = $onlineExams->where('examClass', 'LIKE', '%"' . $this->data['users']->studentClass . '"%');
     }
     $onlineExams = $onlineExams->where('exAcYear', $this->panelInit->selectAcYear);
     $onlineExams = $onlineExams->get();
     foreach ($onlineExams as $key => $onlineExam) {
         $classId = json_decode($onlineExam->examClass);
         if ($this->data['users']->role == "student" and !in_array($this->data['users']->studentClass, $classId)) {
             continue;
         }
         $toReturn['onlineExams'][$key]['id'] = $onlineExam->id;
         $toReturn['onlineExams'][$key]['examTitle'] = $onlineExam->examTitle;
         $toReturn['onlineExams'][$key]['examDescription'] = $onlineExam->examDescription;
         if (isset($subjectArray[$onlineExam->examSubject])) {
             $toReturn['onlineExams'][$key]['examSubject'] = $subjectArray[$onlineExam->examSubject];
         }
         $toReturn['onlineExams'][$key]['ExamEndDate'] = date("F j, Y", $onlineExam->ExamEndDate);
         $toReturn['onlineExams'][$key]['ExamShowGrade'] = $onlineExam->ExamShowGrade;
         $toReturn['onlineExams'][$key]['classes'] = "";
         while (list(, $value) = each($classId)) {
             if (isset($classesArray[$value])) {
                 $toReturn['onlineExams'][$key]['classes'] .= $classesArray[$value]['classTitle'] . ", ";
             }
         }
     }
     $toReturn['userRole'] = $this->data['users']->role;
     return $toReturn;
 }
 function fetch($id)
 {
     $arrayOfDays = array(0 => $this->panelInit->language['Sunday'], 1 => $this->panelInit->language['Monday'], 2 => $this->panelInit->language['Tuesday'], 3 => $this->panelInit->language['Wednesday'], 4 => $this->panelInit->language['Thurusday'], 5 => $this->panelInit->language['Friday'], 6 => $this->panelInit->language['Saturday']);
     $subjectArray = array();
     $subjectObject = subject::get();
     foreach ($subjectObject as $subject) {
         $subjectArray[$subject->id] = $subject->subjectTitle;
     }
     $toReturn = array(0 => array('dayName' => $arrayOfDays[0], 'data' => array()), 1 => array('dayName' => $arrayOfDays[1]), 2 => array('dayName' => $arrayOfDays[2]), 3 => array('dayName' => $arrayOfDays[3]), 4 => array('dayName' => $arrayOfDays[4]), 5 => array('dayName' => $arrayOfDays[5]), 6 => array('dayName' => $arrayOfDays[6]));
     $classSchedule = classSchedule::where('classId', $id)->orderBy('startTime')->get();
     foreach ($classSchedule as $schedule) {
         $toReturn[$schedule->dayOfWeek]['sub'][] = array('id' => $schedule->id, 'classId' => $schedule->classId, 'subjectId' => isset($subjectArray[$schedule->subjectId]) ? $subjectArray[$schedule->subjectId] : "", 'start' => wordwrap($schedule->startTime, 2, ':', true), 'end' => wordwrap($schedule->endTime, 2, ':', true));
     }
     return $toReturn;
 }
 public function listAll()
 {
     $toReturn = array();
     $toReturn['classes'] = classes::where('classAcademicYear', $this->panelInit->selectAcYear)->get()->toArray();
     $classesArray = array();
     while (list(, $class) = each($toReturn['classes'])) {
         $classesArray[$class['id']] = $class['className'];
     }
     $toReturn['subject'] = subject::get()->toArray();
     $subjectArray = array();
     while (list(, $subject) = each($toReturn['subject'])) {
         $subjectArray[$subject['id']] = $subject['subjectTitle'];
     }
     $toReturn['materials'] = array();
     $studyMaterial = new studyMaterial();
     if ($this->data['users']->role == "student") {
         $studyMaterial = $studyMaterial->where('class_id', 'LIKE', '%"' . $this->data['users']->studentClass . '"%');
     }
     if ($this->data['users']->role == "teacher") {
         $studyMaterial = $studyMaterial->where('teacher_id', $this->data['users']->id);
     }
     $studyMaterial = $studyMaterial->get();
     foreach ($studyMaterial as $key => $material) {
         $classId = json_decode($material->class_id);
         if ($this->data['users']->role == "student" and !in_array($this->data['users']->studentClass, $classId)) {
             continue;
         }
         $toReturn['materials'][$key]['id'] = $material->id;
         $toReturn['materials'][$key]['subjectId'] = $material->subject_id;
         $toReturn['materials'][$key]['subject'] = $subjectArray[$material->subject_id];
         $toReturn['materials'][$key]['material_title'] = $material->material_title;
         $toReturn['materials'][$key]['material_description'] = $material->material_description;
         $toReturn['materials'][$key]['material_file'] = $material->material_file;
         $toReturn['materials'][$key]['classes'] = "";
         if (is_array($classId)) {
             while (list(, $value) = each($classId)) {
                 if (isset($classesArray[$value])) {
                     $toReturn['materials'][$key]['classes'] .= $classesArray[$value] . ", ";
                 }
             }
         }
     }
     $toReturn['userRole'] = $this->data['users']->role;
     return $toReturn;
     exit;
 }
Example #5
0
 function attendance($id)
 {
     $toReturn = array();
     $toReturn['attendanceModel'] = $this->data['panelInit']->settingsArray['attendanceModel'];
     $toReturn['attendance'] = attendance::where('studentId', $id)->get()->toArray();
     if ($this->data['panelInit']->settingsArray['attendanceModel'] == "subject") {
         $subjects = subject::get();
         $toReturn['subjects'] = array();
         foreach ($subjects as $subject) {
             $toReturn['subjects'][$subject->id] = $subject->subjectTitle;
         }
     }
     return $toReturn;
 }
 public function search()
 {
     $sql = "select * from attendance where ";
     $sqlArray = array();
     $toReturn = array();
     $students = array();
     $studentArray = User::where('role', 'student')->get();
     foreach ($studentArray as $stOne) {
         $students[$stOne->id] = array('name' => $stOne->fullName, 'studentRollId' => $stOne->studentRollId, 'attendance' => '');
     }
     $subjectsArray = subject::get();
     $subjects = array();
     foreach ($subjectsArray as $subject) {
         $subjects[$subject->id] = $subject->subjectTitle;
     }
     if (Input::get('classId') and Input::get('classId') != "") {
         $sqlArray[] = "classId='" . Input::get('classId') . "'";
     }
     if (Input::get('subjectId') and Input::get('subjectId') != "") {
         $sqlArray[] = "subjectId='" . Input::get('subjectId') . "'";
     }
     if (Input::get('status') and Input::get('status') != "All") {
         $sqlArray[] = "status='" . Input::get('status') . "'";
     }
     if (Input::get('attendanceDay') and Input::get('attendanceDay') != "") {
         $sqlArray[] = "date='" . Input::get('attendanceDay') . "'";
     }
     $sql = $sql . implode(" AND ", $sqlArray);
     $attendanceArray = DB::select(DB::raw($sql));
     foreach ($attendanceArray as $stAttendance) {
         $toReturn[$stAttendance->id] = $stAttendance;
         if (isset($students[$stAttendance->studentId])) {
             $toReturn[$stAttendance->id]->studentName = $students[$stAttendance->studentId]['name'];
             if ($stAttendance->subjectId != "") {
                 $toReturn[$stAttendance->id]->studentSubject = $subjects[$stAttendance->subjectId];
             }
             $toReturn[$stAttendance->id]->studentRollId = $students[$stAttendance->studentId]['studentRollId'];
         }
     }
     return $toReturn;
 }
 public function dashboardData()
 {
     $toReturn = array();
     $toReturn['selectedAcYear'] = $this->panelInit->selectAcYear;
     $toReturn['language'] = $this->panelInit->language;
     $toReturn['role'] = $this->data['users']->role;
     $toReturn['stats'] = array();
     $toReturn['stats']['classes'] = classes::count();
     $toReturn['stats']['students'] = User::where('role', 'student')->where('activated', 1)->count();
     $toReturn['stats']['teachers'] = User::where('role', 'teacher')->where('activated', 1)->count();
     $toReturn['stats']['newMessages'] = messagesList::where('userId', $this->data['users']->id)->where('messageStatus', 1)->count();
     $toReturn['messages'] = DB::select(DB::raw("SELECT messagesList.id as id,messagesList.lastMessageDate as lastMessageDate,messagesList.lastMessage as lastMessage,messagesList.messageStatus as messageStatus,users.fullName as fullName,users.id as userId FROM messagesList LEFT JOIN users ON users.id=IF(messagesList.userId = '" . $this->data['users']->id . "',messagesList.toId,messagesList.userId) where userId='" . $this->data['users']->id . "' order by id DESC limit 5"));
     $toReturn['attendanceModel'] = $this->data['panelInit']->settingsArray['attendanceModel'];
     if ($this->data['panelInit']->settingsArray['attendanceModel'] == "subject") {
         $subjects = subject::get();
         foreach ($subjects as $subject) {
             $toReturn['subjects'][$subject->id] = $subject->subjectTitle;
         }
     }
     $date = date('m/Y');
     $date = explode("/", $date);
     if ($this->data['users']->role == "student") {
         $attendanceArray = attendance::where('studentId', $this->data['users']->id)->where('date', 'like', $date[0] . "%")->where('date', 'like', "%" . $date[1])->get();
         foreach ($attendanceArray as $value) {
             $toReturn['studentAttendance'][] = array("date" => $value->date, "status" => $value->status, "subject" => isset($toReturn['subjects'][$value->subjectId]) ? $toReturn['subjects'][$value->subjectId] : "");
         }
     } elseif ($this->data['users']->role == "parent") {
         if ($this->data['users']->parentOf != "") {
             $parentOf = json_decode($this->data['users']->parentOf, true);
             $ids = array();
             while (list(, $value) = each($parentOf)) {
                 $ids[] = $value['id'];
             }
             $studentArray = User::where('role', 'student')->whereIn('id', $ids)->get();
             foreach ($studentArray as $stOne) {
                 $students[$stOne->id] = array('name' => $stOne->fullName, 'studentRollId' => $stOne->studentRollId);
             }
             if (count($ids) > 0) {
                 $attendanceArray = attendance::whereIn('studentId', $ids)->where('date', 'like', $date[0] . "%")->where('date', 'like', "%" . $date[1])->get();
                 foreach ($attendanceArray as $value) {
                     if (!isset($toReturn['studentAttendance'][$value->studentId])) {
                         $toReturn['studentAttendance'][$value->studentId]['n'] = $students[$value->studentId];
                         $toReturn['studentAttendance'][$value->studentId]['d'] = array();
                     }
                     $toReturn['studentAttendance'][$value->studentId]['d'][] = array("date" => $value->date, "status" => $value->status, "subject" => $value->subjectId);
                 }
             }
         }
     }
     $toReturn['teacherLeaderBoard'] = User::where('role', 'teacher')->where('isLeaderBoard', '!=', '')->where('isLeaderBoard', '!=', '0')->get()->toArray();
     $toReturn['studentLeaderBoard'] = User::where('role', 'student')->where('isLeaderBoard', '!=', '')->where('isLeaderBoard', '!=', '0')->get()->toArray();
     $toReturn['newsEvents'] = array();
     $newsboard = newsboard::where('newsFor', $this->data['users']->role)->orWhere('newsFor', 'all')->orderBy('id', 'desc')->limit(5)->get();
     foreach ($newsboard as $event) {
         $eventsArray['id'] = $event->id;
         $eventsArray['title'] = $event->newsTitle;
         $eventsArray['type'] = "news";
         $eventsArray['start'] = date("F j, Y", strtotime($event->newsDate));
         $toReturn['newsEvents'][] = $eventsArray;
     }
     $events = events::orderBy('id', 'desc')->where('eventFor', $this->data['users']->role)->orWhere('eventFor', 'all')->limit(5)->get();
     foreach ($events as $event) {
         $eventsArray['id'] = $event->id;
         $eventsArray['title'] = $event->eventTitle;
         $eventsArray['type'] = "event";
         $eventsArray['start'] = date("F j, Y", strtotime($event->eventDate));
         $toReturn['newsEvents'][] = $eventsArray;
     }
     $toReturn['academicYear'] = academicYear::get()->toArray();
     $toReturn['baseUser'] = array("id" => $this->data['users']->id, "fullName" => $this->data['users']->fullName, "username" => $this->data['users']->username);
     $polls = polls::where('pollTarget', $this->data['users']->role)->orWhere('pollTarget', 'all')->where('pollStatus', '1')->first();
     if (count($polls) > 0) {
         $toReturn['polls']['title'] = $polls->pollTitle;
         $toReturn['polls']['id'] = $polls->id;
         $toReturn['polls']['view'] = "vote";
         $userVoted = json_decode($polls->userVoted, true);
         if (is_array($userVoted) and in_array($this->data['users']->id, $userVoted)) {
             $toReturn['polls']['voted'] = true;
             $toReturn['polls']['view'] = "results";
         }
         $toReturn['polls']['items'] = json_decode($polls->pollOptions, true);
         $toReturn['polls']['totalCount'] = 0;
         if (is_array($toReturn['polls']['items']) and count($toReturn['polls']['items']) > 0) {
             while (list($key, $value) = each($toReturn['polls']['items'])) {
                 if (isset($value['count'])) {
                     $toReturn['polls']['totalCount'] += $value['count'];
                 }
                 if (!isset($toReturn['polls']['items'][$key]['prec'])) {
                     $toReturn['polls']['items'][$key]['prec'] = 0;
                 }
             }
         }
     }
     return json_encode($toReturn);
 }
 function notifications($id)
 {
     if ($this->data['users']->role != "admin") {
         exit;
     }
     if ($this->panelInit->settingsArray['examDetailsNotif'] == "0") {
         return json_encode(array("jsTitle" => $this->panelInit->language['examDetailsNot'], "jsMessage" => $this->panelInit->language['adjustExamNot']));
     }
     $examsList = examsList::where('id', $id)->first();
     $subjectArray = array();
     $subject = subject::get();
     foreach ($subject as $value) {
         $subjectArray[$value->id] = $value->subjectTitle;
     }
     $usersArray = array();
     if ($this->data['panelInit']->settingsArray['examDetailsNotifTo'] == "parent" || $this->data['panelInit']->settingsArray['examDetailsNotifTo'] == "both") {
         $users = User::where('role', 'student')->orWhere('role', 'parent')->get();
     } else {
         $users = User::where('role', 'student')->get();
     }
     foreach ($users as $value) {
         if ($value->parentOf == "" and $value->role == "parent") {
             continue;
         }
         if (!isset($usersArray[$value->id])) {
             $usersArray[$value->id] = array();
         }
         if ($value->parentOf != "") {
             $value->parentOf = json_decode($value->parentOf);
             if (!is_array($value->parentOf)) {
                 continue;
             }
             if (count($value->parentOf) > 0) {
                 $usersArray[$value->id]['parents'] = array();
             }
             foreach ($value->parentOf as $parentOf) {
                 $usersArray[$parentOf->id]['parents'][$value->id] = array('username' => $value->username, "email" => $value->email, "fullName" => $value->fullName, "mobileNo" => $value->mobileNo);
             }
         }
         $usersArray[$value->id]['student'] = array('username' => $value->username, "studentRollId" => $value->studentRollId, "mobileNo" => $value->mobileNo, "email" => $value->email, "fullName" => $value->fullName);
     }
     $return['marks'] = array();
     $examMarks = examMarks::where('examId', $id)->get();
     foreach ($examMarks as $value) {
         if (!isset($return['marks'][$value->studentId])) {
             $return['marks'][$value->studentId] = array();
         }
         if (isset($subjectArray[$value->subjectId])) {
             $return['marks'][$value->studentId][$subjectArray[$value->subjectId]] = array("examMark" => $value->examMark, "attendanceMark" => $value->attendanceMark, "markComments" => $value->markComments);
         }
     }
     $mailTemplate = mailsmsTemplates::where('templateTitle', 'Exam Details')->first();
     if ($this->panelInit->settingsArray['examDetailsNotif'] == "mail" || $this->panelInit->settingsArray['examDetailsNotif'] == "mailsms") {
         $mail = true;
     }
     if ($this->panelInit->settingsArray['examDetailsNotif'] == "sms" || $this->panelInit->settingsArray['examDetailsNotif'] == "mailsms") {
         $sms = true;
     }
     $sms = true;
     $MailSmsHandler = new MailSmsHandler();
     while (list($key, $value) = each($return['marks'])) {
         if (isset($mail)) {
             $studentTemplate = $mailTemplate->templateMail;
             $examGradesTable = "";
             while (list($keyG, $valueG) = each($value)) {
                 if ($valueG['examMark'] == "" and $valueG['attendanceMark'] == "") {
                     continue;
                 }
                 $examGradesTable .= $keyG . " Grade : " . $valueG['examMark'] . " - Attendance : " . $valueG['attendanceMark'] . " - Comments : " . $valueG['markComments'] . "<br/>";
             }
             if ($examGradesTable == "") {
                 continue;
             }
             $searchArray = array("{studentName}", "{studentRoll}", "{studentEmail}", "{studentUsername}", "{examTitle}", "{examDescription}", "{examDate}", "{schoolTitle}", "{examGradesTable}");
             $replaceArray = array($usersArray[$key]['student']['fullName'], $usersArray[$key]['student']['studentRollId'], $usersArray[$key]['student']['email'], $usersArray[$key]['student']['username'], $examsList->examTitle, $examsList->examDescription, $examsList->examDate, $this->panelInit->settingsArray['siteTitle'], $examGradesTable);
             $studentTemplate = str_replace($searchArray, $replaceArray, $studentTemplate);
             $MailSmsHandler->mail($usersArray[$key]['student']['email'], "Exam grade details", $studentTemplate, $usersArray[$key]['student']['fullName']);
             if (isset($usersArray[$key]['parents'])) {
                 while (list($keyP, $valueP) = each($usersArray[$key]['parents'])) {
                     //	$MailSmsHandler->mail($valueP['email'],"Exam grade details",$studentTemplate,$usersArray[$key]['student']['fullName']);
                 }
             }
         }
         if (isset($sms)) {
             $studentTemplate = $mailTemplate->templateSMS;
             $examGradesTable = "";
             reset($value);
             while (list($keyG, $valueG) = each($value)) {
                 if ($valueG['examMark'] == "" and $valueG['attendanceMark'] == "") {
                     continue;
                 }
                 $examGradesTable .= $keyG . " Grade : " . $valueG['examMark'] . " - Attendance : " . $valueG['attendanceMark'] . " ";
             }
             if ($examGradesTable == "") {
                 continue;
             }
             $searchArray = array("{studentName}", "{studentRoll}", "{studentEmail}", "{studentUsername}", "{examTitle}", "{examDescription}", "{examDate}", "{schoolTitle}", "{examGradesTable}");
             $replaceArray = array($usersArray[$key]['student']['fullName'], $usersArray[$key]['student']['studentRollId'], $usersArray[$key]['student']['email'], $usersArray[$key]['student']['username'], $examsList->examTitle, $examsList->examDescription, $examsList->examDate, $this->panelInit->settingsArray['siteTitle'], $examGradesTable);
             $studentTemplate = str_replace($searchArray, $replaceArray, $studentTemplate);
             if ($usersArray[$key]['student']['mobileNo'] != "") {
                 $MailSmsHandler->sms($usersArray[$key]['student']['mobileNo'], $studentTemplate);
             }
             if (isset($usersArray[$key]['parents'])) {
                 reset($usersArray[$key]['parents']);
                 while (list($keyP, $valueP) = each($usersArray[$key]['parents'])) {
                     if (trim($valueP['mobileNo']) != "") {
                         $MailSmsHandler->sms($valueP['mobileNo'], $studentTemplate);
                     }
                 }
             }
         }
     }
     return $this->panelInit->apiOutput(true, $this->panelInit->language['examDetailsNot'], $this->panelInit->language['examNotSent']);
 }