public function getStats($date = "")
 {
     if ($date == "") {
         $date = date('m/Y');
     }
     $date = explode("/", $date);
     $toReturn = array();
     $classes = classes::where('classAcademicYear', $this->panelInit->selectAcYear)->get();
     $toReturn['classes'] = array();
     $subjList = array();
     foreach ($classes as $class) {
         $class['classSubjects'] = json_decode($class['classSubjects'], true);
         if (is_array($class['classSubjects'])) {
             foreach ($class['classSubjects'] as $subject) {
                 $subjList[] = $subject;
             }
         }
         $toReturn['classes'][$class->id] = $class->className;
     }
     $subjList = array_unique($subjList);
     if ($this->data['panelInit']->settingsArray['attendanceModel'] == "subject") {
         $toReturn['subjects'] = array();
         if (count($subjList) > 0) {
             $subjects = subject::whereIN('id', $subjList)->get();
             foreach ($subjects as $subject) {
                 $toReturn['subjects'][$subject->id] = $subject->subjectTitle;
             }
         }
     }
     $toReturn['role'] = $this->data['users']->role;
     $toReturn['attendanceModel'] = $this->data['panelInit']->settingsArray['attendanceModel'];
     if ($this->data['users']->role == "admin" || $this->data['users']->role == "teacher") {
         $attendanceArray = attendance::where('date', 'like', $date[0] . "%")->where('date', 'like', "%" . $date[1])->orderBy('date')->get();
         foreach ($attendanceArray as $value) {
             $dateHere = str_replace("/" . $date[1], "", $value->date);
             $dateHere = str_replace($date[0] . "/", "", $dateHere);
             $dateHere = preg_replace('/^0/', "", $dateHere);
             if (!isset($toReturn['attendance'][$dateHere][0])) {
                 $toReturn['attendance'][$dateHere][0] = 0;
                 $toReturn['attendance'][$dateHere][1] = 0;
                 $toReturn['attendance'][$dateHere][2] = 0;
                 $toReturn['attendance'][$dateHere][3] = 0;
                 $toReturn['attendance'][$dateHere][4] = 0;
             }
             $toReturn['attendance'][$dateHere][$value->status]++;
         }
         $attendanceArrayToday = attendance::where('date', date('m/d/Y'))->get();
         if ($this->data['panelInit']->settingsArray['attendanceModel'] == "subject") {
             foreach ($attendanceArrayToday as $value) {
                 if (isset($toReturn['subjects'][$value->subjectId])) {
                     if (!isset($toReturn['attendanceDay'][$toReturn['subjects'][$value->subjectId]])) {
                         $toReturn['attendanceDay'][$toReturn['subjects'][$value->subjectId]] = 0;
                     }
                     $toReturn['attendanceDay'][$toReturn['subjects'][$value->subjectId]]++;
                 }
             }
         } else {
             foreach ($attendanceArrayToday as $value) {
                 if (isset($toReturn['classes'][$value->classId])) {
                     if (!isset($toReturn['attendanceDay'][$toReturn['classes'][$value->classId]])) {
                         $toReturn['attendanceDay'][$toReturn['classes'][$value->classId]] = 0;
                     }
                     $toReturn['attendanceDay'][$toReturn['classes'][$value->classId]]++;
                 }
             }
         }
     } elseif ($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);
                 }
             }
         }
     }
     return $toReturn;
 }
Example #2
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 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);
 }