· 5 years ago · Feb 04, 2020, 04:24 AM
1<?php
2
3/**
4 * ApiController class file
5 * @author Joachim Werner <joachim.werner@diggin-data.de>
6 */
7
8/**
9 * ApiController
10 *
11 * @uses Controller
12 * @author Joachim Werner <joachim.werner@diggin-data.de>
13 * @author
14 * @see http://www.gen-x-design.com/archives/making-restful-requests-in-php/
15 * @license (tbd)
16 */
17require_once Yii::app()->basePath . '/extensions/SSDB.php';
18class ApiController extends Controller
19{
20 private $method = ' ';
21 private $format = 'json';
22
23 public function actionTestUpload()
24 {
25 //$post_data = json_decode(urldecode(file_get_contents("php://input")));
26 print_r($_FILES);
27 }
28
29 public function actionTestssdb()
30 {
31 // try{
32 // $ssdb = new SimpleSSDB('127.0.0.1', 8888);
33 // }catch(Exception $e){
34 // die(__LINE__ . ' ' . $e->getMessage());
35 // }
36 // $ret = $ssdb->set('key', 'value');
37 // echo $ssdb->get('key');
38 }
39
40 public function actionTestInput()
41 {
42 $post_data = json_decode(urldecode(file_get_contents("php://input")));
43 //print_r($post_data);
44 }
45
46 public function actionGetQuiz()
47 {
48 $status = true;
49 $prefix = Yii::app()->params['tablePrefix'];
50 $type = array(
51 "uts" => 4,
52 "uas" => 5,
53 "us" => 6
54 );
55
56 //delarasi kondisi sql
57 $condition = 't.trash is null';
58 if (isset($_GET['quiz_id'])) {
59 $condition .= ' and t.id =' . $_GET['quiz_id'];
60 }
61 if (isset($_GET['grade'])) {
62 $condition .= ' and c.class_id =' . $_GET['grade'];
63 }
64 if (isset($_GET['lesson'])) {
65 $condition .= ' and l.list_id =' . $_GET['lesson'];
66 }
67 if (isset($_GET['type'])) {
68 $condition .= ' and t.quiz_type =' . $type[$_GET['type']];
69 }
70 if (isset($_GET['year'])) {
71 $condition .= ' and t.year =' . $_GET['year'];
72 }
73 if (isset($_GET['semester'])) {
74 $condition .= ' and t.semester =' . $_GET['semester'];
75 }
76
77 $criteria = new CDbCriteria();
78 $criteria->mergeWith(array(
79 'order' => 'created_at DESC',
80 'select' => 't.*',
81 'join' => 'JOIN ' . $prefix . 'lesson as l ON l.id = t.lesson_id JOIN ' . $prefix . 'class_detail as c ON c.id = l.class_id',
82 'condition' => $condition,
83 ));
84 $count = Quiz::model()->count($criteria);
85
86 if ($count > 0) {
87 $pages = new CPagination($count);
88 // results per page
89 $pages->CurrentPage = isset($_GET['row']) ? $_GET['row'] : 0;
90 $pages->pageSize = isset($_GET['limit']) ? $_GET['limit'] : 500;
91 $perpage = $pages->pageSize;
92 $pages->applyLimit($criteria);
93 $totalpage = ceil($count / $perpage);
94 $models = Quiz::model()->findAll($criteria);
95
96 $data['success'] = 1;
97 $data['message'] = 'Record(s) Found.';
98 $data['totalCount'] = $count;
99
100 foreach ($models as $row) {
101 $data_fix['id'] = $row->id;
102 $data_fix['title'] = $row->title;
103 $data_fix['lesson'] = $row->lesson->name;
104 $data_fix['lesson_list'] = $row->lesson->list_id;
105 $data_fix['chapter_id'] = $row->chapter_id;
106 $data_fix['quiz_type'] = $row->quiz_type;
107 $data_fix['created_by'] = $row->created_by;
108 $data_fix['start_time'] = $row->start_time;
109 $data_fix['finish_time'] = $row->finish_time;
110 $data_fix['end_time'] = $row->end_time;
111 $data_fix['total_question'] = $row->total_question;
112 $data_fix['status'] = $row->status;
113 $data_fix['add_to_summary'] = $row->add_to_summary;
114 $data_fix['repeat_quiz'] = $row->repeat_quiz;
115 $data_fix['semester'] = $row->semester;
116 $data_fix['year'] = $row->year;
117 $data_fix['random'] = $row->random;
118 $data_fix['show_nilai'] = $row->show_nilai;
119 $data_fix['id_bersama'] = $row->id_bersama;
120 $data_fix['random_opt'] = $row->random_opt;
121 $data_fix['passcode'] = $row->passcode;
122 if (!empty($row->lesson_id)) {
123 $data_fix['class'] = $row->lesson->class->name;
124 $data_fix['grade'] = $row->lesson->class->class_id;
125 }
126 if ($row->question) {
127 $question = Questions::model()->findAll(array('condition' => 'id IN(' . $row->question . ')'));
128 $data_fix['questions'] = CJSON::encode($question);
129 }
130 $data['data']['result'][] = $data_fix;
131 }
132 } else {
133 $models = null;
134 }
135
136 if ($status == false) {
137 $data['success'] = 0;
138 $data['message'] = 'ERROR : Missing or Invalid Parameter !';
139 $data['data'] = null;
140 $json = json_encode($data, JSON_PRETTY_PRINT);
141 header('Content-Type: application/x-javascript');
142 echo $json;
143 } elseif ($models == null) {
144 $data['success'] = 0;
145 $data['message'] = 'ERROR : No Data Found';
146 $data['data'] = null;
147 $json = json_encode($data, JSON_PRETTY_PRINT);
148 header('Content-Type: application/x-javascript');
149 echo $json;
150 } else {
151 $json = json_encode($data, JSON_PRETTY_PRINT);
152 header('Content-Type: application/json');
153 echo $json;
154 }
155 }
156
157 public function actionPullQuiz()
158 {
159 $server = Option::model()->find(array('condition' => 'key_config LIKE "%server%"'));
160 $url = $server->value . "/api/getquiz?year=" . $_GET['year'] . "&semester=" . $_GET['semester'] . "&type=" . $_GET['type'] . "&grade=" . $_GET['grade'] . "&lesson=" . $_GET['lesson'];
161 $datas = json_decode($this->file_get_contents_curl($url), true);
162
163 if ($datas['data']['result']) {
164 $quizes = $datas['data']['result'];
165 foreach ($quizes as $quiz) {
166 //insert question
167 $idsoal = array();
168 if ($quiz["questions"]) {
169 $questions = json_decode($quiz["questions"], true);
170 foreach ($questions as $question) {
171 $model = new Questions;
172 $model->text = $question['text'];
173 $model->quiz_id = $question['quiz_id'];
174 $model->title = $question['title'];
175 $model->choices = $question['choices'];
176 $model->type = $question['type'];
177 $model->key_answer = $question['key_answer'];
178 $model->created_by = $question['created_by'];
179 $model->teacher_id = $question['teacher_id'];
180 $model->kd = $question['kd'];
181
182 if ($model->save()) {
183 $idsoal[] = $model->id;
184 }
185 }
186 }
187 if (isset($idsoal) and $quiz["grade"]) {
188 $classes = ClassDetail::model()->findAll(array('condition' => 'class_id =' . $quiz["grade"] . ''));
189 foreach ($classes as $class) {
190 $lesson = Lesson::model()->find(array(
191 'condition' => 'class_id =' . $class->id . ' and list_id = ' . $quiz["lesson_list"] . ' and semester = ' . $_GET['semester'] . ' and year = ' . $_GET['year'] . ' and trash is NULL'
192 ));
193 if ($lesson) {
194 $cekquiz = Quiz::model()->findByAttributes(array('lesson_id' => $lesson->id, 'quiz_type' => $quiz["quiz_type"], 'semester' => $quiz["semester"], 'year' => $quiz["year"], 'trash' => null));
195 if (empty($cekquiz)) {
196 $model = new Quiz;
197 $model->status = $quiz["status"];
198 $model->lesson_id = $lesson->id;
199 $model->title = $quiz["title"];
200 $model->repeat_quiz = $quiz["repeat_quiz"];
201 $model->quiz_type = $quiz["quiz_type"];
202 $model->year = $quiz["year"];
203 $model->semester = $quiz["semester"];
204 $model->created_by = $quiz["created_by"];
205 $model->random = $quiz["random"];
206 $model->show_nilai = 0;
207 $model->random_opt = $quiz["random_opt"];
208 $model->total_question = $quiz["total_question"];
209 $model->end_time = $quiz["end_time"];
210 $model->finish_time = $quiz["finish_time"];
211 $model->start_time = $quiz["start_time"];
212 $model->id_bersama = $quiz["id"];
213 $model->question = implode(",", $idsoal);
214
215 // $length = 5;
216 // $characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
217 // $charactersLength = strlen($characters);
218
219 // $randomString = '';
220 // for ($i = 0; $i < $length; $i++) {
221 // $randomString .= $characters[rand(0, $charactersLength - 1)];
222 // }
223 //$model->passcode = $randomString;
224 $model->passcode = $quiz["passcode"];
225
226 if ($model->save()) {
227 $idquiz[$model->id]["title"] = $model->title;
228 $idquiz[$model->id]["class"] = $class->name;
229 $idquiz[$model->id]["questions"] = $idsoal;
230 }
231 }
232 }
233 }
234 }
235 }
236 }
237
238 if (isset($idquiz)) {
239 $data['success'] = 1;
240 $data['message'] = 'Success : Datas Has Been Insert';
241 $data['result']['quiz'] = $idquiz;
242 $json = json_encode($data, JSON_PRETTY_PRINT);
243 header('Content-Type: application/x-javascript');
244 echo $json;
245 } else {
246 $data['success'] = 0;
247 $data['message'] = 'Error : No Data Found';
248 $json = json_encode($data, JSON_PRETTY_PRINT);
249 header('Content-Type: application/x-javascript');
250 echo $json;
251 }
252 }
253
254 public function actionSetScore_old()
255 {
256 $post_data = json_decode(urldecode(file_get_contents("php://input")));
257 $id = null;
258 $model = new StudentQuiz;
259 foreach ($post_data as $key => $value) {
260 $model->$key = $value;
261 }
262 $cekNilai = StudentQuiz::model()->findByAttributes(array(
263 'quiz_id' => $model->quiz_id,
264 'display_name' => $model->display_name,
265 'class' => $model->class,
266 'school_name' => $model->school_name,
267 'semester' => $model->semester,
268 'year' => $model->year,
269 'trash' => null));
270 if (empty($cekNilai)) {
271 if ($model->save()) {
272 $id = $model->id;
273 }
274 }
275 $json = json_encode($id, JSON_PRETTY_PRINT);
276 header('Content-Type: application/x-javascript');
277 echo $json;
278 }
279
280 public function actionSetScore()
281 {
282 $post_data = urldecode(file_get_contents("php://input"));
283 $ssdb = new SimpleSSDB('127.0.0.1', 8888);
284 $queue_name = @Option::model()->findByAttributes(array('key_config' => 'queue_name'))->value;
285 $push = $ssdb->qpush($queue_name, $post_data);
286 if (!$push) {
287 $json = "Something error!!";
288 } else {
289 $json = "Your data will be update in a minutes";
290 }
291 header('Content-Type: application/x-javascript');
292 echo $json;
293 }
294
295 public function actionSetDailyAbsent()
296 {
297 $this->checkToken();
298 $post_data = json_decode(urldecode(file_get_contents("php://input")));
299 $id = null;
300 foreach ($post_data as $absen) {
301 $model = new AbsensiHarian;
302 foreach ($absen as $key => $value) {
303 $model->$key = $value;
304 }
305 if (!empty($model)) {
306 if ($model->save()) {
307 $id[] = $model->id;
308 }
309 }
310 }
311 $json = json_encode("Berhasil menambah absen harian " . implode(", ", $id), JSON_PRETTY_PRINT);
312 header('Content-Type: application/x-javascript');
313 header("Access-Control-Allow-Origin: *");
314 echo $json;
315 }
316
317 public function actionGetDailyAbsent()
318 {
319 $status = true;
320 //cek token
321 $this->checkToken();
322
323
324 $Semester = isset($_GET['semester']) ? $_GET['semester'] : Option::model()->findByAttributes(array('key_config' => 'semester'))->value;
325 $TahunAjaran = isset($_GET['year']) ? $_GET['year'] : Option::model()->findByAttributes(array('key_config' => 'tahun_ajaran'))->value;
326
327 $condition = 'id IS NOT NULL';
328 if (isset($_GET['user_id'])) {
329 $condition .= ' and t.user_id =' . $_GET['user_id'];
330 }
331 if (isset($_GET['tgl'])) {
332 $condition .= ' and t.tgl = "' . $_GET['tgl'] . '"';
333 }
334
335 $criteria = new CDbCriteria();
336 $criteria->mergeWith(array(
337 'order' => 'tgl DESC',
338 'select' => 't.*',
339 'condition' => $condition,
340 ));
341 $count = AbsensiHarian::model()->count($criteria);
342
343 if ($count > 0) {
344 $pages = new CPagination($count);
345 // results per page
346 $pages->CurrentPage = isset($_GET['start']) ? $_GET['start'] : 0;
347 $pages->pageSize = isset($_GET['rows']) ? $_GET['rows'] : 10;
348 $perpage = $pages->pageSize;
349 $pages->applyLimit($criteria);
350 $totalpage = ceil($count / $perpage);
351 $models = AbsensiHarian::model()->findAll($criteria);
352
353 $data['success'] = 1;
354 $data['message'] = 'Record(s) Found.';
355 $data['totalCount'] = $count;
356 foreach ($models as $row) {
357 $data_fix['id'] = $row->id;
358 $data_fix['tanggal'] = $row->tgl;
359 $data_fix['absen'] = $row->absen;
360 $data_fix['ket'] = $row->ket;
361
362 $score_siswa = $this->actionScore($_GET['user_id'], $row->tgl, $Semester, $TahunAjaran);
363
364 if ($score_siswa["success"]!=0) {
365 $data_fix['score'] = $score_siswa['data']['result']['quizes'][0]['score'];
366 if (!empty($score_siswa['data']['result']['quizes'])) {
367 $nilai = 0;
368 $index_nilai = 0;
369 $data_fix['score_all'] = $score_siswa['data']['result']['quizes'];
370 foreach ($score_siswa['data']['result']['quizes'] as $key => $value) {
371 $nilai = $nilai + $value['score'];
372 $data_fix['score'] = $nilai;
373 $index_nilai = $index_nilai + 1;
374 $data_fix['index_nilai'] = $index_nilai;
375
376 $data_fix['rata_nilai'] = $nilai / $index_nilai;
377
378 $data_fix['predikat'] = Clases::model()->predikat(round($nilai), 70);
379 }
380 // $data_fix['score'] = $score_siswa['data']['result']['quizes'][0]['score'];
381 } else {
382 $data_fix['score'] = "-";
383 $data_fix['predikat'] = "-";
384 $data_fix['rata_nilai'] = "-";
385 $data_fix['index_nilai'] = "-";
386 }
387 } else {
388 $data_fix['score'] = "-";
389 $data_fix['predikat'] = "-";
390 $data_fix['rata_nilai'] = "-";
391 $data_fix['index_nilai'] = "-";
392 }
393 // $data_fix['score'] = $this->actionScore($_GET['user_id'],$row->tgl,$Semester,$TahunAjaran);
394
395 if (!empty($row->user->id)) {
396 $data_fix['user']['id'] = $row->user_id;
397 $data_fix['user']['name'] = $row->user->display_name;
398 }
399 $data['data']['result'][] = $data_fix;
400 }
401 } else {
402 $models = null;
403 }
404
405 if ($status == false) {
406 $data['success'] = 0;
407 $data['message'] = 'ERROR : Missing or Invalid Parameter !';
408 $data['data'] = null;
409 $json = json_encode($data, JSON_PRETTY_PRINT);
410 header('Content-Type: application/x-javascript');
411 header("Access-Control-Allow-Origin: *");
412 echo $json;
413 } elseif ($models == null) {
414 $data['success'] = 0;
415 $data['message'] = 'ERROR : No Data Found';
416 $data['data'] = null;
417 $json = json_encode($data, JSON_PRETTY_PRINT);
418 header('Content-Type: application/x-javascript');
419 header("Access-Control-Allow-Origin: *");
420 echo $json;
421 } else {
422 $json = json_encode($data, JSON_PRETTY_PRINT);
423 header('Content-Type: application/json');
424 header("Access-Control-Allow-Origin: *");
425 echo $json;
426 }
427 }
428
429
430 public function actionGetDailyFingerPrint()
431 {
432 $status = true;
433 //cek token
434 $this->checkToken();
435
436 // pakai id absen jangan id user
437
438 $usernya = User::model()->findByPk($_GET['user_id']);
439
440 $Semester = isset($_GET['semester']) ? $_GET['semester'] : Option::model()->findByAttributes(array('key_config' => 'semester'))->value;
441 $TahunAjaran = isset($_GET['year']) ? $_GET['year'] : Option::model()->findByAttributes(array('key_config' => 'tahun_ajaran'))->value;
442
443 $condition = 'id IS NOT NULL';
444 if (isset($_GET['user_id'])) {
445 $condition .= ' and t.user_id =' . $usernya->id_absen_solution;
446 }
447 if (isset($_GET['tgl'])) {
448 $condition .= ' and t.datetime = "' . $_GET['tgl'] . '"';
449 }
450
451 $criteria = new CDbCriteria();
452 $criteria->mergeWith(array(
453 'order' => 'datetime ASC',
454 'select' => 't.*',
455 'condition' => $condition,
456 ));
457 $count = AbsensiSolution::model()->count($criteria);
458
459 if ($count > 0) {
460 $pages = new CPagination($count);
461 // results per page
462 $pages->CurrentPage = isset($_GET['start']) ? $_GET['start'] : 0;
463 $pages->pageSize = isset($_GET['rows']) ? $_GET['rows'] : 10000;
464 $perpage = $pages->pageSize;
465 $pages->applyLimit($criteria);
466 $totalpage = ceil($count / $perpage);
467 $models = AbsensiSolution::model()->findAll($criteria);
468
469 $data['success'] = 1;
470 $data['message'] = 'Record(s) Found.';
471 $data['totalCount'] = $count;
472 $data['data']['totalPage'] = $totalpage;
473 $data['data']['perPage'] = $perpage;
474
475
476 $date_array = array();
477
478 foreach ($models as $row) {
479 $s = $row->datetime;
480 $dt = new DateTime($s);
481
482 $thedate = $dt->format('Y-m-d');
483 $thetime = $dt->format('H:i:s');
484 $counts = array_count_values($date_array);
485
486 if (!in_array($thedate, $date_array)) {
487 array_push($date_array, $thedate);
488
489 $data_fix['id'] = $row->id;
490 $data_fix['tanggal'] = $thedate;
491 $data_fix['datang'] = $thetime;
492 $data_fix['pulang'] = "-";
493 $data_fix['absen'] = "Hadir";
494 $data_fix['ket'] = "ket";
495
496 $score_siswa = $this->actionScore($_GET['user_id'], $row->datetime, $Semester, $TahunAjaran);
497
498 if ($score_siswa["success"]!=0) {
499 $data_fix['score'] = $score_siswa['data']['result']['quizes'][0]['score'];
500 if (!empty($score_siswa['data']['result']['quizes'])) {
501 $nilai = 0;
502 $index_nilai = 0;
503 // $data_fix['score_all'] = $score_siswa['data']['result']['quizes'];
504 foreach ($score_siswa['data']['result']['quizes'] as $key => $value) {
505 // $nilai = $nilai + $value['score'];
506 $nilai = $value['score'];
507 $data_fix['score'] = (string)$nilai;
508 $index_nilai = $index_nilai + 1;
509 $data_fix['index_nilai'] = (string)$index_nilai;
510
511 // $data_fix['rata_nilai'] = $nilai / $index_nilai;
512
513 $data_fix['rata_nilai'] = "-";
514
515 // $data_fix['predikat'] = Clases::model()->predikat(round($nilai),70);
516
517 $data_fix['predikat'] = (string)$nilai;
518 }
519 // $data_fix['score'] = $score_siswa['data']['result']['quizes'][0]['score'];
520 } else {
521 $data_fix['score'] = "-";
522 $data_fix['predikat'] = "-";
523 $data_fix['rata_nilai'] = "-";
524 $data_fix['index_nilai'] = "-";
525 }
526 } else {
527 $data_fix['score'] = "-";
528 $data_fix['predikat'] = "-";
529 $data_fix['rata_nilai'] = "-";
530 $data_fix['index_nilai'] = "-";
531 }
532 // $data_fix['score'] = $this->actionScore($_GET['user_id'],$row->tgl,$Semester,$TahunAjaran);
533
534 if (!empty($row->user_id)) {
535 $data_fix['user']['id'] = $row->user_id;
536 $data_fix['user']['name'] = $row->guru->display_name;
537 }
538 $data['data']['result'][] = $data_fix;
539 } else {
540 if (($counts[$thedate] == 1) && (strtotime($thetime) > strtotime('10:00'))) {
541 array_push($date_array, $thedate);
542
543 $data_fix['id'] = $row->id;
544 $data_fix['tanggal'] = $thedate;
545 $data_fix['datang'] = "-";
546 $data_fix['pulang'] = $thetime;
547 $data_fix['absen'] = "Hadir";
548 $data_fix['ket'] = "ket";
549
550 $score_siswa = $this->actionScore($_GET['user_id'], $row->datetime, $Semester, $TahunAjaran);
551
552 if ($score_siswa["success"]!=0) {
553 $data_fix['score'] = $score_siswa['data']['result']['quizes'][0]['score'];
554 if (!empty($score_siswa['data']['result']['quizes'])) {
555 $nilai = 0;
556 $index_nilai = 0;
557 // $data_fix['score_all'] = $score_siswa['data']['result']['quizes'];
558 foreach ($score_siswa['data']['result']['quizes'] as $key => $value) {
559 // $nilai = $nilai + $value['score'];
560 $nilai = $value['score'];
561 $data_fix['score'] = (string)$nilai;
562 $index_nilai = $index_nilai + 1;
563 $data_fix['index_nilai'] = (string)$index_nilai;
564
565 // $data_fix['rata_nilai'] = $nilai / $index_nilai;
566
567 $data_fix['rata_nilai'] = "-";
568
569 // $data_fix['predikat'] = Clases::model()->predikat(round($nilai),70);
570
571 $data_fix['predikat'] = (string)$nilai;
572 }
573 // $data_fix['score'] = $score_siswa['data']['result']['quizes'][0]['score'];
574 } else {
575 $data_fix['score'] = "-";
576 $data_fix['predikat'] = "-";
577 $data_fix['rata_nilai'] = "-";
578 $data_fix['index_nilai'] = "-";
579 }
580 } else {
581 $data_fix['score'] = "-";
582 $data_fix['predikat'] = "-";
583 $data_fix['rata_nilai'] = "-";
584 $data_fix['index_nilai'] = "-";
585 }
586 // $data_fix['score'] = $this->actionScore($_GET['user_id'],$row->tgl,$Semester,$TahunAjaran);
587
588 if (!empty($row->user_id)) {
589 $data_fix['user']['id'] = $row->user_id;
590 $data_fix['user']['name'] = $row->guru->display_name;
591 }
592 $data['data']['result'][] = $data_fix;
593 }
594 }
595 }
596 } else {
597 $models = null;
598 }
599
600 if ($status == false) {
601 $data['success'] = 0;
602 $data['message'] = 'ERROR : Missing or Invalid Parameter !';
603 $data['data'] = null;
604 $json = json_encode($data, JSON_PRETTY_PRINT);
605 header('Content-Type: application/x-javascript');
606 header("Access-Control-Allow-Origin: *");
607 echo $json;
608 } elseif ($models == null) {
609 $data['success'] = 0;
610 $data['message'] = 'ERROR : No Data Found';
611 $data['data'] = null;
612 $json = json_encode($data, JSON_PRETTY_PRINT);
613 header('Content-Type: application/x-javascript');
614 header("Access-Control-Allow-Origin: *");
615 echo $json;
616 } else {
617 $json = json_encode($data, JSON_PRETTY_PRINT);
618 header('Content-Type: application/json');
619 header("Access-Control-Allow-Origin: *");
620 echo $json;
621 }
622 }
623
624 public function actionGetDailyFingerPrintPaginate()
625 {
626 $status = true;
627 //cek token
628 $this->checkToken();
629
630 // pakai id absen jangan id user
631
632 $usernya = User::model()->findByPk($_GET['user_id']);
633
634 $Semester = isset($_GET['semester']) ? $_GET['semester'] : Option::model()->findByAttributes(array('key_config' => 'semester'))->value;
635 $TahunAjaran = isset($_GET['year']) ? $_GET['year'] : Option::model()->findByAttributes(array('key_config' => 'tahun_ajaran'))->value;
636
637 $condition = 'id IS NOT NULL';
638 if (isset($_GET['user_id'])) {
639 $condition .= ' and t.user_id =' . $usernya->id_absen_solution;
640 }
641 if (isset($_GET['tgl'])) {
642 $condition .= ' and t.datetime = "' . $_GET['tgl'] . '"';
643 }
644
645 $criteria = new CDbCriteria();
646 $criteria->mergeWith(array(
647 'order' => 'datetime DESC',
648 'select' => 't.*',
649 'condition' => $condition,
650 ));
651 $count = AbsensiSolution::model()->count($criteria);
652
653 if ($count > 0) {
654 $pages = new CPagination($count);
655 // results per page
656 $pages->CurrentPage = isset($_GET['start']) ? $_GET['start'] : 0;
657 $pages->pageSize = isset($_GET['rows']) ? $_GET['rows'] : 10000;
658 $perpage = $pages->pageSize;
659 $pages->applyLimit($criteria);
660 $totalpage = ceil($count / $perpage);
661 $models = AbsensiSolution::model()->findAll($criteria);
662
663 $data['success'] = 1;
664 $data['message'] = 'Record(s) Found.';
665 $data['totalCount'] = $count;
666 $data['data']['totalPage'] = $totalpage;
667 $data['data']['perPage'] = $perpage;
668
669
670 $date_array = array();
671
672 foreach ($models as $row) {
673 $s = $row->datetime;
674 $dt = new DateTime($s);
675
676 $thedate = $dt->format('Y-m-d');
677 $thetime = $dt->format('H:i:s');
678 $counts = array_count_values($date_array);
679
680 if (!in_array($thedate, $date_array)) {
681 array_push($date_array, $thedate);
682
683 $data_fix['id'] = $row->id;
684 $data_fix['tanggal'] = $thedate;
685 $data_fix['datang'] = $thetime;
686 $data_fix['pulang'] = "-";
687 $data_fix['absen'] = "Hadir";
688 $data_fix['ket'] = "ket";
689
690 $score_siswa = $this->actionScore($_GET['user_id'], $row->datetime, $Semester, $TahunAjaran);
691
692 if ($score_siswa["success"]!=0) {
693 $data_fix['score'] = $score_siswa['data']['result']['quizes'][0]['score'];
694 if (!empty($score_siswa['data']['result']['quizes'])) {
695 $nilai = 0;
696 $index_nilai = 0;
697 $data_fix['score_all'] = $score_siswa['data']['result']['quizes'];
698 foreach ($score_siswa['data']['result']['quizes'] as $key => $value) {
699 $nilai = $nilai + $value['score'];
700 $data_fix['score'] = $nilai;
701 $index_nilai = $index_nilai + 1;
702 $data_fix['index_nilai'] = $index_nilai;
703
704 $data_fix['rata_nilai'] = $nilai / $index_nilai;
705
706 $data_fix['predikat'] = Clases::model()->predikat(round($nilai), 70);
707 }
708 // $data_fix['score'] = $score_siswa['data']['result']['quizes'][0]['score'];
709 } else {
710 $data_fix['score'] = "-";
711 $data_fix['predikat'] = "-";
712 $data_fix['rata_nilai'] = "-";
713 $data_fix['index_nilai'] = "-";
714 }
715 } else {
716 $data_fix['score'] = "-";
717 $data_fix['predikat'] = "-";
718 $data_fix['rata_nilai'] = "-";
719 $data_fix['index_nilai'] = "-";
720 }
721 // $data_fix['score'] = $this->actionScore($_GET['user_id'],$row->tgl,$Semester,$TahunAjaran);
722
723 if (!empty($row->user_id)) {
724 $data_fix['user']['id'] = $row->user_id;
725 $data_fix['user']['name'] = $row->guru->display_name;
726 }
727 $data['data']['result'][] = $data_fix;
728 } else {
729 if (($counts[$thedate] == 1) && (strtotime($thetime) > strtotime('11:00'))) {
730 array_push($date_array, $thedate);
731
732 $data_fix['id'] = $row->id;
733 $data_fix['tanggal'] = $thedate;
734 $data_fix['datang'] = "-";
735 $data_fix['pulang'] = $thetime;
736 $data_fix['absen'] = "Hadir";
737 $data_fix['ket'] = "ket";
738
739 $score_siswa = $this->actionScore($_GET['user_id'], $row->datetime, $Semester, $TahunAjaran);
740
741 if ($score_siswa["success"]!=0) {
742 $data_fix['score'] = $score_siswa['data']['result']['quizes'][0]['score'];
743 if (!empty($score_siswa['data']['result']['quizes'])) {
744 $nilai = 0;
745 $index_nilai = 0;
746 $data_fix['score_all'] = $score_siswa['data']['result']['quizes'];
747 foreach ($score_siswa['data']['result']['quizes'] as $key => $value) {
748 $nilai = $nilai + $value['score'];
749 $data_fix['score'] = $nilai;
750 $index_nilai = $index_nilai + 1;
751 $data_fix['index_nilai'] = $index_nilai;
752
753 $data_fix['rata_nilai'] = $nilai / $index_nilai;
754
755 $data_fix['predikat'] = Clases::model()->predikat(round($nilai), 70);
756 }
757 // $data_fix['score'] = $score_siswa['data']['result']['quizes'][0]['score'];
758 } else {
759 $data_fix['score'] = "-";
760 $data_fix['predikat'] = "-";
761 $data_fix['rata_nilai'] = "-";
762 $data_fix['index_nilai'] = "-";
763 }
764 } else {
765 $data_fix['score'] = "-";
766 $data_fix['predikat'] = "-";
767 $data_fix['rata_nilai'] = "-";
768 $data_fix['index_nilai'] = "-";
769 }
770 // $data_fix['score'] = $this->actionScore($_GET['user_id'],$row->tgl,$Semester,$TahunAjaran);
771
772 if (!empty($row->user_id)) {
773 $data_fix['user']['id'] = $row->user_id;
774 $data_fix['user']['name'] = $row->guru->display_name;
775 }
776 $data['data']['result'][] = $data_fix;
777 }
778 }
779 }
780 } else {
781 $models = null;
782 }
783
784 if ($status == false) {
785 $data['success'] = 0;
786 $data['message'] = 'ERROR : Missing or Invalid Parameter !';
787 $data['data'] = null;
788 $json = json_encode($data, JSON_PRETTY_PRINT);
789 header('Content-Type: application/x-javascript');
790 header("Access-Control-Allow-Origin: *");
791 echo $json;
792 } elseif ($models == null) {
793 $data['success'] = 0;
794 $data['message'] = 'ERROR : No Data Found';
795 $data['data'] = null;
796 $json = json_encode($data, JSON_PRETTY_PRINT);
797 header('Content-Type: application/x-javascript');
798 header("Access-Control-Allow-Origin: *");
799 echo $json;
800 } else {
801 $json = json_encode($data, JSON_PRETTY_PRINT);
802 header('Content-Type: application/json');
803 header("Access-Control-Allow-Origin: *");
804 echo $json;
805 }
806 }
807
808 public function actionTarqiReport()
809 {
810 $this->checkToken();
811
812 $sql = "SELECT u.id as user_id, u.display_name, l.name, a.pertemuan_ke FROM `absensi` as a join `lesson` as l on l.id = a.id_lesson join `users` as u on u.id = l.user_id";
813 $command = Yii::app()->db->createCommand($sql);
814
815 try {
816 $result = $command->queryAll();
817 foreach ($result as $value) {
818 $hasil[$value['display_name']."-".$value['user_id']][$value['name']][$value['pertemuan_ke']] = true;
819 }
820 $data['data']['result'][] = $hasil;
821 $json = json_encode($data, JSON_PRETTY_PRINT);
822 echo $json;
823 } catch (Exception $ex) {
824 // Handle exception
825 }
826 }
827
828 public function actionTarqiReportRekap()
829 {
830 $this->checkToken();
831
832 $sql = "select users.id,users.display_name, rekap.jumlahnya from users LEFT OUTER JOIN (select idnya, namanya, sum(jumlahnya) as jumlahnya from (SELECT u.id as idnya, u.display_name as namanya, l.name, a.pertemuan_ke,count(distinct(a.pertemuan_ke)) as jumlahnya FROM `absensi` as a JOIN `lesson` as l on l.id = a.id_lesson join `users` as u on u.id = l.user_id group by l.name) as subq group by idnya) as rekap on rekap.idnya = users.id where users.role_id = 1 and users.trash is null";
833 $command = Yii::app()->db->createCommand($sql);
834
835 try {
836 $result = $command->queryAll();
837 $data['data']['result'] = $result;
838 $json = json_encode($data, JSON_PRETTY_PRINT);
839 echo $json;
840 } catch (Exception $ex) {
841 // Handle exception
842 }
843 }
844
845
846 public function actionTarqiReportByid()
847 {
848 $this->checkToken();
849
850 if (isset($_GET['user_id'])) {
851 $sql = "SELECT u.id as user_id,u.display_name, l.name, a.pertemuan_ke FROM `absensi` as a join `lesson` as l on l.id = a.id_lesson join `users` as u on u.id = l.user_id where u.id = ".$_GET['user_id'];
852 $command = Yii::app()->db->createCommand($sql);
853
854 try {
855 $result = $command->queryAll();
856 foreach ($result as $value) {
857 $hasil[$value['display_name']."-".$value['user_id']][$value['name']][$value['pertemuan_ke']] = true;
858 }
859 $data['data']['result'][] = $hasil;
860 $json = json_encode($data, JSON_PRETTY_PRINT);
861 echo $json;
862 } catch (Exception $ex) {
863 // Handle exception
864 }
865 }
866 }
867
868 public function actionGetAbsent()
869 {
870 $status = true;
871 //cek token
872 $this->checkToken();
873
874 $condition = 'id IS NOT NULL';
875 if (isset($_GET['user_id'])) {
876 $condition .= ' and t.user_id =' . $_GET['user_id'];
877 }
878
879 if (isset($_GET['id_lesson'])) {
880 $condition .= ' and t.id_lesson =' . $_GET['lesson_id'];
881 }
882
883 $criteria = new CDbCriteria();
884 $criteria->mergeWith(array(
885 'order' => 'created_at DESC',
886 'select' => 't.*',
887 'condition' => $condition,
888 ));
889 $count = Absensi::model()->count($criteria);
890
891 if ($count > 0) {
892 $pages = new CPagination($count);
893 // results per page
894 $pages->CurrentPage = isset($_GET['start']) ? $_GET['start'] : 0;
895 $pages->pageSize = isset($_GET['rows']) ? $_GET['rows'] : 10;
896 $perpage = $pages->pageSize;
897 $pages->applyLimit($criteria);
898 $totalpage = ceil($count / $perpage);
899 $models = Absensi::model()->findAll($criteria);
900
901 $data['success'] = 1;
902 $data['message'] = 'Record(s) Found.';
903 $data['totalCount'] = $count;
904 foreach ($models as $row) {
905 $data_fix['id'] = $row->id;
906 $data_fix['absen'] = $row->absen;
907 $data_fix['created_at'] = $row->created_at;
908 $data_fix['pertemuan_ke'] = $row->pertemuan_ke;
909 $data_fix['keterangan'] = $row->ket;
910 if (!empty($row->user->id)) {
911 $data_fix['user']['id'] = $row->user_id;
912 $data_fix['user']['name'] = $row->user->display_name;
913 }
914 if (!empty($row->lesson->id)) {
915 $data_fix['lesson']['id'] = $row->id_lesson;
916 $data_fix['lesson']['name'] = $row->lesson->name;
917 $data_fix['user']['class'] = $row->lesson->class->name;
918 $data_fix['user']['grade'] = $row->lesson->class->class_id;
919 }
920 $data['data']['result'][] = $data_fix;
921 }
922 } else {
923 $models = null;
924 }
925
926 if ($status == false) {
927 $data['success'] = 0;
928 $data['message'] = 'ERROR : Missing or Invalid Parameter !';
929 $data['data'] = null;
930 $json = json_encode($data, JSON_PRETTY_PRINT);
931 header('Content-Type: application/x-javascript');
932 echo $json;
933 } elseif ($models == null) {
934 $data['success'] = 0;
935 $data['message'] = 'ERROR : No Data Found';
936 $data['data'] = null;
937 $json = json_encode($data, JSON_PRETTY_PRINT);
938 header('Content-Type: application/x-javascript');
939 echo $json;
940 } else {
941 $json = json_encode($data, JSON_PRETTY_PRINT);
942 header('Content-Type: application/json');
943 echo $json;
944 }
945 }
946
947 public function actionGetAnnouncements()
948 {
949 $status = true;
950 //cek token
951 $this->checkToken();
952 $condition = "";
953 if (isset($_GET['id'])) {
954 $condition .= ' and t.id =' . $_GET['id'];
955 }
956 $criteria = new CDbCriteria();
957 $criteria->mergeWith(array(
958 'order' => 'created_at DESC',
959 'select' => 't.*',
960 'condition' => $condition,
961 ));
962 $count = Announcements::model()->count($criteria);
963
964 if ($count > 0) {
965 $pages = new CPagination($count);
966 // results per page
967 $pages->CurrentPage = isset($_GET['start']) ? $_GET['start'] : 0;
968 $pages->pageSize = isset($_GET['rows']) ? $_GET['rows'] : 10;
969 $perpage = $pages->pageSize;
970 $pages->applyLimit($criteria);
971 $totalpage = ceil($count / $perpage);
972 $models = Announcements::model()->findAll($criteria);
973
974 $data['success'] = 1;
975 $data['message'] = 'Record(s) Found.';
976 $data['totalCount'] = $count;
977 foreach ($models as $row) {
978 $data_fix['id'] = $row->id;
979 $data_fix['title'] = $row->title;
980 $data_fix['created_at'] = $row->created_at;
981 $data_fix['content'] = $row->content;
982 $data_fix['type'] = $row->type;
983 $data_fix['author_id'] = $row->author_id;
984
985 $data['data']['result'][] = $data_fix;
986 }
987 } else {
988 $models = null;
989 }
990
991 if ($status == false) {
992 $data['success'] = 0;
993 $data['message'] = 'ERROR : Missing or Invalid Parameter !';
994 $data['data'] = null;
995 $json = json_encode($data, JSON_PRETTY_PRINT);
996 header('Content-Type: application/x-javascript');
997 header("Access-Control-Allow-Origin: *");
998 echo $json;
999 } elseif ($models == null) {
1000 $data['success'] = 0;
1001 $data['message'] = 'ERROR : No Data Found';
1002 $data['data'] = null;
1003 $json = json_encode($data, JSON_PRETTY_PRINT);
1004 header('Content-Type: application/x-javascript');
1005 header("Access-Control-Allow-Origin: *");
1006 echo $json;
1007 } else {
1008 $json = json_encode($data, JSON_PRETTY_PRINT);
1009 header('Content-Type: application/json');
1010 header("Access-Control-Allow-Origin: *");
1011 echo $json;
1012 }
1013 }
1014
1015 public function actionGetStudentFinalMark()
1016 {
1017 $status = true;
1018 //cek token
1019 $this->checkToken();
1020 $Semester = isset($_GET['semester']) ? $_GET['semester'] : Option::model()->findByAttributes(array('key_config' => 'semester'))->value;
1021 $TahunAjaran = isset($_GET['year']) ? $_GET['year'] : Option::model()->findByAttributes(array('key_config' => 'tahun_ajaran'))->value;
1022
1023 $condition = 'tahun_ajaran = ' . $TahunAjaran;
1024 $condition .= ' and semester = ' . $Semester;
1025 if (isset($_GET['user_id'])) {
1026 $condition .= ' and user_id = ' . $_GET['user_id'];
1027 }
1028 $models = FinalMark::model()->findAll(array('condition' => $condition));
1029 if (!empty($models)) {
1030 $data['success'] = 1;
1031 $data['message'] = 'Record(s) Found.';
1032 foreach ($models as $row) {
1033 $data_fix[$row->tipe] = $row->nilai_desc;
1034 }
1035 $data['data']['result'] = $data_fix;
1036 }
1037
1038 if ($status == false) {
1039 $data['success'] = 0;
1040 $data['message'] = 'ERROR : Missing or Invalid Parameter !';
1041 $data['data'] = null;
1042 $json = json_encode($data, JSON_PRETTY_PRINT);
1043 header('Content-Type: application/x-javascript');
1044 header("Access-Control-Allow-Origin: *");
1045 echo $json;
1046 } elseif ($models == null) {
1047 $data['success'] = 0;
1048 $data['message'] = 'ERROR : No Data Found';
1049 $data['data'] = null;
1050 $json = json_encode($data, JSON_PRETTY_PRINT);
1051 header('Content-Type: application/x-javascript');
1052 header("Access-Control-Allow-Origin: *");
1053 echo $json;
1054 } else {
1055 $json = json_encode($data, JSON_PRETTY_PRINT);
1056 header('Content-Type: application/json');
1057 header("Access-Control-Allow-Origin: *");
1058 echo $json;
1059 }
1060 }
1061
1062 public function actionGetStudentQuizes()
1063 {
1064 $status = true;
1065 //cek token
1066 $this->checkToken();
1067 $Semester = isset($_GET['semester']) ? $_GET['semester'] : Option::model()->findByAttributes(array('key_config' => 'semester'))->value;
1068 $TahunAjaran = isset($_GET['year']) ? $_GET['year'] : Option::model()->findByAttributes(array('key_config' => 'tahun_ajaran'))->value;
1069
1070 $token = OauthToken::model()->find('token=:token', [':token' => $_GET['token'] ]);
1071 $role_id = ($token && $token->User) ? $token->User->role_id : null;
1072
1073 $condition = 'q.year = ' . $TahunAjaran;
1074 // $condition .= ' and q.semester = ' . $Semester .' and q.show_nilai IS NOT NULL';
1075
1076 if ($role_id === '2') { //if student
1077 $condition .= ' and q.semester = ' . $Semester;
1078 } else {
1079 $condition .= ' and q.semester = ' . $Semester .' and q.show_nilai IS NOT NULL';
1080 }
1081
1082 if (isset($_GET['user_id'])) {
1083 $condition .= ' and t.student_id = ' . $_GET['user_id'];
1084 }
1085 if (isset($_GET['created_at'])) {
1086 $condition .= ' and DATE_FORMAT(t.created_at, "%Y-%m-%d") ="' . $_GET['created_at'] . '"';
1087 }
1088
1089
1090 $criteria = new CDbCriteria();
1091 $criteria->mergeWith(array(
1092 'join' => 'JOIN quiz AS q ON q.id = t.quiz_id ',
1093 'condition' => $condition,
1094 ));
1095
1096 $models = StudentQuiz::model()->findAll($criteria);
1097
1098 if (!empty($models)) {
1099 $data['success'] = 1;
1100 $data['message'] = 'Record(s) Found.';
1101 $i = 0;
1102 foreach ($models as $row) {
1103 $data_fix['nisn'] = $row->nisn;
1104 $data_fix['display_name'] = $row->display_name;
1105 $data_fix['class'] = $row->class;
1106 $data_fix['school_name'] = $row->school_name;
1107 if ($row->quiz->id) {
1108 $data_fix['quizes'][$i]['id'] = $row->quiz->id;
1109 $data_fix['quizes'][$i]['created_at'] = $row->created_at;
1110 $data_fix['quizes'][$i]['title'] = $row->quiz->title;
1111 $data_fix['quizes'][$i]['right_answer'] = $row->right_answer;
1112 $data_fix['quizes'][$i]['wrong_answer'] = $row->wrong_answer;
1113 $data_fix['quizes'][$i]['unanswered'] = $row->unanswered;
1114 $data_fix['quizes'][$i]['essay_score'] = $row->essay_score;
1115 $data_fix['quizes'][$i]['pg_score'] = $row->pg_score;
1116 $data_fix['quizes'][$i]['score'] = $row->score;
1117 $data_fix['quizes'][$i]['kd'] = json_decode($row->kd);
1118 }
1119 $i++;
1120 }
1121 $data['data']['result'] = $data_fix;
1122 }
1123
1124 if ($status == false) {
1125 $data['success'] = 0;
1126 $data['message'] = 'ERROR : Missing or Invalid Parameter !';
1127 $data['data'] = null;
1128 $json = json_encode($data, JSON_PRETTY_PRINT);
1129 header('Content-Type: application/x-javascript');
1130 header("Access-Control-Allow-Origin: *");
1131 echo $json;
1132 } elseif ($models == null) {
1133 $data['success'] = 0;
1134 $data['message'] = 'ERROR : No Data Found';
1135 $data['data'] = null;
1136 $json = json_encode($data, JSON_PRETTY_PRINT);
1137 header('Content-Type: application/x-javascript');
1138 header("Access-Control-Allow-Origin: *");
1139 echo $json;
1140 } else {
1141 $json = json_encode($data, JSON_PRETTY_PRINT);
1142 header('Content-Type: application/json');
1143 header("Access-Control-Allow-Origin: *");
1144 echo $json;
1145 }
1146 }
1147
1148
1149 public function actionScore($user_id, $created_at, $Semester, $TahunAjaran)
1150 {
1151 $status = true;
1152
1153 $condition = 'q.year = ' . $TahunAjaran;
1154 $condition .= ' and q.semester = ' . $Semester. ' and q.show_nilai IS NOT NULL';
1155 if (isset($user_id)) {
1156 $condition .= ' and t.student_id = ' . $user_id;
1157 }
1158 if (isset($created_at)) {
1159 $thedate = date("Y-m-d", strtotime($created_at));
1160 $condition .= ' and DATE_FORMAT(t.created_at, "%Y-%m-%d") ="' . $thedate . '"';
1161 }
1162
1163
1164 $criteria = new CDbCriteria();
1165 $criteria->mergeWith(array(
1166 'join' => 'JOIN quiz AS q ON q.id = t.quiz_id ',
1167 'condition' => $condition,
1168 ));
1169
1170 $models = StudentQuiz::model()->findAll($criteria);
1171
1172 if (!empty($models)) {
1173 $data['success'] = 1;
1174 $data['message'] = 'Record(s) Found.';
1175 $i = 0;
1176 foreach ($models as $row) {
1177 $data_fix['nisn'] = $row->nisn;
1178 $data_fix['display_name'] = $row->display_name;
1179 $data_fix['class'] = $row->class;
1180 $data_fix['school_name'] = $row->school_name;
1181 if ($row->quiz->id) {
1182 $data_fix['quizes'][$i]['id'] = $row->quiz->id;
1183 $data_fix['quizes'][$i]['created_at'] = $row->created_at;
1184 $data_fix['quizes'][$i]['title'] = $row->quiz->title;
1185 $data_fix['quizes'][$i]['right_answer'] = $row->right_answer;
1186 $data_fix['quizes'][$i]['wrong_answer'] = $row->wrong_answer;
1187 $data_fix['quizes'][$i]['unanswered'] = $row->unanswered;
1188 $data_fix['quizes'][$i]['essay_score'] = $row->essay_score;
1189 $data_fix['quizes'][$i]['pg_score'] = $row->pg_score;
1190 $data_fix['quizes'][$i]['score'] = $row->score;
1191 $data_fix['quizes'][$i]['kd'] = json_decode($row->kd);
1192 }
1193 $i++;
1194 }
1195 $data['data']['result'] = $data_fix;
1196 }
1197
1198 if ($status == false) {
1199 $data['success'] = 0;
1200 $data['message'] = 'ERROR : Missing or Invalid Parameter !';
1201 $data['data'] = null;
1202 // $json = json_encode($data, JSON_PRETTY_PRINT);
1203 // header('Content-Type: application/x-javascript');
1204 // header("Access-Control-Allow-Origin: *");
1205 return $data;
1206 } elseif ($models == null) {
1207 $data['success'] = 0;
1208 $data['message'] = 'ERROR : No Data Found';
1209 $data['data'] = null;
1210 // $json = json_encode($data, JSON_PRETTY_PRINT);
1211 // header('Content-Type: application/x-javascript');
1212 // header("Access-Control-Allow-Origin: *");
1213 return $data;
1214 } else {
1215 // $json = json_encode($data, JSON_PRETTY_PRINT);
1216 // header('Content-Type: application/json');
1217 // header("Access-Control-Allow-Origin: *");
1218 return $data;
1219 }
1220 }
1221
1222 public function actionSetAbsentSolution()
1223 {
1224 $this->checkToken();
1225 $post_data = json_decode(urldecode(file_get_contents("php://input")));
1226 $id = null;
1227 foreach ($post_data as $absen) {
1228 $model = new AbsensiSolution;
1229 foreach ($absen as $key => $value) {
1230 $model->$key = $value;
1231 }
1232 if (!empty($model)) {
1233 if ($model->save()) {
1234 $id[] = $model->id;
1235 }
1236 }
1237 }
1238 $json = json_encode("Berhasil menambah absen harian " . implode(", ", $id), JSON_PRETTY_PRINT);
1239 header('Content-Type: application/x-javascript');
1240 header("Access-Control-Allow-Origin: *");
1241 echo $json;
1242 }
1243
1244 public function actionGetAbsentSolution()
1245 {
1246 $status = true;
1247 //cek token
1248 $this->checkToken();
1249
1250 $condition = 'id IS NOT NULL';
1251 if (isset($_GET['user_id'])) {
1252 $condition .= ' and t.user_id =' . $_GET['user_id'];
1253 }
1254 if (isset($_GET['datetime'])) {
1255 $condition .= ' and DATE_FORMAT(t.datetime, "%Y-%m-%d") ="' . $_GET['datetime'] . '"';
1256 }
1257
1258 $criteria = new CDbCriteria();
1259 $criteria->mergeWith(array(
1260 'order' => 'datetime DESC',
1261 'select' => 't.*',
1262 'condition' => $condition,
1263 ));
1264 $count = AbsensiSolution::model()->count($criteria);
1265
1266 if ($count > 0) {
1267 $pages = new CPagination($count);
1268 // results per page
1269 $pages->CurrentPage = isset($_GET['start']) ? $_GET['start'] : 0;
1270 $pages->pageSize = isset($_GET['rows']) ? $_GET['rows'] : 100000000000;
1271 $perpage = $pages->pageSize;
1272 $pages->applyLimit($criteria);
1273 $totalpage = ceil($count / $perpage);
1274 $models = AbsensiSolution::model()->findAll($criteria);
1275
1276 $data['success'] = 1;
1277 $data['message'] = 'Record(s) Found.';
1278 $data['totalCount'] = $count;
1279 foreach ($models as $row) {
1280 $data_fix['id'] = $row->id;
1281 $data_fix['datetime'] = $row->datetime;
1282 $data_fix['ver'] = $row->ver;
1283 $data_fix['stat'] = $row->stat;
1284 if (!empty($row->guru->id)) {
1285 $data_fix['user']['id'] = $row->guru->id;
1286 $data_fix['user']['solution_id'] = $row->user_id;
1287 $data_fix['user']['name'] = $row->guru->display_name;
1288 if (!empty($row->guru->class->id)) {
1289 $data_fix['user']['class_id'] = $row->guru->class->id;
1290 $data_fix['user']['class_name'] = $row->guru->class->name;
1291 }
1292 }
1293 $data['data']['result'][] = $data_fix;
1294 }
1295 } else {
1296 $models = null;
1297 }
1298
1299 if ($status == false) {
1300 $data['success'] = 0;
1301 $data['message'] = 'ERROR : Missing or Invalid Parameter !';
1302 $data['data'] = null;
1303 $json = json_encode($data, JSON_PRETTY_PRINT);
1304 header('Content-Type: application/x-javascript');
1305 header("Access-Control-Allow-Origin: *");
1306 echo $json;
1307 } elseif ($models == null) {
1308 $data['success'] = 0;
1309 $data['message'] = 'ERROR : No Data Found';
1310 $data['data'] = null;
1311 $json = json_encode($data, JSON_PRETTY_PRINT);
1312 header('Content-Type: application/x-javascript');
1313 header("Access-Control-Allow-Origin: *");
1314 echo $json;
1315 } else {
1316 $json = json_encode($data, JSON_PRETTY_PRINT);
1317 header('Content-Type: application/json');
1318 header("Access-Control-Allow-Origin: *");
1319 echo $json;
1320 }
1321 }
1322
1323 public function actionList()
1324 {
1325 if (isset($_GET['model'])) {
1326 $status = true;
1327 $data = array();
1328
1329 //cek token
1330 $this->checkToken();
1331
1332 switch ($_GET['model']) {
1333 case 'user':
1334 $model = new User;
1335 $criteria = new CDbCriteria;
1336
1337 if (isset($_GET['type'])) {
1338 switch ($_GET['type']) {
1339 case 'students':
1340 $criteria->join = 'INNER JOIN class ON `t`.class_id = class.id AND `t`.trash is null ';
1341 $criteria->select = "class.*,t.*";
1342 $criteria->condition = "role_id = 2";
1343 break;
1344
1345 case 'teachers':
1346 $criteria->condition = "role_id = 1 AND trash is null ";
1347 break;
1348
1349 case 'class':
1350 if (isset($_GET['class_id'])) {
1351 $criteria->condition = "class_id = " . $_GET['class_id'] . " AND trash is null ";
1352 } else {
1353 $status = false;
1354 }
1355 break;
1356
1357 default:
1358 $status = false;
1359 break;
1360 }
1361 } else {
1362 $status = false;
1363 }
1364
1365 $count = User::model()->count($criteria);
1366 // results per page
1367 $pages = new CPagination($count);
1368 $pages->pageSize = 100;
1369 $perpage = $pages->pageSize;
1370 $pages->applyLimit($criteria);
1371 $totalpage = ceil($count / $perpage);
1372 $models = $model->findAll($criteria);
1373
1374 $data['success'] = 1;
1375 $data['message'] = 'Record(s) Found.';
1376 $data['totalCount'] = $count;
1377
1378 $data['data']['totalPage'] = $totalpage;
1379 $data['data']['perPage'] = $perpage;
1380
1381 foreach ($models as $get) {
1382 $data_fix['id'] = $get->id;
1383 $data_fix['username'] = $get->username;
1384 $data_fix['display_name'] = $get->display_name;
1385 $data_fix['email'] = $get->email;
1386 $data_fix['role_id'] = $get->role_id;
1387 $data_fix['class_id'] = $get->class_id;
1388 if (isset($get->class->name)) {
1389 $data_fix['class_name'] = $get->class->name;
1390 } else {
1391 $data_fix['class_name'] = null;
1392 }
1393 $data['data']['results'][] = $data_fix;
1394 //$data['data']['results'][] = $get->attributes;
1395 }
1396 break;
1397
1398 // --------------------------------- lesson API ------------------------------
1399 case 'lesson':
1400 //echo Yii::app()->user->YiiTeacher;exit();
1401 $model = new Lesson;
1402
1403 $current_user = Yii::app()->session['id_user'];
1404 if (Yii::app()->session['role'] == 1) {
1405 $term_condition = "user_id = $current_user and semester=" . $_GET['semester'] . " and year =" . $_GET['tahun_ajaran'] . " and trash is null";
1406
1407 $criteria = new CDbCriteria;
1408 $criteria->condition = $term_condition;
1409 $count = Lesson::model()->count($criteria);
1410 // results per page
1411 $pages = new CPagination($count);
1412 $pages->pageSize = 1000000;
1413 $perpage = $pages->pageSize;
1414 $pages->applyLimit($criteria);
1415 $totalpage = ceil($count / $perpage);
1416 $models = $model->findAll($criteria);
1417
1418 $data['success'] = 1;
1419 $data['message'] = 'Record(s) Found.';
1420 $data['totalCount'] = $count;
1421
1422 $data['data']['totalPage'] = $totalpage;
1423 $data['data']['perPage'] = $perpage;
1424 } elseif (Yii::app()->session['role'] == 2) {
1425 $term_conditon = 't.semester = "' . $_GET['semester'] . '" and t.year = "' . $_GET['tahun_ajaran'] . '" and lm.user_id = "' . $current_user . '" AND t.trash IS NULL';
1426 $dataProvider = new CActiveDataProvider('Lesson', array(
1427 'criteria' => array(
1428 'join' => 'JOIN lesson_mc AS lm ON lm.lesson_id = t.id ',
1429 'condition' => '' . $term_conditon,
1430 ),
1431 ));
1432
1433 $models = $dataProvider->getData();
1434 } else {
1435 $term_condition = " semester=" . $_GET['semester'] . " and year =" . $_GET['tahun_ajaran'] . " and trash is null";
1436
1437 $criteria = new CDbCriteria;
1438 $criteria->condition = $term_condition;
1439 $count = Lesson::model()->count($criteria);
1440 // results per page
1441 $pages = new CPagination($count);
1442 $pages->pageSize = 1000000;
1443 $perpage = $pages->pageSize;
1444 $pages->applyLimit($criteria);
1445 $totalpage = ceil($count / $perpage);
1446 $models = $model->findAll($criteria);
1447
1448 $data['success'] = 1;
1449 $data['message'] = 'Record(s) Found.';
1450 $data['totalCount'] = $count;
1451
1452 $data['data']['totalPage'] = $totalpage;
1453 $data['data']['perPage'] = $perpage;
1454 }
1455
1456
1457 foreach ($models as $get) {
1458 $cek = User::model()->findAll(array('condition' => 'class_id = ' . $get->class->id));
1459 $total = count($cek);
1460 $data_fix['id'] = $get->id;
1461 $data_fix['lesson'] = $get->name;
1462 $data_fix['user_id'] = $get->user_id;
1463 $data_fix['class'] = $get->class->name;
1464 $data_fix['class_id'] = $get->class->id;
1465
1466 if (Yii::app()->session['role'] != 2) {
1467 $data_fix['total_siswa'] = $total;
1468 $data_fix['isStudent'] = false;
1469 } else {
1470 }
1471
1472 $data['data']['result'][] = $data_fix;
1473 }
1474 break;
1475 case 'lessonmc':
1476 //echo Yii::app()->user->YiiTeacher;exit();
1477 $model = new LessonMc;
1478 $join = "JOIN lesson AS l ON l.id = t.lesson_id ";
1479 $term_condition = " t.semester=" . $_GET['semester'] . " and t.year =" . $_GET['year'] . " and t.trash is null";
1480 if (isset($_GET['student_id'])) {
1481 $term_condition .= ' and t.user_id =' . $_GET['student_id'];
1482 }
1483 if (isset($_GET['teacher_id'])) {
1484 $term_condition .= ' and l.user_id =' . $_GET['teacher_id'];
1485 }
1486 if (isset($_GET['lesson_id'])) {
1487 $term_condition .= ' and t.lesson_id =' . $_GET['lesson_id'];
1488 }
1489
1490 $criteria = new CDbCriteria;
1491 $criteria->join = $join;
1492 $criteria->condition = $term_condition;
1493 $count = LessonMc::model()->count($criteria);
1494 // results per page
1495 $pages = new CPagination($count);
1496 $pages->pageSize = 1000000;
1497 $perpage = $pages->pageSize;
1498 $pages->applyLimit($criteria);
1499 $totalpage = ceil($count / $perpage);
1500 $models = $model->findAll($criteria);
1501
1502 $data['success'] = 1;
1503 $data['message'] = 'Record(s) Found.';
1504 $data['totalCount'] = $count;
1505
1506 $data['data']['totalPage'] = $totalpage;
1507 $data['data']['perPage'] = $perpage;
1508
1509 foreach ($models as $get) {
1510 $data_fix['id'] = $get->id;
1511 $data_fix['lesson']['id'] = $get->lesson_id;
1512 $data_fix['teacher']['id'] = $get->lesson->user_id;
1513 $data_fix['student']['id'] = $get->user_id;
1514 $data_fix['class']['id'] = $get->class_id;
1515 $data_fix['presensi_hadir'] = $get->presensi_hadir;
1516 $data_fix['presensi_sakit'] = $get->presensi_sakit;
1517 $data_fix['presensi_izin'] = $get->presensi_izin;
1518 $data_fix['presensi_alfa'] = $get->presensi_alfa;
1519
1520 if (isset($get->lesson)) {
1521 $data_fix['lesson']['name'] = $get->lesson->name;
1522 }
1523 if (isset($get->teacher)) {
1524 $data_fix['teacher']['display_name'] = $get->lesson->users->display_name;
1525 }
1526 if (isset($get->student)) {
1527 $data_fix['student']['display_name'] = $get->student->display_name;
1528 }
1529 if (isset($get->class)) {
1530 $data_fix['class']['name'] = $get->class->name;
1531 }
1532
1533 $data['data']['result'][] = $data_fix;
1534 }
1535 break;
1536
1537 case 'class':
1538 $model = new Clases;
1539 $criteria = new CDbCriteria;
1540 $count = Clases::model()->count($criteria);
1541 // results per page
1542 $pages = new CPagination($count);
1543 $pages->pageSize = 6;
1544 $perpage = $pages->pageSize;
1545 $pages->applyLimit($criteria);
1546 $totalpage = ceil($count / $perpage);
1547 $models = $model->findAll($criteria);
1548 break;
1549
1550 // --------------------------------- quiz API ------------------------------
1551 case 'quiz':
1552
1553 $model = new Quiz;
1554
1555 $optSemester = Option::model()->findByAttributes(array('key_config' => 'semester'))->value;
1556 $optTahunAjaran = Option::model()->findByAttributes(array('key_config' => 'tahun_ajaran'))->value;
1557 $current_user = Yii::app()->session['id_user'];
1558 $modelUser = User::model()->findByPk($current_user);
1559 //if(Yii::app()->user->YiiTeacher || Yii::app()->user->YiiAdmin){
1560 if ($modelUser->role_id == "1") {
1561 $term = 'created_by = ' . Yii::app()->user->id . ' and trash is null';
1562 } elseif ($modelUser->role_id == "2") {
1563 // $cekUsr=User::model()->findByPk(Yii::app()->user->id);
1564 // $kls=$modelUser->class_id;
1565 // $data['data']['debug'] = $kls;
1566 // $lesson_ids = LessonMc::model()->findAll(array('condition'=>'user_id = '.Yii::app()->user->id));
1567 // foreach ($lesson_ids as $value) {
1568 // $lessons_ids[] = $value->lesson_id;
1569 // }
1570 // $lessons_ids = implode(",", $lessons_ids);
1571 // $term='t.status = 1 AND c.id = '.$kls.' and t.trash is null';
1572 //$term='status = 1 AND lesson_id IN ('.$lessons_ids.') and trash is null';
1573 } else {
1574 $term = 't.trash is null';
1575 // $data['data']['debug'] = "salah";
1576 }
1577 $prefix = Yii::app()->params['tablePrefix'];
1578
1579 if ($modelUser->role_id != "2") {
1580 $dataProvider = new CActiveDataProvider('Quiz', array(
1581 'criteria' => array(
1582 'order' => 't.id DESC',
1583 'condition' => $term),
1584 'pagination' => array('pageSize' => 1000)
1585 ));
1586 } else {
1587 // $dataProvider=new CActiveDataProvider('Quiz',array(
1588 // 'criteria'=>array(
1589 // 'select'=>array('t.*'),
1590 // 'join'=>'JOIN '.$prefix.'lesson AS l ON l.id = t.lesson_id JOIN '.$prefix.'class_detail AS c ON l.class_id = c.id',
1591 // 'order'=>'t.id DESC',
1592 // 'condition'=>$term),
1593 // 'pagination'=>array('pageSize'=>1000)
1594 // ));
1595
1596
1597 $criteria = new CDbCriteria();
1598 $criteria->mergeWith(array(
1599 'order' => 'created_at DESC',
1600 'select' => 't.*',
1601 //'join'=>'JOIN '.$prefix.'lesson as l ON l.id = t.lesson_id JOIN '.$prefix.'class_detail as c ON c.id = l.class_id',
1602 'join' => 'JOIN lesson_mc AS lm ON lm.lesson_id = t.lesson_id ',
1603 //'condition'=>'l.class_id = '.$class_student_id.' and t.status is not null and t.trash is null and t.status != 2',
1604 'condition' => 't.semester = "' . $optSemester . '" and t.year = "' . $optTahunAjaran . '" and lm.user_id = ' . $current_user . ' and t.status is not null and t.trash is null and t.status != 2',
1605 //'condition'=>'t.status is not null',
1606 ));
1607 $count = Quiz::model()->count($criteria);
1608 $pages = new CPagination($count);
1609
1610 // results per page
1611 $pages->pageSize = 1000;
1612 $perpage = $pages->pageSize;
1613 $pages->applyLimit($criteria);
1614
1615
1616 // $dataProvider=new CActiveDataProvider('Quiz',array(
1617 // 'criteria'=>array(
1618 // 'order'=>'lesson_id',
1619 // 'condition'=>$term),
1620 // 'pagination'=>array('pageSize'=>100)
1621 // ));
1622 }
1623 // results per page
1624 if ($modelUser->role_id != "2") {
1625 if (!empty($dataProvider->getData())) {
1626 $models = $dataProvider->getData();
1627 }
1628 } else {
1629 $models = Quiz::model()->findAll($criteria);
1630 }
1631
1632 $count = count($models);
1633 $pages = new CPagination($count);
1634 $pages->pageSize = 100000;
1635 $perpage = $pages->pageSize;
1636 //$pages->applyLimit($criteria);
1637 $totalpage = ceil($count / $perpage);
1638 //$models = $model->findAll($criteria);
1639
1640 $data['success'] = 1;
1641 $data['message'] = 'Record(s) Found.';
1642 $data['totalCount'] = $count;
1643
1644 $data['data']['totalPage'] = $totalpage;
1645 $data['data']['perPage'] = $perpage;
1646
1647 foreach ($models as $get) {
1648 //if (Yii::app()->user->YiiStudent) {
1649 if (Yii::app()->session['role'] == 2) {
1650 $data_fix['isStudent'] = true;
1651
1652 $cekQuiz = StudentQuiz::model()->findByAttributes(array('quiz_id' => $get->id, 'student_id' => Yii::app()->session['id_user']));
1653 if (!empty($cekQuiz)) {
1654 $data_fix['status'] = "Sudah Mengerjakan";
1655 } else {
1656 $data_fix['status'] = "Belum Mengerjakan";
1657 }
1658 } else {
1659 // $cek=StudentAssignment::model()->findAll(array('condition'=>'assignment_id = '.$get->id.' and status = 1 and score is null'));
1660 // $total=count($cek);
1661 // $data_fix['status'] = '';
1662 // $data_fix['belum_dinilai'] = $total;
1663 $data_fix['isStudent'] = false;
1664
1665 if (!empty($get->lesson_id)) {
1666 if ($get->lesson->moving_class == 1) {
1667 $data_fix['class'] = $get->lesson->grade->name;
1668 } else {
1669 $data_fix['class'] = $get->lesson->class->name;
1670 }
1671 }
1672 $data_fix['teacher'] = $get->teacher->display_name;
1673
1674 // $data_fix['student_number'] = $get->due_date;
1675 // $data_fix['student_number_done'] = $get->due_date;
1676 // $data_fix['passcode'] = $get->due_date;
1677 // $data_fix['time'] = $get->due_date;
1678 // $data_fix['publish_status'] = $get->due_date;
1679 }
1680 //$data['data']['result'][] = $get->attributes;
1681
1682
1683 $data_fix['id'] = $get->id;
1684 $data_fix['title'] = $get->title;
1685 $data_fix['time_in_minute'] = $get->end_time;
1686 $data_fix['total_question'] = $get->total_question;
1687 $data_fix['lesson'] = $get->lesson->name;
1688 $data_fix['status_tampil'] = $get->status;
1689
1690 $data['data']['result'][] = $data_fix;
1691 }
1692
1693
1694
1695 break;
1696
1697 case 'nilai':
1698 $criteria = new CDbCriteria;
1699 if (isset($_GET['type'])) {
1700 switch ($_GET['type']) {
1701 case 'tugas':
1702 $model = new StudentAssignment;
1703 // if user = students
1704 //if(Yii::app()->user->YiiStudent)
1705 if (Yii::app()->session['role'] == 2) {
1706 $criteria->select = "t.*, u.title as title, u.due_date as due_date, l.name as lesson_name, c.name as class_name";
1707 $criteria->join = 'JOIN assignment AS u ON u.id = t.assignment_id JOIN lesson AS l ON l.id = u.lesson_id JOIN class AS c ON c.id = l.class_id';
1708 $criteria->order = 't.updated_at DESC';
1709 $criteria->condition = "t.student_id =" . Yii::app()->session['id_user'];
1710 $data['data']['isStudent'] = true;
1711 $data['data']['isAdmin'] = false;
1712 }
1713 //elseif(Yii::app()->user->YiiTeacher)
1714 elseif (Yii::app()->session['role'] == 1) {
1715 $criteria->select = "t.*, u.title as title, u.due_date as due_date, l.name as lesson_name, c.name as class_name";
1716 $criteria->join = 'JOIN assignment AS u ON u.id = t.assignment_id JOIN lesson AS l ON l.id = u.lesson_id JOIN class AS c ON c.id = l.class_id';
1717 $criteria->condition = "t.status = 1 and u.created_by = " . Yii::app()->session['id_user'];
1718 $data['data']['isStudent'] = false;
1719 $data['data']['isAdmin'] = false;
1720 } else {
1721 $criteria->select = "t.*, u.title as title, u.due_date as due_date";
1722 $criteria->join = 'JOIN assignment AS u ON u.id = t.assignment_id';
1723 }
1724 $count = StudentAssignment::model()->count($criteria);
1725 // results per page
1726 $pages = new CPagination($count);
1727 $pages->pageSize = 12;
1728 $perpage = $pages->pageSize;
1729 $pages->applyLimit($criteria);
1730 $totalpage = ceil($count / $perpage);
1731 $models = $model->findAll($criteria);
1732
1733 $data['success'] = 1;
1734 $data['message'] = 'Record(s) Found.';
1735 $data['totalCount'] = $count;
1736
1737 $data['data']['totalPage'] = $totalpage;
1738 $data['data']['perPage'] = $perpage;
1739
1740
1741 foreach ($models as $get) {
1742 //if(Yii::app()->user->YiiStudent)
1743 if (Yii::app()->session['role'] == 2) {
1744 $data_fix['id_nilai'] = $get->id;
1745 $data_fix['title'] = $get->title;
1746 $data_fix['lesson_name'] = $get->teacher_assign->lesson->name;
1747 $data_fix['class'] = $get->teacher_assign->lesson->class->name;
1748 $data_fix['updated_at'] = date('d M Y G:i:s', strtotime($get->updated_at));
1749
1750 if (!empty($get->score)) {
1751 $data_fix['status_score'] = "Sudah Mengumpulkan dan Diberi Nilai";
1752 } elseif (empty($get->score) && $get->status == null) {
1753 $data_fix['status_score'] = "Belum Mengumpulkan";
1754 } elseif (empty($get->score) && $get->status == 1) {
1755 $data_fix['status_score'] = "Sudah Mengumpulkan dan Belum Diberi Nilai";
1756 }
1757
1758 $data_fix['score'] = $get->score;
1759 // $data_fix['isStudent'] = true;
1760 // $data_fix['isAdmin'] = false;
1761 $data['data']['result'][] = $data_fix;
1762 }
1763 //else if(Yii::app()->user->YiiTeacher)
1764 elseif (Yii::app()->session['role'] == 1) {
1765 $data_fix['id_nilai'] = $get->id;
1766 $data_fix['student_name'] = $get->student->display_name;
1767 $data_fix['id_tugas'] = $get->assignment_id;
1768 $data_fix['title'] = $get->title;
1769 $data_fix['lesson_name'] = $get->teacher_assign->lesson->name;
1770 $data_fix['class'] = $get->teacher_assign->lesson->class->name;
1771 $data_fix['updated_at'] = date('d M Y G:i:s', strtotime($get->updated_at));
1772
1773 if (!empty($get->due_date > $get->created_at)) {
1774 $data_fix['tepat_waktu'] = "Ya";
1775 } else {
1776 $data_fix['tepat_waktu'] = "Tidak";
1777 }
1778 $data_fix['score'] = $get->score;
1779 $data_fix['isStudent'] = false;
1780 $data_fix['isAdmin'] = false;
1781 $data['data']['result'][] = $data_fix;
1782 }
1783 }
1784
1785 break;
1786
1787 case 'kuis':
1788 $model = new StudentQuiz;
1789 if (Yii::app()->session['role'] == 2) {
1790 $criteria->select = "t.*, u.title as title, l.name as lesson_name, c.name as class_name";
1791 $criteria->join = 'JOIN quiz AS u ON u.id = t.quiz_id JOIN lesson AS l ON l.id = u.lesson_id JOIN class AS c ON c.id = l.class_id';
1792 $criteria->condition = "t.student_id = " . Yii::app()->session['id_user'];
1793 $data['data']['isStudent'] = true;
1794 $data['data']['isAdmin'] = false;
1795 } elseif (Yii::app()->session['role'] == 1) {
1796 $criteria->select = "t.*, u.title as title, l.name as lesson_name, c.name as class_name";
1797 $criteria->join = 'JOIN quiz AS u ON u.id = t.quiz_id JOIN lesson AS l ON l.id = u.lesson_id JOIN class AS c ON c.id = l.class_id';
1798 $criteria->condition = "u.created_by = " . Yii::app()->session['id_user'];
1799 $data['data']['isStudent'] = false;
1800 $data['data']['isAdmin'] = false;
1801 } else {
1802 $criteria->select = "t.*, u.title as title, u.due_date as due_date";
1803 $criteria->join = "JOIN assignment AS u ON u.id = t.assignment_id";
1804 }
1805 $count = StudentQuiz::model()->count($criteria);
1806 // results per page
1807 $pages = new CPagination($count);
1808 $pages->pageSize = 10;
1809 $perpage = $pages->pageSize;
1810 $pages->applyLimit($criteria);
1811 $totalpage = ceil($count / $perpage);
1812 $models = $model->findAll($criteria);
1813
1814 $data['success'] = 1;
1815 $data['message'] = 'Record(s) Found.';
1816 $data['totalCount'] = $count;
1817
1818 $data['data']['totalPage'] = $totalpage;
1819 $data['data']['perPage'] = $perpage;
1820
1821 foreach ($models as $get) {
1822 if (Yii::app()->session['role'] == 2) {
1823 $data_fix['studentQuiz_id'] = $get->id;
1824 $data_fix['student_name'] = $get->user->display_name;
1825 $data_fix['quiz_title'] = $get->quiz->title;
1826 $data_fix['lesson_name'] = $get->quiz->lesson->name;
1827 $data_fix['class'] = $get->quiz->lesson->class->name;
1828 $data_fix['updated_at'] = date('d M Y G:i:s', strtotime($get->updated_at));
1829 $data_fix['score'] = $get->score;
1830 $data_fix['isStudent'] = true;
1831 $data_fix['isAdmin'] = false;
1832 $data['data']['result'][] = $data_fix;
1833 } elseif (Yii::app()->session['role'] == 1) {
1834 $data_fix['studentQuiz_id'] = $get->id;
1835 $data_fix['student_name'] = $get->user->display_name;
1836 $data_fix['id_kuis'] = $get->quiz_id;
1837 $data_fix['quiz_title'] = $get->quiz->title;
1838 $data_fix['lesson_name'] = $get->quiz->lesson->name;
1839 $data_fix['class'] = $get->quiz->lesson->class->name;
1840 $data_fix['updated_at'] = date('d M Y G:i:s', strtotime($get->updated_at));
1841
1842 $data_fix['score'] = $get->score;
1843 $data_fix['isStudent'] = false;
1844 $data_fix['isAdmin'] = false;
1845 $data['data']['result'][] = $data_fix;
1846 }
1847 }
1848
1849 break;
1850
1851 default:
1852 $status = false;
1853 break;
1854 }
1855 } else {
1856 $status = false;
1857 }
1858
1859 break;
1860
1861 // --------------------------------- chapter API ------------------------------
1862 case 'chapter':
1863
1864
1865 if (Yii::app()->session['role'] == 2) {
1866 $model = new Chapters;
1867 $current_user = Yii::app()->session['id_user'];
1868 $term_conditon = 't.semester = "' . $_GET['semester'] . '" and t.year = "' . $_GET['tahun_ajaran'] . '" and lm.user_id = "' . $current_user . '" AND t.trash IS NULL';
1869 $dataProvider = new CActiveDataProvider('chapters', array(
1870 'criteria' => array(
1871 'join' => 'JOIN lesson_mc AS lm ON lm.lesson_id = t.id_lesson ',
1872 'condition' => '' . $term_conditon,
1873 ),
1874 ));
1875
1876 $models = $dataProvider->getData();
1877 } else {
1878 $model = new Chapters;
1879 $criteria = new CDbCriteria;
1880 $count = Chapters::model()->count($criteria);
1881 // results per page
1882 $pages = new CPagination($count);
1883 $pages->pageSize = 10000;
1884 $perpage = $pages->pageSize;
1885 $pages->applyLimit($criteria);
1886 $totalpage = ceil($count / $perpage);
1887 $models = $model->findAll($criteria);
1888
1889 $data['success'] = 1;
1890 $data['message'] = 'Record(s) Found.';
1891 $data['totalCount'] = $count;
1892
1893 $data['data']['totalPage'] = $totalpage;
1894 $data['data']['perPage'] = $perpage;
1895 }
1896
1897
1898
1899 foreach ($models as $get) {
1900 $data_fix['id_chapter'] = $get->id;
1901 $data_fix['id_lesson'] = $get->id_lesson;
1902 $data_fix['lesson'] = $get->mapel->name;
1903 $data_fix['title'] = $get->title;
1904 $data_fix['created_at'] = $get->created_at;
1905 $data['data']['result'][] = $data_fix;
1906 //$data['data']['result'][] = $get->attributes;
1907 }
1908 break;
1909
1910 case 'studentquiz':
1911 $model = new StudentQuiz;
1912 $criteria = new CDbCriteria;
1913 if (!empty($_GET['quiz_id'])) {
1914 $criteria->condition = "quiz_id =" . $_GET['quiz_id'];
1915 }
1916
1917
1918 if (!empty($_GET['meonly'])) {
1919 $criteria->condition = "quiz_id =" . $_GET['quiz_id'] . " and student_id = " . Yii::app()->session['id_user'];
1920 }
1921
1922 $count = StudentQuiz::model()->count($criteria);
1923 // results per page
1924 $pages = new CPagination($count);
1925 $pages->pageSize = 1000;
1926 $perpage = $pages->pageSize;
1927 $pages->applyLimit($criteria);
1928 $totalpage = ceil($count / $perpage);
1929 $models = $model->findAll($criteria);
1930
1931 $data['success'] = 100;
1932 $data['message'] = 'Record(s) Found.';
1933 $data['totalCount'] = $count;
1934
1935 $data['data']['totalPage'] = $totalpage;
1936 $data['data']['perPage'] = $perpage;
1937
1938 foreach ($models as $get) {
1939 $data_fix['student_id'] = $get->student_id;
1940 $data_fix['student_name'] = $get->user->display_name;
1941 $data_fix['created_at'] = $get->user->created_at;
1942 $data_fix['score'] = $get->score;
1943 $data_fix['right_answer'] = $get->right_answer;
1944 $data_fix['wrong_answer'] = $get->wrong_answer;
1945 $data_fix['unanswered'] = $get->unanswered;
1946 $data['data']['result'][] = $data_fix;
1947 }
1948 break;
1949
1950 case 'option':
1951 $model = new Option;
1952 $criteria = new CDbCriteria;
1953 $count = Option::model()->count($criteria);
1954 // results per page
1955 $pages = new CPagination($count);
1956 $pages->pageSize = 100;
1957 $perpage = $pages->pageSize;
1958 $pages->applyLimit($criteria);
1959 $totalpage = ceil($count / $perpage);
1960 $models = $model->findAll($criteria);
1961
1962 $data['success'] = 1;
1963 $data['message'] = 'Record(s) Found.';
1964 $data['totalCount'] = $count;
1965
1966 $data['data']['totalPage'] = $totalpage;
1967 $data['data']['perPage'] = $perpage;
1968
1969 foreach ($models as $get) {
1970 $data_fix['key_config'] = $get->key_config;
1971 $data_fix['value'] = $get->value;
1972 $data['data']['result'][] = $data_fix;
1973 }
1974 break;
1975
1976 case 'naon':
1977
1978 $term_conditon = ' trash IS NULL';
1979
1980 $dataProvider = new CActiveDataProvider('Lesson', array(
1981 'criteria' => array(
1982 //'join'=>'JOIN users AS u ON u.id = t.user_id JOIN class_detail AS cd ON cd.id = u.class_id ',
1983 'condition' => '' . $term_conditon,
1984 ),
1985 'pagination'=>array(
1986 'pageSize'=>100000000000, // or another reasonable high value...
1987 ),
1988 ));
1989
1990
1991
1992 $models_lesson = $dataProvider->getData();
1993 $models = $dataProvider->getData();
1994 $model = $dataProvider->getData();
1995
1996 foreach ($models_lesson as $lesson) {
1997 $lesson_ids[] = $lesson->id;
1998 }
1999
2000 $data['data']['result'][] = $lesson_ids;
2001
2002 break;
2003
2004 case 'absensi':
2005 $current_user = Yii::app()->session['id_user'];
2006 $role_users = Yii::app()->session['role'];
2007 if (isset($_GET['user_id'])) {
2008 $current_user = $_GET['user_id'];
2009 }
2010
2011
2012 if ($role_users == "99") {
2013 $term_conditon = 'trash IS NULL';
2014 } else {
2015 $term_conditon = 'semester = "' . $_GET['semester'] . '" and year = "' . $_GET['tahun_ajaran'] . '" and user_id = "' . $current_user . '" AND trash IS NULL';
2016 }
2017
2018
2019 $dataProvider = new CActiveDataProvider('Lesson', array(
2020 'criteria' => array(
2021// 'join'=>'JOIN users AS u ON u.id = t.user_id JOIN class_detail AS cd ON cd.id = u.class_id ',
2022 'condition' => '' . $term_conditon,
2023 ),
2024 'pagination'=>array(
2025 'pageSize'=>100000000000, // or another reasonable high value...
2026 ),
2027 ));
2028
2029 $models_lesson = $dataProvider->getData();
2030 $models = array();
2031 $count = 0;
2032 $totalpage = 0;
2033 $perpage = 0;
2034 if ($models_lesson) {
2035 foreach ($models_lesson as $lesson) {
2036 $lesson_ids[] = $lesson->id;
2037 }
2038
2039 $lesson_ids = implode(",", $lesson_ids);
2040
2041 $model = new Absensi;
2042 $criteria = new CDbCriteria;
2043 $sql = "id_lesson in (" . $lesson_ids . ")";
2044 if (isset($_GET['created_at'])) {
2045 $sql .= " AND created_at ='" . $_GET['created_at'] . "'" ;
2046 }
2047 $criteria->condition = $sql;
2048
2049 $count = Absensi::model()->count($criteria);
2050 // results per page
2051 $pages = new CPagination($count);
2052 $pages->pageSize = 100000000;
2053 $perpage = $pages->pageSize;
2054 $pages->applyLimit($criteria);
2055 $totalpage = ceil($count / $perpage);
2056 $models = $model->findAll($criteria);
2057 }
2058 $data['success'] = 1;
2059 $data['message'] = 'Record(s) Found.';
2060 $data['totalCount'] = $count;
2061
2062 $data['data']['totalPage'] = $totalpage;
2063 $data['data']['perPage'] = $perpage;
2064
2065 foreach ($models as $get) {
2066 $user = new User;
2067 $users = $user->findByPk($get->user_id);
2068
2069 $data_fix['user_id'] = $get->user_id;
2070 $data_fix['nama'] = $users->display_name;
2071 $data_fix['nama_kelas'] = $users->class->name;
2072 $data_fix['id_lesson'] = $get->id_lesson;
2073 $data_fix['lesson_name'] = $get->lesson->name;
2074 $data_fix['absen'] = $get->absen;
2075 $data_fix['created_at'] = $get->created_at;
2076 $data_fix['pertemuan_ke'] = $get->pertemuan_ke;
2077 $data_fix['ket'] = $get->ket;
2078 $data_fix['created_date'] = $get->created_date;
2079 $data_fix['lesson_ids'] = $term_conditon;
2080 $data['data']['result'][] = $data_fix;
2081 }
2082 break;
2083
2084 case 'absensi_siswa':
2085 $model = new Absensi;
2086 $criteria = new CDbCriteria;
2087 $sql = array();
2088 if (isset($_GET['id_lesson'])) {
2089 $sql[] = "id_lesson = '" . $_GET['id_lesson'] . "'";
2090 }
2091 if (isset($_GET['user_id'])) {
2092 $sql[] = "user_id ='" . $_GET['user_id'] . "'" ;
2093 }
2094 if (isset($_GET['created_at'])) {
2095 $sql[] = "created_at ='" . $_GET['created_at'] . "'" ;
2096 }
2097 $criteria->condition = implode(" AND ", $sql);
2098
2099 $count = Absensi::model()->count($criteria);
2100 // results per page
2101 $pages = new CPagination($count);
2102 $pages->pageSize = 100;
2103 $perpage = $pages->pageSize;
2104 $pages->applyLimit($criteria);
2105 $totalpage = ceil($count / $perpage);
2106 $models = $model->findAll($criteria);
2107
2108 $data['success'] = 1;
2109 $data['message'] = 'Record(s) Found.';
2110 $data['totalCount'] = $count;
2111
2112 $data['data']['totalPage'] = $totalpage;
2113 $data['data']['perPage'] = $perpage;
2114
2115 foreach ($models as $get) {
2116 $user = new User;
2117 $users = $user->findByPk($get->user_id);
2118
2119 $data_fix['user_id'] = $get->user_id;
2120 $data_fix['nama'] = $users->display_name;
2121 $data_fix['nama_kelas'] = $users->class->name;
2122 $data_fix['id_lesson'] = $get->id_lesson;
2123 $data_fix['lesson_name'] = $get->lesson->name;
2124 $data_fix['absen'] = $get->absen;
2125 $data_fix['created_at'] = $get->created_at;
2126 $data_fix['pertemuan_ke'] = $get->pertemuan_ke;
2127 $data_fix['ket'] = $get->ket;
2128 $data_fix['created_date'] = $get->created_date;
2129 $data['data']['result'][] = $data_fix;
2130 }
2131 break;
2132
2133 case 'lesson_list':
2134 $model = new LessonList;
2135 $criteria = new CDbCriteria;
2136 $count = LessonList::model()->count($criteria);
2137 // results per page
2138 $pages = new CPagination($count);
2139 $pages->pageSize = 10000;
2140 $perpage = $pages->pageSize;
2141 $pages->applyLimit($criteria);
2142 $totalpage = ceil($count / $perpage);
2143 $models = $model->findAll($criteria);
2144
2145 $data['success'] = 1;
2146 $data['message'] = 'Record(s) Found.';
2147 $data['totalCount'] = $count;
2148
2149 $data['data']['totalPage'] = $totalpage;
2150 $data['data']['perPage'] = $perpage;
2151
2152 foreach ($models as $get) {
2153 $data_fix['id'] = $get->id;
2154 $data_fix['name'] = $get->name;
2155 $data_fix['group'] = $get->group;
2156 $data['data']['result'][] = $data_fix;
2157 }
2158 break;
2159
2160
2161
2162 case 'class_detail':
2163 $model = new ClassDetail;
2164 $criteria = new CDbCriteria;
2165 /*if (Yii::app()->session['role'] == "1") {
2166 $criteria->condition = "teacher_id =" . Yii::app()->session['id_user'];
2167 }*/
2168
2169
2170
2171 $count = ClassDetail::model()->count($criteria);
2172 // results per page
2173 $pages = new CPagination($count);
2174 $pages->pageSize = 10000;
2175 $perpage = $pages->pageSize;
2176 $pages->applyLimit($criteria);
2177 $totalpage = ceil($count / $perpage);
2178 $models = $model->findAll($criteria);
2179
2180 $data['success'] = 1;
2181 $data['message'] = 'Record(s) Found.';
2182 $data['totalCount'] = $count;
2183
2184 $data['data']['totalPage'] = $totalpage;
2185 $data['data']['perPage'] = $perpage;
2186
2187 foreach ($models as $get) {
2188 $data_fix['id'] = $get->id;
2189 $data_fix['name'] = $get->name;
2190 $data_fix['class_id'] = $get->class_id;
2191 $data_fix['teacher_id'] = $get->teacher_id;
2192 $data['data']['result'][] = $data_fix;
2193 }
2194 break;
2195
2196 default:
2197 //$this->_sendResponse(501, sprintf('Error: Mode <b>list</b> is not implemented for model <b>%s</b>',$_GET['model']) );
2198 $data['success'] = 0;
2199 $data['message'] = 'ERROR : Invalid Parameter';
2200 $data['data'] = null;
2201 $json = json_encode($data, JSON_PRETTY_PRINT);
2202 header('Content-Type: application/x-javascript');
2203 echo $json;
2204 exit();
2205 }
2206
2207 if ($status == false) {
2208 //$this->_sendResponse(501, sprintf('No items where found for model <b>%s</b>', $_GET['model']) );
2209 $data['success'] = 0;
2210 $data['message'] = 'ERROR : Missing or Invalid Parameter !';
2211 $data['data'] = null;
2212 $json = json_encode($data, JSON_PRETTY_PRINT);
2213 header('Content-Type: application/x-javascript');
2214 header("Access-Control-Allow-Origin: *");
2215 echo $json;
2216 exit();
2217 } elseif ($models == null) {
2218 //$this->_sendResponse(501, sprintf('Error: Mode <b>list</b> is not implemented for model <b>%s</b>',$_GET['model']));
2219 //$data['hiyai'] ='x';
2220 $data['success'] = 0;
2221 $data['message'] = 'ERROR : No Data Found';
2222 $data['data'] = null;
2223 $json = json_encode($data, JSON_PRETTY_PRINT);
2224 header('Content-Type: application/x-javascript');
2225 header("Access-Control-Allow-Origin: *");
2226 echo $json;
2227 exit();
2228 } elseif (is_null($model)) {
2229 //$this->_sendResponse(501, sprintf('No items where found for model <b>%s</b>', $_GET['model']) );
2230 $data['success'] = 0;
2231 $data['message'] = 'ERROR : No Data Found';
2232 $data['data'] = null;
2233 $json = json_encode($data, JSON_PRETTY_PRINT);
2234 header('Content-Type: application/x-javascript');
2235 header("Access-Control-Allow-Origin: *");
2236 echo $json;
2237 exit();
2238 }
2239
2240
2241 $json = json_encode($data, JSON_PRETTY_PRINT);
2242 header('Content-Type: application/json');
2243 header("Access-Control-Allow-Origin: *");
2244 echo $json;
2245
2246 //$this->_sendResponse(200, $json );
2247 } else {
2248 $this->_sendResponse(501, sprintf('Error: No model selected.'));
2249 }
2250 }
2251
2252 // }}}
2253 // {{{ actionView
2254 /* Shows a single item
2255 *
2256 * @access public
2257 * @return void
2258 */
2259
2260 public function actionSchoollist()
2261 {
2262 $data['success'] = 1;
2263 $data['message'] = 'Record(s) Found.';
2264 $data_fix[0] = array(
2265 'school_name' => 'Demo',
2266 'url_live' => 'api.pinisi.io',
2267 'ip_address_live' => null,
2268 'url_local' => null,
2269 'ip_address_local' => null
2270 );
2271
2272 $data_fix[1] = array(
2273 'school_name' => 'SMAN 24 Bandung',
2274 'url_live' => 'sman24.pinisi.io',
2275 'ip_address' => null,
2276 'url_local' => 'usdj.sman24.bdg',
2277 'ip_address_local' => '192.168.2.24'
2278 );
2279
2280 $data_fix[2] = array(
2281 'school_name' => 'SMAN 8 Bandung',
2282 'url_live' => 'sman8.pinisi.io',
2283 'ip_address' => null,
2284 'url_local' => 'usdj.sman8.bdg',
2285 'ip_address_local' => '192.168.2.8'
2286 );
2287
2288 $data['data']['result'][] = $data_fix;
2289 $json = json_encode($data, JSON_PRETTY_PRINT);
2290 header('Content-Type: application/json');
2291 echo $json;
2292 }
2293
2294 public function actionView()
2295 {
2296 $status = true;
2297 $data = array();
2298 //cek token
2299 $this->checkToken();
2300
2301 if (!isset($_GET['id'])) {
2302 $this->_sendResponse(500, 'Error: Parameter <b>id</b> is missing');
2303 }
2304 $id = $_GET['id'];
2305
2306 switch ($_GET['model']) {
2307 // Find respective model
2308 case 'lesson':
2309 $model = new Lesson;
2310 $models = $model->findByPk($id);
2311
2312 if (isset($_GET['type'])) {
2313 $type = $_GET['type'];
2314 } else {
2315 $type = null;
2316 $status = false;
2317 }
2318
2319 if (Yii::app()->session['role'] == 2) {
2320 $term = "lesson_id = " . $id . " AND status is not null";
2321 } else {
2322 $term = "lesson_id = " . $id;
2323 }
2324
2325 switch ($type) {
2326 case 'materi':
2327 $datas = Chapters::model()->findAll(array("condition" => "id_lesson = $id"));
2328 break;
2329
2330 case 'tugas':
2331 $datas = Assignment::model()->findAll(array("condition" => "lesson_id = $id AND assignment_type IS NULL AND recipient IS NULL or recipient = " . Yii::app()->session['id_user']));
2332 break;
2333
2334 case 'ulangan':
2335 $datas = Quiz::model()->findAll(array("condition" => $term));
2336 break;
2337
2338 case 'lks':
2339 $datas = Lks::model()->findAll("lesson_id=" . $id);
2340 break;
2341
2342 default:
2343
2344 break;
2345 }
2346
2347 $ti = Assignment::model()->findAll(array("condition" => "lesson_id = $id AND assignment_type IS NULL AND recipient = " . Yii::app()->session['id_user']));
2348
2349
2350 $data['success'] = 1;
2351 $data['message'] = 'Record(s) Found.';
2352
2353 $data_fix['lesson_id'] = $models->id;
2354 $data_fix['lesson_name'] = $models->name;
2355 $data_fix['teacher_name'] = $models->users->display_name;
2356 $data_fix['class_name'] = $models->class->name;
2357 $data_fix['type'] = $type;
2358
2359 foreach ($datas as $get) {
2360 $data_term['id'] = $get->id;
2361 $data_term['term'] = $get->title;
2362
2363 $data_fix['term'][] = $data_term;
2364 }
2365
2366 $data['data']['result'] = $data_fix;
2367 break;
2368
2369 case 'lks': // LKS view
2370
2371 $modelx = new Lks;
2372 $model = $modelx->findByPk($id);
2373 $models = $modelx->findByPk($id);
2374 $materis = '';
2375 $tugases = '';
2376 $ulangans = '';
2377
2378 if (!empty($models->chapters)) {
2379 $materis = $models->chapters;
2380 $materi = Chapters::model()->findAll(array('condition' => 'id_lesson = ' . $model->lesson_id . ' and id not in (' . $materis . ')'));
2381 } else {
2382 $materi = Chapters::model()->findAll(array('condition' => 'id_lesson = ' . $model->lesson_id));
2383 }
2384
2385 if (!empty($model->assignments)) {
2386 $tugases = $model->assignments;
2387 $tugas = Assignment::model()->findAll(array('condition' => 'lesson_id = ' . $model->lesson_id . ' and id not in (' . $tugases . ')'));
2388 } else {
2389 $tugas = Assignment::model()->findAll(array('condition' => 'lesson_id = ' . $model->lesson_id));
2390 }
2391
2392 if (!empty($model->quizes)) {
2393 $ulangans = $model->quizes;
2394
2395 if (Yii::app()->session['role'] == 1) {
2396 $ulangan = Quiz::model()->findAll(array('condition' => 'lesson_id = ' . $model->lesson_id . ' and id not in (' . $ulangans . ')'));
2397 } else {
2398 $ulangan = Quiz::model()->findAll(array('condition' => 'lesson_id = ' . $model->lesson_id . ' and id not in (' . $ulangans . ') and status = 1'));
2399 }
2400 } else {
2401 if (Yii::app()->session['role'] == 1) {
2402 $ulangan = Quiz::model()->findAll(array('condition' => 'lesson_id = ' . $model->lesson_id));
2403 } else {
2404 $ulangan = Quiz::model()->findAll(array('condition' => 'lesson_id = ' . $model->lesson_id . ' and status = 1'));
2405 }
2406 }
2407
2408 //echo '<pre>';print_r($model);echo '</pre>';
2409 //echo '<pre>';print_r($materi);echo '</pre>';
2410 //echo '<pre>';print_r($tugas);echo '</pre>';
2411 //echo '<pre>';print_r($ulangan);echo '</pre>';
2412 //exit;
2413
2414 $data['success'] = 1;
2415 $data['message'] = 'Record(s) Found.';
2416 $data_fix['title'] = $model->title;
2417 $data_fix['lesson_name'] = $model->pelajaran->name;
2418 $data_fix['lesson_class'] = $model->pelajaran->class->name;
2419 $data_fix['teacher_name'] = $model->pelajaran->users->display_name;
2420
2421 if (!empty($model->chapters)) {
2422 $bahan1 = explode(',', $model->chapters);
2423 foreach ($bahan1 as $bhn1) {
2424 $cek1 = Chapters::model()->findByPk($bhn1);
2425 $temp['chapter_id'] = $cek1->id;
2426 $temp['chapter_title'] = $cek1->title;
2427 $data_fix['term']['chapter'][] = $temp;
2428 }
2429 unset($temp);
2430 }
2431
2432 if (!empty($model->assignments)) {
2433 $bahan2 = explode(',', $model->assignments);
2434 foreach ($bahan2 as $bhn2) {
2435 $cek2 = Assignment::model()->findByPk($bhn2);
2436 $temp['assignment_id'] = $cek2->id;
2437 $temp['assignment_title'] = $cek2->title;
2438 $data_fix['term']['assignment'][] = $temp;
2439 }
2440 unset($temp);
2441 }
2442
2443 if (!empty($model->quizes)) {
2444 $bahan3 = explode(',', $model->quizes);
2445 foreach ($bahan3 as $bhn3) {
2446 $cek3 = Quiz::model()->findByPk($bhn3);
2447 $temp['quiz_id'] = $cek3->id;
2448 $temp['quiz_title'] = $cek3->title;
2449 $data_fix['term']['quiz'][] = $temp;
2450 }
2451 unset($temp);
2452 }
2453
2454
2455 $data['data']['result'] = $data_fix;
2456 break;
2457
2458 case 'assignment':
2459 if (isset($_GET['type'])) {
2460 $type = $_GET['type'];
2461 } else {
2462 $type = null;
2463 }
2464
2465 $model = new Assignment;
2466 $studentAssignment = new StudentAssignment;
2467 $notif = new Notification;
2468 $activity = new Activities;
2469 $models = $model->findByPk($id);
2470 $user = User::model()->findByPk(Yii::app()->session['role']);
2471 $user_kelas = $user->class_id;
2472 $mapel = Lesson::model()->findByAttributes(array('id' => $models->lesson_id));
2473 $kelas = Clases::model()->findByAttributes(array('id' => $mapel->class_id));
2474
2475 if ($type == 1) {
2476 $term = 't.status = 1 AND assignment_id = ' . $id . ' AND score is null';
2477 /* elseif($type==2){
2478 $term='t.status = 1 AND assignment_id = '.$id; */
2479 } else {
2480 $term = 't.status = 1 AND assignment_id = ' . $id;
2481 }
2482
2483 $criteria = new CDbCriteria;
2484 $criteria->condition = $term;
2485 $criteria->order = 'student_id ASC';
2486
2487 $studentTasks = studentAssignment::model()->findAll($criteria);
2488 $cekTugas = StudentAssignment::model()->findByAttributes(array('assignment_id' => $models->id, 'student_id' => Yii::app()->session['id_user']));
2489
2490 $data['success'] = 1;
2491 $data['message'] = 'Record(s) Found.';
2492
2493 $data_fix['assignment_id'] = $models->id;
2494 $data_fix['assignment_title'] = $models->title;
2495 $data_fix['due_date'] = $models->due_date;
2496 $data_fix['assignment_content'] = $models->content;
2497 $data_fix['assignment_file'] = $models->file;
2498 $data_fix['teacher_name'] = $models->teacher->display_name;
2499 if (!empty($cekTugas)) {
2500 if (!empty($cekTugas->score)) {
2501 $data_fix['score'] = $cekTugas->score;
2502 $data_fix['isScored'] = true;
2503 } else {
2504 $data_fix['score'] = null;
2505 $data_fix['isScored'] = false;
2506 }
2507 if ($cekTugas->status == null) {
2508 $data_fix['status'] = 'draft';
2509 }
2510 if ($cekTugas->status == 1) {
2511 $data_fix['status'] = 'sent';
2512 }
2513 } else {
2514 $data_fix['score'] = null;
2515 $data_fix['isScored'] = null;
2516 $data_fix['status'] = null;
2517 }
2518 //print_r($cekTugas);exit;
2519
2520 $data['data']['result'] = $data_fix;
2521 break;
2522
2523 case 'chapter':
2524
2525 $model = new Chapters;
2526 $models = $model->findByPk($id);
2527
2528 $chapterFiles = ChapterFiles::model()->findAll(array("condition" => "id_chapter = $id"));
2529 $cekFile = ChapterFiles::model()->findByAttributes(array('id_chapter' => $models->id));
2530
2531 $data['success'] = 1;
2532 $data['message'] = 'Record(s) Found.';
2533
2534 $data_fix['chapter_id'] = $models->id;
2535 $data_fix['chapter_title'] = $models->title;
2536 $data_fix['chapter_type'] = $models->chapter_type;
2537 $data_fix['chapter_content'] = $models->content;
2538 $data_fix['lesson_id'] = $models->mapel->id;
2539 if (!empty($cekFile->file)) {
2540 $data_fix['chapterExist'] = true;
2541 $data_fix['chapterFiles_id'] = $cekFile->id;
2542 $data_fix['chapterFiles_files'] = $cekFile->file;
2543 $data_fix['chapterFiles_type'] = $cekFile->type;
2544 if ($cekFile->type == 'mp4' || $cekFile->type == '3gp' || $cekFile->type == 'avi' || $cekFile->type == 'mpeg') {
2545 $data_fix['chapterVideo'] = true;
2546 $data_fix['chapterPdf'] = false;
2547 $data_fix['chapterPhoto'] = false;
2548 } elseif ($cekFile->type == 'jpg' || $cekFile->type == 'png' || $cekFile->type == 'gif' || $cekFile->type == 'bmp' || $cekFile->type == 'jpeg' || $cekFile->type == 'tif') {
2549 $data_fix['chapterVideo'] = false;
2550 $data_fix['chapterPdf'] = false;
2551 $data_fix['chapterPhoto'] = true;
2552 } else {
2553 $data_fix['chapterVideo'] = false;
2554 $data_fix['chapterPdf'] = true;
2555 $data_fix['chapterPhoto'] = false;
2556 }
2557 } else {
2558 $data_fix['chapterExist'] = false;
2559 $data_fix['chapterFiles_id'] = null;
2560 $data_fix['chapterFiles_files'] = null;
2561 $data_fix['chapterFiles_type'] = null;
2562 }
2563
2564 $data['data']['result'] = $data_fix;
2565 break;
2566
2567 case 'user':
2568
2569 $model = new User;
2570 $models = $model->findByPk($id);
2571
2572 $data['success'] = 1;
2573 $data['message'] = 'Record(s) Found.';
2574
2575 $data_fix['user_id'] = $models->id;
2576 $data_fix['nama'] = $models->display_name;
2577
2578 if (isset($models->spp)) {
2579 // $data_fix['spp'] = $models->spp;
2580
2581 $curl = curl_init();
2582
2583 $ids = explode(",", $models->spp);
2584
2585 $arr_ids['ids'] = $ids;
2586
2587 $the_ids = json_encode($arr_ids);
2588
2589 curl_setopt_array($curl, array(
2590 CURLOPT_PORT => "3000",
2591 CURLOPT_URL => "http://35.198.223.223:3000/transaction/getByIds",
2592 CURLOPT_RETURNTRANSFER => true,
2593 CURLOPT_ENCODING => "",
2594 CURLOPT_MAXREDIRS => 10,
2595 CURLOPT_TIMEOUT => 30,
2596 CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
2597 CURLOPT_CUSTOMREQUEST => "POST",
2598 CURLOPT_POSTFIELDS => $the_ids,
2599 CURLOPT_HTTPHEADER => array(
2600 "Cache-Control: no-cache",
2601 "Content-Type: application/json"
2602 ),
2603 ));
2604
2605 $response = curl_exec($curl);
2606 $err = curl_error($curl);
2607
2608 curl_close($curl);
2609
2610 if ($err) {
2611 $data_fix['spp'] = "cURL Error #:" . $err;
2612 } else {
2613 $data_fix['spp'] = $response;
2614 }
2615 }
2616
2617 if (isset($models->dsp)) {
2618 $curl = curl_init();
2619
2620 $ids = explode(",", $models->dsp);
2621
2622 $arr_ids['ids'] = $ids;
2623
2624 $the_ids = json_encode($arr_ids);
2625
2626 curl_setopt_array($curl, array(
2627 CURLOPT_PORT => "3000",
2628 CURLOPT_URL => "http://35.198.223.223:3000/transaction/getByIds",
2629 CURLOPT_RETURNTRANSFER => true,
2630 CURLOPT_ENCODING => "",
2631 CURLOPT_MAXREDIRS => 10,
2632 CURLOPT_TIMEOUT => 30,
2633 CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
2634 CURLOPT_CUSTOMREQUEST => "POST",
2635 CURLOPT_POSTFIELDS => $the_ids,
2636 CURLOPT_HTTPHEADER => array(
2637 "Cache-Control: no-cache",
2638 "Content-Type: application/json"
2639 ),
2640 ));
2641
2642 $response = curl_exec($curl);
2643 $err = curl_error($curl);
2644
2645 curl_close($curl);
2646
2647 if ($err) {
2648 $data_fix['dsp'] = "cURL Error #:" . $err;
2649 } else {
2650 $data_fix['dsp'] = $response;
2651 }
2652 }
2653
2654 $data['data']['result'] = $data_fix;
2655 break;
2656
2657 /* QUIZ SINGLE API */
2658 case 'quiz':
2659 $cek = Quiz::model()->findByPk($id);
2660 $models = Quiz::model()->findByPk($id);
2661
2662 if (Yii::app()->session['role'] == 2) {
2663 $usr = User::model()->findByPk(Yii::app()->session['id_user']);
2664 $kelas = $usr->class_id;
2665 }
2666
2667 if (Yii::app()->session['role'] == 2 && $kelas != $cek->lesson->class->id) {
2668 // Yii::app()->user->setFlash('success', 'Maaf Anda Tidak Punya Hak Akses');
2669 // $this->redirect(array('index'));
2670 $data_fix['limited_access'] = true;
2671 } else {
2672 $data_fix['limited_access'] = false;
2673 }
2674
2675 $criteria = new CDbCriteria();
2676
2677 if (!empty($cek->question)) {
2678 //$criteria->condition = 'teacher_id = :tid AND id NOT IN('.$cek->question.') and lesson_id = '.$cek->lesson_id;
2679 $criteria->condition = 'teacher_id = :tid AND id NOT IN(' . $cek->question . ')';
2680 } else {
2681 //$criteria->condition = 'teacher_id = :tid and lesson_id = '.$cek->lesson_id;
2682 $criteria->condition = 'teacher_id = :tid';
2683 }
2684
2685 $criteria->order = 'id DESC';
2686 $criteria->params = array(':tid' => $cek->created_by);
2687
2688 $item_count = Questions::model()->count($criteria);
2689
2690 $pages = new CPagination($item_count);
2691 $pages->setPageSize(20);
2692 $pages->applyLimit($criteria);
2693 $questions = Questions::model()->findAll($criteria);
2694
2695 $total_question = Questions::model()->findAll(array('condition' => 'quiz_id = ' . $id));
2696 $student_quiz = StudentQuiz::model()->findAll(array('condition' => 'quiz_id = ' . $id));
2697
2698 $kriteria = new CDbCriteria();
2699 $kriteria->select = 'max(score) as score, student_id';
2700 $kriteria->condition = 'quiz_id = ' . $id;
2701 $max = StudentQuiz::model()->findAll($kriteria);
2702
2703 $minimal = new CDbCriteria();
2704 $minimal->select = 'min(score) as score, student_id';
2705 $minimal->condition = 'quiz_id = ' . $id;
2706 $min = StudentQuiz::model()->findAll($minimal);
2707
2708 $avg = new CDbCriteria();
2709 $avg->select = 'avg(score) as score';
2710 $avg->condition = 'quiz_id = ' . $id;
2711 $rata = StudentQuiz::model()->findAll($avg);
2712
2713 $data['success'] = 1;
2714 $data['message'] = 'Record(s) Found.';
2715
2716 $data_fix['title'] = $models->title;
2717 $data_fix['lesson'] = $models->lesson->name;
2718 $data_fix['end_time'] = $models->end_time;
2719 $data_fix['repeat_quiz'] = $models->repeat_quiz;
2720 $data_fix['total_question'] = $models->total_question;
2721 if ($models->random == 1) {
2722 $data_fix['random'] = "Ya";
2723 } else {
2724 $data_fix['random'] = "Tidak";
2725 }
2726
2727 if ($models->status == null) {
2728 $data_fix['ShowStatus'] = false;
2729 $data_fix['ShowInfo'] = 'Belum Ditampilkan';
2730 } elseif ($models->status == 1) {
2731 $data_fix['ShowStatus'] = true;
2732 $data_fix['ShowInfo'] = 'Sudah Ditampilkan';
2733 } else {
2734 $data_fix['ShowStatus'] = false;
2735 $data_fix['ShowInfo'] = 'Sudah Ditutup';
2736 }
2737
2738 $cekQuiz = StudentQuiz::model()->findByAttributes(array('quiz_id' => $id, 'student_id' => Yii::app()->session['id_user']));
2739
2740 if (!empty($cekQuiz)) {
2741 if ($cekQuiz->attempt == $models->repeat_quiz) {
2742 $data_fix['FinishStatus'] = true;
2743 } else {
2744 $data_fix['FinishStatus'] = false;
2745 }
2746 } else {
2747 $data_fix['FinishStatus'] = false;
2748 }
2749
2750 $data['data']['result'] = $data_fix;
2751 break;
2752
2753 case 'startQuiz':
2754 $model = Quiz::model()->findByPk($id);
2755 $models = Quiz::model()->findByPk($id);
2756
2757 if ($model->question == null) {
2758 // Yii::app()->user->setFlash('success','Belum Ada Soal di Ulangan Ini');
2759 // $this->redirect(array('view','id'=>$id));
2760 $data_fix['isNullQuestion'] = true;
2761 } else {
2762 $data_fix['isNullQuestion'] = false;
2763 }
2764
2765 if (Yii::app()->user->YiiStudent && $model->status != 1) {
2766 // Yii::app()->user->setFlash('success', 'Kuis Belum Dibuka Atau Sudah Selesai');
2767 // $this->redirect(array('/quiz/view','id'=>$id));
2768 //Yii::app()->request->urlReferrer;
2769 $data_fix['isAvailableQuiz'] = false;
2770 } else {
2771 $data_fix['isAvailableQuiz'] = true;
2772 }
2773
2774 $student_quiz = new StudentQuiz;
2775
2776 $criteria = new CDbCriteria();
2777 $criteria->condition = 'quiz_id is null and id IN (' . $model->question . ') ';
2778 if ($model->random == 1) {
2779 $criteria->order = 'RAND()';
2780 } else {
2781 $criteria->order = 'FIELD(id, ' . $model->question . ');';
2782 }
2783 //$criteria->params = array (':id'=>$id);
2784
2785 $item_count = Questions::model()->count($criteria);
2786
2787 $pages = new CPagination($item_count);
2788 $pages->setPageSize(100);
2789 $pages->applyLimit($criteria);
2790
2791 $questions = Questions::model()->findAll($criteria);
2792
2793 if (!empty($model->question)) {
2794 $pertanyaan = explode(',', $model->question);
2795 } else {
2796 $pertanyaan['question'] = null;
2797 }
2798 $cekQuiz = StudentQuiz::model()->findByAttributes(array('student_id' => Yii::app()->session['user_id'], 'quiz_id' => $model->id));
2799 $total_pertanyaan = count($pertanyaan);
2800
2801 $data['success'] = 1;
2802 $data['message'] = 'Record(s) Found.';
2803
2804 if (Yii::app()->session['role'] == 2 && !empty($cekQuiz)) {
2805 $data_fix['cekQuiz_attempt'] = $cekQuiz->attempt;
2806 } else {
2807 $data_fix['cekQuiz_attempt'] = null;
2808 }
2809 $data_fix['repeat_quiz'] = $models->repeat_quiz;
2810
2811 $data_fix['title'] = $models->title;
2812 $data_fix['total_question'] = $total_pertanyaan;
2813 $data_fix['end_time'] = $models->end_time;
2814 $data_fix['passcode'] = $models->passcode;
2815 if ($models->random == 1) {
2816 $data_fix['random'] = "Ya";
2817 } else {
2818 $data_fix['random'] = "Tidak";
2819 }
2820
2821 if ($models->status == null) {
2822 $data_fix['ShowStatus'] = false;
2823 $data_fix['ShowInfo'] = 'Belum Ditampilkan';
2824 } elseif ($models->status == 1) {
2825 $data_fix['ShowStatus'] = true;
2826 $data_fix['ShowInfo'] = 'Sudah Ditampilkan';
2827 } else {
2828 $data_fix['ShowStatus'] = false;
2829 $data_fix['ShowInfo'] = 'Sudah Ditutup';
2830 }
2831
2832 $cekQuiz = StudentQuiz::model()->findByAttributes(array('quiz_id' => $id, 'student_id' => Yii::app()->session['id_user']));
2833
2834 if (!empty($cekQuiz)) {
2835 if ($cekQuiz->attempt == $models->repeat_quiz) {
2836 $data_fix['FinishStatus'] = true;
2837 } else {
2838 $data_fix['FinishStatus'] = false;
2839 }
2840 } else {
2841 $data_fix['FinishStatus'] = false;
2842 }
2843
2844
2845 //risky code.
2846 $index = 1;
2847 foreach ($pertanyaan as $key) {
2848 $detail = Questions::model()->findByPk($key);
2849 $path_image = Clases::model()->path_image($key);
2850 if (!empty($detail)) {
2851 $term['id'] = $detail->id;
2852 $term['text'] = $detail->text;
2853 $term['type'] = $detail->type;
2854 if ($detail->type == null) {
2855 $term['isNullType'] = true;
2856 } else {
2857 $term['isNullType'] = false;
2858 }
2859
2860 $term['file'] = $detail->file;
2861 if ($detail->file == null) {
2862 $term['isNullFile'] = true;
2863 } else {
2864 $term['isNullFile'] = false;
2865 }
2866
2867 $term['choices'] = json_decode($detail->choices);
2868 $term['choices_files'] = json_decode($detail->choices_files);
2869 $term['path_image'] = $path_image;
2870 $term['unique'] = 'step' . $index;
2871 $index++;
2872 $data_fix['term_detail'][] = $term;
2873 }
2874
2875 //$data_fix['end_time'][] = $path_image;
2876 }
2877
2878 $data['data']['result'] = $data_fix;
2879
2880 break;
2881
2882
2883 case 'tugas':
2884 $model = new StudentAssignment;
2885 $models = $model->findByPk($id);
2886
2887
2888 $data['success'] = 1;
2889 $data['message'] = 'Record(s) Found.';
2890
2891 $data_fix['id'] = $models->id;
2892 $data_fix['student_id'] = $models->student_id;
2893 $data_fix['nama_siswa'] = ucfirst($models->student->display_name);
2894 $data_fix['nama_tugas'] = ucfirst($models->teacher_assign->title);
2895 $data_fix['due_date'] = date('d M Y G:i:s', strtotime($models->teacher_assign->due_date));
2896 $data_fix['dikumpulkan'] = date('d M Y G:i:s', strtotime($models->created_at));
2897 $data_fix['score'] = $models->score;
2898 $data_fix['content'] = $models->content;
2899 $data_fix['file'] = $models->file;
2900 if (!empty($models->file)) {
2901 $data_fix['isExistFile'] = true;
2902 } else {
2903 $data_fix['isExistFile'] = false;
2904 }
2905 if (!empty($models->teacher_assign->due_date > $models->created_at)) {
2906 $data_fix['isOnTime'] = 'Ya';
2907 } else {
2908 $data_fix['isOnTime'] = 'Tidak';
2909 }
2910
2911 if (Yii::app()->session['role'] == 1) {
2912 $data_fix['isStudent'] = false;
2913 } else {
2914 $data_fix['isStudent'] = true;
2915 }
2916
2917 $data['data']['result'] = $data_fix;
2918
2919
2920 break;
2921
2922
2923 default:
2924 //$this->_sendResponse(501, sprintf('Error: Mode <b>list</b> is not implemented for model <b>%s</b>',$_GET['model']) );
2925 $data['success'] = 0;
2926 $data['message'] = 'ERROR : Invalid Parameter';
2927 $data['data'] = null;
2928 $json = json_encode($data, JSON_PRETTY_PRINT);
2929 header('Content-Type: application/x-javascript');
2930 echo $json;
2931 exit();
2932 }
2933
2934 if ($status == false) {
2935 //$this->_sendResponse(501, sprintf('No items where found for model <b>%s</b>', $_GET['model']) );
2936 $data['success'] = 0;
2937 $data['message'] = 'ERROR : Missing or Invalid Parameter !';
2938 $data['data'] = null;
2939 $json = json_encode($data, JSON_PRETTY_PRINT);
2940 header('Content-Type: application/x-javascript');
2941 header("Access-Control-Allow-Origin: *");
2942 echo $json;
2943 exit();
2944 }
2945
2946 if ($models == null) {
2947 $data['success'] = 0;
2948 $data['message'] = 'ERROR : No Data Found';
2949 $data['data'] = null;
2950 $json = json_encode($data, JSON_PRETTY_PRINT);
2951 header('Content-Type: application/x-javascript');
2952 header("Access-Control-Allow-Origin: *");
2953 echo $json;
2954 exit();
2955 } elseif (is_null($models)) {
2956 $data['success'] = 0;
2957 $data['message'] = 'ERROR : No Data Found';
2958 $data['data'] = null;
2959 $json = json_encode($data, JSON_PRETTY_PRINT);
2960 header('Content-Type: application/x-javascript');
2961 header("Access-Control-Allow-Origin: *");
2962 echo $json;
2963 exit();
2964 }
2965
2966 //code when success...
2967 $json = json_encode($data, JSON_PRETTY_PRINT);
2968 header('Content-Type: application/json');
2969 header("Access-Control-Allow-Origin: *");
2970 echo $json;
2971 }
2972
2973 /*
2974 * Creates a new item
2975 *
2976 * @access public
2977 * @return void
2978 */
2979
2980 public function actionPost()
2981 {
2982 switch ($_GET['model']) {
2983 case 'login':
2984 $model = new User;
2985 $post_data = json_decode(urldecode(file_get_contents("php://input")));
2986 //print_r($post_data);exit;
2987
2988
2989
2990 if ($_SERVER['REQUEST_METHOD'] === 'OPTIONS') {
2991 header('Access-Control-Allow-Origin: *');
2992 header('Access-Control-Allow-Methods: POST, GET, DELETE, PUT, PATCH, OPTIONS');
2993 header('Access-Control-Allow-Headers: token, Content-Type');
2994 header('Access-Control-Max-Age: 1728000');
2995 header('Content-Length: 0');
2996 header('Content-Type: application/json');
2997 die();
2998 }
2999
3000 if (isset($_GET['type'])) {
3001 if ($_GET['type'] == 'android') {
3002 $username = $_POST['username'];
3003 $password = $_POST['password'];
3004 } elseif ($_GET['type'] == 'angular') {
3005 $username = $post_data->username;
3006 $password = $post_data->password;
3007 }
3008 }
3009
3010 //echo $username;exit;
3011
3012 $ph = new PasswordHash(Yii::app()->params['phpass']['iteration_count_log2'], Yii::app()->params['phpass']['portable_hashes']);
3013
3014 $criteria = new CDbCriteria;
3015 $criteria->condition = 'username=:username OR email=:username';
3016 $criteria->params = array(':username' => $username);
3017
3018 $user = $model->findAll($criteria);
3019
3020 if (!empty($user)) {
3021 foreach ($user as $data) {
3022 if ($ph->CheckPassword($password, $data->encrypted_password)) {
3023 $role = $data->role_id;
3024
3025 $token = new OauthToken;
3026
3027 $tokens = $token->findAll("id_user = :id", array(':id' => $data->id));
3028 if (empty($tokens)) {
3029 $token->id_user = $data->id;
3030 $token->token = $this->random(50);
3031
3032 date_default_timezone_set('Asia/Jakarta');
3033 $datetime = new DateTime();
3034 $datetime->modify('+180 day');
3035 $token->expired_date = $datetime->format('Y-m-d H:i:s');
3036 $token->save(false);
3037
3038 $json['tag'] = 'login';
3039 $json['msg'] = 'Login Success ( New Token )';
3040 $json['error'] = 'FALSE';
3041 $json['uid'] = $data->id;
3042 $json['class_id'] = $data->class_id;
3043 $json['card_id'] = $data->id_absen_solution;
3044 $json['user']['name'] = $data->display_name;
3045 $json['user']['email'] = $data->email;
3046 $json['user']['created_at'] = $data->created_at;
3047 $json['user']['updated_at'] = $data->updated_at;
3048
3049 if (isset($data->child_id)) {
3050 $json['user']['child_id'] = $data->child_id;
3051 } else {
3052 $json['user']['child_id'] = null;
3053 }
3054
3055 $json['role'] = $role;
3056 $json['token'] = $token->token;
3057 } else {
3058 date_default_timezone_set('Asia/Jakarta');
3059 $today = new DateTime();
3060 foreach ($tokens as $get) {
3061 $expired_date = new DateTime($get->expired_date);
3062 $update_token = $token->findByPk($get->id);
3063
3064 if ($today >= $expired_date) {
3065 $old_token = $update_token->token;
3066 $update_token->token = $this->random(25);
3067 $update_token->last_token = $old_token;
3068 $today->modify('+1 day');
3069 $update_token->expired_date = $today->format('Y-m-d H:i:s');
3070 $update_token->save(false);
3071
3072 $json['tag'] = 'login';
3073 $json['msg'] = 'Login Success. ( Change to New Token )';
3074 $json['error'] = 'FALSE';
3075 $json['uid'] = $data->id;
3076 $json['class_id'] = $data->class_id;
3077 $json['card_id'] = $data->id_absen_solution;
3078 $json['user']['name'] = $data->display_name;
3079 $json['user']['email'] = $data->email;
3080 $json['user']['created_at'] = $data->created_at;
3081 $json['user']['updated_at'] = $data->updated_at;
3082
3083 if (isset($data->child_id)) {
3084 $json['user']['child_id'] = $data->child_id;
3085 } else {
3086 $json['user']['child_id'] = null;
3087 }
3088
3089 $json['role'] = $role;
3090 $json['token'] = $update_token->token;
3091 } else {
3092 $json['tag'] = 'login';
3093 $json['msg'] = 'Login Success. (Same Token)';
3094 $json['error'] = 'FALSE';
3095 $json['uid'] = $data->id;
3096 $json['class_id'] = $data->class_id;
3097 $json['card_id'] = $data->id_absen_solution;
3098 $json['user']['name'] = $data->display_name;
3099 $json['user']['email'] = $data->email;
3100 $json['user']['created_at'] = $data->created_at;
3101 $json['user']['updated_at'] = $data->updated_at;
3102
3103 if (isset($data->child_id)) {
3104 $children = explode(",", $data->child_id);
3105 $json['user']['children'] = array();
3106 if (count($children) > 1) {
3107 foreach ($children as $key => $value) {
3108 $data_anak = array();
3109 $child = User::model()->findByPk($value);
3110 $data_anak['child_id'] = $child->id;
3111 $data_anak['child_name'] = $child->display_name;
3112 $data_anak['class_id'] = $child->class_id;
3113 $data_anak['card_id'] = $child->id_absen_solution;
3114 array_push($json['user']['children'], $data_anak);
3115 // $json['user']['children'] = $data_anak;
3116 // $json['user']['children']['child_class'] = $child->kelas->name;
3117 }
3118 } else {
3119 $data_anak = array();
3120 $child = User::model()->findByPk($data->child_id);
3121 $data_anak['child_id'] = $child->id;
3122 $data_anak['child_name'] = $child->display_name;
3123 $data_anak['class_id'] = $child->class_id;
3124 $data_anak['card_id'] = $child->id_absen_solution;
3125 array_push($json['user']['children'], $data_anak);
3126 // $json['user']['child_id'] = $data->child_id;
3127 }
3128 } else {
3129 $json['user']['child_id'] = null;
3130 }
3131
3132 $json['role'] = $role;
3133 $json['token'] = $get->token;
3134 }
3135 }
3136 }
3137 } else {
3138 $json['error'] = 'TRUE';
3139 $json['error_msg'] = 'Username/Password salah';
3140 $json['token'] = null;
3141 }
3142 }
3143 } else {
3144 $json['error'] = 'TRUE';
3145 $json['error_msg'] = 'Username belum terdaftar';
3146 $json['token'] = null;
3147 }
3148
3149 header('Access-Control-Allow-Origin: *');
3150 header('Content-Type: application/json');
3151 echo json_encode($json);
3152 break;
3153
3154 case 'register':
3155 $model = new User;
3156 $post_data = json_decode(urldecode(file_get_contents("php://input")));
3157 //print_r($post_data);exit;
3158
3159 if (isset($_GET['type'])) {
3160 if ($_GET['type'] == 'android') {
3161 $username = $_POST['username'];
3162 $display_name = $_POST['display_name'];
3163 $email = $_POST['email'];
3164 $role_id = "1";
3165 $password = $_POST['password'];
3166 $password2 = $_POST['password2'];
3167 } elseif ($_GET['type'] == 'angular') {
3168 $username = $post_data->username;
3169 $password = $post_data->password;
3170 }
3171 }
3172
3173 //echo $username;exit;
3174 // $ph=new PasswordHash(Yii::app()->params['phpass']['iteration_count_log2'], Yii::app()->params['phpass']['portable_hashes']);
3175
3176 $criteria = new CDbCriteria;
3177 $criteria->condition = 'username=:username OR email=:username';
3178 $criteria->params = array(':username' => $username);
3179
3180 $user = $model->findAll($criteria);
3181
3182 if (!empty($user)) {
3183 $json['error'] = 'TRUE';
3184 $json['error_msg'] = 'Username/email sudah terdaftar';
3185 // $json['token'] = NULL;
3186 } else {
3187 $model->username = $username;
3188 $model->email = $email;
3189 $model->display_name = $display_name;
3190 $model->role_id = $role_id;
3191 $model->encrypted_password = $password;
3192 $model->password2 = $password2;
3193 if ($model->save()) {
3194 $token = new OauthToken;
3195 $token->id_user = $model->id;
3196 $token->token = $this->random(50);
3197
3198 date_default_timezone_set('Asia/Jakarta');
3199 $datetime = new DateTime();
3200 $datetime->modify('+180 day');
3201 $token->expired_date = $datetime->format('Y-m-d H:i:s');
3202 $token->save(false);
3203
3204 $json['success'] = 1;
3205 $json['tag'] = 'register';
3206 $json['msg'] = 'Registrasi Success ( New Token )';
3207 $json['error'] = 'FALSE';
3208 $json['uid'] = $model->id;
3209 $json['user']['name'] = $model->display_name;
3210 $json['user']['email'] = $model->email;
3211 $json['user']['created_at'] = $model->created_at;
3212 $json['user']['updated_at'] = $model->updated_at;
3213 $json['role'] = $model->role_id;
3214 $json['token'] = $token->token;
3215 } else {
3216 $json['error'] = 'TRUE';
3217 $json['error_msg'] = 'Registrasi Gagal.';
3218 // $json['model'] = ;
3219 }
3220
3221
3222
3223
3224 // $json = json_encode($data,JSON_PRETTY_PRINT);
3225 // $json['error'] = 'TRUE';
3226 // $json['error_msg'] = 'Username belum terdaftar';
3227 // $json['token'] = NULL;
3228 }
3229
3230 header("Access-Control-Allow-Origin: *");
3231 echo json_encode($json);
3232 break;
3233
3234
3235 case 'tambah_pelajaran':
3236 $this->checkToken();
3237 $model = new Lesson;
3238 $optSemester = Option::model()->findByAttributes(array('key_config' => 'semester'))->value;
3239 $optTahunAjaran = Option::model()->findByAttributes(array('key_config' => 'tahun_ajaran'))->value;
3240
3241 $post_data = json_decode(urldecode(file_get_contents("php://input")));
3242 //print_r($post_data);exit;
3243
3244 if (isset($_GET['type'])) {
3245 if ($_GET['type'] == 'android') {
3246 // $username = $_POST['username'];
3247 // $display_name = $_POST['display_name'];
3248 // $email = $_POST['email'];
3249 // $role_id = "1";
3250 // $password = $_POST['password'];
3251 // $password2 = $_POST['password2'];
3252 } elseif ($_GET['type'] == 'angular') {
3253 // $username = $post_data->username;
3254 // $password = $post_data->password;
3255 }
3256 }
3257
3258 if (isset($_POST['list_id'])) {
3259 $model->user_id = "(ID:" . Yii::app()->session['id_user'] . ")";
3260 $model->list_id = $_POST['list_id'];
3261 $model->class_id = $_POST['class_id'];
3262
3263 $cekNama = LessonList::model()->findByPk($model->list_id);
3264 $model->name = $cekNama->name;
3265 $model->kelompok = $cekNama->group;
3266
3267 $model->semester = $optSemester;
3268 $model->year = $optTahunAjaran;
3269 if ($model->save()) {
3270 $siswas = User::model()->findAll(array('condition' => 'class_id = ' . $model->class_id . ' and trash is null'));
3271 $sukses = 0;
3272 if (!empty($siswas)) {
3273 foreach ($siswas as $siswa) {
3274 $join = "INSERT INTO lesson_mc (lesson_id,user_id,semester,year) values(" . $model->id . "," . $siswa->id . "," . $optSemester . "," . $optTahunAjaran . ")";
3275
3276 $joinCommand = Yii::app()->db->createCommand($join);
3277
3278 if ($joinCommand->execute()) {
3279 $sukses++;
3280 }
3281 }
3282 }
3283
3284 $json['success'] = 1;
3285 $json['tag'] = 'addLesson';
3286 $json['msg'] = 'Tambah Pelajaran Berhasil';
3287 $json['error'] = 'FALSE';
3288 } else {
3289 $json['error'] = 'TRUE';
3290 $json['error_msg'] = 'Tambah Pelajaran Gagal';
3291 }
3292 }
3293
3294 echo json_encode($json);
3295 break;
3296
3297 case 'register_siswa':
3298 $model = new User;
3299 $this->checkToken();
3300 $post_data = json_decode(file_get_contents("php://input"));
3301
3302
3303 if (isset($_GET['type'])) {
3304 if ($_GET['type'] == 'android') {
3305 // $username = $_POST['username'];
3306 // $display_name = $_POST['display_name'];
3307 // $email = $_POST['email'];
3308 // $role_id = "1";
3309 // $password = $_POST['password'];
3310 // $password2 = $_POST['password2'];
3311 $class_id = $post_data->class_id;
3312 } elseif ($_GET['type'] == 'angular') {
3313 // $username = $post_data->username;
3314 // $password = $post_data->password;
3315 }
3316 }
3317
3318
3319 $prefix = Yii::app()->params['tablePrefix'];
3320 $length = 5;
3321 $characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
3322 $charactersLength = strlen($characters);
3323
3324 $sukses = 0;
3325
3326 foreach ($post_data->siswa as $siswa) {
3327 // foreach ($result as $key => $value) {
3328 $randomString = '';
3329
3330 for ($i = 0; $i < $length; $i++) {
3331 $randomString .= $characters[rand(0, $charactersLength - 1)];
3332 }
3333
3334 $nis = $siswa->nis;
3335 $nama = $siswa->name;
3336 $email = $randomString . "@mail.id";
3337 $password = $randomString;
3338 $role = 2;
3339 $ph = new PasswordHash(Yii::app()->params['phpass']['iteration_count_log2'], Yii::app()->params['phpass']['portable_hashes']);
3340 $passwd = $ph->HashPassword($password);
3341
3342
3343 $cekUE = User::model()->findAll(array("condition" => "username = '$nis' or email = '$email'"));
3344
3345 if (!empty($cekUE)) {
3346
3347 //do nothing
3348 } else {
3349 $insert = "INSERT INTO " . $prefix . "users (email,username,encrypted_password,role_id,created_at,updated_at,reset_password,display_name,class_id) values(:email,:username,:encrypted_password,:role_id,NOW(),NOW(),:reset_password,:display_name,:class_id)";
3350
3351 $insertCommand = Yii::app()->db->createCommand($insert);
3352
3353 $insertCommand->bindParam(":email", $email, PDO::PARAM_STR);
3354 $insertCommand->bindParam(":username", $nis, PDO::PARAM_STR);
3355 $insertCommand->bindParam(":encrypted_password", $passwd, PDO::PARAM_STR);
3356 $insertCommand->bindParam(":role_id", $role, PDO::PARAM_STR);
3357 $insertCommand->bindParam(":reset_password", $password, PDO::PARAM_STR);
3358 $insertCommand->bindParam(":display_name", $nama, PDO::PARAM_STR);
3359 $insertCommand->bindParam(":class_id", $class_id, PDO::PARAM_STR);
3360 if ($insertCommand->execute()) {
3361 $sukses++;
3362 }
3363 }
3364 }
3365
3366 if ($sukses > 0) {
3367 // Yii::app()->user->setFlash('success','Siswa Berhasil Didaftarkan!');
3368 // $this->redirect(array('view','id'=>$id));
3369 $json['success'] = 1;
3370 $json['countSuccess'] = $sukses;
3371 $json['tag'] = 'register';
3372 $json['msg'] = 'Siswa Berhasil Didaftarkan';
3373 } else {
3374 // Yii::app()->user->setFlash('error','Siswa Gagal Didaftarkan!');
3375 // $this->redirect(array('view','id'=>$id));
3376 $json['error'] = 'TRUE';
3377 $json['error_msg'] = 'Siswa Gagal Didaftarkan.';
3378 }
3379
3380
3381
3382
3383
3384
3385
3386 echo json_encode($json);
3387 break;
3388
3389
3390
3391 case 'update_user_spp':
3392 // $this->checkToken();
3393 $model = User::model()->findByPk($_POST['user_id']);
3394 $modelProfile=UserProfile::model()->findByAttributes(array('user_id'=>$_POST['user_id']));
3395
3396 if (isset($model->spp) && isset($_POST['transaction_id'])) {
3397 $arr_spp = explode(',', $model->spp);
3398 array_push($arr_spp, $_POST['transaction_id']);
3399 $model->spp = implode(",", $arr_spp);
3400 }
3401
3402 if (empty($model)) {
3403 $json['error'] = 'TRUE';
3404 $json['error_msg'] = 'User tidak ditemukan.';
3405 // $json['token'] = NULL;
3406 } else {
3407 if ($model->save()) {
3408 $json['success'] = true;
3409 $json['msg'] = 'SPP Berhasil Diupdate';
3410 } else {
3411 $json['success'] = false;
3412 $json['msg'] = 'Update gagal';
3413 // $json['model'] = ;
3414 }
3415 }
3416
3417 echo json_encode($json);
3418 break;
3419
3420 case 'class_detail':
3421 $this->checkToken();
3422 $model = new ClassDetail;
3423 $post_data = json_decode(urldecode(file_get_contents("php://input")));
3424 //print_r($post_data);exit;
3425
3426 if (isset($_GET['type'])) {
3427 if ($_GET['type'] == 'android') {
3428 $name = $_POST['name'];
3429 $class_id = $_POST['level'];
3430 } elseif ($_GET['type'] == 'angular') {
3431 $username = $post_data->username;
3432 $password = $post_data->password;
3433 }
3434 }
3435
3436
3437
3438 $model->name = $name;
3439 $model->class_id = $class_id;
3440 $model->teacher_id = Yii::app()->session['id_user'];
3441
3442 if ($model->save()) {
3443 $json['success'] = 1;
3444 $json['tag'] = 'addClass';
3445 $json['id_kelas'] = $model->id;
3446 $json['msg'] = 'Tambah Kelas Success ( New Token )';
3447 } else {
3448 $json['error'] = 'TRUE';
3449 $json['error_msg'] = 'Tambah Kelas Gagal.';
3450 // $json['model'] = ;
3451 }
3452
3453
3454 echo json_encode($json);
3455 break;
3456
3457 //post ASSIGNMENT file
3458 case 'student_assignment_file':
3459 //$studentAssignment=new StudentAssignment;
3460 //echo $_FILES['file']['tmp_name'];exit;
3461 $notif = new Notification;
3462 $activity = new Activities;
3463 $user = User::model()->findByPk(Yii::app()->session['id_user']);
3464 $student_id = Yii::app()->session['id_user'];
3465 $studentAssignment = new StudentAssignment;
3466 //$pk_id = (int)Yii::app()->session['temp_id'] + 1;
3467 //print_r(Yii::app()->session['form_input']);exit;
3468 //print_r($studentAssignment);exit;
3469 $studentAssignment->assignment_id = Yii::app()->session['form_input']['assignment_id'];
3470 $studentAssignment->content = Yii::app()->session['form_input']['content'];
3471 $studentAssignment->file = $_FILES['file']['name'];
3472 ;
3473 $studentAssignment->student_id = Yii::app()->session['form_input']['student_id'];
3474 $studentAssignment->status = 1;
3475 if ($studentAssignment->save(false)) {
3476 if (!file_exists(Yii::app()->basePath . '/../images/students/' . $student_id)) {
3477 mkdir(Yii::app()->basePath . '/../images/students/' . $student_id, 0775, true);
3478 }
3479
3480 if (!empty($_FILES['file']['name'])) {
3481 //$uploadedFile->saveAs(Yii::app()->basePath.'/../images/students/'.$student_id.'/'.$_FILES['file']['name']);
3482 move_uploaded_file($_FILES['file']['tmp_name'], Yii::app()->basePath . '/../images/students/' . $student_id . '/' . $_FILES['file']['name']);
3483 }
3484 }
3485
3486 break;
3487
3488 //post form data
3489 case 'student_assignment_form':
3490 $post_data = json_decode(urldecode(file_get_contents("php://input")));
3491 //print_r($post_data);exit;
3492 // $studentAssignment=new StudentAssignment;
3493 // $notif=new Notification;
3494 // $activity=new Activities;
3495 // $model=Assignment::model()->findByPk($post_data->assignment_id);
3496 // $user=User::model()->findByPk(Yii::app()->session['id_user']);
3497 // $user_kelas = $user->class_id;
3498 // $mapel=Lesson::model()->findByAttributes(array('id'=>$model->lesson_id));
3499 // $kelas=Clases::model()->findByAttributes(array('id'=>$mapel->class_id));
3500 // if(isset($_POST['save'])){
3501 // $studentAssignment->status=null;
3502 // }elseif(isset($_POST['upload'])){
3503 // $studentAssignment->status=1;
3504 // }
3505 // $studentAssignment->student_id= Yii::app()->session['id_user'];
3506 // $studentAssignment->assignment_id= $post_data->assignment_id;
3507 // $studentAssignment->content = $post_data->jawaban;
3508 //$studentAssignment->status= null;
3509 // $studentAssignment->save(false);
3510 // Yii::app()->session['temp_id'] = $studentAssignment->getPrimaryKey();
3511
3512 Yii::app()->session['form_input'] = array(
3513 'student_id' => Yii::app()->session['id_user'],
3514 'assignment_id' => $post_data->assignment_id,
3515 'content' => $post_data->jawaban,
3516 'state' => $post_data->state
3517 );
3518
3519 //Yii::app()->session['form_input']['student_id'] = Yii::app()->session['id_user'];
3520 // Yii::app()->session['form_input']['assignment_id'] = $post_data->assignment_id;
3521 // Yii::app()->session['form_input']['content'] = $post_data->jawaban;
3522 // Yii::app()->session['form_input']['state'] = $post_data->state;
3523
3524 break;
3525
3526 //post StudentQuiz
3527 case 'studentquiz':
3528
3529 $this->checkToken();
3530 $post_data = json_decode(file_get_contents("php://input"));
3531 //print_r($post_data);
3532 $temp = null;
3533 $temp2 = null;
3534
3535 if (!empty($post_data->jawaban)) {
3536 foreach ($post_data->jawaban as $jawaban) {
3537 // $jawaban = explode('|',$row);
3538 $temp['id_question'] = $jawaban->id_question;
3539 $temp['pilihan'] = $jawaban->pilihan;
3540 $data_jawaban[] = $temp;
3541
3542 if (!empty($temp['pilihan'])) {
3543 $temp2[$temp['id_question']] = $temp['pilihan'];
3544 } else {
3545 $temp2 = null;
3546 }
3547 }
3548 }
3549
3550 $activity = new Activities;
3551 $usr = User::model()->findByPk(Yii::app()->session['id_user']);
3552 $notif = new Notification;
3553 $cekUsr = StudentQuiz::model()->findByAttributes(array('quiz_id' => $post_data->quizId, 'student_id' => Yii::app()->session['id_user']));
3554
3555 if (!$cekUsr) {
3556 $student_quiz = new StudentQuiz;
3557
3558 //$student_quiz->attributes=$_POST['StudentQuiz'];
3559 $student_quiz->quiz_id = $post_data->quizId;
3560 $student_quiz->student_id = Yii::app()->session['id_user'];
3561 $qid = $student_quiz->quiz_id;
3562 $quiz = Quiz::model()->findByPk($qid);
3563
3564 $total_pertanyaan = $quiz->total_question;
3565 $benar = 0;
3566 $salah = 0;
3567 $kosong = 0;
3568 $total_jawab = null;
3569 $jawaban = null;
3570
3571 if (!empty($data_jawaban)) {
3572 foreach ($data_jawaban as $row) {
3573 $cekJawaban = Questions::model()->findByAttributes(array('id' => $row['id_question']));
3574 if (!empty($cekJawaban)) {
3575
3576 // $soal->key_answer = str_replace('\r', '', $soal->key_answer) ;
3577 $cekJawaban->key_answer = preg_replace("/\r|\n/", "", $cekJawaban->key_answer);
3578 // $value = str_replace('\r', '', $value);
3579 $row = preg_replace("/\r|\n/", "", $row);
3580
3581
3582 if (strtolower($cekJawaban->key_answer) == strtolower($row['pilihan'])) {
3583 $benar = $benar + 1;
3584 } else {
3585 $salah = $salah + 1;
3586 }
3587 } else {
3588 $kosong = $total_pertanyaan - ($benar + $salah);
3589 }
3590 }
3591 $total_jawab = count($data_jawaban);
3592 $kosong = $quiz->total_question - $total_jawab;
3593 } else {
3594 $kosong = $total_pertanyaan;
3595 }
3596 $score = round(($benar / $total_pertanyaan) * 100);
3597
3598 $student_quiz->score = $score;
3599 $student_quiz->right_answer = $benar;
3600 $student_quiz->wrong_answer = $salah;
3601 $student_quiz->unanswered = $kosong;
3602
3603 $student_quiz->attempt = $student_quiz->attempt + 1;
3604
3605 if (($temp2 != 'null') && !empty($temp2)) {
3606 $student_quiz->student_answer = json_encode($temp2);
3607
3608 if (Yii::app()->session['role'] == 2) {
3609 if ($student_quiz->save(false)) {
3610 $activity->activity_type = 'Mengerjakan Kuis';
3611 $activity->content = 'Siswa ' . $usr->display_name . ' Mengerjakan Ulangan ' . $quiz->title;
3612 $activity->created_by = Yii::app()->session['id_user'];
3613 $activity->save(false);
3614
3615 $notif->content = "Siswa " . $usr->display_name . " Selesai Mengerjakan Ulangan " . $quiz->title;
3616 $notif->user_id = Yii::app()->session['id_user'];
3617 $notif->relation_id = $student_quiz->id;
3618 $notif->user_id_to = $quiz->created_by;
3619 $notif->tipe = "submit-quiz";
3620 $notif->save(false);
3621 $data['success'] = 1;
3622 $data['message'] = 'Submit Berhasil.';
3623 $json = json_encode($data, JSON_PRETTY_PRINT);
3624 header('Content-Type: application/json');
3625 echo $json;
3626 } else {
3627 $data['success'] = 0;
3628 $data['message'] = 'Submit Gagal.';
3629 $json = json_encode($data, JSON_PRETTY_PRINT);
3630 header('Content-Type: application/json');
3631 echo $json;
3632 }
3633 } else {
3634 $data['success'] = 0;
3635 $data['message'] = 'Submit Gagal. Hanya siswa yang boleh submit.';
3636 $json = json_encode($data, JSON_PRETTY_PRINT);
3637 header('Content-Type: application/json');
3638 echo $json;
3639 }
3640 } else {
3641 $data['success'] = 0;
3642 $data['message'] = 'Submit Gagal.';
3643 $json = json_encode($data, JSON_PRETTY_PRINT);
3644 header('Content-Type: application/json');
3645 echo $json;
3646 }
3647 } else {
3648 $data['success'] = 0;
3649 $data['message'] = 'Submit Gagal. User telah submit sebelumnya';
3650 $json = json_encode($data, JSON_PRETTY_PRINT);
3651 header('Content-Type: application/json');
3652 echo $json;
3653 }
3654
3655 break;
3656
3657 //post absesni
3658
3659 case 'absensi':
3660
3661 $this->checkToken();
3662 $post_data = json_decode(file_get_contents("php://input"));
3663 //print_r($post_data);
3664 $temp = null;
3665 $temp2 = null;
3666 $berhasil = 0;
3667 $data_message = "";
3668
3669 if (!empty($post_data->absensi)) {
3670 foreach ($post_data->absensi as $absensi) {
3671 $activity = new Activities;
3672 $usr = User::model()->findByPk(Yii::app()->session['id_user']);
3673 $notif = new Notification;
3674 $cekUsr = Absensi::model()->findByAttributes(array('user_id' => $absensi->user_id, 'id_lesson' => $absensi->id_lesson, 'pertemuan_ke' => $absensi->pertemuan_ke));
3675
3676 if (!$cekUsr) {
3677 $data_absensi = new Absensi;
3678
3679 $data_absensi->user_id = $absensi->user_id;
3680 $data_absensi->id_lesson = $absensi->id_lesson;
3681 $data_absensi->absen = $absensi->absen;
3682 $data_absensi->pertemuan_ke = $absensi->pertemuan_ke;
3683 $data_absensi->ket = $absensi->ket;
3684
3685 if (!isset($absensi->created_at)) {
3686 $absensi->created_at = "2018-01-01 22:21:39 ";
3687 }
3688
3689 $data_absensi->created_at = $absensi->created_at;
3690
3691 if (Yii::app()->session['role'] != 2) {
3692 if ($data_absensi->save(false)) {
3693 $berhasil++;
3694 } else {
3695 $data_message = 'Submit Gagal.';
3696 }
3697 } else {
3698 $berhasil = 0;
3699 $data_message = 'Submit Gagal. Hanya guru yang boleh submit absensi.';
3700 }
3701 } else {
3702 $cekUsr->user_id = $absensi->user_id;
3703 $cekUsr->id_lesson = $absensi->id_lesson;
3704 $cekUsr->absen = $absensi->absen;
3705 $cekUsr->pertemuan_ke = $absensi->pertemuan_ke;
3706 $cekUsr->ket = $absensi->ket;
3707 $cekUsr->sync_status = "2";
3708
3709 if (!isset($absensi->created_at)) {
3710 $absensi->created_at = "2018-01-01 22:21:39 ";
3711 }
3712
3713 $cekUsr->created_at = $absensi->created_at;
3714
3715
3716 if (Yii::app()->session['role'] != 2) {
3717 if ($cekUsr->save(false)) {
3718 $berhasil++;
3719 } else {
3720 $data_message = 'Submit Gagal.';
3721 }
3722 } else {
3723 $berhasil = 0;
3724 $data_message = 'Submit Gagal. Hanya guru yang boleh submit absensi.';
3725 }
3726 }
3727 }
3728 }
3729
3730 if ($berhasil != 0) {
3731 $data['success'] = 1;
3732 $data['message'] = 'Submit ' . $berhasil . ' data Berhasil.';
3733 $json = json_encode($data, JSON_PRETTY_PRINT);
3734 header('Content-Type: application/json');
3735 echo $json;
3736 } else {
3737 $data['success'] = 0;
3738 $data['message'] = $data_message;
3739 $json = json_encode($data, JSON_PRETTY_PRINT);
3740 header('Content-Type: application/json');
3741 echo $json;
3742 }
3743
3744
3745 break;
3746
3747
3748 case 'absensi_harian':
3749
3750 $this->checkToken();
3751 $post_data = json_decode(file_get_contents("php://input"));
3752 //print_r($post_data);
3753 $temp = null;
3754 $temp2 = null;
3755 $berhasil = 0;
3756 $data_message = "";
3757
3758 if (!empty($post_data->absensi_harian)) {
3759 foreach ($post_data->absensi_harian as $absensi) {
3760 $activity = new Activities;
3761 $usr = User::model()->findByPk(Yii::app()->session['id_user']);
3762 $notif = new Notification;
3763 $cekUsr = AbsensiHarian::model()->findByAttributes(array('user_id' => $absensi->user_id, 'tgl' => $absensi->tgl));
3764
3765 if (!$cekUsr) {
3766 $data_absensi = new AbsensiHarian;
3767
3768 $data_absensi->user_id = $absensi->user_id;
3769 $data_absensi->absen = $absensi->absen;
3770 $data_absensi->tgl = $absensi->tgl;
3771 $data_absensi->ket = $absensi->ket;
3772
3773 if (Yii::app()->session['role'] != 2) {
3774 if ($data_absensi->save(false)) {
3775 $berhasil++;
3776 } else {
3777 $data_message = 'Submit Gagal.';
3778 }
3779 } else {
3780 $berhasil = 0;
3781 $data_message = 'Submit Gagal. Hanya guru yang boleh submit absensi.';
3782 }
3783 } else {
3784 $cekUsr->user_id = $absensi->user_id;
3785 $cekUsr->absen = $absensi->absen;
3786 $cekUsr->tgl = $absensi->tgl;
3787 $cekUsr->ket = $absensi->ket;
3788
3789 if (Yii::app()->session['role'] != 2) {
3790 if ($cekUsr->save(false)) {
3791 $berhasil++;
3792 } else {
3793 $data_message = 'Submit Gagal.';
3794 }
3795 } else {
3796 $berhasil = 0;
3797 $data_message = 'Submit Gagal. Hanya guru yang boleh submit absensi.';
3798 }
3799 }
3800 }
3801 }
3802
3803 if ($berhasil != 0) {
3804 $data['success'] = 1;
3805 $data['message'] = 'Submit ' . $berhasil . ' data Berhasil.';
3806 $json = json_encode($data, JSON_PRETTY_PRINT);
3807 header('Content-Type: application/json');
3808 echo $json;
3809 } else {
3810 $data['success'] = 0;
3811 $data['message'] = $data_message;
3812 $json = json_encode($data, JSON_PRETTY_PRINT);
3813 header('Content-Type: application/json');
3814 echo $json;
3815 }
3816
3817
3818 break;
3819
3820 //end post absesni
3821 //post final_mark
3822
3823
3824 case 'final_mark':
3825
3826 $this->checkToken();
3827 $post_data = json_decode(file_get_contents("php://input"));
3828 //print_r($post_data);
3829 $temp = null;
3830 $temp2 = null;
3831 $berhasil = 0;
3832 $data_message = "";
3833
3834 if (!empty($post_data->nilai)) {
3835 foreach ($post_data->nilai as $nilai) {
3836 $activity = new Activities;
3837 $usr = User::model()->findByPk(Yii::app()->session['id_user']);
3838 $notif = new Notification;
3839 $cekUsr = FinalMark::model()->findByAttributes(array('user_id' => $nilai->user_id));
3840
3841 if (!$cekUsr) {
3842 $data_nilai = new FinalMark;
3843
3844 $data_nilai->user_id = $nilai->user_id;
3845 $data_nilai->lesson_id = $nilai->id_lesson;
3846 $data_nilai->tipe = $nilai->tipe;
3847 $data_nilai->semester = $nilai->semester;
3848 $data_nilai->tahun_ajaran = $nilai->tahun_ajaran;
3849 $data_nilai->nilai = $nilai->nilai;
3850 $data_nilai->created_by = $nilai->created_by;
3851 $data_nilai->created_at = $nilai->created_at;
3852
3853 if (Yii::app()->session['role'] != 2) {
3854 if ($data_nilai->save(false)) {
3855 $berhasil++;
3856 $data_message = 'Submit Gagal.';
3857 } else {
3858 $data_message = 'Submit Gagal masuk database.';
3859 }
3860 } else {
3861 $berhasil = 0;
3862 $data_message = 'Submit Gagal. Hanya guru yang boleh submit absensi.';
3863 }
3864 } else {
3865 $data_message = 'Submit Gagal. User telah submit sebelumnya';
3866 }
3867 }
3868 }
3869
3870 if ($berhasil != 0) {
3871 $data['success'] = 1;
3872 $data['message'] = 'Submit ' . $berhasil . ' data Berhasil.';
3873 $json = json_encode($data, JSON_PRETTY_PRINT);
3874 header('Content-Type: application/json');
3875 echo $json;
3876 } else {
3877 $data['success'] = 0;
3878 $data['message'] = $data_message;
3879 $json = json_encode($data, JSON_PRETTY_PRINT);
3880 header('Content-Type: application/json');
3881 echo $json;
3882 }
3883
3884
3885 break;
3886
3887
3888
3889 //end post final matk
3890 //post QUIZ
3891 case 'quiz':
3892 $model = new Quiz;
3893 $activity = new Activities;
3894
3895 if (isset($_POST['save'])) {
3896 $model->status = null;
3897 } elseif (isset($_POST['show'])) {
3898 $model->status = 1;
3899 } elseif (isset($_POST['close'])) {
3900 $model->status = 2;
3901 }
3902 if (empty($model->repeat_quiz)) {
3903 $model->repeat_quiz = 1;
3904 }
3905
3906 // Try to assign POST values to attributes
3907 foreach ($_POST as $var => $value) {
3908 // Does the model have this attribute?
3909 if ($model->hasAttribute($var)) {
3910 $model->$var = $value;
3911 } else {
3912 // No, raise an error
3913 $this->_sendResponse(500, sprintf('Parameter <b>%s</b> is not allowed for model <b>%s</b>', $var, $_GET['model']));
3914 }
3915 }
3916 if ($model->save()) {
3917 $activity->activity_type = 'Buat Kuis Baru';
3918 $activity->content = 'Guru' . $usr->display_name . ' Membuat Kuis Baru';
3919 $activity->created_by = Yii::app()->user->id;
3920 $activity->save();
3921 $this->_sendResponse(200);
3922 } else {
3923 // Errors occurred
3924 $msg = "<h1>Error</h1>";
3925 $msg .= sprintf("Couldn't create model <b>%s</b>", $_GET['model']);
3926 $msg .= "<ul>";
3927 foreach ($model->errors as $attribute => $attr_errors) {
3928 $msg .= "<li>Attribute: $attribute</li>";
3929 $msg .= "<ul>";
3930 foreach ($attr_errors as $attr_error) {
3931 $msg .= "<li>$attr_error</li>";
3932 }
3933 $msg .= "</ul>";
3934 }
3935 $msg .= "</ul>";
3936 $this->_sendResponse(500, $msg);
3937 }
3938 break;
3939
3940 case 'chapter':
3941 $model = new Chapters;
3942 $model2 = new ChapterFiles;
3943 $notif = new Notification;
3944 $activity = new Activities;
3945
3946 foreach ($_POST as $var => $value) {
3947 // Does the model have this attribute?
3948 if ($model->hasAttribute($var)) {
3949 $model->$var = $value;
3950 } else {
3951 // No, raise an error
3952 $this->_sendResponse(500, sprintf('Parameter <b>%s</b> is not allowed for model <b>%s</b>', $var, $_GET['model']));
3953 }
3954 }
3955
3956 $model->created_by = Yii::app()->user->id;
3957
3958 if ($model->chapter_type == 1) {
3959 $model2->scenario = 'video';
3960 } elseif ($model->chapter_type == 2) {
3961 $model2->scenario = 'gambar';
3962 } elseif ($model->chapter_type == 3) {
3963 $model2->scenario = 'dokumen';
3964 }
3965 if ($model->save()) {
3966 $model2->id_chapter = $model->id;
3967 //$uploadedFile = CUploadedFile::getInstance($model2, 'file');
3968
3969 if (!empty($uploadedFile)) {
3970 $model2->file = $uploadedFile;
3971 $ext = pathinfo($uploadedFile, PATHINFO_EXTENSION);
3972 $model2->type = $ext;
3973 }
3974
3975 $model2->created_by = Yii::app()->user->id;
3976 if ($model2->save()) {
3977 $kelas = Lesson::model()->findByPk($model->id_lesson);
3978 $notif->content = "Guru " . $name . " Menambah Materi Baru";
3979 $notif->user_id = Yii::app()->user->id;
3980 $notif->class_id_to = $kelas->class_id;
3981 $notif->tipe = 'add-chapter';
3982 $notif->relation_id = $model->id;
3983 $notif->save();
3984
3985 $activity->activity_type = "Upload Materi " . $model->title . " " . $kelas->name;
3986 $activity->created_by = Yii::app()->user->id;
3987 $activity->save();
3988
3989 if (!file_exists(Yii::app()->basePath . '/../images/chapters/' . $model->id_lesson)) {
3990 mkdir(Yii::app()->basePath . '/../images/chapters/' . $model->id_lesson, 0775, true);
3991 }
3992
3993 if (!empty($uploadedFile)) {
3994 $uploadedFile->saveAs(Yii::app()->basePath . '/../images/chapters/' . $model->id_lesson . '/' . $uploadedFile);
3995 }
3996 }
3997 }
3998 break;
3999
4000
4001 default:
4002 $this->_sendResponse(501, sprintf('Mode <b>create</b> is not implemented for model <b>%s</b>', $_GET['model']));
4003 exit;
4004 }
4005 // echo '<pre>';
4006 // print_r($_POST);
4007 // print_r($_FILES);
4008 // echo '</pre>';
4009 // exit();
4010 //echo 'sip';exit();
4011 }
4012
4013 // }}}
4014 // {{{ actionUpdate
4015 /**
4016 * Update a single item
4017 *
4018 * @access public
4019 * @return void
4020 */
4021 public function actionUpdate()
4022 {
4023 if (!isset($_GET['id'])) {
4024 $this->_sendResponse(500, 'Error: Parameter <b>id</b> is missing');
4025 }
4026
4027 // Get PUT parameters
4028 parse_str(file_get_contents('php://input'), $put_vars);
4029
4030 //echo '<pre>';
4031 //print_r($put_vars);
4032 //echo '</pre>';
4033 //exit();
4034
4035 switch ($_GET['model']) {
4036 // Find respective model
4037 case 'checkup':
4038
4039 $model = new HospitalCheckUp;
4040 $models = $model->findByPk($_GET['id']);
4041
4042 //$models = Yii::app()->db->createCommand($sql)->queryAll();
4043 break;
4044
4045 default:
4046 $this->_sendResponse(501, sprintf('Error: Mode <b>update</b> is not implemented for model <b>%s</b>', $_GET['model']));
4047 exit;
4048 }
4049
4050 if (is_null($models)) {
4051 $this->_sendResponse(400, sprintf("Error: Didn't find any model <b>%s</b> with ID <b>%s</b>.", $_GET['model'], $_GET['id']));
4052 }
4053
4054 // Try to assign PUT parameters to attributes
4055 foreach ($put_vars as $var => $value) {
4056 // Does model have this attribute?
4057 if ($models->hasAttribute($var)) {
4058 $models->$var = $value;
4059 } else {
4060 // No, raise error
4061 $this->_sendResponse(500, sprintf('Parameter <b>%s</b> is not allowed for model <b>%s</b>', $var, $_GET['model']));
4062 }
4063 }
4064 // Try to save the model
4065 if ($models->save()) {
4066 $this->_sendResponse(200);
4067 } else {
4068 $msg = "<h1>Error</h1>";
4069 $msg .= sprintf("Couldn't update model <b>%s</b>", $_GET['model']);
4070 $msg .= "<ul>";
4071 foreach ($model->errors as $attribute => $attr_errors) {
4072 $msg .= "<li>Attribute: $attribute</li>";
4073 $msg .= "<ul>";
4074 foreach ($attr_errors as $attr_error) {
4075 $msg .= "<li>$attr_error</li>";
4076 }
4077 $msg .= "</ul>";
4078 }
4079 $msg .= "</ul>";
4080 $this->_sendResponse(500, $msg);
4081 }
4082 }
4083
4084 // }}}
4085 // {{{ actionDelete
4086 /**
4087 * Deletes a single item
4088 *
4089 * @access public
4090 * @return void
4091 */
4092 public function actionDelete()
4093 {
4094 switch ($_GET['model']) {
4095 // Load the respective model
4096 case 'checkup':
4097
4098 $model = new HospitalCheckUp;
4099 $models = $model->findByPk($_GET['id']);
4100
4101 //$models = Yii::app()->db->createCommand($sql)->queryAll();
4102 break;
4103
4104 default: // {{{
4105 $this->_sendResponse(501, sprintf('Error: Mode <b>delete</b> is not implemented for model <b>%s</b>', $_GET['model']));
4106 exit; // }}}
4107 }
4108 // Was a model found?
4109 if (is_null($models)) {
4110 // No, raise an error
4111 $this->_sendResponse(400, sprintf("Error: Didn't find any model <b>%s</b> with ID <b>%s</b>.", $_GET['model'], $_GET['id']));
4112 }
4113 // Delete the model
4114 $num = $models->delete();
4115 if ($num > 0) {
4116 $this->_sendResponse(200);
4117 } else {
4118 $this->_sendResponse(500, sprintf("Error: Couldn't delete model <b>%s</b> with ID <b>%s</b>.", $_GET['model'], $_GET['id']));
4119 }
4120 }
4121
4122 // }}}
4123 // }}} End Actionscd
4124 // {{{ Other Methods
4125 // {{{ _sendResponse
4126 /**
4127 * Sends the API response
4128 *
4129 * @param int $status
4130 * @param string $body
4131 * @param string $content_type
4132 * @access private
4133 * @return void
4134 */
4135 private function _sendResponse($status = 200, $body = '', $content_type = 'text/html')
4136 {
4137 $status_header = 'HTTP/1.1 ' . $status . ' ' . $this->_getStatusCodeMessage($status);
4138 // set the status
4139 header($status_header);
4140 // set the content type
4141 header('Content-type: ' . $content_type);
4142
4143 header("Access-Control-Allow-Origin: *");
4144
4145 // pages with body are easy
4146 if ($body != '') {
4147 // send the body
4148 echo $body;
4149 exit;
4150 } // we need to create the body if none is passed
4151 else {
4152 // create some body messages
4153 $message = 'none passed';
4154
4155 // this is purely optional, but makes the pages a little nicer to read
4156 // for your users. Since you won't likely send a lot of different status codes,
4157 // this also shouldn't be too ponderous to maintain
4158 switch ($status) {
4159 case 401:
4160 $message = 'You must be authorized to view this page.';
4161 break;
4162 case 404:
4163 $message = 'The requested URL ' . $_SERVER['REQUEST_URI'] . ' was not found.';
4164 break;
4165 case 500:
4166 $message = 'The server encountered an error processing your request.';
4167 break;
4168 case 501:
4169 $message = 'The requested method is not implemented.';
4170 break;
4171 }
4172
4173 // servers don't always have a signature turned on (this is an apache directive "ServerSignature On")
4174 $signature = ($_SERVER['SERVER_SIGNATURE'] == '') ? $_SERVER['SERVER_SOFTWARE'] . ' Server at ' . $_SERVER['SERVER_NAME'] . ' Port ' . $_SERVER['SERVER_PORT'] : $_SERVER['SERVER_SIGNATURE'];
4175
4176 // this should be templatized in a real-world solution
4177 $body = '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
4178 <html>
4179 <head>
4180 <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
4181 <title>' . $status . ' ' . $this->_getStatusCodeMessage($status) . '</title>
4182 </head>
4183 <body>
4184 <h1>' . $this->_getStatusCodeMessage($status) . '</h1>
4185 <p>' . $message . '</p>
4186 <hr />
4187 <address>' . $signature . '</address>
4188 </body>
4189 </html>';
4190
4191 echo $body;
4192 exit;
4193 }
4194 }
4195
4196 // }}}
4197 // {{{ _getStatusCodeMessage
4198 /**
4199 * Gets the message for a status code
4200 *
4201 * @param mixed $status
4202 * @access private
4203 * @return string
4204 */
4205 private function _getStatusCodeMessage($status)
4206 {
4207 // these could be stored in a .ini file and loaded
4208 // via parse_ini_file()... however, this will suffice
4209 // for an example
4210 $codes = array(
4211 100 => 'Continue',
4212 101 => 'Switching Protocols',
4213 200 => 'OK',
4214 201 => 'Created',
4215 202 => 'Accepted',
4216 203 => 'Non-Authoritative Information',
4217 204 => 'No Content',
4218 205 => 'Reset Content',
4219 206 => 'Partial Content',
4220 300 => 'Multiple Choices',
4221 301 => 'Moved Permanently',
4222 302 => 'Found',
4223 303 => 'See Other',
4224 304 => 'Not Modified',
4225 305 => 'Use Proxy',
4226 306 => '(Unused)',
4227 307 => 'Temporary Redirect',
4228 400 => 'Bad Request',
4229 401 => 'Unauthorized',
4230 402 => 'Payment Required',
4231 403 => 'Forbidden',
4232 404 => 'Not Found',
4233 405 => 'Method Not Allowed',
4234 406 => 'Not Acceptable',
4235 407 => 'Proxy Authentication Required',
4236 408 => 'Request Timeout',
4237 409 => 'Conflict',
4238 410 => 'Gone',
4239 411 => 'Length Required',
4240 412 => 'Precondition Failed',
4241 413 => 'Request Entity Too Large',
4242 414 => 'Request-URI Too Long',
4243 415 => 'Unsupported Media Type',
4244 416 => 'Requested Range Not Satisfiable',
4245 417 => 'Expectation Failed',
4246 500 => 'Internal Server Error',
4247 501 => 'Not Implemented',
4248 502 => 'Bad Gateway',
4249 503 => 'Service Unavailable',
4250 504 => 'Gateway Timeout',
4251 505 => 'HTTP Version Not Supported'
4252 );
4253
4254 return (isset($codes[$status])) ? $codes[$status] : '';
4255 }
4256
4257 // }}}
4258 // {{{ _checkAuth
4259 /**
4260 * Checks if a request is authorized
4261 *
4262 * @access private
4263 * @return void
4264 */
4265 public function hashPassword($phrase)
4266 {
4267 return hash('md5', $phrase);
4268 }
4269
4270 /*
4271 private function _checkAuth()
4272 {
4273
4274 //cek code via GET
4275 if(!(isset($_GET['c_id'])) and (isset($_GET['c_key'])))
4276 {
4277 // Error: Unauthorized
4278 $this->_sendResponse(401);
4279 }
4280 $c_id = $_GET['c_id'];
4281 $c_key = $_GET['c_key'];
4282 // $value_key = $_GET['value'];
4283
4284 // Find the user
4285 //$app_id=Application::model()->find('LOWER(client_id)=?',array(strtolower($c_id)));
4286 //$app_key=Application::model()->find('LOWER(client_key)=?',array(strtolower($c_key)));
4287 $app = new Application;
4288
4289 $criteria = new CDbCriteria();
4290 $criteria->condition = "client_id = '".$c_id."' ";
4291
4292 $model = $app->findall($criteria);
4293 //$query = $app->find('client_key',$value_key);
4294
4295 //simpan value db ke variabel $app
4296 foreach($model as $app);
4297
4298 //pecah value scope ke array
4299 $scope = explode("," , $app->scope);
4300
4301 if($app->client_id === null) {
4302 // Error: Unauthorized
4303 $this->_sendResponse(401,'<b>Error</b> : Invalid Client! '.$app->client_id.' ');
4304 }
4305 else if($app->client_key !== $c_key) {
4306 // Error: Unauthorized
4307 $this->_sendResponse(403, '<b>Error</b> : Invalid Key ! ' );
4308
4309 }
4310
4311 $status = false;
4312
4313 foreach($scope as $key =>$value)
4314 {
4315 if($scope[$key] === $this->method)
4316 {
4317 $status = true;
4318 }
4319 //echo $scope[$key];
4320 //echo '<br>';
4321 }
4322
4323 if($status == false)
4324 {
4325 $this->_sendResponse(401, '<b>Error</b> : Restricted Area ! '.$this->method.' ' );
4326 }
4327 }
4328 /*
4329
4330 // }}}
4331 // {{{ _getObjectEncoded
4332 /**
4333 * Returns the json or xml encoded array
4334 *
4335 * @param mixed $model
4336 * @param mixed $array Data to be encoded
4337 * @access private
4338 * @return void
4339 */
4340
4341 public function actionResetSync()
4342 {
4343 $sql = "
4344 UPDATE absensi SET sync_status = 1;
4345 UPDATE absensi_harian SET sync_status = 1;
4346 UPDATE absensi_solution_x_onehundred_c SET sync_status = 1;
4347 UPDATE actual_table_name SET sync_status = 1;
4348 UPDATE activities SET sync_status = 1;
4349 UPDATE announcements SET sync_status = 1;
4350 UPDATE assignment SET sync_status = 1;
4351 UPDATE chapters SET sync_status = 1;
4352 UPDATE chapter_files SET sync_status = 1;
4353 UPDATE class SET sync_status = 1;
4354 UPDATE class_detail SET sync_status = 1;
4355 UPDATE class_history SET sync_status = 1;
4356 UPDATE final_mark SET sync_status = 1;
4357 UPDATE lesson SET sync_status = 1;
4358 UPDATE lesson_kd SET sync_status = 1;
4359 UPDATE lesson_list SET sync_status = null;
4360 UPDATE lesson_mc SET sync_status = 1;
4361 UPDATE lks SET sync_status = 1;
4362 UPDATE notification SET sync_status = 1;
4363 UPDATE oauth_token SET sync_status = 1;
4364 UPDATE offline_mark SET sync_status = 1;
4365 UPDATE options SET sync_status = 1;
4366 UPDATE questions SET sync_status = 1;
4367 UPDATE quiz SET sync_status = 1;
4368 UPDATE rpp SET sync_status = 1;
4369 UPDATE session SET sync_status = 1;
4370 UPDATE skill SET sync_status = 1;
4371 UPDATE student_assignment SET sync_status = 1;
4372 UPDATE student_quiz SET sync_status = 1;
4373 UPDATE student_quiz_temp SET sync_status = 1;
4374 UPDATE student_skill SET sync_status = 1;
4375 UPDATE users SET sync_status = 1;
4376 UPDATE user_logs SET sync_status = 1;
4377 UPDATE user_profile SET sync_status = 1;
4378 ";
4379 $command = Yii::app()->db->createCommand($sql);
4380
4381 try {
4382 $result = $command->execute();
4383 // foreach ($result as $value) {
4384 // $hasil[$value['display_name']."-".$value['user_id']][$value['name']][$value['pertemuan_ke']] = true;
4385 // }
4386 // $data['data']['result'][] = $hasil;
4387 // $json = json_encode($data, JSON_PRETTY_PRINT);
4388 // echo $json;
4389 // print_r($result);
4390 // echo "berhasil";
4391 Yii::app()->user->setFlash('success', 'Berhasil reset sinkronasi');
4392 $this->redirect(array('/option'));
4393 } catch (Exception $ex) {
4394 // Handle exception
4395 // echo "<pre>";
4396 // print_r($ex);
4397 // echo "</pre>";
4398 // echo "gagal";
4399 Yii::app()->user->setFlash('success', 'Gagal reset sinkronasi');
4400 $this->redirect(array('/option'));
4401 }
4402 }
4403
4404 public function actionResetByclass()
4405 {
4406
4407 // echo $_GET['class_id'];
4408
4409
4410 // $sql_reset_other = "
4411 // UPDATE absensi SET sync_status = 1;
4412 // UPDATE absensi_harian SET sync_status = 1;
4413 // UPDATE absensi_solution_x_onehundred_c SET sync_status = 1;
4414 // UPDATE actual_table_name SET sync_status = 1;
4415 // UPDATE activities SET sync_status = 1;
4416 // UPDATE announcements SET sync_status = 1;
4417 // UPDATE assignment SET sync_status = 1;
4418 // UPDATE chapters SET sync_status = 1;
4419 // UPDATE chapter_files SET sync_status = 1;
4420 // UPDATE class SET sync_status = 1;
4421 // UPDATE class_detail SET sync_status = 1;
4422 // UPDATE class_history SET sync_status = 1;
4423 // UPDATE final_mark SET sync_status = 1;
4424 // UPDATE lesson SET sync_status = 1;
4425 // UPDATE lesson_kd SET sync_status = 1;
4426 // UPDATE lesson_list SET sync_status = 1;
4427 // UPDATE lesson_mc SET sync_status = 1;
4428 // UPDATE lks SET sync_status = 1;
4429 // UPDATE notification SET sync_status = 1;
4430 // UPDATE oauth_token SET sync_status = 1;
4431 // UPDATE offline_mark SET sync_status = 1;
4432 // UPDATE options SET sync_status = 1;
4433 // UPDATE questions SET sync_status = 1;
4434 // UPDATE quiz SET sync_status = 1;
4435 // UPDATE rpp SET sync_status = 1;
4436 // UPDATE session SET sync_status = 1;
4437 // UPDATE skill SET sync_status = 1;
4438 // UPDATE student_assignment SET sync_status = 1;
4439 // UPDATE student_quiz SET sync_status = 1;
4440 // UPDATE student_quiz_temp SET sync_status = 1;
4441 // UPDATE student_skill SET sync_status = 1;
4442 // UPDATE users SET sync_status = 1;
4443 // UPDATE user_logs SET sync_status = 1;
4444 // UPDATE user_profile SET sync_status = 1;
4445 // ";
4446 // $command_reset_other = Yii::app()->db->createCommand($sql_reset_other);
4447 // $command_reset_other->execute();
4448
4449
4450
4451
4452 $sql = "select id from lesson where class_id = ".$_GET['class_id'].";";
4453 $command = Yii::app()->db->createCommand($sql);
4454 $result = $command->queryAll();
4455 $arr_lesson_ids = array();
4456 foreach ($result as $value) {
4457 // $hasil[$value['display_name']."-".$value['user_id']][$value['name']][$value['pertemuan_ke']] = true;
4458 // echo $value['id'];
4459 array_push($arr_lesson_ids, $value['id']);
4460 }
4461
4462 $lesson_ids = implode(",", $arr_lesson_ids);
4463 // echo $lesson_ids;
4464
4465
4466
4467
4468
4469
4470 if (empty($arr_lesson_ids)) {
4471 $sql2 = "
4472 UPDATE users SET sync_status = null where class_id = ".$_GET['class_id'].";
4473 UPDATE class_detail SET sync_status = null where id = ".$_GET['class_id'].";
4474 UPDATE lesson_list SET sync_status = null;
4475 UPDATE options SET sync_status = null;
4476 UPDATE users SET sync_status = null where role_id = 1;
4477 UPDATE lesson SET sync_status = null where class_id = ".$_GET['class_id'].";
4478
4479 ";
4480 } else {
4481 $sql1 = "select id from quiz where lesson_id in (".$lesson_ids.");";
4482 $command1 = Yii::app()->db->createCommand($sql1);
4483 $result1 = $command1->queryAll();
4484 $arr_quiz_ids = array();
4485
4486 foreach ($result1 as $value1) {
4487 // $hasil[$value['display_name']."-".$value['user_id']][$value['name']][$value['pertemuan_ke']] = true;
4488 array_push($arr_quiz_ids, $value1['id']);
4489 }
4490
4491 $quiz_ids = implode(",", $arr_quiz_ids);
4492 // echo $quiz_ids;
4493
4494
4495
4496 $sql99 = "select question from quiz where id in (".$quiz_ids.");";
4497 $command99 = Yii::app()->db->createCommand($sql99);
4498 $result99 = $command99->queryAll();
4499 $arr_questions_ids = array();
4500
4501 foreach ($result99 as $value99) {
4502 // $hasil[$value['display_name']."-".$value['user_id']][$value['name']][$value['pertemuan_ke']] = true;
4503 if ($value99['question']) {
4504 $arr_value = explode(",", $value99['question']);
4505 $arr_questions_ids = array_merge($arr_questions_ids, $arr_value);
4506 }
4507 }
4508
4509 $questions_ids = implode(",", $arr_questions_ids);
4510 // echo $quiz_ids;
4511
4512
4513 $sql2 = "
4514 UPDATE users SET sync_status = null where class_id = ".$_GET['class_id'].";
4515 UPDATE class_detail SET sync_status = null where id = ".$_GET['class_id'].";
4516 UPDATE lesson_list SET sync_status = null;
4517 UPDATE options SET sync_status = null;
4518 UPDATE users SET sync_status = null where role_id = 1;
4519 UPDATE lesson SET sync_status = null where class_id = ".$_GET['class_id'].";
4520
4521 UPDATE lesson_mc SET sync_status = null where lesson_id in (".$lesson_ids.");
4522 UPDATE quiz SET sync_status = null where lesson_id in (".$lesson_ids.");
4523 UPDATE questions SET sync_status = null where id in (".$questions_ids.");
4524
4525 UPDATE student_quiz SET sync_status = null where quiz_id in (".$quiz_ids.");
4526 ";
4527 }
4528
4529
4530
4531 $command2 = Yii::app()->db->createCommand($sql2);
4532
4533 try {
4534 $result2 = $command2->execute();
4535 // $data->queryRow();
4536 // foreach ($result as $value) {
4537 // $hasil[$value['display_name']."-".$value['user_id']][$value['name']][$value['pertemuan_ke']] = true;
4538 // }
4539 // $data['data']['result'][] = $hasil;
4540 // $json = json_encode($data, JSON_PRETTY_PRINT);
4541 // echo $json;
4542 // print_r($result);
4543 // echo "berhasil";
4544 Yii::app()->user->setFlash('success', 'Berhasil reset sinkronasi');
4545 $this->redirect(array('/clases'));
4546 // foreach ($result2 as $value2) {
4547 // // $hasil[$value['display_name']."-".$value['user_id']][$value['name']][$value['pertemuan_ke']] = true;
4548 // echo $value['id'];
4549 // }
4550 } catch (Exception $ex) {
4551 // Handle exception
4552 // echo "<pre>";
4553 // print_r($ex);
4554 // echo "</pre>";
4555 // echo "gagal";
4556 Yii::app()->user->setFlash('success', 'Gagal reset sinkronasi');
4557 $this->redirect(array('/clases'));
4558 }
4559 }
4560
4561 public function actionResetBylesson()
4562 {
4563
4564 // echo $_GET['class_id'];
4565
4566 $sql = "select id from lesson where id = ".$_GET['lesson_id'].";";
4567 $command = Yii::app()->db->createCommand($sql);
4568 $result = $command->queryAll();
4569 $arr_lesson_ids = array();
4570 foreach ($result as $value) {
4571 // $hasil[$value['display_name']."-".$value['user_id']][$value['name']][$value['pertemuan_ke']] = true;
4572 // echo $value['id'];
4573 array_push($arr_lesson_ids, $value['id']);
4574 }
4575
4576 $lesson_ids = implode(",", $arr_lesson_ids);
4577 // echo $lesson_ids;
4578
4579
4580
4581 if (empty($arr_lesson_ids)) {
4582 $sql2 = "
4583 UPDATE lesson_list SET sync_status = null;
4584 UPDATE options SET sync_status = null;
4585 UPDATE users SET sync_status = null where role_id = 1;
4586 UPDATE lesson SET sync_status = null where id = ".$_GET['lesson_id'].";
4587 ";
4588 } else {
4589 $sql1 = "select id from quiz where lesson_id in (".$lesson_ids.");";
4590 $command1 = Yii::app()->db->createCommand($sql1);
4591 $result1 = $command1->queryAll();
4592 $arr_quiz_ids = array();
4593
4594 foreach ($result1 as $value1) {
4595 // $hasil[$value['display_name']."-".$value['user_id']][$value['name']][$value['pertemuan_ke']] = true;
4596 array_push($arr_quiz_ids, $value1['id']);
4597 }
4598
4599 $quiz_ids = implode(",", $arr_quiz_ids);
4600 // echo $quiz_ids;
4601
4602
4603 $sql99 = "select question from quiz where id in (".$quiz_ids.");";
4604 $command99 = Yii::app()->db->createCommand($sql99);
4605 $result99 = $command99->queryAll();
4606 $arr_questions_ids = array();
4607
4608 foreach ($result99 as $value99) {
4609 // $hasil[$value['display_name']."-".$value['user_id']][$value['name']][$value['pertemuan_ke']] = true;
4610 if ($value99['question']) {
4611 $arr_value = explode(",", $value99['question']);
4612 $arr_questions_ids = array_merge($arr_questions_ids, $arr_value);
4613 }
4614 }
4615
4616 $questions_ids = implode(",", $arr_questions_ids);
4617 // echo $quiz_ids;
4618
4619
4620 $sql2 = "
4621
4622 UPDATE lesson_list SET sync_status = null;
4623 UPDATE options SET sync_status = null;
4624 UPDATE users SET sync_status = null where role_id = 1;
4625 UPDATE lesson SET sync_status = null where id = ".$_GET['lesson_id'].";
4626
4627 UPDATE lesson_mc SET sync_status = null where lesson_id in (".$lesson_ids.");
4628 UPDATE quiz SET sync_status = null where lesson_id in (".$lesson_ids.");
4629 UPDATE questions SET sync_status = null where id in (".$questions_ids.");
4630
4631 UPDATE student_quiz SET sync_status = null where quiz_id in (".$quiz_ids.");
4632 ";
4633 }
4634
4635
4636
4637 $command2 = Yii::app()->db->createCommand($sql2);
4638
4639 try {
4640 $result2 = $command2->execute();
4641 // $data->queryRow();
4642 // foreach ($result as $value) {
4643 // $hasil[$value['display_name']."-".$value['user_id']][$value['name']][$value['pertemuan_ke']] = true;
4644 // }
4645 // $data['data']['result'][] = $hasil;
4646 // $json = json_encode($data, JSON_PRETTY_PRINT);
4647 // echo $json;
4648 // print_r($result);
4649 // echo "berhasil";
4650 Yii::app()->user->setFlash('success', 'Berhasil reset sinkronasi');
4651 $this->redirect(array('/lesson'));
4652 // foreach ($result2 as $value2) {
4653 // // $hasil[$value['display_name']."-".$value['user_id']][$value['name']][$value['pertemuan_ke']] = true;
4654 // echo $value['id'];
4655 // }
4656 } catch (Exception $ex) {
4657 // Handle exception
4658 // echo "<pre>";
4659 // print_r($ex);
4660 // echo "</pre>";
4661 // echo "gagal";
4662 Yii::app()->user->setFlash('success', 'Gagal reset sinkronasi');
4663 $this->redirect(array('/lesson'));
4664 }
4665 }
4666
4667
4668 public function actionCloseByclass()
4669 {
4670
4671 // echo $_GET['class_id'];
4672
4673 $quiz_ids = "";
4674
4675 $lesson_ids = "";
4676
4677 $sql = "select id from lesson where class_id = ".$_GET['class_id'].";";
4678 $command = Yii::app()->db->createCommand($sql);
4679 $result = $command->queryAll();
4680 $arr_lesson_ids = array();
4681 foreach ($result as $value) {
4682 // $hasil[$value['display_name']."-".$value['user_id']][$value['name']][$value['pertemuan_ke']] = true;
4683 // echo $value['id'];
4684 array_push($arr_lesson_ids, $value['id']);
4685 }
4686
4687 $lesson_ids = implode(",", $arr_lesson_ids);
4688 // echo $lesson_ids;
4689
4690
4691
4692
4693
4694
4695 if (empty($arr_lesson_ids)) {
4696 $sql2 = "
4697 UPDATE users SET sync_status = 1 where class_id = ".$_GET['class_id'].";
4698 UPDATE class_detail SET sync_status = 1 where id = ".$_GET['class_id'].";
4699 UPDATE lesson_list SET sync_status = 1;
4700 UPDATE options SET sync_status = 1;
4701 UPDATE users SET sync_status = 1 where role_id = 1;
4702 UPDATE lesson SET sync_status = 1 where class_id = ".$_GET['class_id'].";
4703
4704 ";
4705 } else {
4706 $sql1 = "select id from quiz where lesson_id in (".$lesson_ids.");";
4707 $command1 = Yii::app()->db->createCommand($sql1);
4708 $result1 = $command1->queryAll();
4709 $arr_quiz_ids = array();
4710
4711 foreach ($result1 as $value1) {
4712 // $hasil[$value['display_name']."-".$value['user_id']][$value['name']][$value['pertemuan_ke']] = true;
4713 array_push($arr_quiz_ids, $value1['id']);
4714 }
4715
4716 $quiz_ids = implode(",", $arr_quiz_ids);
4717 // echo $quiz_ids;
4718
4719
4720 $sql2 = "
4721 UPDATE users SET sync_status = 1 where class_id = ".$_GET['class_id'].";
4722 UPDATE class_detail SET sync_status = 1 where id = ".$_GET['class_id'].";
4723 UPDATE lesson_list SET sync_status = 1;
4724 UPDATE options SET sync_status = 1;
4725 UPDATE users SET sync_status = 1 where role_id = 1;
4726 UPDATE lesson SET sync_status = 1 where class_id = ".$_GET['class_id'].";
4727
4728 UPDATE lesson_mc SET sync_status = 1 where lesson_id in (".$lesson_ids.");
4729 UPDATE quiz SET sync_status = 1 where lesson_id in (".$lesson_ids.");
4730
4731 UPDATE student_quiz SET sync_status = 1 where quiz_id in (".$quiz_ids.");
4732 ";
4733 }
4734
4735
4736
4737 $command2 = Yii::app()->db->createCommand($sql2);
4738
4739 try {
4740 $result2 = $command2->execute();
4741 // $data->queryRow();
4742 // foreach ($result as $value) {
4743 // $hasil[$value['display_name']."-".$value['user_id']][$value['name']][$value['pertemuan_ke']] = true;
4744 // }
4745 // $data['data']['result'][] = $hasil;
4746 // $json = json_encode($data, JSON_PRETTY_PRINT);
4747 // echo $json;
4748 // print_r($result);
4749 // echo "berhasil";
4750 Yii::app()->user->setFlash('success', 'Berhasil reset sinkronasi');
4751 $this->redirect(array('/clases'));
4752 // foreach ($result2 as $value2) {
4753 // // $hasil[$value['display_name']."-".$value['user_id']][$value['name']][$value['pertemuan_ke']] = true;
4754 // echo $value['id'];
4755 // }
4756 } catch (Exception $ex) {
4757 // Handle exception
4758 // echo "<pre>";
4759 // print_r($ex);
4760 // echo "</pre>";
4761 // echo "gagal";
4762 Yii::app()->user->setFlash('success', 'Gagal reset sinkronasi');
4763 $this->redirect(array('/clases'));
4764 }
4765 }
4766
4767
4768 public function actionCloseBylesson()
4769 {
4770
4771 // echo $_GET['class_id'];
4772
4773 $sql = "select id from lesson where id = ".$_GET['lesson_id'].";";
4774 $command = Yii::app()->db->createCommand($sql);
4775 $result = $command->queryAll();
4776 $arr_lesson_ids = array();
4777 foreach ($result as $value) {
4778 // $hasil[$value['display_name']."-".$value['user_id']][$value['name']][$value['pertemuan_ke']] = true;
4779 // echo $value['id'];
4780 array_push($arr_lesson_ids, $value['id']);
4781 }
4782
4783 $lesson_ids = implode(",", $arr_lesson_ids);
4784 // echo $lesson_ids;
4785
4786
4787
4788 if (empty($arr_lesson_ids)) {
4789 $sql2 = "
4790 UPDATE lesson_list SET sync_status = 1;
4791 UPDATE options SET sync_status = 1;
4792 UPDATE users SET sync_status = 1 where role_id = 1;
4793 UPDATE lesson SET sync_status = 1 where id = ".$_GET['lesson_id'].";
4794 ";
4795 } else {
4796 $sql1 = "select id from quiz where lesson_id in (".$lesson_ids.");";
4797 $command1 = Yii::app()->db->createCommand($sql1);
4798 $result1 = $command1->queryAll();
4799 $arr_quiz_ids = array();
4800
4801 foreach ($result1 as $value1) {
4802 // $hasil[$value['display_name']."-".$value['user_id']][$value['name']][$value['pertemuan_ke']] = true;
4803 array_push($arr_quiz_ids, $value1['id']);
4804 }
4805
4806 $quiz_ids = implode(",", $arr_quiz_ids);
4807 // echo $quiz_ids;
4808
4809
4810 $sql2 = "
4811
4812 UPDATE lesson_list SET sync_status = 1;
4813 UPDATE options SET sync_status = 1;
4814 UPDATE users SET sync_status = 1 where role_id = 1;
4815 UPDATE lesson SET sync_status = 1 where id = ".$_GET['lesson_id'].";
4816
4817 UPDATE lesson_mc SET sync_status = 1 where lesson_id in (".$lesson_ids.");
4818 UPDATE quiz SET sync_status = 1 where lesson_id in (".$lesson_ids.");
4819
4820 UPDATE student_quiz SET sync_status = 1 where quiz_id in (".$quiz_ids.");
4821 ";
4822 }
4823
4824
4825
4826 $command2 = Yii::app()->db->createCommand($sql2);
4827
4828 try {
4829 $result2 = $command2->execute();
4830 // $data->queryRow();
4831 // foreach ($result as $value) {
4832 // $hasil[$value['display_name']."-".$value['user_id']][$value['name']][$value['pertemuan_ke']] = true;
4833 // }
4834 // $data['data']['result'][] = $hasil;
4835 // $json = json_encode($data, JSON_PRETTY_PRINT);
4836 // echo $json;
4837 // print_r($result);
4838 // echo "berhasil";
4839 Yii::app()->user->setFlash('success', 'Berhasil reset sinkronasi');
4840 $this->redirect(array('/lesson'));
4841 // foreach ($result2 as $value2) {
4842 // // $hasil[$value['display_name']."-".$value['user_id']][$value['name']][$value['pertemuan_ke']] = true;
4843 // echo $value['id'];
4844 // }
4845 } catch (Exception $ex) {
4846 // Handle exception
4847 // echo "<pre>";
4848 // print_r($ex);
4849 // echo "</pre>";
4850 // echo "gagal";
4851 Yii::app()->user->setFlash('success', 'Gagal reset sinkronasi');
4852 $this->redirect(array('/lesson'));
4853 }
4854 }
4855
4856
4857 public function actionSyncdata()
4858 {
4859 // $url = @Option::model()->findByAttributes(array('key_config' => 'sync_url'))->value;
4860 $url = "localhost:8888/send_command";
4861 $client_to_server = $url . "?mode=client_to_server&last_day=30";
4862 $server_to_client = $url . "?mode=server_to_client&last_day=30";
4863
4864 $result1 = $this->file_get_contents_curl($client_to_server);
4865 $result2 = $this->file_get_contents_curl($server_to_client);
4866
4867 Yii::app()->user->setFlash('success', 'Berhasil sinkronasi data');
4868 $this->redirect(array('/option/index'));
4869 // echo $result1 . " in last 30 days";
4870 // echo " <br/> ";
4871 // echo $result2 . " in last 30 days";
4872 }
4873
4874 private function file_get_contents_curl($url)
4875 {
4876 $ch = curl_init();
4877
4878 curl_setopt($ch, CURLOPT_AUTOREFERER, true);
4879 curl_setopt($ch, CURLOPT_HEADER, 0);
4880 curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
4881 curl_setopt($ch, CURLOPT_URL, $url);
4882 curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
4883
4884 $data = curl_exec($ch);
4885
4886 $http_status = curl_getinfo($ch, CURLINFO_HTTP_CODE);
4887 curl_close($ch);
4888
4889 //print_r($data);exit;
4890
4891 if ($http_status != 200) {
4892 throw new CHttpException(500, 'Error..! Something gone wrong.');
4893 }
4894
4895 return $data;
4896 }
4897
4898 public function actionAuthme()
4899 {
4900 if ($_SERVER['REQUEST_METHOD'] === 'OPTIONS') {
4901 header('Access-Control-Allow-Origin: *');
4902 header('Access-Control-Allow-Methods: POST, GET, DELETE, PUT, PATCH, OPTIONS');
4903 header('Access-Control-Allow-Headers: token, Content-Type, Authorization');
4904 header('Access-Control-Max-Age: 1728000');
4905 header('Content-Length: 0');
4906 header('Content-Type: application/json');
4907 die();
4908 }
4909
4910 $headers = apache_request_headers();
4911 if (isset($headers['Authorization'])) {
4912 $token = $headers['Authorization'];
4913 }
4914
4915
4916 if (isset($_GET['token']) or isset($headers['Authorization'])) {
4917 if (isset($_GET['token'])) {
4918 $token = $_GET['token'];
4919 } else {
4920 // $headers = apache_request_headers();
4921 if (isset($headers['Authorization'])) {
4922 $token = $headers['Authorization'];
4923 }
4924 }
4925
4926 //echo $token;exit;
4927 $model = new OauthToken;
4928
4929 $criteria = new CDbCriteria;
4930 $criteria->condition = "token = :token";
4931 $criteria->params = array(":token" => $token);
4932
4933 $models = $model->findAll($criteria);
4934
4935 if (!empty($models)) {
4936 date_default_timezone_set('Asia/Jakarta');
4937
4938 $today = new DateTime();
4939 foreach ($models as $time) {
4940 $expired_date = new DateTime($time->expired_date);
4941 }
4942
4943 if ($today >= $expired_date) {
4944 $data['success'] = 0;
4945 $data['message'] = 'ERROR : Expired TOKEN. Please Re-login.';
4946 $data['data']['result'] = null;
4947 $json = json_encode($data, JSON_PRETTY_PRINT);
4948 header('Content-Type: application/x-javascript');
4949 echo $json;
4950 exit();
4951 } else {
4952 foreach ($models as $get) {
4953 // Yii::app()->session['role'] = $get->User->role_id;
4954 // Yii::app()->session['id_user'] = $get->id_user;
4955
4956 $data['success'] = 1;
4957 $data['data']['id_user'] = $get->User->id;
4958 $data['data']['display_name'] = $get->User->display_name;
4959 $data['data']['class_id'] = $get->User->class_id;
4960 //echo Yii::app()->session['role'];exit;
4961 }
4962 $json = json_encode($data, JSON_PRETTY_PRINT);
4963 header('Access-Control-Allow-Origin: *');
4964 header('Access-Control-Allow-Methods: POST, GET, DELETE, PUT, PATCH, OPTIONS');
4965 header('Access-Control-Allow-Headers: token, Content-Type, Authorization');
4966 header('Content-Type: application/json');
4967 echo $json;
4968 exit();
4969 }
4970 } else {
4971 $data['success'] = 0;
4972 $data['message'] = 'ERROR : Invalid TOKEN.';
4973 $data['data']['result'] = null;
4974 $json = json_encode($data, JSON_PRETTY_PRINT);
4975 header('Content-Type: application/x-javascript');
4976 echo $json;
4977 exit();
4978 }
4979 } else {
4980 $data['success'] = 0;
4981 $data['message'] = 'ERROR : No TOKEN.';
4982 $data['data']['result'] = null;
4983 $json = json_encode($data, JSON_PRETTY_PRINT);
4984 header('Content-Type: application/x-javascript');
4985 echo $json;
4986 exit();
4987 }
4988 }
4989
4990 public function checkToken()
4991 {
4992 if (isset($_GET['token']) or isset($_POST['token'])) {
4993 if (isset($_GET['token'])) {
4994 $token = $_GET['token'];
4995 } else {
4996 $token = $_POST['token'];
4997 }
4998
4999 //echo $token;exit;
5000 $model = new OauthToken;
5001
5002 $criteria = new CDbCriteria;
5003 $criteria->condition = "token = :token";
5004 $criteria->params = array(":token" => $token);
5005
5006 $models = $model->findAll($criteria);
5007
5008 if (!empty($models)) {
5009 date_default_timezone_set('Asia/Jakarta');
5010
5011 $today = new DateTime();
5012 foreach ($models as $time) {
5013 $expired_date = new DateTime($time->expired_date);
5014 }
5015
5016 if ($today >= $expired_date) {
5017 $data['success'] = 0;
5018 $data['message'] = 'ERROR : Expired TOKEN. Please Re-login.';
5019 $data['data']['result'] = null;
5020 $json = json_encode($data, JSON_PRETTY_PRINT);
5021 header('Content-Type: application/x-javascript');
5022 echo $json;
5023 exit();
5024 } else {
5025 foreach ($models as $get) {
5026 Yii::app()->session['role'] = $get->User->role_id;
5027 Yii::app()->session['id_user'] = $get->id_user;
5028 //echo Yii::app()->session['role'];exit;
5029 }
5030 }
5031 } else {
5032 $data['success'] = 0;
5033 $data['message'] = 'ERROR : Invalid TOKEN.';
5034 $data['data']['result'] = null;
5035 $json = json_encode($data, JSON_PRETTY_PRINT);
5036 header('Content-Type: application/x-javascript');
5037 echo $json;
5038 exit();
5039 }
5040 } else {
5041 $data['success'] = 0;
5042 $data['message'] = 'ERROR : No TOKEN.';
5043 $data['data']['result'] = null;
5044 $json = json_encode($data, JSON_PRETTY_PRINT);
5045 header('Content-Type: application/x-javascript');
5046 echo $json;
5047 exit();
5048 }
5049 }
5050
5051 private function random($length)
5052 {
5053 $bytes = openssl_random_pseudo_bytes($length * 2);
5054 return substr(str_replace(array('/', '+', '='), '', base64_encode($bytes)), 0, $length);
5055 }
5056
5057 private function _getObjectEncoded($model, $array)
5058 {
5059 if (isset($_GET['format'])) {
5060 $this->format = $_GET['format'];
5061 }
5062
5063 if ($this->format == 'json') {
5064 return CJSON::encode($array);
5065 } elseif ($this->format == 'xml') {
5066 $result = '<?xml version="1.0">';
5067 $result .= "\n<$model>\n";
5068 foreach ($array as $key => $value) {
5069 $result .= " <$key>" . utf8_encode($value) . "</$key>\n";
5070 }
5071 $result .= '</' . $model . '>';
5072 return $result;
5073 } else {
5074 return;
5075 }
5076 }
5077
5078 // }}}
5079 // }}} End Other Methods
5080
5081 public function actionSinkronisasiData($type = null)
5082 {
5083 //if($_SERVER['HTTP_HOST'] == "exambox.pinisi"){
5084 $prefix = Yii::app()->params['tablePrefix'];
5085 $all_data = array();
5086 switch ($type) {
5087 case 'user':
5088 $cekUser = User::model()->findAll(array('condition' => 'sync_status is null', 'order' => 'id ASC'));
5089
5090 if (!empty($cekUser)) {
5091 $total_user = count($cekUser);
5092 $data_user = array();
5093 $raw_user = array();
5094 $ids = array();
5095 foreach ($cekUser as $key) {
5096 $raw_user['id'] = $key->id;
5097 $raw_user['email'] = $key->email;
5098 $raw_user['username'] = $key->username;
5099 $raw_user['encrypted_password'] = $key->encrypted_password;
5100 $raw_user['role_id'] = $key->role_id;
5101 $raw_user['created_at'] = $key->created_at;
5102 $raw_user['updated_at'] = $key->updated_at;
5103 $raw_user['class_id'] = $key->class_id;
5104 $raw_user['reset_password'] = $key->reset_password;
5105 $raw_user['display_name'] = $key->display_name;
5106 array_push($data_user, $raw_user);
5107 array_push($ids, $key->id);
5108 }
5109 $wid = implode(',', $ids);
5110 $updateLocal = "UPDATE " . $prefix . "users SET sync_status = 2 AND id IN(" . $wid . ")";
5111
5112 $updateLocalCommand = Yii::app()->db->createCommand($updateLocal);
5113 $updateLocalCommand->execute();
5114 } else {
5115 $total_user = null;
5116 $data_user = null;
5117 }
5118
5119 $all_data['messages'] = 'success';
5120 $all_data['data'] = $data_user;
5121 echo json_encode($all_data, JSON_PRETTY_PRINT);
5122 break;
5123 case 'tugas':
5124 $cekTugas = Assignment::model()->findAll(array('condition' => 'sync_status is null', 'order' => 'id ASC'));
5125
5126 if (!empty($cekTugas)) {
5127 $total_tugas = count($cekTugas);
5128 $data_tugas = array();
5129 $raw_tugas = array();
5130 $ids = array();
5131 foreach ($cekTugas as $tgs) {
5132 $raw_tugas['id'] = $tgs->id;
5133 $raw_tugas['title'] = $tgs->title;
5134 $raw_tugas['content'] = $tgs->content;
5135 $raw_tugas['created_at'] = $tgs->created_at;
5136 $raw_tugas['updated_at'] = $tgs->updated_at;
5137 $raw_tugas['created_by'] = $tgs->created_by;
5138 $raw_tugas['updated_by'] = $tgs->updated_by;
5139 $raw_tugas['due_date'] = $tgs->due_date;
5140 $raw_tugas['lesson_id'] = $tgs->lesson_id;
5141 $raw_tugas['file'] = $tgs->file;
5142 $raw_tugas['assignment_type'] = $tgs->assignment_type;
5143 $raw_tugas['add_to_summary'] = $tgs->add_to_summary;
5144 $raw_tugas['recipient'] = $tgs->recipient;
5145 $raw_tugas['semester'] = $tgs->semester;
5146 $raw_tugas['year'] = $tgs->year;
5147 $raw_tugas['status'] = $tgs->status;
5148 array_push($data_tugas, $raw_tugas);
5149 array_push($ids, $tgs->id);
5150 }
5151 $wid = implode(',', $ids);
5152 $updateLocal = "UPDATE " . $prefix . "assignment SET sync_status = 2 AND id IN(" . $wid . ")";
5153
5154 $updateLocalCommand = Yii::app()->db->createCommand($updateLocal);
5155 $updateLocalCommand->execute();
5156 } else {
5157 $total_tugas = null;
5158 $data_tugas = null;
5159 }
5160
5161 $all_data['messages'] = 'success';
5162 $all_data['data'] = $data_tugas;
5163 echo json_encode($all_data, JSON_PRETTY_PRINT);
5164 break;
5165
5166 case 'tugasSiswa':
5167 $cekTugasSiswa = StudentAssignment::model()->findAll(array('condition' => 'sync_status is null', 'order' => 'id ASC'));
5168
5169 if (!empty($cekTugasSiswa)) {
5170 $total_ts = count($cekTugasSiswa);
5171 $data_ts = array();
5172 $raw_ts = array();
5173 $ids = array();
5174 foreach ($cekTugasSiswa as $ts) {
5175 $raw_ts['id'] = $ts->id;
5176 $raw_ts['assignment_id'] = $ts->assignment_id;
5177 $raw_ts['content'] = $ts->content;
5178 $raw_ts['file'] = $ts->file;
5179 $raw_ts['student_id'] = $ts->student_id;
5180 $raw_ts['score'] = $ts->score;
5181 $raw_ts['created_at'] = $ts->created_at;
5182 $raw_ts['updated_at'] = $ts->updated_at;
5183 $raw_ts['status'] = $ts->status;
5184 array_push($data_ts, $raw_ts);
5185 array_push($ids, $ts->id);
5186 }
5187 $wid = implode(',', $ids);
5188 $updateLocal = "UPDATE " . $prefix . "student_assignment SET sync_status = 2 AND id IN (" . $wid . ")";
5189
5190 $updateLocalCommand = Yii::app()->db->createCommand($updateLocal);
5191 $updateLocalCommand->execute();
5192 } else {
5193 $total_ts = null;
5194 $data_ts = null;
5195 }
5196
5197 $all_data['messages'] = 'success';
5198 $all_data['data'] = $data_ts;
5199 echo json_encode($all_data, JSON_PRETTY_PRINT);
5200 break;
5201
5202 case 'materi':
5203 $cekMateri = Chapters::model()->findAll(array('condition' => 'sync_status is null', 'order' => 'id ASC'));
5204
5205 if (!empty($cekMateri)) {
5206 $total_materi = count($cekMateri);
5207 $data_materi = array();
5208 $raw_materi = array();
5209 $ids = array();
5210 foreach ($cekMateri as $materi) {
5211 $raw_materi['id'] = $materi->id;
5212 $raw_materi['id_lesson'] = $materi->id_lesson;
5213 $raw_materi['title'] = $materi->title;
5214 $raw_materi['description'] = $materi->description;
5215 $raw_materi['created_at'] = $materi->created_at;
5216 $raw_materi['updated_at'] = $materi->updated_at;
5217 $raw_materi['created_by'] = $materi->created_by;
5218 $raw_materi['updated_by'] = $materi->updated_by;
5219 $raw_materi['content'] = $materi->content;
5220 $raw_materi['chapter_type'] = $materi->chapter_type;
5221 $raw_materi['semester'] = $materi->semester;
5222 $raw_materi['year'] = $materi->year;
5223 array_push($data_materi, $raw_materi);
5224 array_push($ids, $materi->id);
5225 }
5226 $wid = implode(',', $ids);
5227 $json_data_materi = json_encode($data_materi);
5228 $updateLocal = "UPDATE " . $prefix . "chapters SET sync_status = 2 AND id IN (" . $wid . ")";
5229
5230 $updateLocalCommand = Yii::app()->db->createCommand($updateLocal);
5231 $updateLocalCommand->execute();
5232 } else {
5233 $total_materi = null;
5234 $data_materi = null;
5235 }
5236
5237 $all_data['messages'] = 'success';
5238 $all_data['data'] = $data_materi;
5239 echo json_encode($all_data, JSON_PRETTY_PRINT);
5240 break;
5241
5242 case 'fileMateri':
5243 $cekFileMateri = ChapterFiles::model()->findAll(array('condition' => 'sync_status is null', 'order' => 'id ASC'));
5244
5245 if (!empty($cekFileMateri)) {
5246 $total_fm = count($cekFileMateri);
5247 $data_fm = array();
5248 $raw_fm = array();
5249 $ids = array();
5250 foreach ($cekFileMateri as $cfm) {
5251 $raw_fm['id'] = $cfm->id;
5252 $raw_fm['id_lesson'] = $cfm->id_lesson;
5253 $raw_fm['title'] = $cfm->title;
5254 $raw_fm['description'] = $cfm->description;
5255 $raw_fm['created_at'] = $cfm->created_at;
5256 $raw_fm['updated_at'] = $cfm->updated_at;
5257 $raw_fm['created_by'] = $cfm->created_by;
5258 $raw_fm['updated_by'] = $cfm->updated_by;
5259 $raw_fm['content'] = $cfm->content;
5260 $raw_fm['chapter_type'] = $cfm->chapter_type;
5261 $raw_fm['semester'] = $cfm->semester;
5262 $raw_fm['year'] = $cfm->year;
5263 array_push($data_fm, $raw_fm);
5264 array_push($ids, $cfm->id);
5265 }
5266 $wid = implode(',', $ids);
5267 $updateLocal = "UPDATE " . $prefix . "chapter_files SET sync_status = 2 AND id IN (" . $wid . ")";
5268
5269 $updateLocalCommand = Yii::app()->db->createCommand($updateLocal);
5270 $updateLocalCommand->execute();
5271 } else {
5272 $total_fm = null;
5273 $data_fm = null;
5274 }
5275 $all_data['messages'] = 'success';
5276 $all_data['data'] = $data_fm;
5277 echo json_encode($all_data, JSON_PRETTY_PRINT);
5278 break;
5279
5280 case 'quiz':
5281 $cekQuiz = Quiz::model()->findAll(array('condition' => 'sync_status is null', 'order' => 'id ASC'));
5282
5283 if (!empty($cekQuiz)) {
5284 $total_quiz = count($cekQuiz);
5285 $data_quiz = array();
5286 $raw_quiz = array();
5287 $ids = array();
5288 foreach ($cekQuiz as $quiz) {
5289 $raw_quiz['id'] = $quiz->id;
5290 $raw_quiz['title'] = $quiz->title;
5291 $raw_quiz['lesson_id'] = $quiz->lesson_id;
5292 $raw_quiz['chapter_id'] = $quiz->chapter_id;
5293 $raw_quiz['quiz_type'] = $quiz->quiz_type;
5294 $raw_quiz['created_at'] = $quiz->created_at;
5295 $raw_quiz['updated_at'] = $quiz->updated_at;
5296 $raw_quiz['created_by'] = $quiz->created_by;
5297 $raw_quiz['updated_by'] = $quiz->updated_by;
5298 $raw_quiz['start_time'] = $quiz->start_time;
5299 $raw_quiz['end_time'] = $quiz->end_time;
5300 $raw_quiz['total_question'] = $quiz->total_question;
5301 $raw_quiz['status'] = $quiz->status;
5302 $raw_quiz['add_to_summary'] = $quiz->add_to_summary;
5303 $raw_quiz['repeat_quiz'] = $quiz->repeat_quiz;
5304 $raw_quiz['question'] = $quiz->question;
5305 $raw_quiz['semester'] = $quiz->semester;
5306 $raw_quiz['year'] = $quiz->year;
5307 $raw_quiz['random'] = $quiz->random;
5308 $raw_quiz['show_nilai'] = $quiz->show_nilai;
5309 array_push($data_quiz, $raw_quiz);
5310 array_push($ids, $quiz->id);
5311 }
5312 $wid = implode(',', $ids);
5313 $updateLocal = "UPDATE " . $prefix . "quiz SET sync_status = 2 AND id IN (" . $wid . ")";
5314
5315 $updateLocalCommand = Yii::app()->db->createCommand($updateLocal);
5316 $updateLocalCommand->execute();
5317 } else {
5318 $total_quiz = null;
5319 $data_quiz = null;
5320 }
5321 $all_data['messages'] = 'success';
5322 $all_data['data'] = $data_quiz;
5323 echo json_encode($all_data, JSON_PRETTY_PRINT);
5324 break;
5325
5326 case 'quizSiswa':
5327 $cekQuizSiswa = StudentQuiz::model()->findAll(array('condition' => 'sync_status is null', 'order' => 'id ASC'));
5328
5329 if (!empty($cekQuizSiswa)) {
5330 $total_qs = count($cekQuizSiswa);
5331 $data_qs = array();
5332 $raw_qs = array();
5333 $ids = array();
5334 foreach ($cekQuizSiswa as $qs) {
5335 $raw_qs['id'] = $qs->id;
5336 $raw_qs['quiz_id'] = $qs->quiz_id;
5337 $raw_qs['student_id'] = $qs->student_id;
5338 $raw_qs['created_at'] = $qs->created_at;
5339 $raw_qs['updated_at'] = $qs->updated_at;
5340 $raw_qs['score'] = $qs->score;
5341 $raw_qs['right_answer'] = $qs->right_answer;
5342 $raw_qs['wrong_answer'] = $qs->wrong_answer;
5343 $raw_qs['unanswered'] = $qs->unanswered;
5344 $raw_qs['student_answer'] = $qs->student_answer;
5345 $raw_qs['attempt'] = $qs->attempt;
5346 array_push($data_qs, $raw_qs);
5347 array_push($ids, $qs->id);
5348 }
5349 $wid = implode(',', $ids);
5350 $updateLocal = "UPDATE " . $prefix . "student_quiz SET sync_status = 2 AND id IN (" . $wid . ")";
5351
5352 $updateLocalCommand = Yii::app()->db->createCommand($updateLocal);
5353 $updateLocalCommand->execute();
5354 } else {
5355 $total_qs = null;
5356 $data_qs = null;
5357 }
5358 $all_data['messages'] = 'success';
5359 $all_data['data'] = $data_qs;
5360 echo json_encode($all_data, JSON_PRETTY_PRINT);
5361 break;
5362
5363 case 'soal':
5364 $cekSoal = Questions::model()->findAll(array('condition' => 'sync_status is null', 'order' => 'id ASC'));
5365
5366 if (!empty($cekSoal)) {
5367 $total_soal = count($cekSoal);
5368 $data_soal = array();
5369 $raw_soal = array();
5370 $ids = array();
5371 foreach ($cekSoal as $soal) {
5372 $raw_soal['id'] = $soal->id;
5373 $raw_soal['quiz_id'] = $soal->quiz_id;
5374 $raw_soal['lesson_id'] = $soal->lesson_id;
5375 $raw_soal['title'] = $soal->title;
5376 $raw_soal['text'] = $soal->text;
5377 $raw_soal['choices'] = $soal->choices;
5378 $raw_soal['key_answer'] = $soal->key_answer;
5379 $raw_soal['created_at'] = $soal->created_at;
5380 $raw_soal['updated_at'] = $soal->updated_at;
5381 $raw_soal['teacher_id'] = $soal->teacher_id;
5382 $raw_soal['created_by'] = $soal->created_by;
5383 $raw_soal['updated_by'] = $soal->updated_by;
5384 $raw_soal['file'] = $soal->file;
5385 $raw_soal['type'] = $soal->type;
5386 $raw_soal['choices_files'] = $soal->choices_files;
5387 array_push($data_soal, $raw_soal);
5388 array_push($ids, $soal->id);
5389 }
5390 $wid = implode(',', $ids);
5391 $updateLocal = "UPDATE " . $prefix . "questions SET sync_status = 2 AND id IN (" . $wid . ")";
5392
5393 $updateLocalCommand = Yii::app()->db->createCommand($updateLocal);
5394 $updateLocalCommand->execute();
5395 } else {
5396 $total_soal = null;
5397 $data_soal = null;
5398 }
5399 $all_data['messages'] = 'success';
5400 $all_data['data'] = $data_soal;
5401 echo json_encode($all_data, JSON_PRETTY_PRINT);
5402 break;
5403
5404 case 'lks':
5405 $cekLks = Lks::model()->findAll(array('condition' => 'sync_status is null', 'order' => 'id ASC'));
5406
5407 if (!empty($cekLks)) {
5408 $total_lks = count($cekLks);
5409 $data_lks = array();
5410 $raw_lks = array();
5411 $ids = array();
5412 foreach ($cekLks as $lks) {
5413 $raw_lks['id'] = $lks->id;
5414 $raw_lks['title'] = $lks->title;
5415 $raw_lks['lesson_id'] = $lks->lesson_id;
5416 $raw_lks['assignments'] = $lks->assignments;
5417 $raw_lks['chapters'] = $lks->chapters;
5418 $raw_lks['quizes'] = $lks->quizes;
5419 $raw_lks['created_at'] = $lks->created_at;
5420 $raw_lks['updated_at'] = $lks->updated_at;
5421 $raw_lks['created_by'] = $lks->created_by;
5422 $raw_lks['updated_by'] = $lks->updated_by;
5423 $raw_lks['teacher_id'] = $lks->teacher_id;
5424 array_push($data_lks, $raw_lks);
5425 array_push($ids, $lks->id);
5426 }
5427 $wid = implode(',', $ids);
5428 $updateLocal = "UPDATE " . $prefix . "lks SET sync_status = 2 AND id IN (" . $wid . ")";
5429
5430 $updateLocalCommand = Yii::app()->db->createCommand($updateLocal);
5431 $updateLocalCommand->execute();
5432 } else {
5433 $total_lks = null;
5434 $data_lks = null;
5435 }
5436 $all_data['messages'] = 'success';
5437 $all_data['data'] = $data_lks;
5438 echo json_encode($all_data, JSON_PRETTY_PRINT);
5439 break;
5440
5441 case 'pengumuman':
5442 $cekPengumuman = Announcements::model()->findAll(array('condition' => 'sync_status is null', 'order' => 'id ASC'));
5443
5444 if (!empty($cekPengumuman)) {
5445 $total_pengumuman = count($cekPengumuman);
5446 $data_pengumuman = array();
5447 $raw_pengumuman = array();
5448 $ids = array();
5449 foreach ($cekPengumuman as $pengumuman) {
5450 $raw_pengumuman['id'] = $pengumuman->id;
5451 $raw_pengumuman['author_id'] = $pengumuman->author_id;
5452 $raw_pengumuman['title'] = $pengumuman->title;
5453 $raw_pengumuman['created_at'] = $pengumuman->created_at;
5454 $raw_pengumuman['updated_at'] = $pengumuman->updated_at;
5455 $raw_pengumuman['content'] = $pengumuman->created_by;
5456 $raw_pengumuman['type'] = $pengumuman->updated_by;
5457 array_push($data_pengumuman, $raw_pengumuman);
5458 array_push($ids, $pengumuman->id);
5459 }
5460 $wid = implode(',', $ids);
5461 $updateLocal = "UPDATE " . $prefix . "announcements SET sync_status = 2 AND id IN (" . $wid . ")";
5462
5463 $updateLocalCommand = Yii::app()->db->createCommand($updateLocal);
5464 $updateLocalCommand->execute();
5465 } else {
5466 $total_pengumuman = null;
5467 $data_pengumuman = null;
5468 }
5469 $all_data['messages'] = 'success';
5470 $all_data['data'] = $data_pengumuman;
5471 echo json_encode($all_data, JSON_PRETTY_PRINT);
5472 break;
5473
5474 case 'aktivitas':
5475 $cekAktivitas = Activities::model()->findAll(array('condition' => 'sync_status is null', 'order' => 'id ASC'));
5476
5477 if (!empty($cekAktivitas)) {
5478 $total_aktivitas = count($cekAktivitas);
5479 $data_aktivitas = array();
5480 $raw_aktivitas = array();
5481 $ids = array();
5482 foreach ($cekAktivitas as $aktivitas) {
5483 $raw_aktivitas['id'] = $aktivitas->id;
5484 $raw_aktivitas['activity_type'] = $aktivitas->activity_type;
5485 $raw_aktivitas['content'] = $aktivitas->content;
5486 $raw_aktivitas['created_at'] = $aktivitas->created_at;
5487 $raw_aktivitas['updated_at'] = $aktivitas->updated_at;
5488 $raw_aktivitas['created_by'] = $aktivitas->created_by;
5489 $raw_aktivitas['updated_by'] = $aktivitas->updated_by;
5490 array_push($data_aktivitas, $raw_aktivitas);
5491 array_push($ids, $aktivitas->id);
5492 }
5493 $wid = implode(',', $ids);
5494 $updateLocal = "UPDATE " . $prefix . "activities SET sync_status = 2 AND id IN (" . $wid . ")";
5495
5496 $updateLocalCommand = Yii::app()->db->createCommand($updateLocal);
5497 $updateLocalCommand->execute();
5498 } else {
5499 $total_aktivitas = null;
5500 $data_aktivitas = null;
5501 }
5502 $all_data['messages'] = 'success';
5503 $all_data['data'] = $data_aktivitas;
5504 echo json_encode($all_data, JSON_PRETTY_PRINT);
5505 break;
5506
5507 case 'notif':
5508 $cekNotif = Notification::model()->findAll(array('condition' => 'sync_status is null', 'order' => 'id ASC'));
5509
5510 if (!empty($cekNotif)) {
5511 $total_notif = count($cekNotif);
5512 $data_notif = array();
5513 $raw_notif = array();
5514 $ids = array();
5515 foreach ($cekNotif as $notif) {
5516 $raw_notif['id'] = $notif->id;
5517 $raw_notif['content'] = $notif->content;
5518 $raw_notif['user_id'] = $notif->user_id;
5519 $raw_notif['user_id_to'] = $notif->user_id_to;
5520 $raw_notif['tipe'] = $notif->tipe;
5521 $raw_notif['created_at'] = $notif->created_at;
5522 $raw_notif['updated_at'] = $notif->updated_at;
5523 $raw_notif['read_at'] = $notif->read_at;
5524 $raw_notif['status'] = $notif->status;
5525 $raw_notif['relation_id'] = $notif->relation_id;
5526 $raw_notif['class_id_to'] = $notif->class_id_to;
5527 $raw_notif['read_id'] = $notif->read_id;
5528 array_push($data_notif, $raw_notif);
5529 array_push($ids, $notif->id);
5530 }
5531 $wid = implode(',', $ids);
5532 $updateLocal = "UPDATE " . $prefix . "notification SET sync_status = 2 AND id IN (" . $wid . ")";
5533
5534 $updateLocalCommand = Yii::app()->db->createCommand($updateLocal);
5535 $updateLocalCommand->execute();
5536 } else {
5537 $total_notif = null;
5538 $data_notif = null;
5539 }
5540 $all_data['messages'] = 'success';
5541 $all_data['data'] = $data_notif;
5542 echo json_encode($all_data, JSON_PRETTY_PRINT);
5543
5544 break;
5545
5546 case 'noffline':
5547 $cekNilaiOffline = OfflineMark::model()->findAll(array('condition' => 'sync_status is null', 'order' => 'id ASC'));
5548
5549 if (!empty($cekNilaiOffline)) {
5550 $total_nilai_offline = count($cekNilaiOffline);
5551 $data_noffline = array();
5552 $raw_noffline = array();
5553 $ids = array();
5554 foreach ($cekNilaiOffline as $noffline) {
5555 $raw_noffline['id'] = $noffline->id;
5556 $raw_noffline['lesson_id'] = $noffline->lesson_id;
5557 $raw_noffline['assignment_id'] = $noffline->assignment_id;
5558 $raw_noffline['student_id'] = $noffline->student_id;
5559 $raw_noffline['created_at'] = $noffline->created_at;
5560 $raw_noffline['updated_at'] = $noffline->updated_at;
5561 $raw_noffline['created_by'] = $noffline->created_by;
5562 $raw_noffline['updated_by'] = $noffline->updated_by;
5563 $raw_noffline['score'] = $noffline->score;
5564 $raw_noffline['file'] = $noffline->file;
5565 $raw_noffline['mark_type'] = $noffline->mark_type;
5566 array_push($data_noffline, $raw_noffline);
5567 array_push($ids, $noffline->id);
5568 }
5569 $wid = implode(',', $ids);
5570 $updateLocal = "UPDATE " . $prefix . "offline_mark SET sync_status = 2 AND id IN (" . $wid . ")";
5571
5572 $updateLocalCommand = Yii::app()->db->createCommand($updateLocal);
5573 $updateLocalCommand->execute();
5574 } else {
5575 $total_nilai_offline = null;
5576 $data_noffline = null;
5577 }
5578 $all_data['messages'] = 'success';
5579 $all_data['data'] = $data_noffline;
5580 echo json_encode($all_data, JSON_PRETTY_PRINT);
5581 break;
5582
5583 case 'kelas':
5584 $cekKelas = Clases::model()->findAll(array('condition' => 'sync_status is null', 'order' => 'id ASC'));
5585
5586 if (!empty($cekKelas)) {
5587 $total_kelas = count($cekKelas);
5588 $data_kelas = array();
5589 $raw_kelas = array();
5590 $ids = array();
5591 foreach ($cekKelas as $kelas) {
5592 $raw_kelas['id'] = $kelas->id;
5593 $raw_kelas['name'] = $kelas->name;
5594 $raw_kelas['teacher_id'] = $kelas->teacher_id;
5595 array_push($data_kelas, $raw_kelas);
5596 array_push($ids, $kelas->id);
5597 }
5598 $wid = implode(',', $ids);
5599 $updateLocal = "UPDATE " . $prefix . "clases SET sync_status = 2 AND id IN (" . $wid . ")";
5600
5601 $updateLocalCommand = Yii::app()->db->createCommand($updateLocal);
5602 $updateLocalCommand->execute();
5603 } else {
5604 $total_kelas = null;
5605 $data_kelas = null;
5606 }
5607 $all_data['messages'] = 'success';
5608 $all_data['data'] = $data_kelas;
5609 echo json_encode($all_data, JSON_PRETTY_PRINT);
5610 break;
5611
5612 case 'pelajaran':
5613 $cekMapel = Lesson::model()->findAll(array('condition' => 'sync_status is null', 'order' => 'id ASC'));
5614
5615 if (!empty($cekMapel)) {
5616 $total_mapel = count($cekMapel);
5617 $data_pelajaran = array();
5618 $raw_pelajaran = array();
5619 $ids = array();
5620 foreach ($cekMapel as $pelajaran) {
5621 $raw_pelajaran['id'] = $pelajaran->id;
5622 $raw_pelajaran['name'] = $pelajaran->name;
5623 $raw_pelajaran['user_id'] = $pelajaran->user_id;
5624 $raw_pelajaran['class_id'] = $pelajaran->class_id;
5625 $raw_pelajaran['created_at'] = $pelajaran->created_at;
5626 $raw_pelajaran['updated_at'] = $pelajaran->updated_at;
5627 $raw_pelajaran['created_by'] = $pelajaran->created_by;
5628 $raw_pelajaran['updated_by'] = $pelajaran->updated_by;
5629 array_push($data_pelajaran, $raw_pelajaran);
5630 array_push($ids, $pelajaran->id);
5631 }
5632 $wid = implode(',', $ids);
5633 $updateLocal = "UPDATE " . $prefix . "lesson SET sync_status = 2 AND id IN (" . $wid . ")";
5634
5635 $updateLocalCommand = Yii::app()->db->createCommand($updateLocal);
5636 $updateLocalCommand->execute();
5637 } else {
5638 $total_mapel = null;
5639 $data_pelajaran = null;
5640 }
5641 $all_data['messages'] = 'success';
5642 $all_data['data'] = $data_pelajaran;
5643 echo json_encode($all_data, JSON_PRETTY_PRINT);
5644 break;
5645
5646 case 'absensi':
5647 $cekAbsensi = Absensi::model()->findAll(array('condition' => 'sync_status is null', 'order' => 'id ASC'));
5648
5649 if (!empty($cekAbsensi)) {
5650 $total_absensi = count($cekAbsensi);
5651 $data_absensi = array();
5652 $raw_absensi = array();
5653 $ids = array();
5654 foreach ($cekAbsensi as $absensi) {
5655 $raw_absensi['id'] = $absensi->id;
5656 $raw_absensi['user_id'] = $absensi->user_id;
5657 $raw_absensi['type'] = $absensi->type;
5658 $raw_absensi['status'] = $absensi->status;
5659 $raw_absensi['alasan'] = $absensi->alasan;
5660 $raw_absensi['created_date'] = $absensi->created_date;
5661 array_push($data_absensi, $raw_absensi);
5662 array_push($ids, $absensi->id);
5663 }
5664 $wid = implode(',', $ids);
5665 $updateLocal = "UPDATE " . $prefix . "absensi SET sync_status = 2 WHERE id IN (" . $wid . ")";
5666
5667 $updateLocalCommand = Yii::app()->db->createCommand($updateLocal);
5668 $updateLocalCommand->execute();
5669 } else {
5670 $total_absensi = null;
5671 $data_absensi = null;
5672 }
5673 $all_data['messages'] = 'success';
5674 $all_data['data'] = $data_absensi;
5675 echo json_encode($all_data, JSON_PRETTY_PRINT);
5676 break;
5677
5678 default:
5679 echo "selesai";
5680 break;
5681 }
5682 }
5683
5684 public function actionSinkronisasi($cekStatus = null)
5685 {
5686
5687 //if($_SERVER['HTTP_HOST'] == "exambox.pinisi"){
5688 //$url = "http://exambox.pinisi.co/api/sinkronisasidata";
5689 $post_url = "http://exambox.pinisi.co/api/postlocaldata";
5690 //}elseif($_SERVER['HTTP_HOST'] == "exambox.pinisi.co"){
5691 //$url = "http://exambox.pinisi/api/sinkronisasidata";
5692 //$post_url = "http://exambox.pinisi/api/postlocaldata";
5693 //}else{
5694 //$url = "http://exambox.pinisi/api/sinkronisasidata";
5695 //$post_url = "http://exambox.pinisi/api/postlocaldata";
5696 //}
5697 //$i = 14;
5698 //$cekStatus = NULL;
5699 date_default_timezone_set("Asia/Jakarta");
5700 $now_time = date("H:i");
5701 //echo $now_time;
5702 //if(($now_time >= "08:00") && ($now_time <= "18:00")){
5703 //do {
5704 $prefix = Yii::app()->params['tablePrefix'];
5705 switch ($cekStatus) {
5706 case null:
5707 $cekUser = User::model()->findAll(array('condition' => 'sync_status is null', 'order' => 'id ASC'));
5708
5709 if (!empty($cekUser)) {
5710 $total_user = count($cekUser);
5711 $pass_user_data = array();
5712 $rpud = array();
5713 $ids = array();
5714 //$tes = array();
5715 foreach ($cekUser as $nud) {
5716 $rpud['id'] = $nud->id;
5717 $rpud['email'] = $nud->email;
5718 $rpud['username'] = $nud->username;
5719 $rpud['encrypted_password'] = $nud->encrypted_password;
5720 $rpud['role_id'] = $nud->role_id;
5721 $rpud['created_at'] = $nud->created_at;
5722 $rpud['updated_at'] = $nud->updated_at;
5723 $rpud['class_id'] = $nud->class_id;
5724 $rpud['reset_password'] = $nud->reset_password;
5725 $rpud['display_name'] = $nud->display_name;
5726 array_push($pass_user_data, $rpud);
5727 array_push($ids, $nud->id);
5728 //array_push($tes, $nud->id);
5729 }
5730 $json_user_data = json_encode($pass_user_data, JSON_PRETTY_PRINT);
5731 /* echo "<pre>";
5732 echo $json_user_data;
5733 echo "</pre>"; */
5734
5735 $post_user_url = $post_url . "?type=user";
5736 $curlUser = curl_init();
5737 $wid = implode(',', $ids);
5738
5739 curl_setopt_array($curlUser, array(
5740 CURLOPT_URL => $post_user_url,
5741 CURLOPT_VERBOSE => true,
5742 CURLOPT_RETURNTRANSFER => true,
5743 CURLOPT_ENCODING => "",
5744 CURLOPT_MAXREDIRS => 10,
5745 CURLOPT_TIMEOUT => 3000,
5746 CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
5747 CURLOPT_CUSTOMREQUEST => "POST",
5748 CURLOPT_POSTFIELDS => $json_user_data,
5749 CURLOPT_HTTPHEADER => array(
5750 "content-type: application/json"
5751 ),
5752 ));
5753
5754 $responseUser = curl_exec($curlUser);
5755 $errUser = curl_error($curlUser);
5756
5757 curl_close($curlUser);
5758
5759 if ($errUser) {
5760 echo "cURL Error #:" . $errUser;
5761 } else {
5762 $dataUser = json_decode($responseUser);
5763 // //echo $data->messages;
5764 if (!empty($dataUser)) {
5765 if ($dataUser->gagal == null) {
5766 $updateLocal = "UPDATE " . $prefix . "users SET sync_status = 2 WHERE id IN (" . $wid . ")";
5767
5768 $updateLocalCommand = Yii::app()->db->createCommand($updateLocal);
5769 $updateLocalCommand->execute();
5770 }
5771 }
5772
5773 // //$cekStatus = "tugas";
5774 echo "tugas";
5775 }
5776 } else {
5777 $total_user = null;
5778 //$cekStatus = "tugas";
5779 echo "tugas";
5780 }
5781 break;
5782
5783 case "tugas":
5784 $cekTugas = Assignment::model()->findAll(array('condition' => 'sync_status is null', 'order' => 'id ASC'));
5785
5786 if (!empty($cekTugas)) {
5787 $total_tugas = count($cekTugas);
5788 $data_tugas = array();
5789 $raw_tugas = array();
5790 $ids = array();
5791 foreach ($cekTugas as $tgs) {
5792 $raw_tugas['id'] = $tgs->id;
5793 $raw_tugas['title'] = $tgs->title;
5794 $raw_tugas['content'] = $tgs->content;
5795 $raw_tugas['created_at'] = $tgs->created_at;
5796 $raw_tugas['updated_at'] = $tgs->updated_at;
5797 $raw_tugas['created_by'] = $tgs->created_by;
5798 $raw_tugas['updated_by'] = $tgs->updated_by;
5799 $raw_tugas['due_date'] = $tgs->due_date;
5800 $raw_tugas['lesson_id'] = $tgs->lesson_id;
5801 $raw_tugas['file'] = $tgs->file;
5802 $raw_tugas['assignment_type'] = $tgs->assignment_type;
5803 $raw_tugas['add_to_summary'] = $tgs->add_to_summary;
5804 $raw_tugas['recipient'] = $tgs->recipient;
5805 $raw_tugas['semester'] = $tgs->semester;
5806 $raw_tugas['year'] = $tgs->year;
5807 $raw_tugas['status'] = $tgs->status;
5808 array_push($data_tugas, $raw_tugas);
5809 array_push($ids, $tgs->id);
5810 }
5811 $json_data_tugas = json_encode($data_tugas, JSON_PRETTY_PRINT);
5812 //echo $json_data_tugas;
5813 $wid = implode(',', $ids);
5814
5815 $post_tugas_url = $post_url . "?type=tugas";
5816 $curlTugas = curl_init();
5817
5818 curl_setopt_array($curlTugas, array(
5819 CURLOPT_URL => $post_tugas_url,
5820 CURLOPT_VERBOSE => true,
5821 CURLOPT_RETURNTRANSFER => true,
5822 CURLOPT_ENCODING => "",
5823 CURLOPT_MAXREDIRS => 10,
5824 CURLOPT_TIMEOUT => 3000,
5825 CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
5826 CURLOPT_CUSTOMREQUEST => "POST",
5827 CURLOPT_POSTFIELDS => $json_data_tugas,
5828 CURLOPT_HTTPHEADER => array(
5829 "content-type: application/json"
5830 ),
5831 ));
5832
5833 $responseTugas = curl_exec($curlTugas);
5834 $errTugas = curl_error($curlTugas);
5835
5836 curl_close($curlTugas);
5837
5838 if ($errTugas) {
5839 echo "cURL Error #:" . $errTugas;
5840 } else {
5841 $dataTugas = json_decode($responseTugas);
5842 //echo $data->messages;
5843 if (!empty($dataTugas)) {
5844 if ($dataTugas->gagal == null) {
5845 $updateLocal = "UPDATE " . $prefix . "assignment SET sync_status = 2 WHERE id IN (" . $wid . ")";
5846
5847 $updateLocalCommand = Yii::app()->db->createCommand($updateLocal);
5848 $updateLocalCommand->execute();
5849 }
5850 }
5851 //$cekStatus = "tugasSiswa";
5852 echo "tugasSiswa";
5853 }
5854 } else {
5855 $total_tugas = null;
5856 //$cekStatus = "tugasSiswa";
5857 echo "tugasSiswa";
5858 }
5859 break;
5860
5861 case "tugasSiswa":
5862 $cekTugasSiswa = StudentAssignment::model()->findAll(array('condition' => 'sync_status is null', 'order' => 'id ASC'));
5863
5864 if (!empty($cekTugasSiswa)) {
5865 $total_ts = count($cekTugasSiswa);
5866 $data_tugas_siswa = array();
5867 $raw_tugas_siswa = array();
5868 $ids = array();
5869 foreach ($cekTugasSiswa as $ts) {
5870 $raw_tugas_siswa['id'] = $ts->id;
5871 $raw_tugas_siswa['assignment_id'] = $ts->assignment_id;
5872 $raw_tugas_siswa['content'] = $ts->content;
5873 $raw_tugas_siswa['file'] = $ts->file;
5874 $raw_tugas_siswa['student_id'] = $ts->student_id;
5875 $raw_tugas_siswa['score'] = $ts->score;
5876 $raw_tugas_siswa['created_at'] = $ts->created_at;
5877 $raw_tugas_siswa['updated_at'] = $ts->updated_at;
5878 $raw_tugas_siswa['status'] = $ts->status;
5879 array_push($data_tugas_siswa, $raw_tugas_siswa);
5880 array_push($ids, $ts->id);
5881 }
5882 $json_data_tugas_siswa = json_encode($data_tugas_siswa, JSON_PRETTY_PRINT);
5883 //echo $json_data_tugas_siswa;
5884 $wid = implode(',', $ids);
5885
5886 $post_tugas_siswa_url = $post_url . "?type=tugasSiswa";
5887 $curlTugasSiswa = curl_init();
5888
5889 curl_setopt_array($curlTugasSiswa, array(
5890 CURLOPT_URL => $post_tugas_siswa_url,
5891 CURLOPT_VERBOSE => true,
5892 CURLOPT_RETURNTRANSFER => true,
5893 CURLOPT_ENCODING => "",
5894 CURLOPT_MAXREDIRS => 10,
5895 CURLOPT_TIMEOUT => 3000,
5896 CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
5897 CURLOPT_CUSTOMREQUEST => "POST",
5898 CURLOPT_POSTFIELDS => $json_data_tugas_siswa,
5899 CURLOPT_HTTPHEADER => array(
5900 "content-type: application/json"
5901 ),
5902 ));
5903
5904 $responseTugasSiswa = curl_exec($curlTugasSiswa);
5905 $errTugasSiswa = curl_error($curlTugasSiswa);
5906
5907 curl_close($curlTugasSiswa);
5908
5909 if ($errTugasSiswa) {
5910 echo "cURL Error #:" . $errTugas;
5911 } else {
5912 $dataTugasSiswa = json_decode($responseTugasSiswa);
5913 //echo $data->messages;
5914 if (!empty($dataTugasSiswa)) {
5915 if ($dataTugasSiswa->gagal == null) {
5916 $updateLocal = "UPDATE " . $prefix . "student_assignment SET sync_status = 2 WHERE id IN(" . $wid . ")";
5917
5918 $updateLocalCommand = Yii::app()->db->createCommand($updateLocal);
5919 $updateLocalCommand->execute();
5920 }
5921 }
5922
5923 //$cekStatus = "materi";
5924 echo "materi";
5925 }
5926 } else {
5927 $total_ts = null;
5928 //$cekStatus = "materi";
5929 echo "materi";
5930 }
5931 break;
5932
5933 case "materi":
5934 $cekMateri = Chapters::model()->findAll(array('condition' => 'sync_status is null', 'order' => 'id ASC'));
5935
5936 if (!empty($cekMateri)) {
5937 $total_materi = count($cekMateri);
5938 $data_materi = array();
5939 $raw_materi = array();
5940 $ids = array();
5941 foreach ($cekMateri as $materi) {
5942 $raw_materi['id'] = $materi->id;
5943 $raw_materi['id_lesson'] = $materi->id_lesson;
5944 $raw_materi['title'] = $materi->title;
5945 $raw_materi['description'] = $materi->description;
5946 $raw_materi['created_at'] = $materi->created_at;
5947 $raw_materi['updated_at'] = $materi->updated_at;
5948 $raw_materi['created_by'] = $materi->created_by;
5949 $raw_materi['updated_by'] = $materi->updated_by;
5950 $raw_materi['content'] = $materi->content;
5951 $raw_materi['chapter_type'] = $materi->chapter_type;
5952 $raw_materi['semester'] = $materi->semester;
5953 $raw_materi['year'] = $materi->year;
5954 array_push($data_materi, $raw_materi);
5955 array_push($ids, $materi->id);
5956 }
5957 $json_data_materi = json_encode($data_materi, JSON_PRETTY_PRINT);
5958 //echo $json_data_materi;
5959 $wid = implode(',', $ids);
5960
5961 $post_materi = $post_url . "?type=materi";
5962 $curlMateri = curl_init();
5963
5964 curl_setopt_array($curlMateri, array(
5965 CURLOPT_URL => $post_materi,
5966 CURLOPT_VERBOSE => true,
5967 CURLOPT_RETURNTRANSFER => true,
5968 CURLOPT_ENCODING => "",
5969 CURLOPT_MAXREDIRS => 10,
5970 CURLOPT_TIMEOUT => 3000,
5971 CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
5972 CURLOPT_CUSTOMREQUEST => "POST",
5973 CURLOPT_POSTFIELDS => $json_data_materi,
5974 CURLOPT_HTTPHEADER => array(
5975 "content-type: application/json"
5976 ),
5977 ));
5978
5979 $responseMateri = curl_exec($curlMateri);
5980 $errMateri = curl_error($curlMateri);
5981
5982 curl_close($curlMateri);
5983
5984 if ($errMateri) {
5985 echo "cURL Error #:" . $errMateri;
5986 } else {
5987 $dataMateri = json_decode($responseMateri);
5988 //echo $data->messages;
5989 if (!empty($dataMateri)) {
5990 if ($dataMateri->gagal == null) {
5991 $updateLocal = "UPDATE " . $prefix . "chapters SET sync_status = 2 WHERE id IN(" . $wid . ")";
5992
5993 $updateLocalCommand = Yii::app()->db->createCommand($updateLocal);
5994 $updateLocalCommand->execute();
5995 }
5996 }
5997 //print_r($dataMateri);
5998 //$cekStatus = "materiFile";
5999 echo "materiFile";
6000 }
6001 } else {
6002 $total_materi = null;
6003 //$cekStatus = "materiFile";
6004 echo "materiFile";
6005 }
6006 break;
6007
6008 case "materiFile":
6009 $cekFileMateri = ChapterFiles::model()->findAll(array('condition' => 'sync_status is null', 'order' => 'id ASC'));
6010
6011 if (!empty($cekFileMateri)) {
6012 $total_fm = count($cekFileMateri);
6013 $data_fm = array();
6014 $raw_fm = array();
6015 $ids = array();
6016 foreach ($cekFileMateri as $cfm) {
6017 $raw_fm['id'] = $cfm->id;
6018 $raw_fm['id_chapter'] = $cfm->id_chapter;
6019 $raw_fm['created_at'] = $cfm->created_at;
6020 $raw_fm['updated_at'] = $cfm->updated_at;
6021 $raw_fm['created_by'] = $cfm->created_by;
6022 $raw_fm['updated_by'] = $cfm->updated_by;
6023 $raw_fm['file'] = $cfm->file;
6024 $raw_fm['type'] = $cfm->type;
6025 $raw_fm['content'] = $cfm->content;
6026 array_push($data_fm, $raw_fm);
6027 array_push($ids, $cfm->id);
6028 }
6029 $json_data_fm = json_encode($data_fm);
6030 //echo $json_data_fm;
6031 $wid = implode(',', $ids);
6032 $post_fm = $post_url . "?type=fileMateri";
6033 $curlFileMateri = curl_init();
6034
6035 curl_setopt_array($curlFileMateri, array(
6036 CURLOPT_URL => $post_fm,
6037 CURLOPT_VERBOSE => true,
6038 CURLOPT_RETURNTRANSFER => true,
6039 CURLOPT_ENCODING => "",
6040 CURLOPT_MAXREDIRS => 10,
6041 CURLOPT_TIMEOUT => 3000,
6042 CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
6043 CURLOPT_CUSTOMREQUEST => "POST",
6044 CURLOPT_POSTFIELDS => $json_data_fm,
6045 CURLOPT_HTTPHEADER => array(
6046 "content-type: application/json"
6047 ),
6048 ));
6049
6050 $responseFileMateri = curl_exec($curlFileMateri);
6051 $errFileMateri = curl_error($curlFileMateri);
6052
6053 curl_close($curlFileMateri);
6054
6055 if ($errFileMateri) {
6056 echo "cURL Error #:" . $errFileMateri;
6057 } else {
6058 $dataFileMateri = json_decode($responseFileMateri);
6059 //echo $data->messages;
6060 if (!empty($dataFileMateri)) {
6061 if ($dataFileMateri->gagal == null) {
6062 $updateLocal = "UPDATE " . $prefix . "chapter_files SET sync_status = 2 WHERE id IN(" . $wid . ")";
6063
6064 $updateLocalCommand = Yii::app()->db->createCommand($updateLocal);
6065 $updateLocalCommand->execute();
6066 }
6067 }
6068
6069 //$cekStatus = "quiz";
6070 echo "quiz";
6071 }
6072 } else {
6073 $total_fm = null;
6074 //$cekStatus = "quiz";
6075 echo "quiz";
6076 }
6077 break;
6078
6079 case "quiz":
6080 $cekQuiz = Quiz::model()->findAll(array('condition' => 'sync_status is null', 'order' => 'id ASC'));
6081
6082 if (!empty($cekQuiz)) {
6083 $total_quiz = count($cekQuiz);
6084 $data_quiz = array();
6085 $raw_quiz = array();
6086 $ids = array();
6087 foreach ($cekQuiz as $quiz) {
6088 $raw_quiz['id'] = $quiz->id;
6089 $raw_quiz['title'] = $quiz->title;
6090 $raw_quiz['lesson_id'] = $quiz->lesson_id;
6091 $raw_quiz['chapter_id'] = $quiz->chapter_id;
6092 $raw_quiz['quiz_type'] = $quiz->quiz_type;
6093 $raw_quiz['created_at'] = $quiz->created_at;
6094 $raw_quiz['updated_at'] = $quiz->updated_at;
6095 $raw_quiz['created_by'] = $quiz->created_by;
6096 $raw_quiz['updated_by'] = $quiz->updated_by;
6097 $raw_quiz['start_time'] = $quiz->start_time;
6098 $raw_quiz['end_time'] = $quiz->end_time;
6099 $raw_quiz['total_question'] = $quiz->total_question;
6100 $raw_quiz['status'] = $quiz->status;
6101 $raw_quiz['add_to_summary'] = $quiz->add_to_summary;
6102 $raw_quiz['repeat_quiz'] = $quiz->repeat_quiz;
6103 $raw_quiz['question'] = $quiz->question;
6104 $raw_quiz['semester'] = $quiz->semester;
6105 $raw_quiz['year'] = $quiz->year;
6106 $raw_quiz['random'] = $quiz->random;
6107 $raw_quiz['show_nilai'] = $quiz->show_nilai;
6108 $raw_quiz['trash'] = $quiz->trash;
6109 array_push($data_quiz, $raw_quiz);
6110 array_push($ids, $quiz->id);
6111 }
6112 $json_data_quiz = json_encode($data_quiz, JSON_PRETTY_PRINT);
6113 /* echo "<pre>";
6114 echo $json_data_quiz;
6115 echo "</pre>"; */
6116
6117 $wid = implode(',', $ids);
6118
6119 $post_quiz = $post_url . "?type=quiz";
6120 $curlQuiz = curl_init();
6121
6122 curl_setopt_array($curlQuiz, array(
6123 CURLOPT_URL => $post_quiz,
6124 CURLOPT_VERBOSE => true,
6125 CURLOPT_RETURNTRANSFER => true,
6126 CURLOPT_ENCODING => "",
6127 CURLOPT_MAXREDIRS => 10,
6128 CURLOPT_TIMEOUT => 3000,
6129 CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
6130 CURLOPT_CUSTOMREQUEST => "POST",
6131 CURLOPT_POSTFIELDS => $json_data_quiz,
6132 CURLOPT_HTTPHEADER => array(
6133 "content-type: application/json"
6134 ),
6135 ));
6136
6137 $responseQuiz = curl_exec($curlQuiz);
6138 $errQuiz = curl_error($curlQuiz);
6139
6140 curl_close($curlQuiz);
6141
6142 if ($errQuiz) {
6143 echo "cURL Error #:" . $errQuiz;
6144 } else {
6145 $dataQuiz = json_decode($responseQuiz);
6146 //echo $data->messages;
6147 if (!empty($dataQuiz)) {
6148 if ($dataQuiz->gagal == null) {
6149 $updateLocal = "UPDATE " . $prefix . "quiz SET sync_status = 2 WHERE id IN(" . $wid . ")";
6150
6151 $updateLocalCommand = Yii::app()->db->createCommand($updateLocal);
6152 $updateLocalCommand->execute();
6153 }
6154 }
6155
6156 //$cekStatus = "quizSiswa";
6157 echo "quizSiswa";
6158 }
6159 } else {
6160 $total_quiz = null;
6161 //$cekStatus = "quizSiswa";
6162 echo "quizSiswa";
6163 }
6164 break;
6165
6166 case "quizSiswa":
6167 $cekQuizSiswa = StudentQuiz::model()->findAll(array('condition' => 'sync_status is null', 'order' => 'id ASC'));
6168
6169 if (!empty($cekQuizSiswa)) {
6170 $total_qs = count($cekQuizSiswa);
6171 $data_qs = array();
6172 $raw_qs = array();
6173 $ids = array();
6174 foreach ($cekQuizSiswa as $qs) {
6175 $raw_qs['id'] = $qs->id;
6176 $raw_qs['quiz_id'] = $qs->quiz_id;
6177 $raw_qs['student_id'] = $qs->student_id;
6178 $raw_qs['created_at'] = $qs->created_at;
6179 $raw_qs['updated_at'] = $qs->updated_at;
6180 $raw_qs['score'] = $qs->score;
6181 $raw_qs['right_answer'] = $qs->right_answer;
6182 $raw_qs['wrong_answer'] = $qs->wrong_answer;
6183 $raw_qs['unanswered'] = $qs->unanswered;
6184 $raw_qs['student_answer'] = $qs->student_answer;
6185 $raw_qs['attempt'] = $qs->attempt;
6186 array_push($data_qs, $raw_qs);
6187 array_push($ids, $qs->id);
6188 }
6189 $json_data_qs = json_encode($data_qs);
6190 //echo $json_data_qs;
6191 $wid = implode(',', $ids);
6192
6193 $post_qs = $post_url . "?type=quizSiswa";
6194 $curlQs = curl_init();
6195
6196 curl_setopt_array($curlQs, array(
6197 CURLOPT_URL => $post_qs,
6198 CURLOPT_VERBOSE => true,
6199 CURLOPT_RETURNTRANSFER => true,
6200 CURLOPT_ENCODING => "",
6201 CURLOPT_MAXREDIRS => 10,
6202 CURLOPT_TIMEOUT => 3000,
6203 CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
6204 CURLOPT_CUSTOMREQUEST => "POST",
6205 CURLOPT_POSTFIELDS => $json_data_qs,
6206 CURLOPT_HTTPHEADER => array(
6207 "content-type: application/json"
6208 ),
6209 ));
6210
6211 $responseQs = curl_exec($curlQs);
6212 $errQs = curl_error($curlQs);
6213
6214 curl_close($curlQs);
6215
6216 if ($errQs) {
6217 echo "cURL Error #:" . $errQs;
6218 } else {
6219 $dataQs = json_decode($responseQs);
6220 //echo $data->messages;
6221 if (!empty($dataQs)) {
6222 if ($dataQs->gagal == null) {
6223 $updateLocal = "UPDATE " . $prefix . "student_quiz SET sync_status = 2 WHERE id IN(" . $wid . ")";
6224
6225 $updateLocalCommand = Yii::app()->db->createCommand($updateLocal);
6226 $updateLocalCommand->execute();
6227 }
6228 }
6229
6230 //$cekStatus = "soal";
6231 echo "soal";
6232 }
6233 } else {
6234 $total_qs = null;
6235 //$cekStatus = "soal";
6236 echo "soal";
6237 }
6238 break;
6239
6240 case "soal":
6241 $cekSoal = Questions::model()->findAll(array('condition' => 'sync_status is null', 'order' => 'id ASC'));
6242
6243 if (!empty($cekSoal)) {
6244 $total_soal = count($cekSoal);
6245 $data_soal = array();
6246 $raw_soal = array();
6247 $ids = array();
6248 foreach ($cekSoal as $soal) {
6249 $raw_soal['id'] = $soal->id;
6250 $raw_soal['quiz_id'] = $soal->quiz_id;
6251 $raw_soal['lesson_id'] = $soal->lesson_id;
6252 $raw_soal['title'] = $soal->title;
6253 $raw_soal['text'] = $soal->text;
6254 $raw_soal['choices'] = $soal->choices;
6255 $raw_soal['key_answer'] = $soal->key_answer;
6256 $raw_soal['created_at'] = $soal->created_at;
6257 $raw_soal['updated_at'] = $soal->updated_at;
6258 $raw_soal['teacher_id'] = $soal->teacher_id;
6259 $raw_soal['created_by'] = $soal->created_by;
6260 $raw_soal['updated_by'] = $soal->updated_by;
6261 $raw_soal['file'] = $soal->file;
6262 $raw_soal['type'] = $soal->type;
6263 $raw_soal['choices_files'] = $soal->choices_files;
6264 array_push($data_soal, $raw_soal);
6265 array_push($ids, $soal->id);
6266 }
6267 $json_data_soal = json_encode($data_soal);
6268 //echo $json_data_soal;
6269 $wid = implode(',', $ids);
6270
6271 $post_soal = $post_url . "?type=soal";
6272 $curlSoal = curl_init();
6273
6274 curl_setopt_array($curlSoal, array(
6275 CURLOPT_URL => $post_soal,
6276 CURLOPT_VERBOSE => true,
6277 CURLOPT_RETURNTRANSFER => true,
6278 CURLOPT_ENCODING => "",
6279 CURLOPT_MAXREDIRS => 10,
6280 CURLOPT_TIMEOUT => 3000,
6281 CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
6282 CURLOPT_CUSTOMREQUEST => "POST",
6283 CURLOPT_POSTFIELDS => $json_data_soal,
6284 CURLOPT_HTTPHEADER => array(
6285 "content-type: application/json"
6286 ),
6287 ));
6288
6289 $responseSoal = curl_exec($curlSoal);
6290 $errSoal = curl_error($curlSoal);
6291
6292 curl_close($curlSoal);
6293
6294 if ($errSoal) {
6295 echo "cURL Error #:" . $errSoal;
6296 } else {
6297 $dataSoal = json_decode($responseSoal);
6298 //echo $data->messages;
6299 if (!empty($dataSoal)) {
6300 if ($dataSoal->gagal == null) {
6301 $updateLocal = "UPDATE " . $prefix . "questions SET sync_status = 2 WHERE id IN(" . $wid . ")";
6302
6303 $updateLocalCommand = Yii::app()->db->createCommand($updateLocal);
6304 $updateLocalCommand->execute();
6305 }
6306 }
6307
6308 //$cekStatus = "lks";
6309 echo "lks";
6310 }
6311 } else {
6312 $total_soal = null;
6313 echo "lks";
6314 //$cekStatus = "lks";
6315 }
6316
6317 break;
6318 case "lks":
6319 $cekLks = Lks::model()->findAll(array('condition' => 'sync_status is null', 'order' => 'id ASC'));
6320
6321 if (!empty($cekLks)) {
6322 $total_lks = count($cekLks);
6323 $data_lks = array();
6324 $raw_lks = array();
6325 $ids = array();
6326 foreach ($cekLks as $lks) {
6327 $raw_lks['id'] = $lks->id;
6328 $raw_lks['title'] = $lks->title;
6329 $raw_lks['lesson_id'] = $lks->lesson_id;
6330 $raw_lks['assignments'] = $lks->assignments;
6331 $raw_lks['chapters'] = $lks->chapters;
6332 $raw_lks['quizes'] = $lks->quizes;
6333 $raw_lks['created_at'] = $lks->created_at;
6334 $raw_lks['updated_at'] = $lks->updated_at;
6335 $raw_lks['created_by'] = $lks->created_by;
6336 $raw_lks['updated_by'] = $lks->updated_by;
6337 $raw_lks['teacher_id'] = $lks->teacher_id;
6338 array_push($data_lks, $raw_lks);
6339 array_push($ids, $lks->id);
6340 }
6341 $json_data_lks = json_encode($data_lks);
6342 //echo $json_data_tugas;
6343 $wid = implode(',', $ids);
6344
6345 $post_lks = $post_url . "?type=lks";
6346 $curlLks = curl_init();
6347
6348 curl_setopt_array($curlLks, array(
6349 CURLOPT_URL => $post_lks,
6350 CURLOPT_VERBOSE => true,
6351 CURLOPT_RETURNTRANSFER => true,
6352 CURLOPT_ENCODING => "",
6353 CURLOPT_MAXREDIRS => 10,
6354 CURLOPT_TIMEOUT => 3000,
6355 CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
6356 CURLOPT_CUSTOMREQUEST => "POST",
6357 CURLOPT_POSTFIELDS => $json_data_lks,
6358 CURLOPT_HTTPHEADER => array(
6359 "content-type: application/json"
6360 ),
6361 ));
6362
6363 $responseLks = curl_exec($curlLks);
6364 $errLks = curl_error($curlLks);
6365
6366 curl_close($curlLks);
6367
6368 if ($errLks) {
6369 echo "cURL Error #:" . $errLks;
6370 } else {
6371 $dataLks = json_decode($responseLks);
6372 //echo $data->messages;
6373 if (!empty($dataLks)) {
6374 if ($dataLks->gagal == null) {
6375 $updateLocal = "UPDATE " . $prefix . "lks SET sync_status = 2 WHERE id IN(" . $wid . ")";
6376
6377 $updateLocalCommand = Yii::app()->db->createCommand($updateLocal);
6378 $updateLocalCommand->execute();
6379 }
6380 }
6381
6382 //$cekStatus = "pengumuman";
6383 echo "pengumuman";
6384 }
6385 } else {
6386 $total_lks = null;
6387 //$cekStatus = "pengumuman";
6388 echo "pengumuman";
6389 }
6390 break;
6391
6392 case "pengumuman":
6393 $cekPengumuman = Announcements::model()->findAll(array('condition' => 'sync_status is null', 'order' => 'id ASC'));
6394
6395 if (!empty($cekPengumuman)) {
6396 $total_pengumuman = count($cekPengumuman);
6397 $data_pengumuman = array();
6398 $raw_pengumuman = array();
6399 $ids = array();
6400 foreach ($cekPengumuman as $pengumuman) {
6401 $raw_pengumuman['id'] = $pengumuman->id;
6402 $raw_pengumuman['author_id'] = $pengumuman->author_id;
6403 $raw_pengumuman['title'] = $pengumuman->title;
6404 $raw_pengumuman['created_at'] = $pengumuman->created_at;
6405 $raw_pengumuman['updated_at'] = $pengumuman->updated_at;
6406 $raw_pengumuman['content'] = $pengumuman->created_by;
6407 $raw_pengumuman['type'] = $pengumuman->updated_by;
6408 array_push($data_pengumuman, $raw_pengumuman);
6409 array_push($ids, $pengumuman->id);
6410 }
6411 $json_data_pengumuman = json_encode($data_pengumuman);
6412 //echo $json_data_tugas;
6413 $wid = implode(',', $ids);
6414
6415 $post_pengumuman = $post_url . "?type=pengumuman";
6416 $curlPengumuman = curl_init();
6417
6418 curl_setopt_array($curlPengumuman, array(
6419 CURLOPT_URL => $post_pengumuman,
6420 CURLOPT_VERBOSE => true,
6421 CURLOPT_RETURNTRANSFER => true,
6422 CURLOPT_ENCODING => "",
6423 CURLOPT_MAXREDIRS => 10,
6424 CURLOPT_TIMEOUT => 3000,
6425 CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
6426 CURLOPT_CUSTOMREQUEST => "POST",
6427 CURLOPT_POSTFIELDS => $json_data_pengumuman,
6428 CURLOPT_HTTPHEADER => array(
6429 "content-type: application/json"
6430 ),
6431 ));
6432
6433 $responsePengumuman = curl_exec($curlPengumuman);
6434 $errPengumuman = curl_error($curlPengumuman);
6435
6436 curl_close($curlPengumuman);
6437
6438 if ($errPengumuman) {
6439 echo "cURL Error #:" . $errPengumuman;
6440 } else {
6441 $dataPengumuman = json_decode($responsePengumuman);
6442 //echo $data->messages;
6443 if (!empty($dataPengumuman)) {
6444 if ($dataPengumuman->gagal == null) {
6445 $updateLocal = "UPDATE " . $prefix . "announcements SET sync_status = 2 WHERE id IN(" . $wid . ")";
6446
6447 $updateLocalCommand = Yii::app()->db->createCommand($updateLocal);
6448 $updateLocalCommand->execute();
6449 }
6450 }
6451
6452 //$cekStatus = "nilaiOffline";
6453 echo "nilaiOffline";
6454 }
6455 } else {
6456 $total_pengumuman = null;
6457 //$cekStatus = "nilaiOffline";
6458 echo "nilaiOffline";
6459 }
6460 break;
6461
6462 case "nilaiOffline":
6463 $cekNilaiOffline = OfflineMark::model()->findAll(array('condition' => 'sync_status is null', 'order' => 'id ASC'));
6464
6465 if (!empty($cekNilaiOffline)) {
6466 $total_nilai_offline = count($cekNilaiOffline);
6467 $data_noffline = array();
6468 $raw_noffline = array();
6469 $ids = array();
6470 foreach ($cekNilaiOffline as $noffline) {
6471 $raw_noffline['id'] = $noffline->id;
6472 $raw_noffline['lesson_id'] = $noffline->lesson_id;
6473 $raw_noffline['assignment_id'] = $noffline->assignment_id;
6474 $raw_noffline['student_id'] = $noffline->student_id;
6475 $raw_noffline['created_at'] = $noffline->created_at;
6476 $raw_noffline['updated_at'] = $noffline->updated_at;
6477 $raw_noffline['created_by'] = $noffline->created_by;
6478 $raw_noffline['updated_by'] = $noffline->updated_by;
6479 $raw_noffline['score'] = $noffline->score;
6480 $raw_noffline['file'] = $noffline->file;
6481 $raw_noffline['mark_type'] = $noffline->mark_type;
6482 array_push($data_noffline, $raw_noffline);
6483 array_push($ids, $noffline->id);
6484 }
6485 $json_data_noffline = json_encode($data_noffline);
6486 //echo $json_data_tugas;
6487 $wid = implode(',', $ids);
6488
6489 $post_noffline = $post_url . "?type=noffline";
6490 $curlNoffline = curl_init();
6491
6492 curl_setopt_array($curlNoffline, array(
6493 CURLOPT_URL => $post_noffline,
6494 CURLOPT_VERBOSE => true,
6495 CURLOPT_RETURNTRANSFER => true,
6496 CURLOPT_ENCODING => "",
6497 CURLOPT_MAXREDIRS => 10,
6498 CURLOPT_TIMEOUT => 3000,
6499 CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
6500 CURLOPT_CUSTOMREQUEST => "POST",
6501 CURLOPT_POSTFIELDS => $json_data_noffline,
6502 CURLOPT_HTTPHEADER => array(
6503 "content-type: application/json"
6504 ),
6505 ));
6506
6507 $responseNoffline = curl_exec($curlNoffline);
6508 $errNoffline = curl_error($curlNoffline);
6509
6510 curl_close($curlNoffline);
6511
6512 if ($errNoffline) {
6513 echo "cURL Error #:" . $errNoffline;
6514 } else {
6515 $dataNoffline = json_decode($responseNoffline);
6516 //echo $data->messages;
6517 if (!empty($dataNoffline)) {
6518 if ($dataNoffline->gagal == null) {
6519 $updateLocal = "UPDATE " . $prefix . "offline_mark SET sync_status = 2 WHERE id IN(" . $wid . ")";
6520
6521 $updateLocalCommand = Yii::app()->db->createCommand($updateLocal);
6522 $updateLocalCommand->execute();
6523 }
6524 }
6525
6526 //$cekStatus = "aktivitas";
6527 echo "aktivitas";
6528 }
6529 } else {
6530 $total_nilai_offline = null;
6531 //$cekStatus = "aktivitas";
6532 echo "aktivitas";
6533 }
6534 break;
6535
6536 case "aktivitas":
6537 $cekAktivitas = Activities::model()->findAll(array('condition' => 'sync_status is null', 'order' => 'id ASC'));
6538
6539 if (!empty($cekAktivitas)) {
6540 $total_aktivitas = count($cekAktivitas);
6541 $data_aktivitas = array();
6542 $raw_aktivitas = array();
6543 $ids = array();
6544 foreach ($cekAktivitas as $aktivitas) {
6545 $raw_aktivitas['id'] = $aktivitas->id;
6546 $raw_aktivitas['activity_type'] = $aktivitas->activity_type;
6547 $raw_aktivitas['content'] = $aktivitas->content;
6548 $raw_aktivitas['created_at'] = $aktivitas->created_at;
6549 $raw_aktivitas['updated_at'] = $aktivitas->updated_at;
6550 $raw_aktivitas['created_by'] = $aktivitas->created_by;
6551 $raw_aktivitas['updated_by'] = $aktivitas->updated_by;
6552 array_push($data_aktivitas, $raw_aktivitas);
6553 array_push($ids, $aktivitas->id);
6554 }
6555 $json_data_aktivitas = json_encode($data_aktivitas);
6556 //echo $json_data_tugas;
6557 $wid = implode(',', $ids);
6558
6559 $post_aktivitas = $post_url . "?type=aktivitas";
6560 $curlAktivitas = curl_init();
6561
6562 curl_setopt_array($curlAktivitas, array(
6563 CURLOPT_URL => $post_aktivitas,
6564 CURLOPT_VERBOSE => true,
6565 CURLOPT_RETURNTRANSFER => true,
6566 CURLOPT_ENCODING => "",
6567 CURLOPT_MAXREDIRS => 10,
6568 CURLOPT_TIMEOUT => 3000,
6569 CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
6570 CURLOPT_CUSTOMREQUEST => "POST",
6571 CURLOPT_POSTFIELDS => $json_data_aktivitas,
6572 CURLOPT_HTTPHEADER => array(
6573 "content-type: application/json"
6574 ),
6575 ));
6576
6577 $responseAktivitas = curl_exec($curlAktivitas);
6578 $errAktivitas = curl_error($curlAktivitas);
6579
6580 curl_close($curlAktivitas);
6581
6582 if ($errAktivitas) {
6583 echo "cURL Error #:" . $errAktivitas;
6584 } else {
6585 $dataAktivitas = json_decode($responseAktivitas);
6586 //echo $data->messages;
6587 if (!empty($dataAktivitas)) {
6588 if ($dataAktivitas->gagal == null) {
6589 $updateLocal = "UPDATE " . $prefix . "activities SET sync_status = 2 WHERE id IN(" . $wid . ")";
6590
6591 $updateLocalCommand = Yii::app()->db->createCommand($updateLocal);
6592 $updateLocalCommand->execute();
6593 }
6594 }
6595
6596 //$cekStatus = "notifikasi";
6597 echo "notifikasi";
6598 }
6599 } else {
6600 $total_aktivitas = null;
6601 //$cekStatus = "notifikasi";
6602 echo "notifikasi";
6603 }
6604 break;
6605
6606 case "notifikasi":
6607 $cekNotif = Notification::model()->findAll(array('condition' => 'sync_status is null', 'order' => 'id ASC'));
6608
6609 if (!empty($cekNotif)) {
6610 $total_notif = count($cekNotif);
6611 $data_notif = array();
6612 $raw_notif = array();
6613 $ids = array();
6614 foreach ($cekNotif as $notif) {
6615 $raw_notif['id'] = $notif->id;
6616 $raw_notif['content'] = $notif->content;
6617 $raw_notif['user_id'] = $notif->user_id;
6618 $raw_notif['user_id_to'] = $notif->user_id_to;
6619 $raw_notif['tipe'] = $notif->tipe;
6620 $raw_notif['created_at'] = $notif->created_at;
6621 $raw_notif['updated_at'] = $notif->updated_at;
6622 $raw_notif['read_at'] = $notif->read_at;
6623 $raw_notif['status'] = $notif->status;
6624 $raw_notif['relation_id'] = $notif->relation_id;
6625 $raw_notif['class_id_to'] = $notif->class_id_to;
6626 $raw_notif['read_id'] = $notif->read_id;
6627 array_push($data_notif, $raw_notif);
6628 array_push($ids, $notif->id);
6629 }
6630 $json_data_notif = json_encode($data_notif);
6631 //echo $json_data_notif;
6632 $wid = implode(',', $ids);
6633
6634 $post_notif = $post_url . "?type=notif";
6635 $curlNotif = curl_init();
6636
6637 curl_setopt_array($curlNotif, array(
6638 CURLOPT_URL => $post_notif,
6639 CURLOPT_VERBOSE => true,
6640 CURLOPT_RETURNTRANSFER => true,
6641 CURLOPT_ENCODING => "",
6642 CURLOPT_MAXREDIRS => 10,
6643 CURLOPT_TIMEOUT => 3000,
6644 CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
6645 CURLOPT_CUSTOMREQUEST => "POST",
6646 CURLOPT_POSTFIELDS => $json_data_notif,
6647 CURLOPT_HTTPHEADER => array(
6648 "content-type: application/json"
6649 ),
6650 ));
6651
6652 $responseNotif = curl_exec($curlNotif);
6653 $errNotif = curl_error($curlNotif);
6654
6655 curl_close($curlNotif);
6656
6657 if ($errNotif) {
6658 echo "cURL Error #:" . $errNotif;
6659 } else {
6660 $dataNotif = json_decode($responseNotif);
6661 //echo $data->messages;
6662 if (!empty($dataNotif)) {
6663 if ($dataNotif->gagal == null) {
6664 $updateLocal = "UPDATE " . $prefix . "notification SET sync_status = 2 WHERE id IN(" . $wid . ")";
6665
6666 $updateLocalCommand = Yii::app()->db->createCommand($updateLocal);
6667 $updateLocalCommand->execute();
6668 }
6669 }
6670
6671 //$cekStatus = "kelas";
6672 echo "kelas";
6673 }
6674 } else {
6675 $total_notif = null;
6676 //$cekStatus = "kelas";
6677 echo "kelas";
6678 }
6679 break;
6680
6681 case "kelas":
6682 $cekKelas = Clases::model()->findAll(array('condition' => 'sync_status is null', 'order' => 'id ASC'));
6683
6684 if (!empty($cekKelas)) {
6685 $total_kelas = count($cekKelas);
6686 $data_kelas = array();
6687 $raw_kelas = array();
6688 $ids = array();
6689 foreach ($cekKelas as $kelas) {
6690 $raw_kelas['id'] = $kelas->id;
6691 $raw_kelas['name'] = $kelas->name;
6692 $raw_kelas['teacher_id'] = $kelas->teacher_id;
6693 array_push($data_kelas, $raw_kelas);
6694 array_push($ids, $kelas->id);
6695 }
6696 $json_data_kelas = json_encode($data_kelas);
6697 //echo $json_data_kelas;
6698 $wid = implode(',', $ids);
6699
6700 $post_kelas = $post_url . "?type=kelas";
6701 $curlKelas = curl_init();
6702
6703 curl_setopt_array($curlKelas, array(
6704 CURLOPT_URL => $post_kelas,
6705 CURLOPT_VERBOSE => true,
6706 CURLOPT_RETURNTRANSFER => true,
6707 CURLOPT_ENCODING => "",
6708 CURLOPT_MAXREDIRS => 10,
6709 CURLOPT_TIMEOUT => 3000,
6710 CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
6711 CURLOPT_CUSTOMREQUEST => "POST",
6712 CURLOPT_POSTFIELDS => $json_data_kelas,
6713 CURLOPT_HTTPHEADER => array(
6714 "content-type: application/json"
6715 ),
6716 ));
6717
6718 $responseKelas = curl_exec($curlKelas);
6719 $errKelas = curl_error($curlKelas);
6720
6721 curl_close($curlKelas);
6722
6723 if ($errKelas) {
6724 echo "cURL Error #:" . $errKelas;
6725 } else {
6726 $dataKelas = json_decode($responseKelas);
6727 //echo $data->messages;
6728 if (!empty($dataMateri)) {
6729 if ($dataKelas->gagal == null) {
6730 $updateLocal = "UPDATE " . $prefix . "class SET sync_status = 2 WHERE id IN(" . $wid . ")";
6731
6732 $updateLocalCommand = Yii::app()->db->createCommand($updateLocal);
6733 $updateLocalCommand->execute();
6734 }
6735 }
6736
6737 //$cekStatus = "pelajaran";
6738 echo "pelajaran";
6739 }
6740 } else {
6741 $total_kelas = null;
6742 //$cekStatus = "pelajaran";
6743 echo "pelajaran";
6744 }
6745 break;
6746
6747 case "pelajaran":
6748 $cekMapel = Lesson::model()->findAll(array('condition' => 'sync_status is null', 'order' => 'id ASC'));
6749
6750 if (!empty($cekMapel)) {
6751 $total_mapel = count($cekMapel);
6752 $data_pelajaran = array();
6753 $raw_pelajaran = array();
6754 $ids = array();
6755 foreach ($cekMapel as $pelajaran) {
6756 $raw_pelajaran['id'] = $pelajaran->id;
6757 $raw_pelajaran['name'] = $pelajaran->name;
6758 $raw_pelajaran['user_id'] = $pelajaran->user_id;
6759 $raw_pelajaran['class_id'] = $pelajaran->class_id;
6760 $raw_pelajaran['created_at'] = $pelajaran->created_at;
6761 $raw_pelajaran['updated_at'] = $pelajaran->updated_at;
6762 $raw_pelajaran['created_by'] = $pelajaran->created_by;
6763 $raw_pelajaran['updated_by'] = $pelajaran->updated_by;
6764 array_push($data_pelajaran, $raw_pelajaran);
6765 array_push($ids, $pelajaran->id);
6766 }
6767 $json_data_pelajaran = json_encode($data_pelajaran);
6768 //echo $json_data_tugas;
6769 $wid = implode(',', $ids);
6770
6771 $post_pelajaran = $post_url . "?type=pelajaran";
6772 $curlPelajaran = curl_init();
6773
6774 curl_setopt_array($curlPelajaran, array(
6775 CURLOPT_URL => $post_pelajaran,
6776 CURLOPT_VERBOSE => true,
6777 CURLOPT_RETURNTRANSFER => true,
6778 CURLOPT_ENCODING => "",
6779 CURLOPT_MAXREDIRS => 10,
6780 CURLOPT_TIMEOUT => 3000,
6781 CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
6782 CURLOPT_CUSTOMREQUEST => "POST",
6783 CURLOPT_POSTFIELDS => $json_data_pelajaran,
6784 CURLOPT_HTTPHEADER => array(
6785 "content-type: application/json"
6786 ),
6787 ));
6788
6789 $responsePelajaran = curl_exec($curlPelajaran);
6790 $errPelajaran = curl_error($curlPelajaran);
6791
6792 curl_close($curlPelajaran);
6793
6794 if ($errPelajaran) {
6795 echo "cURL Error #:" . $errPelajaran;
6796 } else {
6797 $dataPelajaran = json_decode($responsePelajaran);
6798 //echo $data->messages;
6799 if (!empty($dataPelajaran)) {
6800 if ($dataPelajaran->gagal == null) {
6801 $updateLocal = "UPDATE " . $prefix . "lesson SET sync_status = 2 WHERE id IN(" . $wid . ")";
6802
6803 $updateLocalCommand = Yii::app()->db->createCommand($updateLocal);
6804 $updateLocalCommand->execute();
6805 }
6806 }
6807
6808 //$cekStatus = "absensi";
6809 echo "absensi";
6810 }
6811 } else {
6812 $total_mapel = null;
6813 echo "absensi";
6814 }
6815 break;
6816
6817 case "absensi":
6818 $cekAbsensi = Absensi::model()->findAll(array('condition' => 'sync_status is null', 'order' => 'id ASC'));
6819
6820 if (!empty($cekAbsensi)) {
6821 $total_absensi = count($cekAbsensi);
6822 $data_absensi = array();
6823 $raw_absensi = array();
6824 $ids = array();
6825 foreach ($cekAbsensi as $absensi) {
6826 $raw_absensi['id'] = $absensi->id;
6827 $raw_absensi['user_id'] = $absensi->user_id;
6828 $raw_absensi['type'] = $absensi->type;
6829 $raw_absensi['status'] = $absensi->status;
6830 $raw_absensi['alasan'] = $absensi->alasan;
6831 $raw_absensi['created_date'] = $absensi->created_date;
6832 array_push($data_absensi, $raw_absensi);
6833 array_push($ids, $absensi->id);
6834 }
6835 $json_data_absensi = json_encode($data_absensi);
6836 //echo $json_data_tugas;
6837 $wid = implode(',', $ids);
6838
6839 $post_absensi = $post_url . "?type=absensi";
6840 $curlAbsensi = curl_init();
6841
6842 curl_setopt_array($curlAbsensi, array(
6843 CURLOPT_URL => $post_absensi,
6844 CURLOPT_VERBOSE => true,
6845 CURLOPT_RETURNTRANSFER => true,
6846 CURLOPT_ENCODING => "",
6847 CURLOPT_MAXREDIRS => 10,
6848 CURLOPT_TIMEOUT => 3000,
6849 CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
6850 CURLOPT_CUSTOMREQUEST => "POST",
6851 CURLOPT_POSTFIELDS => $json_data_absensi,
6852 CURLOPT_HTTPHEADER => array(
6853 "content-type: application/json"
6854 ),
6855 ));
6856
6857 $responseAbsensi = curl_exec($curlAbsensi);
6858 $errAbsensi = curl_error($curlAbsensi);
6859
6860 curl_close($curlAbsensi);
6861
6862 if ($errAbsensi) {
6863 echo "cURL Error #:" . $errAbsensi;
6864 } else {
6865 $dataAbsensi = json_decode($responseAbsensi);
6866 //echo $data->messages;
6867 if (!empty($dataAbsensi)) {
6868 if ($dataAbsensi->gagal == null) {
6869 $updateLocal = "UPDATE " . $prefix . "absensi SET sync_status = 2 WHERE id IN(" . $wid . ")";
6870
6871 $updateLocalCommand = Yii::app()->db->createCommand($updateLocal);
6872 $updateLocalCommand->execute();
6873 }
6874 }
6875
6876 //$cekStatus = "Selesai";
6877 echo "selesai";
6878 }
6879 } else {
6880 $total_absensi = null;
6881 echo "selesai";
6882 //$cekStatus = "Selesai";
6883 }
6884 break;
6885
6886 default:
6887 //echo "selesai";
6888 break;
6889 }
6890 //$i++;
6891 //} while ($i <= 15);
6892 //echo $i;
6893 //echo $cekStatus;
6894 //}else{
6895 //}
6896 }
6897
6898 public function actionLiveSinkronisasi($cekStatus = null)
6899 {
6900 $url = "http://exambox.pinisi.co/api/sinkronisasiData";
6901
6902 $berhasil = null;
6903 $gagal = null;
6904 $prefix = Yii::app()->params['tablePrefix'];
6905 switch ($cekStatus) {
6906 case 'user':
6907 $user_url = $url . "?type=user";
6908 // Initiate curl
6909 $curlUser = curl_init();
6910
6911 curl_setopt_array($curlUser, array(
6912 CURLOPT_URL => $user_url,
6913 CURLOPT_VERBOSE => true,
6914 CURLOPT_RETURNTRANSFER => true,
6915 CURLOPT_SSL_VERIFYPEER => false,
6916 CURLOPT_ENCODING => "",
6917 CURLOPT_MAXREDIRS => 10,
6918 CURLOPT_TIMEOUT => 3000,
6919 CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
6920 ));
6921 // Execute
6922 $json_user = curl_exec($curlUser);
6923 // Closing
6924 curl_close($curlUser);
6925
6926 $responseUser = json_decode($json_user, true);
6927 //print_r($responseUser);
6928 if (!empty($responseUser['data'])) {
6929 //print_r($responseUser);
6930 $id_gagal = array();
6931
6932 foreach ($responseUser['data'] as $value) {
6933 $cekUserLocal = User::model()->findByPk($value['id']);
6934 $user_id = $value['id'];
6935 $username = $value['username'];
6936 $email = $value['email'];
6937 $encrypted_password = $value['encrypted_password'];
6938 $role_id = $value['role_id'];
6939 $created_at = $value['created_at'];
6940 $updated_at = $value['updated_at'];
6941 $class_id = $value['class_id'];
6942 $reset_password = $value['reset_password'];
6943 $display_name = $value['display_name'];
6944 $sync_status = 1;
6945
6946 if (!empty($cekUserLocal)) {
6947 $update = "UPDATE " . $prefix . "users SET email = :email, username = :username, encrypted_password = :encrypted_password, role_id = :role_id, created_at = :created_at, updated_at = :updated_at, class_id = :class_id, reset_password = :reset_password, display_name = :display_name, sync_status = :sync_status WHERE id = :id";
6948
6949 $updateCommand = Yii::app()->db->createCommand($update);
6950
6951 $updateCommand->bindParam(":id", $user_id, PDO::PARAM_STR);
6952 $updateCommand->bindParam(":email", $email, PDO::PARAM_STR);
6953 $updateCommand->bindParam(":username", $username, PDO::PARAM_STR);
6954 $updateCommand->bindParam(":encrypted_password", $encrypted_password, PDO::PARAM_STR);
6955 $updateCommand->bindParam(":role_id", $role_id, PDO::PARAM_STR);
6956 $updateCommand->bindParam(":created_at", $created_at, PDO::PARAM_STR);
6957 $updateCommand->bindParam(":updated_at", $updated_at, PDO::PARAM_STR);
6958 $updateCommand->bindParam(":class_id", $class_id, PDO::PARAM_STR);
6959 $updateCommand->bindParam(":reset_password", $reset_password, PDO::PARAM_STR);
6960 $updateCommand->bindParam(":display_name", $display_name, PDO::PARAM_STR);
6961 $updateCommand->bindParam(":sync_status", $sync_status, PDO::PARAM_STR);
6962 if ($updateCommand->execute()) {
6963 $berhasil = $berhasil + 1;
6964 } else {
6965 $gagal = $gagal + 1;
6966 array_push($id_gagal, $user_id);
6967 }
6968 } else {
6969 $insert = "INSERT INTO " . $prefix . "users (email,username,encrypted_password,role_id,created_at,updated_at,class_id,reset_password,display_name,sync_status) values(:email,:username,:encrypted_password,:role_id,:created_at,:updated_at,:class_id,:reset_password,:display_name,:sync_status)";
6970
6971 $insertCommand = Yii::app()->db->createCommand($insert);
6972
6973 $insertCommand->bindParam(":email", $email, PDO::PARAM_STR);
6974 $insertCommand->bindParam(":username", $username, PDO::PARAM_STR);
6975 $insertCommand->bindParam(":encrypted_password", $encrypted_password, PDO::PARAM_STR);
6976 $insertCommand->bindParam(":role_id", $role_id, PDO::PARAM_STR);
6977 $insertCommand->bindParam(":created_at", $created_at, PDO::PARAM_STR);
6978 $insertCommand->bindParam(":updated_at", $updated_at, PDO::PARAM_STR);
6979 $insertCommand->bindParam(":class_id", $class_id, PDO::PARAM_STR);
6980 $insertCommand->bindParam(":reset_password", $reset_password, PDO::PARAM_STR);
6981 $insertCommand->bindParam(":display_name", $display_name, PDO::PARAM_STR);
6982 $insertCommand->bindParam(":sync_status", $sync_status, PDO::PARAM_STR);
6983
6984 if ($insertCommand->execute()) {
6985 $berhasil = $berhasil + 1;
6986 } else {
6987 $gagal = $gagal + 1;
6988 array_push($id_gagal, $user_id);
6989 }
6990 }
6991 }
6992 echo "tugas";
6993 } else {
6994 echo "tugas";
6995 }
6996 //$cekStatus = "tugas";
6997
6998 break;
6999
7000 case "tugas":
7001 $tugas_url = $url . "?type=tugas";
7002 // Initiate curl
7003 $curlTugas = curl_init();
7004
7005 curl_setopt_array($curlTugas, array(
7006 CURLOPT_URL => $tugas_url,
7007 CURLOPT_VERBOSE => true,
7008 CURLOPT_RETURNTRANSFER => true,
7009 CURLOPT_SSL_VERIFYPEER => false,
7010 CURLOPT_ENCODING => "",
7011 CURLOPT_MAXREDIRS => 10,
7012 CURLOPT_TIMEOUT => 3000,
7013 CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
7014 ));
7015 // Execute
7016 $json_tugas = curl_exec($curlTugas);
7017 // Closing
7018 curl_close($curlTugas);
7019
7020 $responseTugas = json_decode($json_tugas, true);
7021 $id_gagal = array();
7022 //print_r($responseTugas);
7023 if (!empty($responseTugas['data'])) {
7024 foreach ($responseTugas['data'] as $value) {
7025 $cekTugasLocal = Assignment::model()->findByPk($value['id']);
7026 $tugas_id = $value['id'];
7027 $title = $value['title'];
7028 $content = $value['content'];
7029 $created_at = $value['created_at'];
7030 $updated_at = $value['updated_at'];
7031 $created_by = $value['created_by'];
7032 $updated_by = $value['updated_by'];
7033 $due_date = $value['due_date'];
7034 $lesson_id = $value['lesson_id'];
7035 $file = $value['file'];
7036 $assignment_type = $value['assignment_type'];
7037 $add_to_summary = $value['add_to_summary'];
7038 $recipient = $value['recipient'];
7039 $semester = $value['semester'];
7040 $year = $value['year'];
7041 $status = $value['status'];
7042 $sync_status = 2;
7043
7044 if (!empty($cekTugasLocal)) {
7045 $update = "UPDATE " . $prefix . "assignment SET content = :content, title = :title, created_at = :created_at, updated_at = :updated_at, created_by = :created_by, updated_by = :updated_by, due_date = :due_date, lesson_id = :lesson_id, file = :file, assignment_type = :assignment_type, add_to_summary = :add_to_summary, sync_status = :sync_status, recipient = :recipient, semester = :semester, year = :year, status = :status, sync_status = :sync_status WHERE id = :id";
7046
7047 $updateCommand = Yii::app()->db->createCommand($update);
7048
7049 $updateCommand->bindParam(":id", $tugas_id, PDO::PARAM_STR);
7050 $updateCommand->bindParam(":content", $content, PDO::PARAM_STR);
7051 $updateCommand->bindParam(":title", $title, PDO::PARAM_STR);
7052 $updateCommand->bindParam(":created_at", $created_at, PDO::PARAM_STR);
7053 $updateCommand->bindParam(":updated_at", $updated_at, PDO::PARAM_STR);
7054 $updateCommand->bindParam(":created_by", $created_by, PDO::PARAM_STR);
7055 $updateCommand->bindParam(":updated_by", $updated_by, PDO::PARAM_STR);
7056 $updateCommand->bindParam(":due_date", $due_date, PDO::PARAM_STR);
7057 $updateCommand->bindParam(":lesson_id", $lesson_id, PDO::PARAM_STR);
7058 $updateCommand->bindParam(":file", $file, PDO::PARAM_STR);
7059 $updateCommand->bindParam(":assignment_type", $assignment_type, PDO::PARAM_STR);
7060 $updateCommand->bindParam(":add_to_summary", $add_to_summary, PDO::PARAM_STR);
7061 $updateCommand->bindParam(":recipient", $recipient, PDO::PARAM_STR);
7062 $updateCommand->bindParam(":semester", $semester, PDO::PARAM_STR);
7063 $updateCommand->bindParam(":year", $year, PDO::PARAM_STR);
7064 $updateCommand->bindParam(":status", $status, PDO::PARAM_STR);
7065 $updateCommand->bindParam(":sync_status", $sync_status, PDO::PARAM_STR);
7066 if ($updateCommand->execute()) {
7067 $berhasil = $berhasil + 1;
7068 } else {
7069 $gagal = $gagal + 1;
7070 array_push($id_gagal, $tugas_id);
7071 }
7072 } else {
7073 $insert = "INSERT INTO " . $prefix . "assignment (content,title,created_at,updated_at,created_by,updated_by,due_date,lesson_id,file,assignment_type,add_to_summary,recipient,semester,year,status,sync_status) values(:content,:title,:created_at,:updated_at,:created_by,:updated_by,:due_date,:lesson_id,:file,:assignment_type,:add_to_summary,:recipient,:semester,:year,:status,:sync_status)";
7074
7075 $insertCommand = Yii::app()->db->createCommand($insert);
7076
7077 $insertCommand->bindParam(":content", $content, PDO::PARAM_STR);
7078 $insertCommand->bindParam(":title", $title, PDO::PARAM_STR);
7079 $insertCommand->bindParam(":created_at", $created_at, PDO::PARAM_STR);
7080 $insertCommand->bindParam(":updated_at", $updated_at, PDO::PARAM_STR);
7081 $insertCommand->bindParam(":created_by", $created_by, PDO::PARAM_STR);
7082 $insertCommand->bindParam(":updated_by", $updated_by, PDO::PARAM_STR);
7083 $insertCommand->bindParam(":due_date", $due_date, PDO::PARAM_STR);
7084 $insertCommand->bindParam(":lesson_id", $lesson_id, PDO::PARAM_STR);
7085 $insertCommand->bindParam(":file", $file, PDO::PARAM_STR);
7086 $insertCommand->bindParam(":assignment_type", $assignment_type, PDO::PARAM_STR);
7087 $insertCommand->bindParam(":add_to_summary", $add_to_summary, PDO::PARAM_STR);
7088 $insertCommand->bindParam(":recipient", $recipient, PDO::PARAM_STR);
7089 $insertCommand->bindParam(":semester", $semester, PDO::PARAM_STR);
7090 $insertCommand->bindParam(":year", $year, PDO::PARAM_STR);
7091 $insertCommand->bindParam(":status", $status, PDO::PARAM_STR);
7092 $insertCommand->bindParam(":sync_status", $sync_status, PDO::PARAM_STR);
7093
7094 if ($insertCommand->execute()) {
7095 $berhasil = $berhasil + 1;
7096 } else {
7097 $gagal = $gagal + 1;
7098 array_push($id_gagal, $tugas_id);
7099 }
7100 }
7101 }
7102 echo "tugasSiswa";
7103 } else {
7104 echo "tugasSiswa";
7105 }
7106 //$cekStatus = "tugasSiswa";
7107
7108 break;
7109
7110 case "tugasSiswa":
7111 $ts_url = $url . "?type=tugasSiswa";
7112 // Initiate curl
7113 $curlTs = curl_init();
7114 // Disable SSL verification
7115 curl_setopt_array($curlTs, array(
7116 CURLOPT_URL => $ts_url,
7117 CURLOPT_VERBOSE => true,
7118 CURLOPT_RETURNTRANSFER => true,
7119 CURLOPT_SSL_VERIFYPEER => false,
7120 CURLOPT_ENCODING => "",
7121 CURLOPT_MAXREDIRS => 10,
7122 CURLOPT_TIMEOUT => 3000,
7123 CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
7124 ));
7125 // Execute
7126 $json_ts = curl_exec($curlTs);
7127 // Closing
7128 curl_close($curlTs);
7129
7130 $responseTs = json_decode($json_ts, true);
7131 $id_gagal = array();
7132 //print_r($responseTs);
7133 if (!empty($responseTs['data'])) {
7134 foreach ($responseTs['data'] as $value) {
7135 $cekTsLokal = StudentAssignment::model()->findByPk($value['id']);
7136 $ts_id = $value['id'];
7137 $assignment_id = $value['assignment_id'];
7138 $content = $value['content'];
7139 $created_at = $value['created_at'];
7140 $updated_at = $value['updated_at'];
7141 $file = $value['file'];
7142 $student_id = $value['student_id'];
7143 $score = $value['score'];
7144 $status = $value['status'];
7145 $sync_status = 2;
7146
7147 if (!empty($cekTsLokal)) {
7148 $update = "UPDATE " . $prefix . "student_assignment SET content = :content, assignment_id = :assignment_id, created_at = :created_at, updated_at = :updated_at, file = :file, student_id = :student_id, score = :score, status = :status, sync_status = :sync_status WHERE id = :id";
7149
7150 $updateCommand = Yii::app()->db->createCommand($update);
7151
7152 $updateCommand->bindParam(":id", $ts_id, PDO::PARAM_STR);
7153 $updateCommand->bindParam(":content", $content, PDO::PARAM_STR);
7154 $updateCommand->bindParam(":assignment_id", $assignment_id, PDO::PARAM_STR);
7155 $updateCommand->bindParam(":created_at", $created_at, PDO::PARAM_STR);
7156 $updateCommand->bindParam(":updated_at", $updated_at, PDO::PARAM_STR);
7157 $updateCommand->bindParam(":file", $file, PDO::PARAM_STR);
7158 $updateCommand->bindParam(":student_id", $student_id, PDO::PARAM_STR);
7159 $updateCommand->bindParam(":score", $score, PDO::PARAM_STR);
7160 $updateCommand->bindParam(":status", $status, PDO::PARAM_STR);
7161 $updateCommand->bindParam(":sync_status", $sync_status, PDO::PARAM_STR);
7162 if ($updateCommand->execute()) {
7163 $berhasil = $berhasil + 1;
7164 } else {
7165 $gagal = $gagal + 1;
7166 array_push($id_gagal, $ts_id);
7167 }
7168 } else {
7169 $insert = "INSERT INTO " . $prefix . "student_assignment (content,assignment_id,created_at,updated_at,file,student_id,score,status,sync_status) values(:content,:assignment_id,:created_at,:updated_at,:file,:student_id,:score,:status,:sync_status)";
7170
7171 $insertCommand = Yii::app()->db->createCommand($insert);
7172
7173 $insertCommand->bindParam(":content", $content, PDO::PARAM_STR);
7174 $insertCommand->bindParam(":assignment_id", $assignment_id, PDO::PARAM_STR);
7175 $insertCommand->bindParam(":created_at", $created_at, PDO::PARAM_STR);
7176 $insertCommand->bindParam(":updated_at", $updated_at, PDO::PARAM_STR);
7177 $insertCommand->bindParam(":file", $file, PDO::PARAM_STR);
7178 $insertCommand->bindParam(":student_id", $student_id, PDO::PARAM_STR);
7179 $insertCommand->bindParam(":score", $score, PDO::PARAM_STR);
7180 $insertCommand->bindParam(":status", $status, PDO::PARAM_STR);
7181 $insertCommand->bindParam(":sync_status", $sync_status, PDO::PARAM_STR);
7182
7183 if ($insertCommand->execute()) {
7184 $berhasil = $berhasil + 1;
7185 } else {
7186 $gagal = $gagal + 1;
7187 array_push($id_gagal, $ts_id);
7188 }
7189 }
7190 }
7191 echo "materi";
7192 } else {
7193 echo "materi";
7194 }
7195 //$cekStatus = "materi";
7196
7197 break;
7198
7199 case "materi":
7200 $materi_url = $url . "?type=materi";
7201 // Initiate curl
7202 $curlMateri = curl_init();
7203 // Disable SSL verification
7204 curl_setopt_array($curlMateri, array(
7205 CURLOPT_URL => $materi_url,
7206 CURLOPT_VERBOSE => true,
7207 CURLOPT_RETURNTRANSFER => true,
7208 CURLOPT_SSL_VERIFYPEER => false,
7209 CURLOPT_ENCODING => "",
7210 CURLOPT_MAXREDIRS => 10,
7211 CURLOPT_TIMEOUT => 3000,
7212 CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
7213 ));
7214 // Execute
7215 $json_materi = curl_exec($curlMateri);
7216 // Closing
7217 curl_close($curlMateri);
7218
7219 $responseMateri = json_decode($json_materi, true);
7220 $id_gagal = array();
7221 //print_r($responseMateri);
7222
7223 if (!empty($responseMateri['data'])) {
7224 foreach ($responseMateri['data'] as $value) {
7225 $cekMateriLokal = Chapters::model()->findByPk($value['id']);
7226 $materi_id = $value['id'];
7227 $id_lesson = $value['id_lesson'];
7228 $title = $value['title'];
7229 $description = $value['description'];
7230 $created_at = $value['created_at'];
7231 $updated_at = $value['updated_at'];
7232 $created_by = $value['created_by'];
7233 $updated_by = $value['updated_by'];
7234 $content = $value['content'];
7235 $chapter_type = $value['chapter_type'];
7236 $semester = $value['semester'];
7237 $year = $value['year'];
7238 $sync_status = 2;
7239
7240 if (!empty($cekMateriLokal)) {
7241 $update = "UPDATE " . $prefix . "chapters SET id_lesson = :id_lesson, title = :title, description = :description, created_at = :created_at, updated_at = :updated_at, created_by = :created_by, updated_by = :updated_by, content = :content, chapter_type = :chapter_type, semester = :semester , year = :year, sync_status = :sync_status WHERE id = :id";
7242
7243 $updateCommand = Yii::app()->db->createCommand($update);
7244
7245 $updateCommand->bindParam(":id", $materi_id, PDO::PARAM_STR);
7246 $updateCommand->bindParam(":id_lesson", $id_lesson, PDO::PARAM_STR);
7247 $updateCommand->bindParam(":title", $title, PDO::PARAM_STR);
7248 $updateCommand->bindParam(":description", $description, PDO::PARAM_STR);
7249 $updateCommand->bindParam(":created_at", $created_at, PDO::PARAM_STR);
7250 $updateCommand->bindParam(":updated_at", $updated_at, PDO::PARAM_STR);
7251 $updateCommand->bindParam(":created_by", $created_by, PDO::PARAM_STR);
7252 $updateCommand->bindParam(":updated_by", $updated_by, PDO::PARAM_STR);
7253 $updateCommand->bindParam(":content", $content, PDO::PARAM_STR);
7254 $updateCommand->bindParam(":chapter_type", $chapter_type, PDO::PARAM_STR);
7255 $updateCommand->bindParam(":semester ", $semester, PDO::PARAM_STR);
7256 $updateCommand->bindParam(":year", $year, PDO::PARAM_STR);
7257 $updateCommand->bindParam(":sync_status", $sync_status, PDO::PARAM_STR);
7258 if ($updateCommand->execute()) {
7259 $berhasil = $berhasil + 1;
7260 } else {
7261 $gagal = $gagal + 1;
7262 array_push($id_gagal, $materi_id);
7263 }
7264 } else {
7265 $insert = "INSERT INTO " . $prefix . "chapters (id_lesson,title,description,created_at,updated_at,created_by,updated_by,content,chapter_type,semester,year,sync_status) values(:id_lesson,:title,:description,:created_at,:updated_at,:created_by,:updated_by,:content,:chapter_type,:semester,:year,:sync_status)";
7266
7267 $insertCommand = Yii::app()->db->createCommand($insert);
7268
7269 $insertCommand->bindParam(":id_lesson", $id_lesson, PDO::PARAM_STR);
7270 $insertCommand->bindParam(":title", $title, PDO::PARAM_STR);
7271 $insertCommand->bindParam(":description", $description, PDO::PARAM_STR);
7272 $insertCommand->bindParam(":created_at", $created_at, PDO::PARAM_STR);
7273 $insertCommand->bindParam(":updated_at", $updated_at, PDO::PARAM_STR);
7274 $insertCommand->bindParam(":created_by", $created_by, PDO::PARAM_STR);
7275 $insertCommand->bindParam(":updated_by", $updated_by, PDO::PARAM_STR);
7276 $insertCommand->bindParam(":content", $content, PDO::PARAM_STR);
7277 $insertCommand->bindParam(":chapter_type", $chapter_type, PDO::PARAM_STR);
7278 $insertCommand->bindParam(":semester", $semester, PDO::PARAM_STR);
7279 $insertCommand->bindParam(":year", $year, PDO::PARAM_STR);
7280 $insertCommand->bindParam(":sync_status", $sync_status, PDO::PARAM_STR);
7281
7282 if ($insertCommand->execute()) {
7283 $berhasil = $berhasil + 1;
7284 } else {
7285 $gagal = $gagal + 1;
7286 array_push($id_gagal, $materi_id);
7287 }
7288 }
7289 }
7290 echo "materiFile";
7291 } else {
7292 echo "materiFile";
7293 }
7294 //$cekStatus = "materiFile";
7295
7296 break;
7297
7298 case "materiFile":
7299 $fm_url = $url . "?type=fileMateri";
7300 // Initiate curl
7301 $curlMf = curl_init();
7302 // Disable SSL verification
7303 curl_setopt_array($curlMf, array(
7304 CURLOPT_URL => $fm_url,
7305 CURLOPT_VERBOSE => true,
7306 CURLOPT_RETURNTRANSFER => true,
7307 CURLOPT_SSL_VERIFYPEER => false,
7308 CURLOPT_ENCODING => "",
7309 CURLOPT_MAXREDIRS => 10,
7310 CURLOPT_TIMEOUT => 3000,
7311 CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
7312 ));
7313 // Execute
7314 $json_mf = curl_exec($curlMf);
7315 // Closing
7316 curl_close($curlMf);
7317
7318 $responseMf = json_decode($json_mf, true);
7319 $id_gagal = array();
7320 //print_r($responseMf);
7321
7322 if (!empty($responseMf['data'])) {
7323 foreach ($responseMf['data'] as $value) {
7324 $cekMfLokal = ChapterFiles::model()->findByPk($value['id']);
7325 $mf_id = $value['id'];
7326 $id_chapter = $value['id_chapter'];
7327 $file = $value['file'];
7328 $type = $value['type'];
7329 $created_at = $value['created_at'];
7330 $updated_at = $value['updated_at'];
7331 $created_by = $value['created_by'];
7332 $updated_by = $value['updated_by'];
7333 $content = $value['content'];
7334 $sync_status = 2;
7335
7336 if (!empty($cekMfLokal)) {
7337 $update = "UPDATE " . $prefix . "chapter_files SET id_chapter = :id_chapter, file = :file, type = :type, created_at = :created_at, updated_at = :updated_at, created_by = :created_by, updated_by = :updated_by, content = :content, sync_status = :sync_status WHERE id = :id";
7338
7339 $updateCommand = Yii::app()->db->createCommand($update);
7340
7341 $updateCommand->bindParam(":id", $mf_id, PDO::PARAM_STR);
7342 $updateCommand->bindParam(":id_chapter", $id_chapter, PDO::PARAM_STR);
7343 $updateCommand->bindParam(":file", $file, PDO::PARAM_STR);
7344 $updateCommand->bindParam(":type", $type, PDO::PARAM_STR);
7345 $updateCommand->bindParam(":created_at", $created_at, PDO::PARAM_STR);
7346 $updateCommand->bindParam(":updated_at", $updated_at, PDO::PARAM_STR);
7347 $updateCommand->bindParam(":created_by", $created_by, PDO::PARAM_STR);
7348 $updateCommand->bindParam(":updated_by", $updated_by, PDO::PARAM_STR);
7349 $updateCommand->bindParam(":content", $content, PDO::PARAM_STR);
7350 $updateCommand->bindParam(":sync_status", $sync_status, PDO::PARAM_STR);
7351 if ($updateCommand->execute()) {
7352 $berhasil = $berhasil + 1;
7353 } else {
7354 $gagal = $gagal + 1;
7355 array_push($id_gagal, $mf_id);
7356 }
7357 } else {
7358 $insert = "INSERT INTO " . $prefix . "chapter_files (id_chapter,file,type,created_at,updated_at,created_by,updated_by,content,sync_status) values(:id_chapter,:file,:type,:created_at,:updated_at,:created_by,:updated_by,:content,:sync_status)";
7359
7360 $insertCommand = Yii::app()->db->createCommand($insert);
7361
7362 $insertCommand->bindParam(":content", $content, PDO::PARAM_STR);
7363 $insertCommand->bindParam(":id_chapter", $id_chapter, PDO::PARAM_STR);
7364 $insertCommand->bindParam(":file", $file, PDO::PARAM_STR);
7365 $insertCommand->bindParam(":type", $type, PDO::PARAM_STR);
7366 $insertCommand->bindParam(":created_at", $created_at, PDO::PARAM_STR);
7367 $insertCommand->bindParam(":updated_at", $updated_at, PDO::PARAM_STR);
7368 $insertCommand->bindParam(":created_by", $created_by, PDO::PARAM_STR);
7369 $insertCommand->bindParam(":updated_by", $updated_by, PDO::PARAM_STR);
7370 $insertCommand->bindParam(":sync_status", $sync_status, PDO::PARAM_STR);
7371
7372 if ($insertCommand->execute()) {
7373 $berhasil = $berhasil + 1;
7374 } else {
7375 $gagal = $gagal + 1;
7376 array_push($id_gagal, $mf_id);
7377 }
7378 }
7379 }
7380 echo "quiz";
7381 } else {
7382 echo "quiz";
7383 }
7384 //$cekStatus = "quiz";
7385
7386 break;
7387
7388 case "quiz":
7389 $quiz_url = $url . "?type=quiz";
7390 // Initiate curl
7391 $curlQuiz = curl_init();
7392 // Disable SSL verification
7393 curl_setopt_array($curlQuiz, array(
7394 CURLOPT_URL => $quiz_url,
7395 CURLOPT_VERBOSE => true,
7396 CURLOPT_RETURNTRANSFER => true,
7397 CURLOPT_SSL_VERIFYPEER => false,
7398 CURLOPT_ENCODING => "",
7399 CURLOPT_MAXREDIRS => 10,
7400 CURLOPT_TIMEOUT => 3000,
7401 CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
7402 ));
7403 // Execute
7404 $json_quiz = curl_exec($curlQuiz);
7405 // Closing
7406 curl_close($curlQuiz);
7407
7408 $responseQuiz = json_decode($json_quiz, true);
7409 $id_gagal = array();
7410 //print_r($responseQuiz);
7411
7412 if (!empty($responseQuiz['data'])) {
7413 foreach ($responseQuiz['data'] as $value) {
7414 $cekQuizLokal = Quiz::model()->findByPk($value['id']);
7415 $quiz_id = $value['id'];
7416 $title = $value['title'];
7417 $lesson_id = $value['lesson_id'];
7418 $chapter_id = $value['chapter_id'];
7419 $quiz_type = $value['quiz_type'];
7420 $created_at = $value['created_at'];
7421 $updated_at = $value['updated_at'];
7422 $created_by = $value['created_by'];
7423 $updated_by = $value['updated_by'];
7424 $start_time = $value['start_time'];
7425 $end_time = $value['end_time'];
7426 $total_question = $value['total_question'];
7427 $status = $value['status'];
7428 $add_to_summary = $value['add_to_summary'];
7429 $repeat_quiz = $value['repeat_quiz'];
7430 $question = $value['question'];
7431 $semester = $value['semester'];
7432 $year = $value['year'];
7433 $random = $value['random'];
7434 $random = $value['show_nilai'];
7435 $sync_status = 2;
7436
7437 if (!empty($cekQuizLokal)) {
7438 $update = "UPDATE " . $prefix . "quiz SET title = :title, lesson_id = :lesson_id, chapter_id = :chapter_id, quiz_type = :quiz_type, created_at = :created_at, updated_at = :updated_at, created_by = :created_by, updated_by = :updated_by, start_time = :start_time, end_time = :end_time, total_question = :total_question, status = :status, add_to_summary = :add_to_summary, repeat_quiz = :repeat_quiz, question = :question, semester = :semester, year = :year, random = :random, sync_status = :sync_status, show_nilai = :show_nilai WHERE id = :id";
7439
7440 $updateCommand = Yii::app()->db->createCommand($update);
7441
7442 $updateCommand->bindParam(":id", $quiz_id, PDO::PARAM_STR);
7443 $updateCommand->bindParam(":title", $title, PDO::PARAM_STR);
7444 $updateCommand->bindParam(":lesson_id", $lesson_id, PDO::PARAM_STR);
7445 $updateCommand->bindParam(":chapter_id", $chapter_id, PDO::PARAM_STR);
7446 $updateCommand->bindParam(":quiz_type", $quiz_type, PDO::PARAM_STR);
7447 $updateCommand->bindParam(":created_at", $created_at, PDO::PARAM_STR);
7448 $updateCommand->bindParam(":updated_at", $updated_at, PDO::PARAM_STR);
7449 $updateCommand->bindParam(":created_by", $created_by, PDO::PARAM_STR);
7450 $updateCommand->bindParam(":updated_by", $updated_by, PDO::PARAM_STR);
7451 $updateCommand->bindParam(":start_time", $start_time, PDO::PARAM_STR);
7452 $updateCommand->bindParam(":end_time", $end_time, PDO::PARAM_STR);
7453 $updateCommand->bindParam(":total_question", $total_question, PDO::PARAM_STR);
7454 $updateCommand->bindParam(":status", $status, PDO::PARAM_STR);
7455 $updateCommand->bindParam(":add_to_summary", $add_to_summary, PDO::PARAM_STR);
7456 $updateCommand->bindParam(":repeat_quiz", $repeat_quiz, PDO::PARAM_STR);
7457 $updateCommand->bindParam(":question", $question, PDO::PARAM_STR);
7458 $updateCommand->bindParam(":semester", $semester, PDO::PARAM_STR);
7459 $updateCommand->bindParam(":year", $year, PDO::PARAM_STR);
7460 $updateCommand->bindParam(":random", $random, PDO::PARAM_STR);
7461 $updateCommand->bindParam(":sync_status", $sync_status, PDO::PARAM_STR);
7462 $updateCommand->bindParam(":show_nilai", $show_nilai, PDO::PARAM_STR);
7463 if ($updateCommand->execute()) {
7464 $berhasil = $berhasil + 1;
7465 } else {
7466 $gagal = $gagal + 1;
7467 array_push($id_gagal, $quiz_id);
7468 }
7469 } else {
7470 $insert = "INSERT INTO " . $prefix . "quiz (title,lesson_id,chapter_id,quiz_type,created_at,updated_at,created_by,updated_by,start_time,end_time,total_question,status,add_to_summary,repeat_quiz,question,semester,year,random,sync_status) values(:title,:lesson_id,:chapter_id,:quiz_type,:created_at,:updated_at,:created_by,:updated_by,:start_time,:end_time,:total_question,:status,:add_to_summary,:repeat_quiz,:question,:semester,:year,:random,:sync_status)";
7471
7472 $insertCommand = Yii::app()->db->createCommand($insert);
7473
7474 $insertCommand->bindParam(":title", $title, PDO::PARAM_STR);
7475 $insertCommand->bindParam(":lesson_id", $lesson_id, PDO::PARAM_STR);
7476 $insertCommand->bindParam(":chapter_id", $chapter_id, PDO::PARAM_STR);
7477 $insertCommand->bindParam(":quiz_type", $quiz_type, PDO::PARAM_STR);
7478 $insertCommand->bindParam(":created_at", $created_at, PDO::PARAM_STR);
7479 $insertCommand->bindParam(":updated_at", $updated_at, PDO::PARAM_STR);
7480 $insertCommand->bindParam(":created_by", $created_by, PDO::PARAM_STR);
7481 $insertCommand->bindParam(":updated_by", $updated_by, PDO::PARAM_STR);
7482 $insertCommand->bindParam(":start_time", $start_time, PDO::PARAM_STR);
7483 $insertCommand->bindParam(":end_time", $end_time, PDO::PARAM_STR);
7484 $insertCommand->bindParam(":total_question", $total_question, PDO::PARAM_STR);
7485 $insertCommand->bindParam(":status", $status, PDO::PARAM_STR);
7486 $insertCommand->bindParam(":add_to_summary", $add_to_summary, PDO::PARAM_STR);
7487 $insertCommand->bindParam(":repeat_quiz", $repeat_quiz, PDO::PARAM_STR);
7488 $insertCommand->bindParam(":question", $question, PDO::PARAM_STR);
7489 $insertCommand->bindParam(":semester", $semester, PDO::PARAM_STR);
7490 $insertCommand->bindParam(":year", $year, PDO::PARAM_STR);
7491 $insertCommand->bindParam(":random", $random, PDO::PARAM_STR);
7492 $insertCommand->bindParam(":sync_status", $sync_status, PDO::PARAM_STR);
7493
7494 if ($insertCommand->execute()) {
7495 $berhasil = $berhasil + 1;
7496 } else {
7497 $gagal = $gagal + 1;
7498 array_push($id_gagal, $quiz_id);
7499 }
7500 }
7501 }
7502 echo "quizSiswa";
7503 } else {
7504 echo "quizSiswa";
7505 }
7506 //$cekStatus = "quizSiswa";
7507
7508 break;
7509
7510 case "quizSiswa":
7511 $qs_url = $url . "?type=quizSiswa";
7512 // Initiate curl
7513 $curlQs = curl_init();
7514 // Disable SSL verification
7515 curl_setopt_array($curlQs, array(
7516 CURLOPT_URL => $qs_url,
7517 CURLOPT_VERBOSE => true,
7518 CURLOPT_RETURNTRANSFER => true,
7519 CURLOPT_SSL_VERIFYPEER => false,
7520 CURLOPT_ENCODING => "",
7521 CURLOPT_MAXREDIRS => 10,
7522 CURLOPT_TIMEOUT => 3000,
7523 CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
7524 ));
7525 // Execute
7526 $json_qs = curl_exec($curlQs);
7527 // Closing
7528 curl_close($curlQs);
7529
7530 $responseQs = json_decode($json_qs, true);
7531 $id_gagal = array();
7532 //print_r($responseQs);
7533
7534 if (!empty($responseQs['data'])) {
7535 foreach ($responseQs['data'] as $value) {
7536 $cekQzLokal = StudentQuiz::model()->findByPk($value['id']);
7537 $qz_id = $value['id'];
7538 $quiz_id = $value['quiz_id'];
7539 $student_id = $value['student_id'];
7540 $created_at = $value['created_at'];
7541 $updated_at = $value['updated_at'];
7542 $score = $value['score'];
7543 $right_answer = $value['right_answer'];
7544 $wrong_answer = $value['wrong_answer'];
7545 $unanswered = $value['unanswered'];
7546 $student_answer = $value['student_answer'];
7547 $attempt = $value['attempt'];
7548 $sync_status = 2;
7549
7550 if (!empty($cekQzLokal)) {
7551 $update = "UPDATE " . $prefix . "student_quiz SET quiz_id = :quiz_id, student_id = :student_id, created_at = :created_at, updated_at = :updated_at, score = :score, right_answer = :right_answer, wrong_answer = :wrong_answer, unanswered = :unanswered, student_answer = :student_answer, attempt = :attempt, sync_status = :sync_status WHERE id = :id";
7552
7553 $updateCommand = Yii::app()->db->createCommand($update);
7554
7555 $updateCommand->bindParam(":id", $qz_id, PDO::PARAM_STR);
7556 $updateCommand->bindParam(":quiz_id", $quiz_id, PDO::PARAM_STR);
7557 $updateCommand->bindParam(":student_id", $student_id, PDO::PARAM_STR);
7558 $updateCommand->bindParam(":created_at", $created_at, PDO::PARAM_STR);
7559 $updateCommand->bindParam(":updated_at", $updated_at, PDO::PARAM_STR);
7560 $updateCommand->bindParam(":score", $score, PDO::PARAM_STR);
7561 $updateCommand->bindParam(":right_answer", $right_answer, PDO::PARAM_STR);
7562 $updateCommand->bindParam(":wrong_answer", $wrong_answer, PDO::PARAM_STR);
7563 $updateCommand->bindParam(":unanswered", $unanswered, PDO::PARAM_STR);
7564 $updateCommand->bindParam(":student_answer", $student_answer, PDO::PARAM_STR);
7565 $updateCommand->bindParam(":attempt", $attempt, PDO::PARAM_STR);
7566 $updateCommand->bindParam(":sync_status", $sync_status, PDO::PARAM_STR);
7567 if ($updateCommand->execute()) {
7568 $berhasil = $berhasil + 1;
7569 } else {
7570 $gagal = $gagal + 1;
7571 array_push($id_gagal, $qz_id);
7572 }
7573 } else {
7574 $insert = "INSERT INTO " . $prefix . "student_quiz (quiz_id,student_id,created_at,updated_at,score,right_answer,wrong_answer,unanswered,student_answer,attempt,sync_status) values(:quiz_id,:student_id,:created_at,:updated_at,:score,:right_answer,:wrong_answer,:unanswered,:student_answer,:attempt,:sync_status)";
7575
7576 $insertCommand = Yii::app()->db->createCommand($insert);
7577
7578 $insertCommand->bindParam(":unanswered", $unanswered, PDO::PARAM_STR);
7579 $insertCommand->bindParam(":quiz_id", $quiz_id, PDO::PARAM_STR);
7580 $insertCommand->bindParam(":student_id", $student_id, PDO::PARAM_STR);
7581 $insertCommand->bindParam(":created_at", $created_at, PDO::PARAM_STR);
7582 $insertCommand->bindParam(":updated_at", $updated_at, PDO::PARAM_STR);
7583 $insertCommand->bindParam(":score", $score, PDO::PARAM_STR);
7584 $insertCommand->bindParam(":right_answer", $right_answer, PDO::PARAM_STR);
7585 $insertCommand->bindParam(":wrong_answer", $wrong_answer, PDO::PARAM_STR);
7586 $insertCommand->bindParam(":student_answer", $student_answer, PDO::PARAM_STR);
7587 $insertCommand->bindParam(":attempt", $attempt, PDO::PARAM_STR);
7588 $insertCommand->bindParam(":sync_status", $sync_status, PDO::PARAM_STR);
7589
7590 if ($insertCommand->execute()) {
7591 $berhasil = $berhasil + 1;
7592 } else {
7593 $gagal = $gagal + 1;
7594 array_push($id_gagal, $qz_id);
7595 }
7596 }
7597 }
7598 echo "soal";
7599 } else {
7600 echo "soal";
7601 }
7602 //$cekStatus = "soal";
7603
7604 break;
7605
7606 case "soal":
7607 $soal_url = $url . "?type=soal";
7608 // Initiate curl
7609 $curlSoal = curl_init();
7610 // Disable SSL verification
7611 curl_setopt_array($curlSoal, array(
7612 CURLOPT_URL => $soal_url,
7613 CURLOPT_VERBOSE => true,
7614 CURLOPT_RETURNTRANSFER => true,
7615 CURLOPT_SSL_VERIFYPEER => false,
7616 CURLOPT_ENCODING => "",
7617 CURLOPT_MAXREDIRS => 10,
7618 CURLOPT_TIMEOUT => 3000,
7619 CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
7620 ));
7621 // Execute
7622 $json_soal = curl_exec($curlSoal);
7623 // Closing
7624 curl_close($curlSoal);
7625
7626 $responseSoal = json_decode($json_soal, true);
7627 $id_gagal = array();
7628 //print_r($responseSoal);
7629
7630 if (!empty($responseSoal['data'])) {
7631 foreach ($responseSoal['data'] as $value) {
7632 $cekQuestionLokal = Questions::model()->findByPk($value['id']);
7633 $question_id = $value['id'];
7634 $id_quiz = $value['quiz_id'];
7635 $lesson_id = $value['lesson_id'];
7636 $title = $value['title'];
7637 $text = $value['text'];
7638 $choices = $value['choices'];
7639 $key_answer = $value['key_answer'];
7640 $created_at = $value['created_at'];
7641 $updated_at = $value['updated_at'];
7642 $teacher_id = $value['teacher_id'];
7643 $created_by = $value['created_by'];
7644 $updated_by = $value['updated_by'];
7645 $file = $value['file'];
7646 $type = $value['type'];
7647 $choices_files = $value['choices_files'];
7648 $sync_status = 2;
7649
7650 if (!empty($cekQuestionLokal)) {
7651 $update = "UPDATE " . $prefix . "questions SET quiz_id = :quiz_id, lesson_id = :lesson_id, title = :title, text = :text, choices = :choices, key_answer = :key_answer, created_at = :created_at, updated_at = :updated_at, teacher_id = :teacher_id, created_by = :created_by, updated_by = :updated_by, file = :file, type = :type, choices_files = :choices_files, sync_status = :sync_status WHERE id = :id";
7652
7653 $updateCommand = Yii::app()->db->createCommand($update);
7654
7655 $updateCommand->bindParam(":id", $question_id, PDO::PARAM_STR);
7656 $updateCommand->bindParam(":quiz_id", $id_quiz, PDO::PARAM_STR);
7657 $updateCommand->bindParam(":lesson_id", $lesson_id, PDO::PARAM_STR);
7658 $updateCommand->bindParam(":title", $title, PDO::PARAM_STR);
7659 $updateCommand->bindParam(":text", $text, PDO::PARAM_STR);
7660 $updateCommand->bindParam(":choices", $choices, PDO::PARAM_STR);
7661 $updateCommand->bindParam(":key_answer", $key_answer, PDO::PARAM_STR);
7662 $updateCommand->bindParam(":created_at", $created_at, PDO::PARAM_STR);
7663 $updateCommand->bindParam(":updated_at", $updated_at, PDO::PARAM_STR);
7664 $updateCommand->bindParam(":teacher_id", $teacher_id, PDO::PARAM_STR);
7665 $updateCommand->bindParam(":created_by", $created_by, PDO::PARAM_STR);
7666 $updateCommand->bindParam(":updated_by", $updated_by, PDO::PARAM_STR);
7667 $updateCommand->bindParam(":file", $file, PDO::PARAM_STR);
7668 $updateCommand->bindParam(":type", $type, PDO::PARAM_STR);
7669 $updateCommand->bindParam(":choices_files", $choices_files, PDO::PARAM_STR);
7670 $updateCommand->bindParam(":sync_status", $sync_status, PDO::PARAM_STR);
7671 if ($updateCommand->execute()) {
7672 $berhasil = $berhasil + 1;
7673 } else {
7674 $gagal = $gagal + 1;
7675 array_push($id_gagal, $question_id);
7676 }
7677 } else {
7678 $insert = "INSERT INTO " . $prefix . "questions (quiz_id,lesson_id,title,text,choices,key_answer,created_at,updated_at,teacher_id,created_by,updated_by,file,type,choices_files,sync_status) values(:quiz_id,:lesson_id,:title,:text,:choices,:key_answer,:created_at,:updated_at,:teacher_id,:created_by,:updated_by,:file,:type,:choices_files,:sync_status)";
7679
7680 $insertCommand = Yii::app()->db->createCommand($insert);
7681
7682 $insertCommand->bindParam(":updated_at", $updated_at, PDO::PARAM_STR);
7683 $insertCommand->bindParam(":quiz_id", $id_quiz, PDO::PARAM_STR);
7684 $insertCommand->bindParam(":lesson_id", $lesson_id, PDO::PARAM_STR);
7685 $insertCommand->bindParam(":title", $title, PDO::PARAM_STR);
7686 $insertCommand->bindParam(":text", $text, PDO::PARAM_STR);
7687 $insertCommand->bindParam(":choices", $choices, PDO::PARAM_STR);
7688 $insertCommand->bindParam(":key_answer", $key_answer, PDO::PARAM_STR);
7689 $insertCommand->bindParam(":created_at", $created_at, PDO::PARAM_STR);
7690 $insertCommand->bindParam(":teacher_id", $teacher_id, PDO::PARAM_STR);
7691 $insertCommand->bindParam(":created_by", $created_by, PDO::PARAM_STR);
7692 $insertCommand->bindParam(":updated_by", $updated_by, PDO::PARAM_STR);
7693 $insertCommand->bindParam(":file", $file, PDO::PARAM_STR);
7694 $insertCommand->bindParam(":type", $type, PDO::PARAM_STR);
7695 $insertCommand->bindParam(":choices_files", $choices_files, PDO::PARAM_STR);
7696 $insertCommand->bindParam(":sync_status", $sync_status, PDO::PARAM_STR);
7697
7698 if ($insertCommand->execute()) {
7699 $berhasil = $berhasil + 1;
7700 } else {
7701 $gagal = $gagal + 1;
7702 array_push($id_gagal, $question_id);
7703 }
7704 }
7705 }
7706 echo "lks";
7707 } else {
7708 echo "lks";
7709 }
7710 //$cekStatus = "lks";
7711
7712 break;
7713 case "lks":
7714 $lks_url = $url . "?type=lks";
7715 // Initiate curl
7716 $curlLks = curl_init();
7717 // Disable SSL verification
7718 curl_setopt_array($curlLks, array(
7719 CURLOPT_URL => $lks_url,
7720 CURLOPT_VERBOSE => true,
7721 CURLOPT_RETURNTRANSFER => true,
7722 CURLOPT_SSL_VERIFYPEER => false,
7723 CURLOPT_ENCODING => "",
7724 CURLOPT_MAXREDIRS => 10,
7725 CURLOPT_TIMEOUT => 3000,
7726 CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
7727 ));
7728 // Execute
7729 $json_lks = curl_exec($curlLks);
7730 // Closing
7731 curl_close($curlLks);
7732
7733 $responseLks = json_decode($json_lks, true);
7734 $id_gagal = array();
7735 if (!empty($responseLks['data'])) {
7736 foreach ($responseLks['data'] as $value) {
7737 $cekLksLokal = Lks::model()->findByPk($value['id']);
7738 $lks_id = $value['id'];
7739 $title = $value['title'];
7740 $lesson_id = $value['lesson_id'];
7741 $assignments = $value['assignments'];
7742 $chapters = $value['chapters'];
7743 $quizes = $value['quizes'];
7744 $created_at = $value['created_at'];
7745 $updated_at = $value['updated_at'];
7746 $teacher_id = $value['teacher_id'];
7747 $created_by = $value['created_by'];
7748 $updated_by = $value['updated_by'];
7749 $file = $value['file'];
7750 $type = $value['type'];
7751 $choices_files = $value['choices_files'];
7752 $sync_status = 2;
7753
7754 if (!empty($cekLksLokal)) {
7755 $update = "UPDATE " . $prefix . "lks SET title = :title, lesson_id = :lesson_id, assignments = :assignments, chapters = :chapters, quizes = :quizes, created_at = :created_at, updated_at = :updated_at, teacher_id = :teacher_id, created_by = :created_by, updated_by = :updated_by, sync_status = :sync_status WHERE id = :id";
7756
7757 $updateCommand = Yii::app()->db->createCommand($update);
7758
7759 $updateCommand->bindParam(":id", $lks_id, PDO::PARAM_STR);
7760 $updateCommand->bindParam(":title", $title, PDO::PARAM_STR);
7761 $updateCommand->bindParam(":lesson_id", $lesson_id, PDO::PARAM_STR);
7762 $updateCommand->bindParam(":assignments", $assignments, PDO::PARAM_STR);
7763 $updateCommand->bindParam(":chapters", $chapters, PDO::PARAM_STR);
7764 $updateCommand->bindParam(":quizes", $quizes, PDO::PARAM_STR);
7765 $updateCommand->bindParam(":created_at", $created_at, PDO::PARAM_STR);
7766 $updateCommand->bindParam(":updated_at", $updated_at, PDO::PARAM_STR);
7767 $updateCommand->bindParam(":teacher_id", $teacher_id, PDO::PARAM_STR);
7768 $updateCommand->bindParam(":created_by", $created_by, PDO::PARAM_STR);
7769 $updateCommand->bindParam(":updated_by", $updated_by, PDO::PARAM_STR);
7770 $updateCommand->bindParam(":sync_status", $sync_status, PDO::PARAM_STR);
7771 if ($updateCommand->execute()) {
7772 $berhasil = $berhasil + 1;
7773 } else {
7774 $gagal = $gagal + 1;
7775 array_push($id_gagal, $lks_id);
7776 }
7777 } else {
7778 $insert = "INSERT INTO " . $prefix . "lks (title,lesson_id,assignments,chapters,quizes,created_at,updated_at,teacher_id,created_by,sync_status) values(:title,:lesson_id,:assignments,:chapters,:quizes,:created_at,:updated_at,:teacher_id,:created_by,:sync_status)";
7779
7780 $insertCommand = Yii::app()->db->createCommand($insert);
7781
7782 $insertCommand->bindParam(":updated_at", $updated_at, PDO::PARAM_STR);
7783 $insertCommand->bindParam(":title", $title, PDO::PARAM_STR);
7784 $insertCommand->bindParam(":lesson_id", $lesson_id, PDO::PARAM_STR);
7785 $insertCommand->bindParam(":assignments", $assignments, PDO::PARAM_STR);
7786 $insertCommand->bindParam(":chapters", $chapters, PDO::PARAM_STR);
7787 $insertCommand->bindParam(":quizes", $quizes, PDO::PARAM_STR);
7788 $insertCommand->bindParam(":updated_at", $updated_at, PDO::PARAM_STR);
7789 $insertCommand->bindParam(":created_at", $created_at, PDO::PARAM_STR);
7790 $insertCommand->bindParam(":teacher_id", $teacher_id, PDO::PARAM_STR);
7791 $insertCommand->bindParam(":created_by", $created_by, PDO::PARAM_STR);
7792 $insertCommand->bindParam(":updated_by", $updated_by, PDO::PARAM_STR);
7793 $insertCommand->bindParam(":sync_status", $sync_status, PDO::PARAM_STR);
7794
7795 if ($insertCommand->execute()) {
7796 $berhasil = $berhasil + 1;
7797 } else {
7798 $gagal = $gagal + 1;
7799 array_push($id_gagal, $lks_id);
7800 }
7801 }
7802 }
7803 echo "pengumuman";
7804 } else {
7805 echo "pengumuman";
7806 }
7807 //$cekStatus = "pengumuman";
7808
7809 break;
7810
7811 case "pengumuman":
7812 $pengumuman_url = $url . "?type=pengumuman";
7813 // Initiate curl
7814 $curlPengumuman = curl_init();
7815 // Disable SSL verification
7816 curl_setopt_array($curlPengumuman, array(
7817 CURLOPT_URL => $pengumuman_url,
7818 CURLOPT_VERBOSE => true,
7819 CURLOPT_RETURNTRANSFER => true,
7820 CURLOPT_SSL_VERIFYPEER => false,
7821 CURLOPT_ENCODING => "",
7822 CURLOPT_MAXREDIRS => 10,
7823 CURLOPT_TIMEOUT => 3000,
7824 CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
7825 ));
7826 // Execute
7827 $json_pengumuman = curl_exec($curlPengumuman);
7828 // Closing
7829 curl_close($curlPengumuman);
7830
7831 $responsePengumuman = json_decode($json_pengumuman, true);
7832 $id_gagal = array();
7833 if (!empty($responsePengumuman['data'])) {
7834 foreach ($responsePengumuman['data'] as $value) {
7835 $cekPengumumanLokal = Announcements::model()->findByPk($value['id']);
7836 $pengumuman_id = $value['id'];
7837 $author_id = $value['author_id'];
7838 $title = $value['title'];
7839 $content = $value['content'];
7840 $created_at = $value['created_at'];
7841 $updated_at = $value['updated_at'];
7842 $type = $value['type'];
7843 $sync_status = 2;
7844
7845 if (!empty($cekPengumumanLokal)) {
7846 $update = "UPDATE " . $prefix . "pengumuman SET author_id = :author_id, title = :title, content = :content, created_at = :created_at, updated_at = :updated_at, type = :type, created_by = :created_by, updated_by = :updated_by, sync_status = :sync_status WHERE id = :id";
7847
7848 $updateCommand = Yii::app()->db->createCommand($update);
7849
7850 $updateCommand->bindParam(":id", $pengumuman_id, PDO::PARAM_STR);
7851 $updateCommand->bindParam(":author_id", $author_id, PDO::PARAM_STR);
7852 $updateCommand->bindParam(":title", $title, PDO::PARAM_STR);
7853 $updateCommand->bindParam(":content", $content, PDO::PARAM_STR);
7854 $updateCommand->bindParam(":created_at", $created_at, PDO::PARAM_STR);
7855 $updateCommand->bindParam(":updated_at", $updated_at, PDO::PARAM_STR);
7856 $updateCommand->bindParam(":type", $type, PDO::PARAM_STR);
7857 $updateCommand->bindParam(":sync_status", $sync_status, PDO::PARAM_STR);
7858 if ($updateCommand->execute()) {
7859 $berhasil = $berhasil + 1;
7860 } else {
7861 $gagal = $gagal + 1;
7862 array_push($id_gagal, $pengumuman_id);
7863 }
7864 } else {
7865 $insert = "INSERT INTO " . $prefix . "pengumuman (author_id,title,content,created_at,updated_at,type,created_by,sync_status) values(:author_id,:title,:content,:created_at,:updated_at,:type,:sync_status)";
7866
7867 $insertCommand = Yii::app()->db->createCommand($insert);
7868
7869 $insertCommand->bindParam(":updated_at", $updated_at, PDO::PARAM_STR);
7870 $insertCommand->bindParam(":author_id", $author_id, PDO::PARAM_STR);
7871 $insertCommand->bindParam(":title", $title, PDO::PARAM_STR);
7872 $insertCommand->bindParam(":content", $content, PDO::PARAM_STR);
7873 $insertCommand->bindParam(":updated_at", $updated_at, PDO::PARAM_STR);
7874 $insertCommand->bindParam(":created_at", $created_at, PDO::PARAM_STR);
7875 $insertCommand->bindParam(":type", $type, PDO::PARAM_STR);
7876 $insertCommand->bindParam(":sync_status", $sync_status, PDO::PARAM_STR);
7877
7878 if ($insertCommand->execute()) {
7879 $berhasil = $berhasil + 1;
7880 } else {
7881 $gagal = $gagal + 1;
7882 array_push($id_gagal, $pengumuman_id);
7883 }
7884 }
7885 }
7886 echo "nilaiOffline";
7887 } else {
7888 echo "nilaiOffline";
7889 }
7890 //$cekStatus = "nilaiOffline";
7891
7892 break;
7893
7894 case "nilaiOffline":
7895 $noffline_url = $url . "?type=noffline";
7896 // Initiate curl
7897 $curlNoffline = curl_init();
7898 // Disable SSL verification
7899 curl_setopt_array($curlNoffline, array(
7900 CURLOPT_URL => $noffline_url,
7901 CURLOPT_VERBOSE => true,
7902 CURLOPT_RETURNTRANSFER => true,
7903 CURLOPT_SSL_VERIFYPEER => false,
7904 CURLOPT_ENCODING => "",
7905 CURLOPT_MAXREDIRS => 10,
7906 CURLOPT_TIMEOUT => 3000,
7907 CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
7908 ));
7909 // Execute
7910 $json_noffline = curl_exec($curlNoffline);
7911 // Closing
7912 curl_close($curlNoffline);
7913
7914 $responseNoffline = json_decode($json_noffline, true);
7915 $id_gagal = array();
7916 if (!empty($responseNoffline['data'])) {
7917 foreach ($responseNoffline['data'] as $value) {
7918 $cekNofflineLokal = OfflineMark::model()->findByPk($value['id']);
7919 $noffline_id = $value['id'];
7920 $lesson_id = $value['lesson_id'];
7921 $student_id = $value['student_id'];
7922 $score = $value['score'];
7923 $file = $value['file'];
7924 $created_at = $value['created_at'];
7925 $updated_at = $value['updated_at'];
7926 $created_by = $value['created_by'];
7927 $updated_by = $value['updated_by'];
7928 $mark_type = $value['mark_type'];
7929 $sync_status = 2;
7930
7931 if (!empty($cekNofflineLokal)) {
7932 $update = "UPDATE " . $prefix . "offline_mark SET lesson_id = :lesson_id, student_id = :student_id, score = :score, file = :file, created_at = :created_at, updated_at = :updated_at, created_by = :created_by, updated_by = :updated_by, mark_type = :mark_type, sync_status = :sync_status WHERE id = :id";
7933
7934 $updateCommand = Yii::app()->db->createCommand($update);
7935
7936 $updateCommand->bindParam(":id", $noffline_id, PDO::PARAM_STR);
7937 $updateCommand->bindParam(":lesson_id", $lesson_id, PDO::PARAM_STR);
7938 $updateCommand->bindParam(":student_id", $student_id, PDO::PARAM_STR);
7939 $updateCommand->bindParam(":score", $score, PDO::PARAM_STR);
7940 $updateCommand->bindParam(":file", $type, PDO::PARAM_STR);
7941 $updateCommand->bindParam(":created_at", $created_at, PDO::PARAM_STR);
7942 $updateCommand->bindParam(":updated_at", $updated_at, PDO::PARAM_STR);
7943 $updateCommand->bindParam(":created_by", $created_by, PDO::PARAM_STR);
7944 $updateCommand->bindParam(":updated_by", $updated_by, PDO::PARAM_STR);
7945 $updateCommand->bindParam(":mark_type", $mark_type, PDO::PARAM_STR);
7946 $updateCommand->bindParam(":sync_status", $sync_status, PDO::PARAM_STR);
7947 if ($updateCommand->execute()) {
7948 $berhasil = $berhasil + 1;
7949 } else {
7950 $gagal = $gagal + 1;
7951 array_push($id_gagal, $noffline_id);
7952 }
7953 } else {
7954 $insert = "INSERT INTO " . $prefix . "offline_mark (lesson_id,score,file,created_at,updated_at,created_by,updated_by,mark_type,sync_status) values(:lesson_id,:student_id,:score,:file,:created_at,:updated_at,:created_by,:updated_by,:mark_type,:sync_status)";
7955
7956 $insertCommand = Yii::app()->db->createCommand($insert);
7957
7958 $insertCommand->bindParam(":updated_at", $updated_at, PDO::PARAM_STR);
7959 $insertCommand->bindParam(":lesson_id", $lesson_id, PDO::PARAM_STR);
7960 $insertCommand->bindParam(":student_id", $student_id, PDO::PARAM_STR);
7961 $insertCommand->bindParam(":score", $score, PDO::PARAM_STR);
7962 $insertCommand->bindParam(":file", $type, PDO::PARAM_STR);
7963 $insertCommand->bindParam(":updated_at", $updated_at, PDO::PARAM_STR);
7964 $insertCommand->bindParam(":created_at", $created_at, PDO::PARAM_STR);
7965 $insertCommand->bindParam(":created_by", $created_by, PDO::PARAM_STR);
7966 $insertCommand->bindParam(":updated_by", $updated_by, PDO::PARAM_STR);
7967 $insertCommand->bindParam(":mark_type", $mark_type, PDO::PARAM_STR);
7968 $insertCommand->bindParam(":sync_status", $sync_status, PDO::PARAM_STR);
7969
7970 if ($insertCommand->execute()) {
7971 $berhasil = $berhasil + 1;
7972 } else {
7973 $gagal = $gagal + 1;
7974 array_push($id_gagal, $noffline_id);
7975 }
7976 }
7977 }
7978 echo "aktivitas";
7979 } else {
7980 echo "aktivitas";
7981 }
7982 //$cekStatus = "aktivitas";
7983
7984 break;
7985
7986 case "aktivitas":
7987 $aktivitas_url = $url . "?type=aktivitas";
7988 // Initiate curl
7989 $curlAktivitas = curl_init();
7990 // Disable SSL verification
7991 curl_setopt_array($curlAktivitas, array(
7992 CURLOPT_URL => $aktivitas_url,
7993 CURLOPT_VERBOSE => true,
7994 CURLOPT_RETURNTRANSFER => true,
7995 CURLOPT_SSL_VERIFYPEER => false,
7996 CURLOPT_ENCODING => "",
7997 CURLOPT_MAXREDIRS => 10,
7998 CURLOPT_TIMEOUT => 3000,
7999 CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
8000 ));
8001 // Execute
8002 $json_aktivitas = curl_exec($curlAktivitas);
8003 // Closing
8004 curl_close($curlAktivitas);
8005
8006 $responseAktivitas = json_decode($json_aktivitas, true);
8007
8008 $id_gagal = array();
8009 if (!empty($responseAktivitas['data'])) {
8010 foreach ($responseAktivitas['data'] as $value) {
8011 $cekAktivitasLokal = Activities::model()->findByPk($value['id']);
8012 $aktivitas_id = $value['id'];
8013 $activity_type = $value['activity_type'];
8014 $content = $value['content'];
8015 $created_by = $value['created_by'];
8016 $updated_by = $value['updated_by'];
8017 $created_at = $value['created_at'];
8018 $updated_at = $value['updated_at'];
8019 $sync_status = 2;
8020
8021 if (!empty($cekAktivitasLokal)) {
8022 $update = "UPDATE " . $prefix . "activities SET activity_type = :activity_type, content = :content, created_by = :created_by, updated_by = :updated_by, created_at = :created_at, updated_at = :updated_at, sync_status = :sync_status WHERE id = :id";
8023
8024 $updateCommand = Yii::app()->db->createCommand($update);
8025
8026 $updateCommand->bindParam(":id", $aktivitas_id, PDO::PARAM_STR);
8027 $updateCommand->bindParam(":activity_type", $activity_type, PDO::PARAM_STR);
8028 $updateCommand->bindParam(":content", $content, PDO::PARAM_STR);
8029 $updateCommand->bindParam(":created_by", $created_by, PDO::PARAM_STR);
8030 $updateCommand->bindParam(":created_at", $created_at, PDO::PARAM_STR);
8031 $updateCommand->bindParam(":updated_at", $updated_at, PDO::PARAM_STR);
8032 $updateCommand->bindParam(":updated_by", $type, PDO::PARAM_STR);
8033 $updateCommand->bindParam(":sync_status", $sync_status, PDO::PARAM_STR);
8034 if ($updateCommand->execute()) {
8035 $berhasil = $berhasil + 1;
8036 } else {
8037 $gagal = $gagal + 1;
8038 array_push($id_gagal, $aktivitas_id);
8039 }
8040 } else {
8041 $insert = "INSERT INTO " . $prefix . "activities (activity_type,content,created_by,updated_by,created_at,updated_at,sync_status) values(:activity_type,:content,:created_by,:updated_by,:created_at,:updated_at,:sync_status)";
8042
8043 $insertCommand = Yii::app()->db->createCommand($insert);
8044
8045 $insertCommand->bindParam(":updated_at", $updated_at, PDO::PARAM_STR);
8046 $insertCommand->bindParam(":activity_type", $activity_type, PDO::PARAM_STR);
8047 $insertCommand->bindParam(":content", $content, PDO::PARAM_STR);
8048 $insertCommand->bindParam(":created_by", $created_by, PDO::PARAM_STR);
8049 $insertCommand->bindParam(":updated_at", $updated_at, PDO::PARAM_STR);
8050 $insertCommand->bindParam(":created_at", $created_at, PDO::PARAM_STR);
8051 $insertCommand->bindParam(":updated_by", $type, PDO::PARAM_STR);
8052 $insertCommand->bindParam(":sync_status", $sync_status, PDO::PARAM_STR);
8053
8054 if ($insertCommand->execute()) {
8055 $berhasil = $berhasil + 1;
8056 } else {
8057 $gagal = $gagal + 1;
8058 array_push($id_gagal, $aktivitas_id);
8059 }
8060 }
8061 }
8062 //echo "<pre>";
8063 //print_r($responseAktivitas['data']);
8064 //echo "<pre>";
8065 //echo json_encode(array('messages'=>'success','berhasil'=>$berhasil,'gagal'=>$gagal,'id_gagal'=>$id_gagal));
8066 echo "notifikasi";
8067 } else {
8068 echo "notifikasi";
8069 }
8070 //$cekStatus = "notifikasi";
8071
8072 break;
8073
8074 case "notifikasi":
8075 $notif_url = $url . "?type=notif";
8076 // Initiate curl
8077 $curlNotif = curl_init();
8078 // Disable SSL verification
8079 curl_setopt_array($curlNotif, array(
8080 CURLOPT_URL => $notif_url,
8081 CURLOPT_VERBOSE => true,
8082 CURLOPT_RETURNTRANSFER => true,
8083 CURLOPT_SSL_VERIFYPEER => false,
8084 CURLOPT_ENCODING => "",
8085 CURLOPT_MAXREDIRS => 10,
8086 CURLOPT_TIMEOUT => 3000,
8087 CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
8088 ));
8089 // Execute
8090 $json_notif = curl_exec($curlNotif);
8091 // Closing
8092 curl_close($curlNotif);
8093
8094 $responseNotif = json_decode($json_notif, true);
8095 $id_gagal = array();
8096 if (!empty($responseNotif['data'])) {
8097 foreach ($responseNotif['data'] as $value) {
8098 $cekNotifLokal = Notification::model()->findByPk($value['id']);
8099 $notif_id = $value['id'];
8100 $content = $value['content'];
8101 $user_id = $value['user_id'];
8102 $user_id_to = $value['user_id_to'];
8103 $tipe = $value['tipe'];
8104 $created_at = $value['created_at'];
8105 $updated_at = $value['updated_at'];
8106 $read_at = $value['read_at'];
8107 $status = $value['status'];
8108 $relation_id = $value['relation_id'];
8109 $class_id_to = $value['class_id_to'];
8110 $read_id = $value['read_id'];
8111 $sync_status = 2;
8112
8113 if (!empty($cekNotifLokal)) {
8114 $update = "UPDATE " . $prefix . "notification SET content = :content, user_id = :user_id, user_id_to = :user_id_to, tipe = :tipe, created_at = :created_at, updated_at = :updated_at, read_at = :read_at, status = :status, relation_id = :relation_id, class_id_to = :class_id_to, read_id = :read_id, sync_status = :sync_status WHERE id = :id";
8115
8116 $updateCommand = Yii::app()->db->createCommand($update);
8117
8118 $updateCommand->bindParam(":id", $notif_id, PDO::PARAM_STR);
8119 $updateCommand->bindParam(":content", $content, PDO::PARAM_STR);
8120 $updateCommand->bindParam(":user_id", $user_id, PDO::PARAM_STR);
8121 $updateCommand->bindParam(":user_id_to", $user_id_to, PDO::PARAM_STR);
8122 $updateCommand->bindParam(":tipe", $tipe, PDO::PARAM_STR);
8123 $updateCommand->bindParam(":created_at", $created_at, PDO::PARAM_STR);
8124 $updateCommand->bindParam(":updated_at", $updated_at, PDO::PARAM_STR);
8125 $updateCommand->bindParam(":read_at", $read_at, PDO::PARAM_STR);
8126 $updateCommand->bindParam(":status", $status, PDO::PARAM_STR);
8127 $updateCommand->bindParam(":relation_id", $relation_id, PDO::PARAM_STR);
8128 $updateCommand->bindParam(":class_id_to", $class_id_to, PDO::PARAM_STR);
8129 $updateCommand->bindParam(":read_id", $read_id, PDO::PARAM_STR);
8130 $updateCommand->bindParam(":sync_status", $sync_status, PDO::PARAM_STR);
8131 if ($updateCommand->execute()) {
8132 $berhasil = $berhasil + 1;
8133 } else {
8134 $gagal = $gagal + 1;
8135 array_push($id_gagal, $notif_id);
8136 }
8137 } else {
8138 $insert = "INSERT INTO " . $prefix . "notification (content,user_id,user_id_to,tipe,created_at,updated_at,read_at,status,relation_id,class_id_to,read_id,sync_status) values(:content,:user_id,:user_id_to,:tipe,:created_at,:updated_at,:read_at,:status,:relation_id,:class_id_to,:read_id,:sync_status)";
8139
8140 $insertCommand = Yii::app()->db->createCommand($insert);
8141
8142 $insertCommand->bindParam(":updated_at", $updated_at, PDO::PARAM_STR);
8143 $insertCommand->bindParam(":content", $content, PDO::PARAM_STR);
8144 $insertCommand->bindParam(":user_id", $user_id, PDO::PARAM_STR);
8145 $insertCommand->bindParam(":user_id_to", $user_id_to, PDO::PARAM_STR);
8146 $insertCommand->bindParam(":tipe", $tipe, PDO::PARAM_STR);
8147 $insertCommand->bindParam(":updated_at", $updated_at, PDO::PARAM_STR);
8148 $insertCommand->bindParam(":created_at", $created_at, PDO::PARAM_STR);
8149 $insertCommand->bindParam(":read_at", $read_at, PDO::PARAM_STR);
8150 $insertCommand->bindParam(":status", $status, PDO::PARAM_STR);
8151 $insertCommand->bindParam(":relation_id", $relation_id, PDO::PARAM_STR);
8152 $insertCommand->bindParam(":class_id_to", $class_id_to, PDO::PARAM_STR);
8153 $insertCommand->bindParam(":read_id", $read_id, PDO::PARAM_STR);
8154 $insertCommand->bindParam(":sync_status", $sync_status, PDO::PARAM_STR);
8155
8156 if ($insertCommand->execute()) {
8157 $berhasil = $berhasil + 1;
8158 } else {
8159 $gagal = $gagal + 1;
8160 array_push($id_gagal, $user_id);
8161 }
8162 }
8163 }
8164 echo "kelas";
8165 } else {
8166 echo "kelas";
8167 }
8168 //$cekStatus = "kelas";
8169
8170 break;
8171
8172 case "kelas":
8173 $curlKelas = $url . "?type=kelas";
8174 // Initiate curl
8175 $curlKelas = curl_init();
8176 // Disable SSL verification
8177 curl_setopt_array($curlKelas, array(
8178 CURLOPT_URL => $curlKelas,
8179 CURLOPT_VERBOSE => true,
8180 CURLOPT_RETURNTRANSFER => true,
8181 CURLOPT_SSL_VERIFYPEER => false,
8182 CURLOPT_ENCODING => "",
8183 CURLOPT_MAXREDIRS => 10,
8184 CURLOPT_TIMEOUT => 3000,
8185 CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
8186 ));
8187 // Execute
8188 $json_kelas = curl_exec($curlKelas);
8189 // Closing
8190 curl_close($curlKelas);
8191
8192 $responseKelas = json_decode($json_kelas, true);
8193 $id_gagal = array();
8194 if (!empty($responseKelas['data'])) {
8195 foreach ($responseKelas['data'] as $value) {
8196 $cekKelasLokal = Clases::model()->findByPk($value['id']);
8197 $kelas_id = $value['id'];
8198 $name = $value['name'];
8199 $teacher_id = $value['teacher_id'];
8200 $sync_status = 2;
8201
8202 if (!empty($cekKelasLokal)) {
8203 $update = "UPDATE " . $prefix . "class SET name = :name, teacher_id = :teacher_id, sync_status = :sync_status WHERE id = :id";
8204
8205 $updateCommand = Yii::app()->db->createCommand($update);
8206
8207 $updateCommand->bindParam(":id", $kelas_id, PDO::PARAM_STR);
8208 $updateCommand->bindParam(":name", $name, PDO::PARAM_STR);
8209 $updateCommand->bindParam(":teacher_id", $teacher_id, PDO::PARAM_STR);
8210 $updateCommand->bindParam(":sync_status", $sync_status, PDO::PARAM_STR);
8211 if ($updateCommand->execute()) {
8212 $berhasil = $berhasil + 1;
8213 } else {
8214 $gagal = $gagal + 1;
8215 array_push($id_gagal, $kelas_id);
8216 }
8217 } else {
8218 $insert = "INSERT INTO " . $prefix . "class (name,teacher_id,sync_status) values(:name,:teacher_id,:sync_status)";
8219
8220 $insertCommand = Yii::app()->db->createCommand($insert);
8221
8222 $insertCommand->bindParam(":name", $name, PDO::PARAM_STR);
8223 $insertCommand->bindParam(":teacher_id", $teacher_id, PDO::PARAM_STR);
8224 $insertCommand->bindParam(":sync_status", $sync_status, PDO::PARAM_STR);
8225
8226 if ($insertCommand->execute()) {
8227 $berhasil = $berhasil + 1;
8228 } else {
8229 $gagal = $gagal + 1;
8230 array_push($id_gagal, $kelas_id);
8231 }
8232 }
8233 }
8234 echo "pelajaran";
8235 } else {
8236 echo "pelajaran";
8237 }
8238 //$cekStatus = "pelajaran";
8239
8240 break;
8241
8242 case "pelajaran":
8243 $pelajaran_url = $url . "?type=pelajaran";
8244 // Initiate curl
8245 $curlPelajaran = curl_init();
8246 // Disable SSL verification
8247 curl_setopt_array($curlPelajaran, array(
8248 CURLOPT_URL => $pelajaran_url,
8249 CURLOPT_VERBOSE => true,
8250 CURLOPT_RETURNTRANSFER => true,
8251 CURLOPT_SSL_VERIFYPEER => false,
8252 CURLOPT_ENCODING => "",
8253 CURLOPT_MAXREDIRS => 10,
8254 CURLOPT_TIMEOUT => 3000,
8255 CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
8256 ));
8257 // Execute
8258 $json_pelajaran = curl_exec($curlPelajaran);
8259 // Closing
8260 curl_close($curlPelajaran);
8261
8262 $responsePelajaran = json_decode($json_pelajaran, true);
8263 $id_gagal = array();
8264 if (!empty($responsePelajaran['data'])) {
8265 foreach ($responsePelajaran['data'] as $value) {
8266 $cekMapelLokal = Clases::model()->findByPk($value['id']);
8267 $mapel_id = $value['id'];
8268 $name = $value['name'];
8269 $user_id = $value['user_id'];
8270 $class_id = $value['class_id'];
8271 $created_at = $value['created_at'];
8272 $updated_at = $value['updated_at'];
8273 $created_by = $value['created_by'];
8274 $updated_by = $value['updated_by'];
8275 $sync_status = 2;
8276
8277 if (!empty($cekMapelLokal)) {
8278 $update = "UPDATE " . $prefix . "lesson SET name = :name, user_id = :user_id, class_id = :class_id, created_at = :created_at, updated_at = :updated_at, created_by = :created_by, updated_by = :updated_by, sync_status = :sync_status WHERE id = :id";
8279
8280 $updateCommand = Yii::app()->db->createCommand($update);
8281
8282 $updateCommand->bindParam(":id", $mapel_id, PDO::PARAM_STR);
8283 $updateCommand->bindParam(":name", $name, PDO::PARAM_STR);
8284 $updateCommand->bindParam(":user_id", $user_id, PDO::PARAM_STR);
8285 $updateCommand->bindParam(":class_id", $class_id, PDO::PARAM_STR);
8286 $updateCommand->bindParam(":created_at", $created_at, PDO::PARAM_STR);
8287 $updateCommand->bindParam(":updated_at", $updated_at, PDO::PARAM_STR);
8288 $updateCommand->bindParam(":created_by", $created_by, PDO::PARAM_STR);
8289 $updateCommand->bindParam(":updated_by", $updated_by, PDO::PARAM_STR);
8290 $updateCommand->bindParam(":sync_status", $sync_status, PDO::PARAM_STR);
8291 if ($updateCommand->execute()) {
8292 $berhasil = $berhasil + 1;
8293 } else {
8294 $gagal = $gagal + 1;
8295 array_push($id_gagal, $mapel_id);
8296 }
8297 } else {
8298 $insert = "INSERT INTO " . $prefix . "lesson (name,user_id,class_id,created_at,updated_at,created_by,updated_by,sync_status) values(:name,:user_id,:class_id,:created_at,:updated_at,:created_by,:updated_by,:sync_status)";
8299
8300 $insertCommand = Yii::app()->db->createCommand($insert);
8301
8302 $insertCommand->bindParam(":name", $name, PDO::PARAM_STR);
8303 $insertCommand->bindParam(":user_id", $user_id, PDO::PARAM_STR);
8304 $insertCommand->bindParam(":class_id", $class_id, PDO::PARAM_STR);
8305 $insertCommand->bindParam(":created_at", $created_at, PDO::PARAM_STR);
8306 $insertCommand->bindParam(":updated_at", $updated_at, PDO::PARAM_STR);
8307 $insertCommand->bindParam(":created_by", $created_by, PDO::PARAM_STR);
8308 $insertCommand->bindParam(":updated_by", $updated_by, PDO::PARAM_STR);
8309 $insertCommand->bindParam(":sync_status", $sync_status, PDO::PARAM_STR);
8310
8311 if ($insertCommand->execute()) {
8312 $berhasil = $berhasil + 1;
8313 } else {
8314 $gagal = $gagal + 1;
8315 array_push($id_gagal, $mapel_id);
8316 }
8317 }
8318 }
8319 echo "absensi";
8320 } else {
8321 echo "absensi";
8322 }
8323 //$cekStatus = "absensi";
8324
8325 break;
8326
8327 case "absensi":
8328 $absensi_url = $url . "?type=absensi";
8329 // Initiate curl
8330 $curlAbsensi = curl_init();
8331 // Disable SSL verification
8332 curl_setopt_array($curlAbsensi, array(
8333 CURLOPT_URL => $absensi_url,
8334 CURLOPT_VERBOSE => true,
8335 CURLOPT_RETURNTRANSFER => true,
8336 CURLOPT_SSL_VERIFYPEER => false,
8337 CURLOPT_ENCODING => "",
8338 CURLOPT_MAXREDIRS => 10,
8339 CURLOPT_TIMEOUT => 3000,
8340 CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
8341 ));
8342 // Execute
8343 $json_absensi = curl_exec($curlAbsensi);
8344 // Closing
8345 curl_close($curlAbsensi);
8346
8347 $responseAbsensi = json_decode($json_absensi, true);
8348 $id_gagal = array();
8349 if (!empty($responseAbsensi['data'])) {
8350 foreach ($responseAbsensi['data'] as $value) {
8351 $cekAbsensiLokal = Clases::model()->findByPk($value['id']);
8352 $absensi_id = $value['id'];
8353 $type = $value['type'];
8354 $user_id = $value['user_id'];
8355 $status = $value['status'];
8356 $created_at = $value['created_at'];
8357 $alasan = $value['alasan'];
8358 $created_date = $value['created_date'];
8359 $sync_status = 2;
8360
8361 if (!empty($cekAbsensiLokal)) {
8362 $update = "UPDATE " . $prefix . "absensi SET type = :type, user_id = :user_id, status = :status, created_at = :created_at, alasan = :alasan, created_date = :created_date, sync_status = :sync_status WHERE id = :id";
8363
8364 $updateCommand = Yii::app()->db->createCommand($update);
8365
8366 $updateCommand->bindParam(":id", $absensi_id, PDO::PARAM_STR);
8367 $updateCommand->bindParam(":type", $type, PDO::PARAM_STR);
8368 $updateCommand->bindParam(":user_id", $user_id, PDO::PARAM_STR);
8369 $updateCommand->bindParam(":status", $status, PDO::PARAM_STR);
8370 $updateCommand->bindParam(":created_at", $created_at, PDO::PARAM_STR);
8371 $updateCommand->bindParam(":alasan", $alasan, PDO::PARAM_STR);
8372 $updateCommand->bindParam(":created_date", $created_date, PDO::PARAM_STR);
8373 $updateCommand->bindParam(":sync_status", $sync_status, PDO::PARAM_STR);
8374 if ($updateCommand->execute()) {
8375 $berhasil = $berhasil + 1;
8376 } else {
8377 $gagal = $gagal + 1;
8378 array_push($id_gagal, $absensi_id);
8379 }
8380 } else {
8381 $insert = "INSERT INTO " . $prefix . "absensi (type,user_id,status,created_at,alasan,created_date,sync_status) values(:type,:user_id,:status,:created_at,:alasan,:created_date,:sync_status)";
8382
8383 $insertCommand = Yii::app()->db->createCommand($insert);
8384
8385 $insertCommand->bindParam(":type", $type, PDO::PARAM_STR);
8386 $insertCommand->bindParam(":user_id", $user_id, PDO::PARAM_STR);
8387 $insertCommand->bindParam(":status", $status, PDO::PARAM_STR);
8388 $insertCommand->bindParam(":created_at", $created_at, PDO::PARAM_STR);
8389 $insertCommand->bindParam(":alasan", $alasan, PDO::PARAM_STR);
8390 $insertCommand->bindParam(":created_date", $created_date, PDO::PARAM_STR);
8391 $insertCommand->bindParam(":sync_status", $sync_status, PDO::PARAM_STR);
8392
8393 if ($insertCommand->execute()) {
8394 $berhasil = $berhasil + 1;
8395 } else {
8396 $gagal = $gagal + 1;
8397 array_push($id_gagal, $absensi_id);
8398 }
8399 }
8400 }
8401 echo "selesai";
8402 } else {
8403 echo "selesai";
8404 }
8405 //$cekStatus = "Selesai";
8406
8407 break;
8408
8409 default:
8410 //echo "selesai";
8411 break;
8412 }
8413 }
8414
8415 public function actionPostLocalData($type = null)
8416 {
8417 $data = file_get_contents('php://input');
8418 //print $data;
8419 $berhasil = null;
8420 $gagal = null;
8421 $prefix = Yii::app()->params['tablePrefix'];
8422 switch ($type) {
8423 case 'user':
8424 $data_user_local = json_decode($data);
8425 $id_gagal = array();
8426
8427 foreach ($data_user_local as $user) {
8428 $cekUserLive = User::model()->findByPk($user->id);
8429 $user_id = $user->id;
8430 $username = $user->username;
8431 $email = $user->email;
8432 $encrypted_password = $user->encrypted_password;
8433 $role_id = $user->role_id;
8434 $created_at = $user->created_at;
8435 $updated_at = $user->updated_at;
8436 $class_id = $user->class_id;
8437 $reset_password = $user->reset_password;
8438 $display_name = $user->display_name;
8439 $sync_status = 2;
8440
8441 if (!empty($cekUserLive)) {
8442 $update = "UPDATE " . $prefix . "users SET email = :email, username = :username, encrypted_password = :encrypted_password, role_id = :role_id, created_at = :created_at, updated_at = :updated_at, class_id = :class_id, reset_password = :reset_password, display_name = :display_name, sync_status = :sync_status WHERE id = :id";
8443
8444 $updateCommand = Yii::app()->db->createCommand($update);
8445
8446 $updateCommand->bindParam(":id", $user_id, PDO::PARAM_STR);
8447 $updateCommand->bindParam(":email", $email, PDO::PARAM_STR);
8448 $updateCommand->bindParam(":username", $username, PDO::PARAM_STR);
8449 $updateCommand->bindParam(":encrypted_password", $encrypted_password, PDO::PARAM_STR);
8450 $updateCommand->bindParam(":role_id", $role_id, PDO::PARAM_STR);
8451 $updateCommand->bindParam(":created_at", $created_at, PDO::PARAM_STR);
8452 $updateCommand->bindParam(":updated_at", $updated_at, PDO::PARAM_STR);
8453 $updateCommand->bindParam(":class_id", $class_id, PDO::PARAM_STR);
8454 $updateCommand->bindParam(":reset_password", $reset_password, PDO::PARAM_STR);
8455 $updateCommand->bindParam(":display_name", $display_name, PDO::PARAM_STR);
8456 $updateCommand->bindParam(":sync_status", $sync_status, PDO::PARAM_STR);
8457 if ($updateCommand->execute()) {
8458 $berhasil = $berhasil + 1;
8459 } else {
8460 $gagal = $gagal + 1;
8461 array_push($id_gagal, $user_id);
8462 }
8463 } else {
8464 $insert = "INSERT INTO " . $prefix . "users (email,username,encrypted_password,role_id,created_at,updated_at,class_id,reset_password,display_name,sync_status) values(:email,:username,:encrypted_password,:role_id,:created_at,:updated_at,:class_id,:reset_password,:display_name,:sync_status)";
8465
8466 $insertCommand = Yii::app()->db->createCommand($insert);
8467
8468 $insertCommand->bindParam(":email", $email, PDO::PARAM_STR);
8469 $insertCommand->bindParam(":username", $username, PDO::PARAM_STR);
8470 $insertCommand->bindParam(":encrypted_password", $encrypted_password, PDO::PARAM_STR);
8471 $insertCommand->bindParam(":role_id", $role_id, PDO::PARAM_STR);
8472 $insertCommand->bindParam(":created_at", $created_at, PDO::PARAM_STR);
8473 $insertCommand->bindParam(":updated_at", $updated_at, PDO::PARAM_STR);
8474 $insertCommand->bindParam(":class_id", $class_id, PDO::PARAM_STR);
8475 $insertCommand->bindParam(":reset_password", $reset_password, PDO::PARAM_STR);
8476 $insertCommand->bindParam(":display_name", $display_name, PDO::PARAM_STR);
8477 $insertCommand->bindParam(":sync_status", $sync_status, PDO::PARAM_STR);
8478
8479 if ($insertCommand->execute()) {
8480 $berhasil = $berhasil + 1;
8481 } else {
8482 $gagal = $gagal + 1;
8483 array_push($id_gagal, $user_id);
8484 }
8485 }
8486 }
8487
8488 echo json_encode(array('messages' => 'success', 'berhasil' => $berhasil, 'gagal' => $gagal, 'id_gagal' => $id_gagal));
8489 break;
8490 case 'tugas':
8491 $data_tugas_local = json_decode($data);
8492 $id_gagal = array();
8493
8494 foreach ($data_tugas_local as $tgs) {
8495 $cekTugasLive = Assignment::model()->findByPk($tgs->id);
8496 $tugas_id = $tgs->id;
8497 $title = $tgs->title;
8498 $content = $tgs->content;
8499 $created_at = $tgs->created_at;
8500 $updated_at = $tgs->updated_at;
8501 $created_by = $tgs->created_by;
8502 $updated_by = $tgs->updated_by;
8503 $due_date = $tgs->due_date;
8504 $lesson_id = $tgs->lesson_id;
8505 $file = $tgs->file;
8506 $assignment_type = $tgs->assignment_type;
8507 $add_to_summary = $tgs->add_to_summary;
8508 $recipient = $tgs->recipient;
8509 $semester = $tgs->semester;
8510 $year = $tgs->year;
8511 $status = $tgs->status;
8512 $sync_status = 2;
8513
8514 if (!empty($cekTugasLive)) {
8515 $update = "UPDATE " . $prefix . "assignment SET content = :content, title = :title, created_at = :created_at, updated_at = :updated_at, created_by = :created_by, updated_by = :updated_by, due_date = :due_date, lesson_id = :lesson_id, file = :file, assignment_type = :assignment_type, add_to_summary = :add_to_summary, sync_status = :sync_status, recipient = :recipient, semester = :semester, year = :year, status = :status, sync_status = :sync_status WHERE id = :id";
8516
8517 $updateCommand = Yii::app()->db->createCommand($update);
8518
8519 $updateCommand->bindParam(":id", $tugas_id, PDO::PARAM_STR);
8520 $updateCommand->bindParam(":content", $content, PDO::PARAM_STR);
8521 $updateCommand->bindParam(":title", $title, PDO::PARAM_STR);
8522 $updateCommand->bindParam(":created_at", $created_at, PDO::PARAM_STR);
8523 $updateCommand->bindParam(":updated_at", $updated_at, PDO::PARAM_STR);
8524 $updateCommand->bindParam(":created_by", $created_by, PDO::PARAM_STR);
8525 $updateCommand->bindParam(":updated_by", $updated_by, PDO::PARAM_STR);
8526 $updateCommand->bindParam(":due_date", $due_date, PDO::PARAM_STR);
8527 $updateCommand->bindParam(":lesson_id", $lesson_id, PDO::PARAM_STR);
8528 $updateCommand->bindParam(":file", $file, PDO::PARAM_STR);
8529 $updateCommand->bindParam(":assignment_type", $assignment_type, PDO::PARAM_STR);
8530 $updateCommand->bindParam(":add_to_summary", $add_to_summary, PDO::PARAM_STR);
8531 $updateCommand->bindParam(":recipient", $recipient, PDO::PARAM_STR);
8532 $updateCommand->bindParam(":semester", $semester, PDO::PARAM_STR);
8533 $updateCommand->bindParam(":year", $year, PDO::PARAM_STR);
8534 $updateCommand->bindParam(":status", $status, PDO::PARAM_STR);
8535 $updateCommand->bindParam(":sync_status", $sync_status, PDO::PARAM_STR);
8536 if ($updateCommand->execute()) {
8537 $berhasil = $berhasil + 1;
8538 } else {
8539 $gagal = $gagal + 1;
8540 array_push($id_gagal, $tugas_id);
8541 }
8542 } else {
8543 $insert = "INSERT INTO " . $prefix . "assignment (content,title,created_at,updated_at,created_by,updated_by,due_date,lesson_id,file,assignment_type,add_to_summary,recipient,semester,year,status,sync_status) values(:content,:title,:created_at,:updated_at,:created_by,:updated_by,:due_date,:lesson_id,:file,:assignment_type,:add_to_summary,:recipient,:semester,:year,:status,:sync_status)";
8544
8545 $insertCommand = Yii::app()->db->createCommand($insert);
8546
8547 $insertCommand->bindParam(":content", $content, PDO::PARAM_STR);
8548 $insertCommand->bindParam(":title", $title, PDO::PARAM_STR);
8549 $insertCommand->bindParam(":created_at", $created_at, PDO::PARAM_STR);
8550 $insertCommand->bindParam(":updated_at", $updated_at, PDO::PARAM_STR);
8551 $insertCommand->bindParam(":created_by", $created_by, PDO::PARAM_STR);
8552 $insertCommand->bindParam(":updated_by", $updated_by, PDO::PARAM_STR);
8553 $insertCommand->bindParam(":due_date", $due_date, PDO::PARAM_STR);
8554 $insertCommand->bindParam(":lesson_id", $lesson_id, PDO::PARAM_STR);
8555 $insertCommand->bindParam(":file", $file, PDO::PARAM_STR);
8556 $insertCommand->bindParam(":assignment_type", $assignment_type, PDO::PARAM_STR);
8557 $insertCommand->bindParam(":add_to_summary", $add_to_summary, PDO::PARAM_STR);
8558 $insertCommand->bindParam(":recipient", $recipient, PDO::PARAM_STR);
8559 $insertCommand->bindParam(":semester", $semester, PDO::PARAM_STR);
8560 $insertCommand->bindParam(":year", $year, PDO::PARAM_STR);
8561 $insertCommand->bindParam(":status", $status, PDO::PARAM_STR);
8562 $insertCommand->bindParam(":sync_status", $sync_status, PDO::PARAM_STR);
8563
8564 if ($insertCommand->execute()) {
8565 $berhasil = $berhasil + 1;
8566 } else {
8567 $gagal = $gagal + 1;
8568 array_push($id_gagal, $tugas_id);
8569 }
8570 }
8571 }
8572
8573 echo json_encode(array('messages' => 'success', 'berhasil' => $berhasil, 'gagal' => $gagal, 'id_gagal' => $id_gagal));
8574 break;
8575
8576 case 'tugasSiswa':
8577 $data_ts_local = json_decode($data);
8578 $id_gagal = array();
8579
8580 foreach ($data_ts_local as $ts) {
8581 $cekTsLive = StudentAssignment::model()->findByPk($ts->id);
8582 $ts_id = $ts->id;
8583 $assignment_id = $ts->assignment_id;
8584 $content = $ts->content;
8585 $created_at = $ts->created_at;
8586 $updated_at = $ts->updated_at;
8587 $file = $ts->file;
8588 $student_id = $ts->student_id;
8589 $score = $ts->score;
8590 $status = $ts->status;
8591 $sync_status = 2;
8592
8593 if (!empty($cekTsLive)) {
8594 $update = "UPDATE " . $prefix . "student_assignment SET content = :content, assignment_id = :assignment_id, created_at = :created_at, updated_at = :updated_at, file = :file, student_id = :student_id, score = :score, status = :status, sync_status = :sync_status WHERE id = :id";
8595
8596 $updateCommand = Yii::app()->db->createCommand($update);
8597
8598 $updateCommand->bindParam(":id", $ts_id, PDO::PARAM_STR);
8599 $updateCommand->bindParam(":content", $content, PDO::PARAM_STR);
8600 $updateCommand->bindParam(":assignment_id", $assignment_id, PDO::PARAM_STR);
8601 $updateCommand->bindParam(":created_at", $created_at, PDO::PARAM_STR);
8602 $updateCommand->bindParam(":updated_at", $updated_at, PDO::PARAM_STR);
8603 $updateCommand->bindParam(":file", $file, PDO::PARAM_STR);
8604 $updateCommand->bindParam(":student_id", $student_id, PDO::PARAM_STR);
8605 $updateCommand->bindParam(":score", $score, PDO::PARAM_STR);
8606 $updateCommand->bindParam(":status", $status, PDO::PARAM_STR);
8607 $updateCommand->bindParam(":sync_status", $sync_status, PDO::PARAM_STR);
8608 if ($updateCommand->execute()) {
8609 $berhasil = $berhasil + 1;
8610 } else {
8611 $gagal = $gagal + 1;
8612 array_push($id_gagal, $ts_id);
8613 }
8614 } else {
8615 $insert = "INSERT INTO " . $prefix . "student_assignment (content,assignment_id,created_at,updated_at,file,student_id,score,status,sync_status) values(:content,:assignment_id,:created_at,:updated_at,:file,:student_id,:score,:status,:sync_status)";
8616
8617 $insertCommand = Yii::app()->db->createCommand($insert);
8618
8619 $insertCommand->bindParam(":content", $content, PDO::PARAM_STR);
8620 $insertCommand->bindParam(":assignment_id", $assignment_id, PDO::PARAM_STR);
8621 $insertCommand->bindParam(":created_at", $created_at, PDO::PARAM_STR);
8622 $insertCommand->bindParam(":updated_at", $updated_at, PDO::PARAM_STR);
8623 $insertCommand->bindParam(":file", $file, PDO::PARAM_STR);
8624 $insertCommand->bindParam(":student_id", $student_id, PDO::PARAM_STR);
8625 $insertCommand->bindParam(":score", $score, PDO::PARAM_STR);
8626 $insertCommand->bindParam(":status", $status, PDO::PARAM_STR);
8627 $insertCommand->bindParam(":sync_status", $sync_status, PDO::PARAM_STR);
8628
8629 if ($insertCommand->execute()) {
8630 $berhasil = $berhasil + 1;
8631 } else {
8632 $gagal = $gagal + 1;
8633 array_push($id_gagal, $ts_id);
8634 }
8635 }
8636 }
8637
8638 echo json_encode(array('messages' => 'success', 'berhasil' => $berhasil, 'gagal' => $gagal, 'id_gagal' => $id_gagal));
8639 break;
8640
8641 case 'materi':
8642 $data_materi_local = json_decode($data);
8643 $id_gagal = array();
8644 //print_r($data);
8645 foreach ($data_materi_local as $materi) {
8646 $cekMateriLive = Chapters::model()->findByPk($materi->id);
8647 $materi_id = $materi->id;
8648 $id_lesson = $materi->id_lesson;
8649 $title = $materi->title;
8650 $description = $materi->description;
8651 $created_at = $materi->created_at;
8652 $updated_at = $materi->updated_at;
8653 $created_by = $materi->created_by;
8654 $updated_by = $materi->updated_by;
8655 $content = $materi->content;
8656 $chapter_type = $materi->chapter_type;
8657 $semester = $materi->semester;
8658 $year = $materi->year;
8659 $sync_status = 2;
8660
8661 if (!empty($cekMateriLive)) {
8662 $update = "UPDATE " . $prefix . "chapters SET id_lesson = :id_lesson, title = :title, description = :description, created_at = :created_at, updated_at = :updated_at, created_by = :created_by, updated_by = :updated_by, content = :content, chapter_type = :chapter_type, semester = :semester , year = :year, sync_status = :sync_status WHERE id = :id";
8663
8664 $updateCommand = Yii::app()->db->createCommand($update);
8665
8666 $updateCommand->bindParam(":id", $materi_id, PDO::PARAM_STR);
8667 $updateCommand->bindParam(":id_lesson", $id_lesson, PDO::PARAM_STR);
8668 $updateCommand->bindParam(":title", $title, PDO::PARAM_STR);
8669 $updateCommand->bindParam(":description", $description, PDO::PARAM_STR);
8670 $updateCommand->bindParam(":created_at", $created_at, PDO::PARAM_STR);
8671 $updateCommand->bindParam(":updated_at", $updated_at, PDO::PARAM_STR);
8672 $updateCommand->bindParam(":created_by", $created_by, PDO::PARAM_STR);
8673 $updateCommand->bindParam(":updated_by", $updated_by, PDO::PARAM_STR);
8674 $updateCommand->bindParam(":content", $content, PDO::PARAM_STR);
8675 $updateCommand->bindParam(":chapter_type", $chapter_type, PDO::PARAM_STR);
8676 $updateCommand->bindParam(":semester ", $semester, PDO::PARAM_STR);
8677 $updateCommand->bindParam(":year", $year, PDO::PARAM_STR);
8678 $updateCommand->bindParam(":sync_status", $sync_status, PDO::PARAM_STR);
8679 if ($updateCommand->execute()) {
8680 $berhasil = $berhasil + 1;
8681 } else {
8682 $gagal = $gagal + 1;
8683 array_push($id_gagal, $materi_id);
8684 }
8685 } else {
8686 $insert = "INSERT INTO " . $prefix . "chapters (id_lesson,title,description,created_at,updated_at,created_by,updated_by,content,chapter_type,semester,year,sync_status) values(:id_lesson,:title,:description,:created_at,:updated_at,:created_by,:updated_by,:content,:chapter_type,:semester,:year,:sync_status)";
8687
8688 $insertCommand = Yii::app()->db->createCommand($insert);
8689
8690 $insertCommand->bindParam(":id_lesson", $id_lesson, PDO::PARAM_STR);
8691 $insertCommand->bindParam(":title", $title, PDO::PARAM_STR);
8692 $insertCommand->bindParam(":description", $description, PDO::PARAM_STR);
8693 $insertCommand->bindParam(":created_at", $created_at, PDO::PARAM_STR);
8694 $insertCommand->bindParam(":updated_at", $updated_at, PDO::PARAM_STR);
8695 $insertCommand->bindParam(":created_by", $created_by, PDO::PARAM_STR);
8696 $insertCommand->bindParam(":updated_by", $updated_by, PDO::PARAM_STR);
8697 $insertCommand->bindParam(":content", $content, PDO::PARAM_STR);
8698 $insertCommand->bindParam(":chapter_type", $chapter_type, PDO::PARAM_STR);
8699 $insertCommand->bindParam(":semester", $semester, PDO::PARAM_STR);
8700 $insertCommand->bindParam(":year", $year, PDO::PARAM_STR);
8701 $insertCommand->bindParam(":sync_status", $sync_status, PDO::PARAM_STR);
8702
8703 if ($insertCommand->execute()) {
8704 $berhasil = $berhasil + 1;
8705 } else {
8706 $gagal = $gagal + 1;
8707 array_push($id_gagal, $materi_id);
8708 }
8709 }
8710 }
8711
8712 echo json_encode(array('messages' => 'success', 'berhasil' => $berhasil, 'gagal' => $gagal, 'id_gagal' => $id_gagal));
8713 break;
8714
8715 case 'fileMateri':
8716 $data_mf_local = json_decode($data);
8717 $id_gagal = array();
8718
8719 foreach ($data_mf_local as $mf) {
8720 $cekMfLive = ChapterFiles::model()->findByPk($mf->id);
8721 $mf_id = $mf->id;
8722 $id_chapter = $mf->id_chapter;
8723 $file = $mf->file;
8724 $type = $mf->type;
8725 $created_at = $mf->created_at;
8726 $updated_at = $mf->updated_at;
8727 $created_by = $mf->created_by;
8728 $updated_by = $mf->updated_by;
8729 $content = $mf->content;
8730 $sync_status = 2;
8731
8732 if (!empty($cekMfLive)) {
8733 $update = "UPDATE " . $prefix . "chapter_files SET id_chapter = :id_chapter, file = :file, type = :type, created_at = :created_at, updated_at = :updated_at, created_by = :created_by, updated_by = :updated_by, content = :content, sync_status = :sync_status WHERE id = :id";
8734
8735 $updateCommand = Yii::app()->db->createCommand($update);
8736
8737 $updateCommand->bindParam(":id", $mf_id, PDO::PARAM_STR);
8738 $updateCommand->bindParam(":id_chapter", $id_chapter, PDO::PARAM_STR);
8739 $updateCommand->bindParam(":file", $file, PDO::PARAM_STR);
8740 $updateCommand->bindParam(":type", $type, PDO::PARAM_STR);
8741 $updateCommand->bindParam(":created_at", $created_at, PDO::PARAM_STR);
8742 $updateCommand->bindParam(":updated_at", $updated_at, PDO::PARAM_STR);
8743 $updateCommand->bindParam(":created_by", $created_by, PDO::PARAM_STR);
8744 $updateCommand->bindParam(":updated_by", $updated_by, PDO::PARAM_STR);
8745 $updateCommand->bindParam(":content", $content, PDO::PARAM_STR);
8746 $updateCommand->bindParam(":sync_status", $sync_status, PDO::PARAM_STR);
8747 if ($updateCommand->execute()) {
8748 $berhasil = $berhasil + 1;
8749 } else {
8750 $gagal = $gagal + 1;
8751 array_push($id_gagal, $mf_id);
8752 }
8753 } else {
8754 $insert = "INSERT INTO " . $prefix . "chapter_files (id_chapter,file,type,created_at,updated_at,created_by,updated_by,content,sync_status) values(:id_chapter,:file,:type,:created_at,:updated_at,:created_by,:updated_by,:content,:sync_status)";
8755
8756 $insertCommand = Yii::app()->db->createCommand($insert);
8757
8758 $insertCommand->bindParam(":content", $content, PDO::PARAM_STR);
8759 $insertCommand->bindParam(":id_chapter", $id_chapter, PDO::PARAM_STR);
8760 $insertCommand->bindParam(":file", $file, PDO::PARAM_STR);
8761 $insertCommand->bindParam(":type", $type, PDO::PARAM_STR);
8762 $insertCommand->bindParam(":created_at", $created_at, PDO::PARAM_STR);
8763 $insertCommand->bindParam(":updated_at", $updated_at, PDO::PARAM_STR);
8764 $insertCommand->bindParam(":created_by", $created_by, PDO::PARAM_STR);
8765 $insertCommand->bindParam(":updated_by", $updated_by, PDO::PARAM_STR);
8766 $insertCommand->bindParam(":sync_status", $sync_status, PDO::PARAM_STR);
8767
8768 if ($insertCommand->execute()) {
8769 $berhasil = $berhasil + 1;
8770 } else {
8771 $gagal = $gagal + 1;
8772 array_push($id_gagal, $mf_id);
8773 }
8774 }
8775 }
8776
8777 echo json_encode(array('messages' => 'success', 'berhasil' => $berhasil, 'gagal' => $gagal, 'id_gagal' => $id_gagal));
8778 break;
8779
8780 case 'quiz':
8781 $data_quiz_local = json_decode($data);
8782 $id_gagal = array();
8783
8784 foreach ($data_quiz_local as $quiz) {
8785 $cekQuizLive = Quiz::model()->findByPk($quiz->id);
8786 $quiz_id = $quiz->id;
8787 $title = $quiz->title;
8788 $lesson_id = $quiz->lesson_id;
8789 $chapter_id = $quiz->chapter_id;
8790 $quiz_type = $quiz->quiz_type;
8791 $created_at = $quiz->created_at;
8792 $updated_at = $quiz->updated_at;
8793 $created_by = $quiz->created_by;
8794 $updated_by = $quiz->updated_by;
8795 $start_time = $quiz->start_time;
8796 $end_time = $quiz->end_time;
8797 $total_question = $quiz->total_question;
8798 $status = $quiz->status;
8799 $add_to_summary = $quiz->add_to_summary;
8800 $repeat_quiz = $quiz->repeat_quiz;
8801 $question = $quiz->question;
8802 $semester = $quiz->semester;
8803 $year = $quiz->year;
8804 $random = $quiz->random;
8805 $show_nilai = $quiz->show_nilai;
8806 $sync_status = 2;
8807
8808 if (!empty($cekQuizLive)) {
8809 $update = "UPDATE " . $prefix . "quiz SET title = :title, lesson_id = :lesson_id, chapter_id = :chapter_id, quiz_type = :quiz_type, created_at = :created_at, updated_at = :updated_at, created_by = :created_by, updated_by = :updated_by, start_time = :start_time, end_time = :end_time, total_question = :total_question, status = :status, add_to_summary = :add_to_summary, repeat_quiz = :repeat_quiz, question = :question, semester = :semester, year = :year, random = :random, sync_status = :sync_status, show_nilai = :show_nilai WHERE id = :id";
8810
8811 $updateCommand = Yii::app()->db->createCommand($update);
8812
8813 $updateCommand->bindParam(":id", $quiz_id, PDO::PARAM_STR);
8814 $updateCommand->bindParam(":title", $title, PDO::PARAM_STR);
8815 $updateCommand->bindParam(":lesson_id", $lesson_id, PDO::PARAM_STR);
8816 $updateCommand->bindParam(":chapter_id", $chapter_id, PDO::PARAM_STR);
8817 $updateCommand->bindParam(":quiz_type", $quiz_type, PDO::PARAM_STR);
8818 $updateCommand->bindParam(":created_at", $created_at, PDO::PARAM_STR);
8819 $updateCommand->bindParam(":updated_at", $updated_at, PDO::PARAM_STR);
8820 $updateCommand->bindParam(":created_by", $created_by, PDO::PARAM_STR);
8821 $updateCommand->bindParam(":updated_by", $updated_by, PDO::PARAM_STR);
8822 $updateCommand->bindParam(":start_time", $start_time, PDO::PARAM_STR);
8823 $updateCommand->bindParam(":end_time", $end_time, PDO::PARAM_STR);
8824 $updateCommand->bindParam(":total_question", $total_question, PDO::PARAM_STR);
8825 $updateCommand->bindParam(":status", $status, PDO::PARAM_STR);
8826 $updateCommand->bindParam(":add_to_summary", $add_to_summary, PDO::PARAM_STR);
8827 $updateCommand->bindParam(":repeat_quiz", $repeat_quiz, PDO::PARAM_STR);
8828 $updateCommand->bindParam(":question", $question, PDO::PARAM_STR);
8829 $updateCommand->bindParam(":semester", $semester, PDO::PARAM_STR);
8830 $updateCommand->bindParam(":year", $year, PDO::PARAM_STR);
8831 $updateCommand->bindParam(":random", $random, PDO::PARAM_STR);
8832 $updateCommand->bindParam(":sync_status", $sync_status, PDO::PARAM_STR);
8833 $updateCommand->bindParam(":show_nilai", $show_nilai, PDO::PARAM_STR);
8834 if ($updateCommand->execute()) {
8835 $berhasil = $berhasil + 1;
8836 } else {
8837 $gagal = $gagal + 1;
8838 array_push($id_gagal, $quiz_id);
8839 }
8840 } else {
8841 $insert = "INSERT INTO " . $prefix . "quiz (title,lesson_id,chapter_id,quiz_type,created_at,updated_at,created_by,updated_by,start_time,end_time,total_question,status,add_to_summary,repeat_quiz,question,semester,year,random,sync_status) values(:title,:lesson_id,:chapter_id,:quiz_type,:created_at,:updated_at,:created_by,:updated_by,:start_time,:end_time,:total_question,:status,:add_to_summary,:repeat_quiz,:question,:semester,:year,:random,:sync_status)";
8842
8843 $insertCommand = Yii::app()->db->createCommand($insert);
8844
8845 $insertCommand->bindParam(":title", $title, PDO::PARAM_STR);
8846 $insertCommand->bindParam(":lesson_id", $lesson_id, PDO::PARAM_STR);
8847 $insertCommand->bindParam(":chapter_id", $chapter_id, PDO::PARAM_STR);
8848 $insertCommand->bindParam(":quiz_type", $quiz_type, PDO::PARAM_STR);
8849 $insertCommand->bindParam(":created_at", $created_at, PDO::PARAM_STR);
8850 $insertCommand->bindParam(":updated_at", $updated_at, PDO::PARAM_STR);
8851 $insertCommand->bindParam(":created_by", $created_by, PDO::PARAM_STR);
8852 $insertCommand->bindParam(":updated_by", $updated_by, PDO::PARAM_STR);
8853 $insertCommand->bindParam(":start_time", $start_time, PDO::PARAM_STR);
8854 $insertCommand->bindParam(":end_time", $end_time, PDO::PARAM_STR);
8855 $insertCommand->bindParam(":total_question", $total_question, PDO::PARAM_STR);
8856 $insertCommand->bindParam(":status", $status, PDO::PARAM_STR);
8857 $insertCommand->bindParam(":add_to_summary", $add_to_summary, PDO::PARAM_STR);
8858 $insertCommand->bindParam(":repeat_quiz", $repeat_quiz, PDO::PARAM_STR);
8859 $insertCommand->bindParam(":question", $question, PDO::PARAM_STR);
8860 $insertCommand->bindParam(":semester", $semester, PDO::PARAM_STR);
8861 $insertCommand->bindParam(":year", $year, PDO::PARAM_STR);
8862 $insertCommand->bindParam(":random", $random, PDO::PARAM_STR);
8863 $insertCommand->bindParam(":sync_status", $sync_status, PDO::PARAM_STR);
8864
8865 if ($insertCommand->execute()) {
8866 $berhasil = $berhasil + 1;
8867 } else {
8868 $gagal = $gagal + 1;
8869 array_push($id_gagal, $quiz_id);
8870 }
8871 }
8872 }
8873
8874 echo json_encode(array('messages' => 'success', 'berhasil' => $berhasil, 'gagal' => $gagal, 'id_gagal' => $id_gagal));
8875 break;
8876
8877 case 'quizSiswa':
8878 $data_qz_local = json_decode($data);
8879 $id_gagal = array();
8880
8881 foreach ($data_qz_local as $qz) {
8882 $cekQzLive = StudentQuiz::model()->findByPk($qz->id);
8883 $qz_id = $qz->id;
8884 $quiz_id = $qz->quiz_id;
8885 $student_id = $qz->student_id;
8886 $created_at = $qz->created_at;
8887 $updated_at = $qz->updated_at;
8888 $score = $qz->score;
8889 $right_answer = $qz->right_answer;
8890 $wrong_answer = $qz->wrong_answer;
8891 $unanswered = $qz->unanswered;
8892 $student_answer = $qz->student_answer;
8893 $attempt = $qz->attempt;
8894 $sync_status = 2;
8895
8896 if (!empty($cekQzLive)) {
8897 $update = "UPDATE " . $prefix . "student_quiz SET quiz_id = :quiz_id, student_id = :student_id, created_at = :created_at, updated_at = :updated_at, score = :score, right_answer = :right_answer, wrong_answer = :wrong_answer, unanswered = :unanswered, student_answer = :student_answer, attempt = :attempt, sync_status = :sync_status WHERE id = :id";
8898
8899 $updateCommand = Yii::app()->db->createCommand($update);
8900
8901 $updateCommand->bindParam(":id", $qz_id, PDO::PARAM_STR);
8902 $updateCommand->bindParam(":quiz_id", $quiz_id, PDO::PARAM_STR);
8903 $updateCommand->bindParam(":student_id", $student_id, PDO::PARAM_STR);
8904 $updateCommand->bindParam(":created_at", $created_at, PDO::PARAM_STR);
8905 $updateCommand->bindParam(":updated_at", $updated_at, PDO::PARAM_STR);
8906 $updateCommand->bindParam(":score", $score, PDO::PARAM_STR);
8907 $updateCommand->bindParam(":right_answer", $right_answer, PDO::PARAM_STR);
8908 $updateCommand->bindParam(":wrong_answer", $wrong_answer, PDO::PARAM_STR);
8909 $updateCommand->bindParam(":unanswered", $unanswered, PDO::PARAM_STR);
8910 $updateCommand->bindParam(":student_answer", $student_answer, PDO::PARAM_STR);
8911 $updateCommand->bindParam(":attempt", $attempt, PDO::PARAM_STR);
8912 $updateCommand->bindParam(":sync_status", $sync_status, PDO::PARAM_STR);
8913 if ($updateCommand->execute()) {
8914 $berhasil = $berhasil + 1;
8915 } else {
8916 $gagal = $gagal + 1;
8917 array_push($id_gagal, $qz_id);
8918 }
8919 } else {
8920 $insert = "INSERT INTO " . $prefix . "student_quiz (quiz_id,student_id,created_at,updated_at,score,right_answer,wrong_answer,unanswered,student_answer,attempt,sync_status) values(:quiz_id,:student_id,:created_at,:updated_at,:score,:right_answer,:wrong_answer,:unanswered,:student_answer,:attempt,:sync_status)";
8921
8922 $insertCommand = Yii::app()->db->createCommand($insert);
8923
8924 $insertCommand->bindParam(":unanswered", $unanswered, PDO::PARAM_STR);
8925 $insertCommand->bindParam(":quiz_id", $quiz_id, PDO::PARAM_STR);
8926 $insertCommand->bindParam(":student_id", $student_id, PDO::PARAM_STR);
8927 $insertCommand->bindParam(":created_at", $created_at, PDO::PARAM_STR);
8928 $insertCommand->bindParam(":updated_at", $updated_at, PDO::PARAM_STR);
8929 $insertCommand->bindParam(":score", $score, PDO::PARAM_STR);
8930 $insertCommand->bindParam(":right_answer", $right_answer, PDO::PARAM_STR);
8931 $insertCommand->bindParam(":wrong_answer", $wrong_answer, PDO::PARAM_STR);
8932 $insertCommand->bindParam(":student_answer", $student_answer, PDO::PARAM_STR);
8933 $insertCommand->bindParam(":attempt", $attempt, PDO::PARAM_STR);
8934 $insertCommand->bindParam(":sync_status", $sync_status, PDO::PARAM_STR);
8935
8936 if ($insertCommand->execute()) {
8937 $berhasil = $berhasil + 1;
8938 } else {
8939 $gagal = $gagal + 1;
8940 array_push($id_gagal, $qz_id);
8941 }
8942 }
8943 }
8944
8945 echo json_encode(array('messages' => 'success', 'berhasil' => $berhasil, 'gagal' => $gagal, 'id_gagal' => $id_gagal));
8946 break;
8947
8948 case 'soal':
8949 $data_qs_local = json_decode($data);
8950 $id_gagal = array();
8951 //print $data;
8952 //echo json_decode($data);
8953 //echo $data_qs_local;
8954 foreach ($data_qs_local as $quest) {
8955 $cekQuestionLive = Questions::model()->findByPk($quest->id);
8956 $question_id = $quest->id;
8957 $id_quiz = $quest->quiz_id;
8958 $lesson_id = $quest->lesson_id;
8959 $title = $quest->title;
8960 $text = $quest->text;
8961 $choices = $quest->choices;
8962 $key_answer = $quest->key_answer;
8963 $created_at = $quest->created_at;
8964 $updated_at = $quest->updated_at;
8965 $teacher_id = $quest->teacher_id;
8966 $created_by = $quest->created_by;
8967 $updated_by = $quest->updated_by;
8968 $file = $quest->file;
8969 $type = $quest->type;
8970 $choices_files = $quest->choices_files;
8971 $sync_status = 2;
8972
8973 if (!empty($cekQuestionLive)) {
8974 $update = "UPDATE " . $prefix . "questions SET quiz_id = :quiz_id, lesson_id = :lesson_id, title = :title, text = :text, choices = :choices, key_answer = :key_answer, created_at = :created_at, updated_at = :updated_at, teacher_id = :teacher_id, created_by = :created_by, updated_by = :updated_by, file = :file, type = :type, choices_files = :choices_files, sync_status = :sync_status WHERE id = :id";
8975
8976 $updateCommand = Yii::app()->db->createCommand($update);
8977
8978 $updateCommand->bindParam(":id", $question_id, PDO::PARAM_STR);
8979 $updateCommand->bindParam(":quiz_id", $id_quiz, PDO::PARAM_STR);
8980 $updateCommand->bindParam(":lesson_id", $lesson_id, PDO::PARAM_STR);
8981 $updateCommand->bindParam(":title", $title, PDO::PARAM_STR);
8982 $updateCommand->bindParam(":text", $text, PDO::PARAM_STR);
8983 $updateCommand->bindParam(":choices", $choices, PDO::PARAM_STR);
8984 $updateCommand->bindParam(":key_answer", $key_answer, PDO::PARAM_STR);
8985 $updateCommand->bindParam(":created_at", $created_at, PDO::PARAM_STR);
8986 $updateCommand->bindParam(":updated_at", $updated_at, PDO::PARAM_STR);
8987 $updateCommand->bindParam(":teacher_id", $teacher_id, PDO::PARAM_STR);
8988 $updateCommand->bindParam(":created_by", $created_by, PDO::PARAM_STR);
8989 $updateCommand->bindParam(":updated_by", $updated_by, PDO::PARAM_STR);
8990 $updateCommand->bindParam(":file", $file, PDO::PARAM_STR);
8991 $updateCommand->bindParam(":type", $type, PDO::PARAM_STR);
8992 $updateCommand->bindParam(":choices_files", $choices_files, PDO::PARAM_STR);
8993 $updateCommand->bindParam(":sync_status", $sync_status, PDO::PARAM_STR);
8994 if ($updateCommand->execute()) {
8995 $berhasil = $berhasil + 1;
8996 } else {
8997 $gagal = $gagal + 1;
8998 array_push($id_gagal, $question_id);
8999 }
9000 } else {
9001 $insert = "INSERT INTO " . $prefix . "questions (quiz_id,lesson_id,title,text,choices,key_answer,created_at,updated_at,teacher_id,created_by,updated_by,file,type,choices_files,sync_status) values(:quiz_id,:lesson_id,:title,:text,:choices,:key_answer,:created_at,:updated_at,:teacher_id,:created_by,:updated_by,:file,:type,:choices_files,:sync_status)";
9002
9003 $insertCommand = Yii::app()->db->createCommand($insert);
9004
9005 $insertCommand->bindParam(":updated_at", $updated_at, PDO::PARAM_STR);
9006 $insertCommand->bindParam(":quiz_id", $id_quiz, PDO::PARAM_STR);
9007 $insertCommand->bindParam(":lesson_id", $lesson_id, PDO::PARAM_STR);
9008 $insertCommand->bindParam(":title", $title, PDO::PARAM_STR);
9009 $insertCommand->bindParam(":text", $text, PDO::PARAM_STR);
9010 $insertCommand->bindParam(":choices", $choices, PDO::PARAM_STR);
9011 $insertCommand->bindParam(":key_answer", $key_answer, PDO::PARAM_STR);
9012 $insertCommand->bindParam(":created_at", $created_at, PDO::PARAM_STR);
9013 $insertCommand->bindParam(":teacher_id", $teacher_id, PDO::PARAM_STR);
9014 $insertCommand->bindParam(":created_by", $created_by, PDO::PARAM_STR);
9015 $insertCommand->bindParam(":updated_by", $updated_by, PDO::PARAM_STR);
9016 $insertCommand->bindParam(":file", $file, PDO::PARAM_STR);
9017 $insertCommand->bindParam(":type", $type, PDO::PARAM_STR);
9018 $insertCommand->bindParam(":choices_files", $choices_files, PDO::PARAM_STR);
9019 $insertCommand->bindParam(":sync_status", $sync_status, PDO::PARAM_STR);
9020
9021 if ($insertCommand->execute()) {
9022 $berhasil = $berhasil + 1;
9023 } else {
9024 $gagal = $gagal + 1;
9025 array_push($id_gagal, $question_id);
9026 }
9027 }
9028 }
9029 echo json_encode(array('messages' => 'success', 'berhasil' => $berhasil, 'gagal' => $gagal, 'id_gagal' => $id_gagal));
9030 break;
9031
9032 case 'lks':
9033 $data_lks_local = json_decode($data);
9034 $id_gagal = array();
9035
9036 foreach ($data_lks_local as $lks) {
9037 $cekLksLive = Lks::model()->findByPk($lks->id);
9038 $lks_id = $lks->id;
9039 $title = $lks->title;
9040 $lesson_id = $lks->lesson_id;
9041 $assignments = $lks->assignments;
9042 $chapters = $lks->chapters;
9043 $quizes = $lks->quizes;
9044 $created_at = $lks->created_at;
9045 $updated_at = $lks->updated_at;
9046 $teacher_id = $lks->teacher_id;
9047 $created_by = $lks->created_by;
9048 $updated_by = $lks->updated_by;
9049 $file = $lks->file;
9050 $type = $lks->type;
9051 $choices_files = $lks->choices_files;
9052 $sync_status = 2;
9053
9054 if (!empty($cekLksLive)) {
9055 $update = "UPDATE " . $prefix . "lks SET title = :title, lesson_id = :lesson_id, assignments = :assignments, chapters = :chapters, quizes = :quizes, created_at = :created_at, updated_at = :updated_at, teacher_id = :teacher_id, created_by = :created_by, updated_by = :updated_by, sync_status = :sync_status WHERE id = :id";
9056
9057 $updateCommand = Yii::app()->db->createCommand($update);
9058
9059 $updateCommand->bindParam(":id", $lks_id, PDO::PARAM_STR);
9060 $updateCommand->bindParam(":title", $title, PDO::PARAM_STR);
9061 $updateCommand->bindParam(":lesson_id", $lesson_id, PDO::PARAM_STR);
9062 $updateCommand->bindParam(":assignments", $assignments, PDO::PARAM_STR);
9063 $updateCommand->bindParam(":chapters", $chapters, PDO::PARAM_STR);
9064 $updateCommand->bindParam(":quizes", $quizes, PDO::PARAM_STR);
9065 $updateCommand->bindParam(":created_at", $created_at, PDO::PARAM_STR);
9066 $updateCommand->bindParam(":updated_at", $updated_at, PDO::PARAM_STR);
9067 $updateCommand->bindParam(":teacher_id", $teacher_id, PDO::PARAM_STR);
9068 $updateCommand->bindParam(":created_by", $created_by, PDO::PARAM_STR);
9069 $updateCommand->bindParam(":updated_by", $updated_by, PDO::PARAM_STR);
9070 $updateCommand->bindParam(":sync_status", $sync_status, PDO::PARAM_STR);
9071 if ($updateCommand->execute()) {
9072 $berhasil = $berhasil + 1;
9073 } else {
9074 $gagal = $gagal + 1;
9075 array_push($id_gagal, $lks_id);
9076 }
9077 } else {
9078 $insert = "INSERT INTO " . $prefix . "lks (title,lesson_id,assignments,chapters,quizes,created_at,updated_at,teacher_id,created_by,sync_status) values(:title,:lesson_id,:assignments,:chapters,:quizes,:created_at,:updated_at,:teacher_id,:created_by,:sync_status)";
9079
9080 $insertCommand = Yii::app()->db->createCommand($insert);
9081
9082 $insertCommand->bindParam(":updated_at", $updated_at, PDO::PARAM_STR);
9083 $insertCommand->bindParam(":title", $title, PDO::PARAM_STR);
9084 $insertCommand->bindParam(":lesson_id", $lesson_id, PDO::PARAM_STR);
9085 $insertCommand->bindParam(":assignments", $assignments, PDO::PARAM_STR);
9086 $insertCommand->bindParam(":chapters", $chapters, PDO::PARAM_STR);
9087 $insertCommand->bindParam(":quizes", $quizes, PDO::PARAM_STR);
9088 $insertCommand->bindParam(":updated_at", $updated_at, PDO::PARAM_STR);
9089 $insertCommand->bindParam(":created_at", $created_at, PDO::PARAM_STR);
9090 $insertCommand->bindParam(":teacher_id", $teacher_id, PDO::PARAM_STR);
9091 $insertCommand->bindParam(":created_by", $created_by, PDO::PARAM_STR);
9092 $insertCommand->bindParam(":updated_by", $updated_by, PDO::PARAM_STR);
9093 $insertCommand->bindParam(":sync_status", $sync_status, PDO::PARAM_STR);
9094
9095 if ($insertCommand->execute()) {
9096 $berhasil = $berhasil + 1;
9097 } else {
9098 $gagal = $gagal + 1;
9099 array_push($id_gagal, $lks_id);
9100 }
9101 }
9102 }
9103
9104 echo json_encode(array('messages' => 'success', 'berhasil' => $berhasil, 'gagal' => $gagal, 'id_gagal' => $id_gagal));
9105 break;
9106
9107 case 'pengumuman':
9108 $data_pengumuman_local = json_decode($data);
9109 $id_gagal = array();
9110
9111 foreach ($data_pengumuman_local as $pengumuman) {
9112 $cekPengumumanLive = Announcements::model()->findByPk($pengumuman->id);
9113 $pengumuman_id = $pengumuman->id;
9114 $author_id = $pengumuman->author_id;
9115 $title = $pengumuman->title;
9116 $content = $pengumuman->content;
9117 $created_at = $pengumuman->created_at;
9118 $updated_at = $pengumuman->updated_at;
9119 $type = $pengumuman->type;
9120 $sync_status = 2;
9121
9122 if (!empty($cekPengumumanLive)) {
9123 $update = "UPDATE " . $prefix . "pengumuman SET author_id = :author_id, title = :title, content = :content, created_at = :created_at, updated_at = :updated_at, type = :type, created_by = :created_by, updated_by = :updated_by, sync_status = :sync_status WHERE id = :id";
9124
9125 $updateCommand = Yii::app()->db->createCommand($update);
9126
9127 $updateCommand->bindParam(":id", $pengumuman_id, PDO::PARAM_STR);
9128 $updateCommand->bindParam(":author_id", $author_id, PDO::PARAM_STR);
9129 $updateCommand->bindParam(":title", $title, PDO::PARAM_STR);
9130 $updateCommand->bindParam(":content", $content, PDO::PARAM_STR);
9131 $updateCommand->bindParam(":created_at", $created_at, PDO::PARAM_STR);
9132 $updateCommand->bindParam(":updated_at", $updated_at, PDO::PARAM_STR);
9133 $updateCommand->bindParam(":type", $type, PDO::PARAM_STR);
9134 $updateCommand->bindParam(":sync_status", $sync_status, PDO::PARAM_STR);
9135 if ($updateCommand->execute()) {
9136 $berhasil = $berhasil + 1;
9137 } else {
9138 $gagal = $gagal + 1;
9139 array_push($id_gagal, $pengumuman_id);
9140 }
9141 } else {
9142 $insert = "INSERT INTO " . $prefix . "pengumuman (author_id,title,content,created_at,updated_at,type,created_by,sync_status) values(:author_id,:title,:content,:created_at,:updated_at,:type,:sync_status)";
9143
9144 $insertCommand = Yii::app()->db->createCommand($insert);
9145
9146 $insertCommand->bindParam(":updated_at", $updated_at, PDO::PARAM_STR);
9147 $insertCommand->bindParam(":author_id", $author_id, PDO::PARAM_STR);
9148 $insertCommand->bindParam(":title", $title, PDO::PARAM_STR);
9149 $insertCommand->bindParam(":content", $content, PDO::PARAM_STR);
9150 $insertCommand->bindParam(":updated_at", $updated_at, PDO::PARAM_STR);
9151 $insertCommand->bindParam(":created_at", $created_at, PDO::PARAM_STR);
9152 $insertCommand->bindParam(":type", $type, PDO::PARAM_STR);
9153 $insertCommand->bindParam(":sync_status", $sync_status, PDO::PARAM_STR);
9154
9155 if ($insertCommand->execute()) {
9156 $berhasil = $berhasil + 1;
9157 } else {
9158 $gagal = $gagal + 1;
9159 array_push($id_gagal, $pengumuman_id);
9160 }
9161 }
9162 }
9163
9164 echo json_encode(array('messages' => 'success', 'berhasil' => $berhasil, 'gagal' => $gagal, 'id_gagal' => $id_gagal));
9165 break;
9166
9167 case 'aktivitas':
9168 $data_aktivitas_local = json_decode($data);
9169 $id_gagal = array();
9170
9171 foreach ($data_aktivitas_local as $aktivitas) {
9172 $cekAktivitasLive = Activities::model()->findByPk($aktivitas->id);
9173 $aktivitas_id = $aktivitas->id;
9174 $activity_type = $aktivitas->activity_type;
9175 $content = $aktivitas->content;
9176 $created_by = $aktivitas->created_by;
9177 $updated_by = $aktivitas->updated_by;
9178 $created_at = $aktivitas->created_at;
9179 $updated_at = $aktivitas->updated_at;
9180 $sync_status = 2;
9181
9182 if (!empty($cekAktivitasLive)) {
9183 $update = "UPDATE " . $prefix . "activities SET activity_type = :activity_type, content = :content, created_by = :created_by, updated_by = :updated_by, created_at = :created_at, updated_at = :updated_at, sync_status = :sync_status WHERE id = :id";
9184
9185 $updateCommand = Yii::app()->db->createCommand($update);
9186
9187 $updateCommand->bindParam(":id", $aktivitas_id, PDO::PARAM_STR);
9188 $updateCommand->bindParam(":activity_type", $activity_type, PDO::PARAM_STR);
9189 $updateCommand->bindParam(":content", $content, PDO::PARAM_STR);
9190 $updateCommand->bindParam(":created_by", $created_by, PDO::PARAM_STR);
9191 $updateCommand->bindParam(":created_at", $created_at, PDO::PARAM_STR);
9192 $updateCommand->bindParam(":updated_at", $updated_at, PDO::PARAM_STR);
9193 $updateCommand->bindParam(":updated_by", $type, PDO::PARAM_STR);
9194 $updateCommand->bindParam(":sync_status", $sync_status, PDO::PARAM_STR);
9195 if ($updateCommand->execute()) {
9196 $berhasil = $berhasil + 1;
9197 } else {
9198 $gagal = $gagal + 1;
9199 array_push($id_gagal, $aktivitas_id);
9200 }
9201 } else {
9202 $insert = "INSERT INTO " . $prefix . "activities (activity_type,content,created_by,updated_by,created_at,updated_at,sync_status) values(:activity_type,:content,:created_by,:updated_by,:created_at,:updated_at,:sync_status)";
9203
9204 $insertCommand = Yii::app()->db->createCommand($insert);
9205
9206 $insertCommand->bindParam(":updated_at", $updated_at, PDO::PARAM_STR);
9207 $insertCommand->bindParam(":activity_type", $activity_type, PDO::PARAM_STR);
9208 $insertCommand->bindParam(":content", $content, PDO::PARAM_STR);
9209 $insertCommand->bindParam(":created_by", $created_by, PDO::PARAM_STR);
9210 $insertCommand->bindParam(":updated_at", $updated_at, PDO::PARAM_STR);
9211 $insertCommand->bindParam(":created_at", $created_at, PDO::PARAM_STR);
9212 $insertCommand->bindParam(":updated_by", $type, PDO::PARAM_STR);
9213 $insertCommand->bindParam(":sync_status", $sync_status, PDO::PARAM_STR);
9214
9215 if ($insertCommand->execute()) {
9216 $berhasil = $berhasil + 1;
9217 } else {
9218 $gagal = $gagal + 1;
9219 array_push($id_gagal, $aktivitas_id);
9220 }
9221 }
9222 }
9223
9224 echo json_encode(array('messages' => 'success', 'berhasil' => $berhasil, 'gagal' => $gagal, 'id_gagal' => $id_gagal));
9225 break;
9226
9227 case 'notif':
9228 $data_notif_local = json_decode($data);
9229 $id_gagal = array();
9230
9231 foreach ($data_notif_local as $notif) {
9232 $cekNotifLive = Notification::model()->findByPk($notif->id);
9233 $notif_id = $notif->id;
9234 $content = $notif->content;
9235 $user_id = $notif->user_id;
9236 $user_id_to = $notif->user_id_to;
9237 $tipe = $notif->tipe;
9238 $created_at = $notif->created_at;
9239 $updated_at = $notif->updated_at;
9240 $read_at = $notif->read_at;
9241 $status = $notif->status;
9242 $relation_id = $notif->relation_id;
9243 $class_id_to = $notif->class_id_to;
9244 $read_id = $notif->read_id;
9245 $sync_status = 2;
9246
9247 if (!empty($cekNotifLive)) {
9248 $update = "UPDATE " . $prefix . "notification SET content = :content, user_id = :user_id, user_id_to = :user_id_to, tipe = :tipe, created_at = :created_at, updated_at = :updated_at, read_at = :read_at, status = :status, relation_id = :relation_id, class_id_to = :class_id_to, read_id = :read_id, sync_status = :sync_status WHERE id = :id";
9249
9250 $updateCommand = Yii::app()->db->createCommand($update);
9251
9252 $updateCommand->bindParam(":id", $notif_id, PDO::PARAM_STR);
9253 $updateCommand->bindParam(":content", $content, PDO::PARAM_STR);
9254 $updateCommand->bindParam(":user_id", $user_id, PDO::PARAM_STR);
9255 $updateCommand->bindParam(":user_id_to", $user_id_to, PDO::PARAM_STR);
9256 $updateCommand->bindParam(":tipe", $tipe, PDO::PARAM_STR);
9257 $updateCommand->bindParam(":created_at", $created_at, PDO::PARAM_STR);
9258 $updateCommand->bindParam(":updated_at", $updated_at, PDO::PARAM_STR);
9259 $updateCommand->bindParam(":read_at", $read_at, PDO::PARAM_STR);
9260 $updateCommand->bindParam(":status", $status, PDO::PARAM_STR);
9261 $updateCommand->bindParam(":relation_id", $relation_id, PDO::PARAM_STR);
9262 $updateCommand->bindParam(":class_id_to", $class_id_to, PDO::PARAM_STR);
9263 $updateCommand->bindParam(":read_id", $read_id, PDO::PARAM_STR);
9264 $updateCommand->bindParam(":sync_status", $sync_status, PDO::PARAM_STR);
9265 if ($updateCommand->execute()) {
9266 $berhasil = $berhasil + 1;
9267 } else {
9268 $gagal = $gagal + 1;
9269 array_push($id_gagal, $notif_id);
9270 }
9271 } else {
9272 $insert = "INSERT INTO " . $prefix . "notification (content,user_id,user_id_to,tipe,created_at,updated_at,read_at,status,relation_id,class_id_to,read_id,sync_status) values(:content,:user_id,:user_id_to,:tipe,:created_at,:updated_at,:read_at,:status,:relation_id,:class_id_to,:read_id,:sync_status)";
9273
9274 $insertCommand = Yii::app()->db->createCommand($insert);
9275
9276 $insertCommand->bindParam(":updated_at", $updated_at, PDO::PARAM_STR);
9277 $insertCommand->bindParam(":content", $content, PDO::PARAM_STR);
9278 $insertCommand->bindParam(":user_id", $user_id, PDO::PARAM_STR);
9279 $insertCommand->bindParam(":user_id_to", $user_id_to, PDO::PARAM_STR);
9280 $insertCommand->bindParam(":tipe", $tipe, PDO::PARAM_STR);
9281 $insertCommand->bindParam(":updated_at", $updated_at, PDO::PARAM_STR);
9282 $insertCommand->bindParam(":created_at", $created_at, PDO::PARAM_STR);
9283 $insertCommand->bindParam(":read_at", $read_at, PDO::PARAM_STR);
9284 $insertCommand->bindParam(":status", $status, PDO::PARAM_STR);
9285 $insertCommand->bindParam(":relation_id", $relation_id, PDO::PARAM_STR);
9286 $insertCommand->bindParam(":class_id_to", $class_id_to, PDO::PARAM_STR);
9287 $insertCommand->bindParam(":read_id", $read_id, PDO::PARAM_STR);
9288 $insertCommand->bindParam(":sync_status", $sync_status, PDO::PARAM_STR);
9289
9290 if ($insertCommand->execute()) {
9291 $berhasil = $berhasil + 1;
9292 } else {
9293 $gagal = $gagal + 1;
9294 array_push($id_gagal, $user_id);
9295 }
9296 }
9297 }
9298
9299 echo json_encode(array('messages' => 'success', 'berhasil' => $berhasil, 'gagal' => $gagal, 'id_gagal' => $id_gagal));
9300 break;
9301
9302 case 'noffline':
9303 $data_noffline_local = json_decode($data);
9304 $id_gagal = array();
9305
9306 foreach ($data_noffline_local as $noffline) {
9307 $cekNofflineLive = OfflineMark::model()->findByPk($noffline->id);
9308 $noffline_id = $noffline->id;
9309 $lesson_id = $noffline->lesson_id;
9310 $student_id = $noffline->student_id;
9311 $score = $noffline->score;
9312 $file = $noffline->file;
9313 $created_at = $noffline->created_at;
9314 $updated_at = $noffline->updated_at;
9315 $created_by = $noffline->created_by;
9316 $updated_by = $noffline->updated_by;
9317 $mark_type = $noffline->mark_type;
9318 $sync_status = 2;
9319
9320 if (!empty($cekNofflineLive)) {
9321 $update = "UPDATE " . $prefix . "offline_mark SET lesson_id = :lesson_id, student_id = :student_id, score = :score, file = :file, created_at = :created_at, updated_at = :updated_at, created_by = :created_by, updated_by = :updated_by, mark_type = :mark_type, sync_status = :sync_status WHERE id = :id";
9322
9323 $updateCommand = Yii::app()->db->createCommand($update);
9324
9325 $updateCommand->bindParam(":id", $noffline_id, PDO::PARAM_STR);
9326 $updateCommand->bindParam(":lesson_id", $lesson_id, PDO::PARAM_STR);
9327 $updateCommand->bindParam(":student_id", $student_id, PDO::PARAM_STR);
9328 $updateCommand->bindParam(":score", $score, PDO::PARAM_STR);
9329 $updateCommand->bindParam(":file", $type, PDO::PARAM_STR);
9330 $updateCommand->bindParam(":created_at", $created_at, PDO::PARAM_STR);
9331 $updateCommand->bindParam(":updated_at", $updated_at, PDO::PARAM_STR);
9332 $updateCommand->bindParam(":created_by", $created_by, PDO::PARAM_STR);
9333 $updateCommand->bindParam(":updated_by", $updated_by, PDO::PARAM_STR);
9334 $updateCommand->bindParam(":mark_type", $mark_type, PDO::PARAM_STR);
9335 $updateCommand->bindParam(":sync_status", $sync_status, PDO::PARAM_STR);
9336 if ($updateCommand->execute()) {
9337 $berhasil = $berhasil + 1;
9338 } else {
9339 $gagal = $gagal + 1;
9340 array_push($id_gagal, $noffline_id);
9341 }
9342 } else {
9343 $insert = "INSERT INTO " . $prefix . "offline_mark (lesson_id,score,file,created_at,updated_at,created_by,updated_by,mark_type,sync_status) values(:lesson_id,:student_id,:score,:file,:created_at,:updated_at,:created_by,:updated_by,:mark_type,:sync_status)";
9344
9345 $insertCommand = Yii::app()->db->createCommand($insert);
9346
9347 $insertCommand->bindParam(":updated_at", $updated_at, PDO::PARAM_STR);
9348 $insertCommand->bindParam(":lesson_id", $lesson_id, PDO::PARAM_STR);
9349 $insertCommand->bindParam(":student_id", $student_id, PDO::PARAM_STR);
9350 $insertCommand->bindParam(":score", $score, PDO::PARAM_STR);
9351 $insertCommand->bindParam(":file", $type, PDO::PARAM_STR);
9352 $insertCommand->bindParam(":updated_at", $updated_at, PDO::PARAM_STR);
9353 $insertCommand->bindParam(":created_at", $created_at, PDO::PARAM_STR);
9354 $insertCommand->bindParam(":created_by", $created_by, PDO::PARAM_STR);
9355 $insertCommand->bindParam(":updated_by", $updated_by, PDO::PARAM_STR);
9356 $insertCommand->bindParam(":mark_type", $mark_type, PDO::PARAM_STR);
9357 $insertCommand->bindParam(":sync_status", $sync_status, PDO::PARAM_STR);
9358
9359 if ($insertCommand->execute()) {
9360 $berhasil = $berhasil + 1;
9361 } else {
9362 $gagal = $gagal + 1;
9363 array_push($id_gagal, $noffline_id);
9364 }
9365 }
9366 }
9367
9368 echo json_encode(array('messages' => 'success', 'berhasil' => $berhasil, 'gagal' => $gagal, 'id_gagal' => $id_gagal));
9369 break;
9370
9371 case 'kelas':
9372 $data_kelas_local = json_decode($data);
9373 $id_gagal = array();
9374
9375 foreach ($data_kelas_local as $kelas) {
9376 $cekKelasLive = Clases::model()->findByPk($kelas->id);
9377 $kelas_id = $kelas->id;
9378 $name = $kelas->name;
9379 $teacher_id = $kelas->teacher_id;
9380 $sync_status = 2;
9381
9382 if (!empty($cekKelasLive)) {
9383 $update = "UPDATE " . $prefix . "class SET name = :name, teacher_id = :teacher_id, sync_status = :sync_status WHERE id = :id";
9384
9385 $updateCommand = Yii::app()->db->createCommand($update);
9386
9387 $updateCommand->bindParam(":id", $kelas_id, PDO::PARAM_STR);
9388 $updateCommand->bindParam(":name", $name, PDO::PARAM_STR);
9389 $updateCommand->bindParam(":teacher_id", $teacher_id, PDO::PARAM_STR);
9390 $updateCommand->bindParam(":sync_status", $sync_status, PDO::PARAM_STR);
9391 if ($updateCommand->execute()) {
9392 $berhasil = $berhasil + 1;
9393 } else {
9394 $gagal = $gagal + 1;
9395 array_push($id_gagal, $kelas_id);
9396 }
9397 } else {
9398 $insert = "INSERT INTO " . $prefix . "class (name,teacher_id,sync_status) values(:name,:teacher_id,:sync_status)";
9399
9400 $insertCommand = Yii::app()->db->createCommand($insert);
9401
9402 $insertCommand->bindParam(":name", $name, PDO::PARAM_STR);
9403 $insertCommand->bindParam(":teacher_id", $teacher_id, PDO::PARAM_STR);
9404 $insertCommand->bindParam(":sync_status", $sync_status, PDO::PARAM_STR);
9405
9406 if ($insertCommand->execute()) {
9407 $berhasil = $berhasil + 1;
9408 } else {
9409 $gagal = $gagal + 1;
9410 array_push($id_gagal, $kelas_id);
9411 }
9412 }
9413 }
9414
9415 echo json_encode(array('messages' => 'success', 'berhasil' => $berhasil, 'gagal' => $gagal, 'id_gagal' => $id_gagal));
9416 break;
9417
9418 case 'pelajaran':
9419 $data_mapel_local = json_decode($data);
9420 $id_gagal = array();
9421
9422 foreach ($data_mapel_local as $mapel) {
9423 $cekMapelLive = Clases::model()->findByPk($mapel->id);
9424 $mapel_id = $mapel->id;
9425 $name = $mapel->name;
9426 $user_id = $mapel->user_id;
9427 $class_id = $mapel->class_id;
9428 $created_at = $mapel->created_at;
9429 $updated_at = $mapel->updated_at;
9430 $created_by = $mapel->created_by;
9431 $updated_by = $mapel->updated_by;
9432 $sync_status = 2;
9433
9434 if (!empty($cekMapelLive)) {
9435 $update = "UPDATE " . $prefix . "lesson SET name = :name, user_id = :user_id, class_id = :class_id, created_at = :created_at, updated_at = :updated_at, created_by = :created_by, updated_by = :updated_by, sync_status = :sync_status WHERE id = :id";
9436
9437 $updateCommand = Yii::app()->db->createCommand($update);
9438
9439 $updateCommand->bindParam(":id", $mapel_id, PDO::PARAM_STR);
9440 $updateCommand->bindParam(":name", $name, PDO::PARAM_STR);
9441 $updateCommand->bindParam(":user_id", $user_id, PDO::PARAM_STR);
9442 $updateCommand->bindParam(":class_id", $class_id, PDO::PARAM_STR);
9443 $updateCommand->bindParam(":created_at", $created_at, PDO::PARAM_STR);
9444 $updateCommand->bindParam(":updated_at", $updated_at, PDO::PARAM_STR);
9445 $updateCommand->bindParam(":created_by", $created_by, PDO::PARAM_STR);
9446 $updateCommand->bindParam(":updated_by", $updated_by, PDO::PARAM_STR);
9447 $updateCommand->bindParam(":sync_status", $sync_status, PDO::PARAM_STR);
9448 if ($updateCommand->execute()) {
9449 $berhasil = $berhasil + 1;
9450 } else {
9451 $gagal = $gagal + 1;
9452 array_push($id_gagal, $mapel_id);
9453 }
9454 } else {
9455 $insert = "INSERT INTO " . $prefix . "lesson (name,user_id,class_id,created_at,updated_at,created_by,updated_by,sync_status) values(:name,:user_id,:class_id,:created_at,:updated_at,:created_by,:updated_by,:sync_status)";
9456
9457 $insertCommand = Yii::app()->db->createCommand($insert);
9458
9459 $insertCommand->bindParam(":name", $name, PDO::PARAM_STR);
9460 $insertCommand->bindParam(":user_id", $user_id, PDO::PARAM_STR);
9461 $insertCommand->bindParam(":class_id", $class_id, PDO::PARAM_STR);
9462 $insertCommand->bindParam(":created_at", $created_at, PDO::PARAM_STR);
9463 $insertCommand->bindParam(":updated_at", $updated_at, PDO::PARAM_STR);
9464 $insertCommand->bindParam(":created_by", $created_by, PDO::PARAM_STR);
9465 $insertCommand->bindParam(":updated_by", $updated_by, PDO::PARAM_STR);
9466 $insertCommand->bindParam(":sync_status", $sync_status, PDO::PARAM_STR);
9467
9468 if ($insertCommand->execute()) {
9469 $berhasil = $berhasil + 1;
9470 } else {
9471 $gagal = $gagal + 1;
9472 array_push($id_gagal, $mapel_id);
9473 }
9474 }
9475 }
9476
9477 echo json_encode(array('messages' => 'success', 'berhasil' => $berhasil, 'gagal' => $gagal, 'id_gagal' => $id_gagal));
9478 break;
9479
9480 case 'absensi':
9481 $data_absensi_local = json_decode($data);
9482 $id_gagal = array();
9483
9484 foreach ($data_absensi_local as $absensi) {
9485 $cekAbsensiLive = Clases::model()->findByPk($absensi->id);
9486 $absensi_id = $absensi->id;
9487 $type = $absensi->type;
9488 $user_id = $absensi->user_id;
9489 $status = $absensi->status;
9490 $created_at = $absensi->created_at;
9491 $alasan = $absensi->alasan;
9492 $created_date = $absensi->created_date;
9493 $sync_status = 2;
9494
9495 if (!empty($cekAbsensiLive)) {
9496 $update = "UPDATE " . $prefix . "absensi SET type = :type, user_id = :user_id, status = :status, created_at = :created_at, alasan = :alasan, created_date = :created_date, sync_status = :sync_status WHERE id = :id";
9497
9498 $updateCommand = Yii::app()->db->createCommand($update);
9499
9500 $updateCommand->bindParam(":id", $absensi_id, PDO::PARAM_STR);
9501 $updateCommand->bindParam(":type", $type, PDO::PARAM_STR);
9502 $updateCommand->bindParam(":user_id", $user_id, PDO::PARAM_STR);
9503 $updateCommand->bindParam(":status", $status, PDO::PARAM_STR);
9504 $updateCommand->bindParam(":created_at", $created_at, PDO::PARAM_STR);
9505 $updateCommand->bindParam(":alasan", $alasan, PDO::PARAM_STR);
9506 $updateCommand->bindParam(":created_date", $created_date, PDO::PARAM_STR);
9507 $updateCommand->bindParam(":sync_status", $sync_status, PDO::PARAM_STR);
9508 if ($updateCommand->execute()) {
9509 $berhasil = $berhasil + 1;
9510 } else {
9511 $gagal = $gagal + 1;
9512 array_push($id_gagal, $absensi_id);
9513 }
9514 } else {
9515 $insert = "INSERT INTO " . $prefix . "absensi (type,user_id,status,created_at,alasan,created_date,sync_status) values(:type,:user_id,:status,:created_at,:alasan,:created_date,:sync_status)";
9516
9517 $insertCommand = Yii::app()->db->createCommand($insert);
9518
9519 $insertCommand->bindParam(":type", $type, PDO::PARAM_STR);
9520 $insertCommand->bindParam(":user_id", $user_id, PDO::PARAM_STR);
9521 $insertCommand->bindParam(":status", $status, PDO::PARAM_STR);
9522 $insertCommand->bindParam(":created_at", $created_at, PDO::PARAM_STR);
9523 $insertCommand->bindParam(":alasan", $alasan, PDO::PARAM_STR);
9524 $insertCommand->bindParam(":created_date", $created_date, PDO::PARAM_STR);
9525 $insertCommand->bindParam(":sync_status", $sync_status, PDO::PARAM_STR);
9526
9527 if ($insertCommand->execute()) {
9528 $berhasil = $berhasil + 1;
9529 } else {
9530 $gagal = $gagal + 1;
9531 array_push($id_gagal, $absensi_id);
9532 }
9533 }
9534 }
9535
9536 echo json_encode(array('messages' => 'success', 'berhasil' => $berhasil, 'gagal' => $gagal, 'id_gagal' => $id_gagal));
9537 break;
9538
9539 default:
9540
9541 break;
9542 }
9543
9544 //print "fasdfs";
9545 //var_dump(json_decode(file_get_contents("php://input")));
9546 }
9547
9548 public function actionGetColumnName($cekStatus = null)
9549 {
9550 //$post_url = "http://exambox.pinisi.co/api/postlocaldata";
9551 $post_url = "http://schoolraspi.com/api/postdatatolive";
9552
9553 $prefix = Yii::app()->params['tablePrefix'];
9554 $table_name = $prefix;
9555
9556 switch ($cekStatus) {
9557 case 'user':
9558 $table_name .= 'users';
9559 break;
9560
9561 case "tugas":
9562 $table_name .= 'assignment';
9563 break;
9564
9565 case "materi":
9566 $table_name .= 'chapters';
9567 break;
9568
9569 case "materiFile":
9570 $table_name .= 'chapter_files';
9571 break;
9572
9573 case "quiz":
9574 $table_name .= 'quiz';
9575 break;
9576
9577 case "quizSiswa":
9578 $table_name .= 'student_quiz';
9579 break;
9580
9581 case "soal":
9582 $table_name .= 'questions';
9583 break;
9584
9585 case "lks":
9586 $table_name .= 'lks';
9587 break;
9588
9589 case "pengumuman":
9590 $table_name .= 'announcements';
9591 break;
9592
9593 case "nilaiOffline":
9594 $table_name .= 'offline_mark';
9595 break;
9596
9597 case "aktivitas":
9598 $table_name .= 'activities';
9599 break;
9600
9601 case "notifikasi":
9602 $table_name .= 'notification';
9603 break;
9604
9605 case "kelas":
9606 $table_name .= 'class';
9607 break;
9608
9609 case "pelajaran":
9610 $table_name .= 'lesson';
9611 break;
9612
9613 case "absensi":
9614 $table_name .= 'absensi';
9615 break;
9616
9617 default:
9618 $table_name .= 'users';
9619 break;
9620 }
9621 //echo $table_name;
9622 $sql = "SELECT * FROM $table_name WHERE sync_status IS NULL";
9623 $command = Yii::app()->db->createCommand($sql);
9624
9625 try {
9626 $result = $command->queryAll();
9627 } catch (Exception $ex) {
9628 // Handle exception
9629 }
9630 echo "<pre>";
9631 if (!empty($result)) {
9632 //print_r($result);
9633 $total_row = count($result);
9634 $pass_data = array();
9635 $raw_data = array();
9636 $ids = array();
9637 foreach ($result as $columnName => $columnValue) {
9638 $raw_data[$columnName] = $columnValue;
9639 array_push($pass_data, $raw_data);
9640 //array_push($ids, $nud->id);
9641 }
9642 //$json_data = json_encode(array('table_name'=>$table_name,'data'=>$pass_data),JSON_PRETTY_PRINT);
9643 $json_data = json_encode($pass_data, JSON_PRETTY_PRINT);
9644 print_r($pass_data);
9645 //echo $post_url;
9646 //echo $json_data;
9647 //$post_data_url = $post_url."?type=user";
9648 $post_data_url = $post_url;
9649 $curl = curl_init();
9650 $wid = implode(',', $ids);
9651
9652 /* curl_setopt_array($curl, array(
9653 CURLOPT_URL => $post_data_url,
9654 CURLOPT_VERBOSE => true,
9655 CURLOPT_RETURNTRANSFER => true,
9656 CURLOPT_ENCODING => "",
9657 CURLOPT_MAXREDIRS => 10,
9658 CURLOPT_TIMEOUT => 3000,
9659 CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
9660 CURLOPT_CUSTOMREQUEST => "POST",
9661 CURLOPT_POSTFIELDS => $json_data,
9662 CURLOPT_HTTPHEADER => array(
9663 "content-type: application/json"
9664 ),
9665 ));
9666
9667 $response = curl_exec($curl);
9668 $err = curl_error($curl);
9669
9670 curl_close($curl);
9671
9672 if ($err) {
9673 echo "cURL Error #:" . $err;
9674 } else {
9675 $dataResponse = json_decode($response);
9676 print_r($response);
9677 // if(!empty($dataUser)){
9678 // if($dataUser->gagal == NULL){
9679 // $updateLocal="UPDATE ".$prefix."users SET sync_status = 1 WHERE id IN (".$wid.")";
9680
9681 // $updateLocalCommand=Yii::app()->db->createCommand($updateLocal);
9682 // $updateLocalCommand->execute();
9683 // }
9684 // }
9685
9686 //echo "tugas";
9687 } */
9688 }
9689 echo "</pre>";
9690
9691 /* foreach (Yii::app()->db->schema->getTable($table_name)->getColumnNames() as $columnName)
9692 {
9693 echo "<pre>";
9694 print_r($columnName);
9695 echo "</pre>";
9696 } */
9697 }
9698
9699 public function actionPostDataToLive($type = null)
9700 {
9701 $json_data = file_get_contents('php://input');
9702 //print $data;
9703 $berhasil = null;
9704 $gagal = null;
9705 $prefix = Yii::app()->params['tablePrefix'];
9706 //echo json_encode(array('messages'=>'success','berhasil'=>$berhasil,'gagal'=>$gagal,'id_gagal'=>$id_gagal));
9707 //echo "<pre>";
9708 $local_data = json_decode($json_data);
9709 //echo $json_data;
9710 print_r($local_data);
9711 //$table_name = $local_data->table_name;
9712 //$data = $local_data->data;
9713 //echo $table_name;
9714 //print_r($data);
9715 // foreach ($data as $key => $value) {
9716 // print_r($key);
9717 // }
9718 //echo "</pre>";
9719 }
9720}
9721
9722/* vim:set ai sw=4 sts=4 et fdm=marker fdc=4: */