public function actionMarkTest() { $arrQuestion = isset($_REQUEST["arrQuestion"]) ? $_REQUEST["arrQuestion"] : array(); $user_test_id = isset($_REQUEST["user_test_id"]) ? $_REQUEST["user_test_id"] : NULL; $json = array("result" => "true"); if (!empty($arrQuestion)) { $checkSave = TRUE; foreach ($arrQuestion as $itemquestion) { $model = WUserAnswers::model()->find("question_id=" . $itemquestion["idquestion"] . ' AND user_test_id=' . $itemquestion["user_test_id"]); if (!empty($model)) { $model->point_answer_text = $itemquestion["point_answer_text"]; $model->comment_trainer = $itemquestion["comment_question"]; if (!$model->save()) { $checkSave = FALSE; } } } if ($checkSave == TRUE) { $arrPointQuestion = array(); // Lay Point cua cau hoi $db = Yii::app()->db; $comm = $db->createCommand()->select('t.*,t2.test_name')->from('pls_user_test t')->LeftJoin('pls_test_parent t2', 't2.id=t.test_id')->LeftJoin('pls_course t3', 't3.id=t.course_id')->where('t.id=' . $user_test_id . ' AND t3.created_by=' . Yii::app()->user->id); $dataUserTest = $comm->queryRow(); $comm->reset(); $comm = $db->createCommand()->select('t.*')->from('pls_test_user t')->where('t.id_test_parent=' . $dataUserTest["test_id"] . ' AND user_id=' . $dataUserTest["user_id"] . ' AND kind=' . $dataUserTest["test_kind"] . ' AND t.course_id=' . $dataUserTest["course_id"] . ' AND t.lecture_id=' . $dataUserTest["lecture_id"]); $dataTestUser = $comm->queryRow(); if (!empty($dataTestUser)) { if (!empty($dataTestUser["dataquestion"])) { $dataquestion = json_decode($dataTestUser["dataquestion"], true); if (!empty($dataquestion)) { foreach ($dataquestion as $itemdataquestion) { $arrPointQuestion[$itemdataquestion["idquestion"]]["point"] = $itemdataquestion["point"]; $arrPointQuestion[$itemdataquestion["idquestion"]]["answertrue"] = WQuestionAnswerLib::getAnswerTrueQuestion($itemdataquestion["idquestion"]); } } } } // Select Nhung cau tra loi cua hoc vien $comm->reset(); $comm = $db->createCommand()->select('t.*')->from('pls_user_answers t')->where('t.user_test_id=' . $user_test_id); $dataUserAnswer = $comm->queryAll(); if (!empty($dataUserAnswer)) { foreach ($dataUserAnswer as $itemdataUserAnswer) { $arrPointQuestion[$itemdataUserAnswer["question_id"]]["question_type"] = $itemdataUserAnswer["question_type"]; $arrPointQuestion[$itemdataUserAnswer["question_id"]]["question_id"] = $itemdataUserAnswer["question_id"]; $arrPointQuestion[$itemdataUserAnswer["question_id"]]["doing"] = $itemdataUserAnswer["doing"]; if ($itemdataUserAnswer["question_type"] == 1 or $itemdataUserAnswer["question_type"] == 4) { $arrPointQuestion[$itemdataUserAnswer["question_id"]]["useranswer"] = $itemdataUserAnswer["user_answer_id"]; } elseif ($itemdataUserAnswer["question_type"] == 2) { $arrPointQuestion[$itemdataUserAnswer["question_id"]]["useranswer"] = $itemdataUserAnswer["user_answer_text"]; } $arrPointQuestion[$itemdataUserAnswer["question_id"]]["point_answer_text"] = $itemdataUserAnswer["point_answer_text"]; $arrPointQuestion[$itemdataUserAnswer["question_id"]]["comment_trainer"] = $itemdataUserAnswer["comment_trainer"]; } } // Kiem tra nhung cau tra loi dung $dataNew = array(); $total_point = 0; if (!empty($arrPointQuestion)) { foreach ($arrPointQuestion as $key => $itemPointQuestion) { $dataNew[$key] = $itemPointQuestion; if (!empty($itemPointQuestion["answertrue"])) { if ($itemPointQuestion["question_type"] == 4 or $itemPointQuestion["question_type"] == 1) { // Truong hop nhieu dap an $dataAnswer = explode(',', $itemPointQuestion["useranswer"]); $dataAnswerNew = array(); foreach ($dataAnswer as $item) { if (!empty($item)) { $dataAnswerNew[] = $item; } } $check = TRUE; if (count($dataAnswerNew) == count($itemPointQuestion["answertrue"])) { foreach ($dataAnswerNew as $itemdataAnswerNew) { if (!in_array($itemdataAnswerNew, $itemPointQuestion["answertrue"])) { $check = FALSE; } } } else { $check = FALSE; } if ($check == TRUE) { $dataNew[$key]["check"] = "OK"; $total_point += $itemPointQuestion["point"]; } else { $dataNew[$key]["check"] = "NOK"; } } } if ($itemPointQuestion["question_type"] == 2) { if (isset($itemPointQuestion["point_answer_text"])) { $total_point += $itemPointQuestion["point_answer_text"]; } } } } // Luu ket qua vao database $model = WTestUser::model()->find('user_id=' . $dataUserTest["user_id"] . ' AND id_test_parent=' . $dataUserTest["test_id"] . ' AND kind=' . $dataUserTest["test_kind"] . ' AND course_id=' . $dataUserTest["course_id"] . ' AND lecture_id=' . $dataUserTest["lecture_id"]); $model->datafinish = json_encode($dataNew); $model->save(); $modelUserTest = WUserTest::model()->find('id=' . $user_test_id); $modelUserTest->pass_score_point = $total_point; $modelUserTest->success = 2; if ($modelUserTest->save()) { //$testDetails = WTest::model()->find("id=".$test_id); $username = WUser::getFullNameUser($dataUserTest["user_id"]); $trainer = WUser::getFullNameUser(Yii::app()->user->id); $title = "Giáo viên " . $trainer . " đã chấm bài test: " . $dataUserTest["test_name"] . " của bạn"; if (!empty($dataUserTest["success"]) and $dataUserTest["success"] == 2) { $title = "Giáo viên " . $trainer . " đã chấm bài lại test: " . $dataUserTest["test_name"] . " của bạn"; } $content = "Dear <strong>" . $username . "</strong>"; //$content .="<br/>Bài làm Test :".$testDetails->test_name." của bạn đã được Giáo viên: <strong>".$trainer.'</strong> chấm xong'; $content .= "<br/>Giáo viên <strong>" . $trainer . '</strong> đã chấm bài: <strong>"' . $dataUserTest["test_name"] . '"</strong> của bạn'; $url = Yii::app()->createUrl("wCourseLecture/Viewresult", array("user_test_id" => $dataUserTest["id"])); $content .= "<br/><a href='" . $url . "'>Click Để xem kết quả bài test</a>"; WMessage::SendMessage($title, $content, "notifi", Yii::app()->user->id, $dataUserTest["user_id"]); $json = array("result" => "true"); } } else { $json = array("result" => "false", "message" => ""); } } echo json_encode($json); }
/** * Luu ket qua test vao db **/ public function actionResult() { $this->layout = '//layouts/main_trainer'; $cs = Yii::app()->getClientScript(); $cs->registerCssFile(Yii::app()->theme->baseUrl . '/css/jquery-ui.css?ver=' . time()); $cs->registerCssFile(Yii::app()->theme->baseUrl . '/css/dialog.css?ver=' . time()); //$cs->registerCssFile(Yii::app()->theme->baseUrl.'/css/jquery.countdown.css?ver='.time()); $cs->registerScriptFile(Yii::app()->theme->baseUrl . '/js/jquery.simplemodal-1.4.4.js', CClientScript::POS_END); $cs->registerScriptFile(Yii::app()->theme->baseUrl . '/js/jquery-ui.js'); $cs->registerScriptFile(Yii::app()->theme->baseUrl . '/js/jquery.slimscroll.min.js'); $courseid = isset($_REQUEST['course_id']) ? $_REQUEST['course_id'] : ''; $lecture_id = isset($_REQUEST['lecture_id']) ? $_REQUEST['lecture_id'] : ''; $test_id = isset($_REQUEST['test_id']) ? $_REQUEST['test_id'] : ''; $total = isset($_REQUEST['total']) ? $_REQUEST['total'] : ''; $kind = isset($_REQUEST['kind']) ? $_REQUEST['kind'] : ''; //Thong tin bai test $testDetails = WTestParent::model()->find("id=" . $test_id); //Get tong so cau hoi $db = Yii::app()->db; $comm = $db->createCommand()->select('t.*')->from('pls_test_user t')->where('t.id_test_parent=' . $test_id . ' AND t.user_id=' . Yii::app()->user->id . ' AND kind=' . $kind . ' AND t.course_id=' . $courseid . ' AND t.lecture_id=' . $lecture_id); $dataTestUser = $comm->queryRow(); if (empty($dataTestUser)) { $this->redirect(Yii::app()->createUrl("/")); } $totalquestion = 0; $totalTrue = 0; $totalQuestionText = 0; $totalfails = 0; $totalnotdoing = 0; $totalnoanswer = 0; if (!empty($dataTestUser) and !empty($dataTestUser["dataquestion"])) { if (!empty($dataTestUser["dataquestion"])) { $dataquestion = json_decode($dataTestUser["dataquestion"], true); $totalquestion = count($dataquestion); } //lay so cau hoi dung if (!empty($dataTestUser["datafinish"])) { $datafinish = json_decode($dataTestUser["datafinish"], true); foreach ($datafinish as $itemdatafinish) { if ($itemdatafinish["question_type"] != 2 and isset($itemdatafinish["check"]) and $itemdatafinish["check"] == "OK") { ++$totalTrue; } elseif ($itemdatafinish["question_type"] != 2 and isset($itemdatafinish["check"]) and $itemdatafinish["check"] == "NOK" and isset($itemdatafinish["doing"]) and $itemdatafinish["doing"] == 1) { $totalfails++; } elseif ($itemdatafinish["question_type"] != 2 and isset($itemdatafinish["check"]) and $itemdatafinish["check"] == "NOK" and isset($itemdatafinish["doing"]) and $itemdatafinish["doing"] == 0) { $totalnotdoing++; } elseif ($itemdatafinish["question_type"] == 2) { ++$totalQuestionText; } elseif (!isset($itemdatafinish["check"])) { ++$totalnoanswer; } } } } // Tong diem $comm->reset(); $comm = $db->createCommand()->select('t.*')->from('pls_user_test t')->where('t.test_id=' . $test_id . ' AND test_kind=' . $kind . ' AND t.course_id=' . $courseid . ' AND t.lecture_id=' . $lecture_id . ' AND user_id=' . Yii::app()->user->id); $dataUserTest = $comm->queryRow(); $courseDetails = WCourse::model()->find("id=" . $courseid); $username = WUser::getFullNameUser(Yii::app()->user->id); $trainer = WUser::getFullNameUser($courseDetails->created_by); $title = "Học viên " . $username . " Làm xong bài Test :" . $testDetails->test_name; $content = "Dear <strong>" . $trainer . "</strong>"; $content .= "<br/>Có học viên <strong>" . $username . "</strong> làm xong bài test : " . $testDetails->test_name . " (" . date('H:i d/m/Y') . ")"; $content .= "<br/><a href='" . Yii::app()->createUrl("wUserTest/viewdetails", array("id" => $dataUserTest["id"])) . "'>Click để xem chi tiết</a>"; WMessage::SendMessage($title, $content, "notifi", WUser::getIDMinUser(), $courseDetails->created_by); $modeltest = WTest::model()->find('id=:id', array(':id' => $test_id)); $this->render('/wTest/trainee/_result', array('testDetails' => $testDetails, 'totalquestion' => $totalquestion, 'totalQuestionText' => $totalQuestionText, 'totalTrue' => $totalTrue, 'totalfails' => $totalfails, 'totalnotdoing' => $totalnotdoing, 'totalnoanswer' => $totalnoanswer, 'dataUserTest' => $dataUserTest, 'dataTestUser' => $dataTestUser)); }
public function actionSendComment() { $dataType = $_REQUEST["dataType"]; $dataId = $_REQUEST["dataId"]; $action_url = $_REQUEST["action_url"]; $contentComment = $_REQUEST["contentComment"]; $parent_id = $_REQUEST["parent_id"]; $_db = Yii::app()->db; $comm = $_db->createCommand(); $result = $comm->insert('pls_comment', array('parent_id' => $parent_id, 'user_id' => Yii::app()->user->id, 'content' => $contentComment, 'data_id' => $dataId, 'data_type' => $dataType, 'status' => 1, 'created_date' => date('Y-m-d H:i:s'), 'action_url' => strtolower($action_url))); if ($result) { $idnewrecord = Yii::app()->db->getLastInsertID($result); if ($dataType == "course") { $courseDetails = WCourse::model()->find("id=" . $dataId); if (Yii::app()->user->id != $courseDetails->created_by) { $title = "Bình Luận Khóa học: " . $courseDetails->course_name; $content = ""; $user = WUser::getUserById(Yii::app()->user->id); if (Yii::app()->session["group_id"] == 1) { $content .= "Có giáo viên <strong>" . $user->username . "</strong> bình luận tại Khóa học: <a href='" . Yii::app()->createUrl('wCourse/view', array("id" => $dataId, "row" => "comment_row_" . $idnewrecord)) . "'>\"" . $courseDetails->course_name . "\"</a>"; } else { if (Yii::app()->session["group_id"] == 2) { $content .= "Có học viên <strong>" . $user->username . "</strong> bình luận tại Khóa học: <a href='" . Yii::app()->createUrl('wCourse/view', array("id" => $dataId, "row" => "comment_row_" . $idnewrecord)) . "'>\"" . $courseDetails->course_name . "\"</a>"; } else { if (Yii::app()->session["group_id"] == 3) { $content .= "Có Quản trị viên <strong>" . $user->username . "</strong> bình luận tại Khóa học: <a href='" . Yii::app()->createUrl('wCourse/view', array("id" => $dataId, "row" => "comment_row_" . $idnewrecord)) . "'>\"" . $courseDetails->course_name . "\"</a>"; } } } $content .= '<br/>Click xem chi tiết: <a href="' . Yii::app()->createUrl('wCourse/view', array("id" => $dataId, "row" => "comment_row_" . $idnewrecord)) . '">' . $courseDetails->course_name . '</a>'; WMessage::SendMessage($title, $content, "notifi", WUser::getIDMinUser(), $courseDetails->created_by); } } elseif ($dataType == "courselecture") { $courseLecture = WLecture::model()->find("id=" . $dataId); if (Yii::app()->user->id != $courseLecture->created_by) { $title = "Bình Luận Bài Giảng: " . $courseLecture->lecture_name; $content = ""; $user = WUser::getUserById(Yii::app()->user->id); if (Yii::app()->session["group_id"] == 1) { $content .= "Có giáo viên <strong>" . $user->username . "</strong> bình luận tại Bài Giảng: <a href='" . Yii::app()->createUrl('wLecture/View', array("id" => $dataId, "row" => "comment_row_" . $idnewrecord)) . "'>\"" . $courseLecture->lecture_name . "\"</a>"; } else { if (Yii::app()->session["group_id"] == 2) { $content .= "Có học viên <strong>" . $user->username . "</strong> bình luận tại Bài Giảng: <a href='" . Yii::app()->createUrl('wLecture/View', array("id" => $dataId, "row" => "comment_row_" . $idnewrecord)) . "'>\"" . $courseLecture->lecture_name . "\"</a>"; } else { if (Yii::app()->session["group_id"] == 3) { $content .= "Có Quản trị viên <strong>" . $user->username . "</strong> bình luận tại Bài Giảng: <a href='" . Yii::app()->createUrl('wLecture/View', array("id" => $dataId, "row" => "comment_row_" . $idnewrecord)) . "'>\"" . $courseLecture->lecture_name . "\"</a>"; } } } $content .= '<br/>Click xem chi tiết: <a href="' . Yii::app()->createUrl('wLecture/View', array("id" => $dataId, "row" => "comment_row_" . $idnewrecord)) . '">' . $courseLecture->lecture_name . '</a>'; WMessage::SendMessage($title, $content, "notifi", WUser::getIDMinUser(), $courseLecture->created_by); } } echo json_encode(array("result" => "true")); } else { echo json_encode(array("result" => "false")); } }
public function actionSendMessage() { if (empty(Yii::app()->user->id)) { echo json_encode(array('result' => 'false', 'html' => 'Bạn cần đăng nhập để sử dụng chức năng này')); } $username = $_REQUEST["username"]; $titlemessage = $_REQUEST["titlemessage"]; $contentmessage = $_REQUEST["contentmessage"]; $arrUserTo = array(); $date = date('Y-m-d H:i:s'); if (!empty($username)) { $message = new WMessage(); $message->status = 1; $message->title = $titlemessage; $message->created_by = Yii::app()->user->id; $message->created_date = $date; $message->type_message = "message"; if ($message->save()) { $idmessage = $message->id; $messgetTrash = new WMessageTrash(); $messgetTrash->id_message = $idmessage; $messgetTrash->trash = 0; $messgetTrash->save(); $messageContent = new WMessageContent(); $messageContent->created_date = $date; $messageContent->content = $contentmessage; $messageContent->id_message = $idmessage; $messageContent->created_by = Yii::app()->user->id; $messageContent->status = 1; if ($messageContent->save()) { $idmessagecontent = $messageContent->id; $arrUserTo = explode(',', $username); $arrUserTo = self::convertArr($arrUserTo); foreach ($arrUserTo as $user) { if (!empty($user)) { $dataUser = WUser::getUserByUsername($user); $messageSendto = new WMessageSendto(); $messageSendto->id_message = $idmessage; $messageSendto->id_message_content = $idmessagecontent; $messageSendto->id_user_to = $dataUser->id; $messageSendto->status = 0; $messageSendto->trash = 0; $messageSendto->type_message = "message"; if ($messageSendto->save()) { } else { echo json_encode(array('result' => 'false', 'html' => 'Lỗi thao tác 03. Mời bạn thử lại')); die; } } } } else { echo json_encode(array('result' => 'false', 'html' => 'Lỗi thao tác 02. Mời bạn thử lại')); die; } } else { echo json_encode(array('result' => 'false', 'html' => 'Lỗi thao tác 01. Mời bạn thử lại')); die; } } else { echo json_encode(array('result' => 'false', 'html' => 'Không có User nào cần gửi')); } echo json_encode(array('result' => 'true', 'html' => 'Bạn gửi tin nhắn thành công')); die; }
public static function SendMessage($title, $content, $typeSend = "notifi", $iduserFrom = NULL, $iduserTo) { $titlemessage = $title; $contentmessage = $content; if (empty($iduserFrom)) { $iduserFrom = WUser::getIDMinUser(); } $date = date('Y-m-d H:i:s'); if (!empty($iduserTo)) { $message = new WMessage(); $message->status = 1; $message->title = $titlemessage; $message->created_by = $iduserFrom; $message->created_date = $date; $message->type_message = $typeSend; if ($message->save()) { $idmessage = $message->id; $messgetTrash = new WMessageTrash(); $messgetTrash->id_message = $idmessage; $messgetTrash->trash = 0; $messgetTrash->save(); $messageContent = new WMessageContent(); $messageContent->created_date = $date; $messageContent->content = $contentmessage; $messageContent->id_message = $idmessage; $messageContent->created_by = $iduserFrom; $messageContent->status = 1; if ($messageContent->save()) { $idmessagecontent = $messageContent->id; if (!empty($iduserTo)) { $dataUser = WUser::getUserByUsername($iduserTo); $messageSendto = new WMessageSendto(); $messageSendto->id_message = $idmessage; $messageSendto->id_message_content = $idmessagecontent; $messageSendto->id_user_to = $iduserTo; $messageSendto->type_message = $typeSend; $messageSendto->status = 0; $messageSendto->trash = 0; if ($messageSendto->save()) { } else { echo json_encode(array('result' => 'false', 'html' => 'Lỗi thao tác 03. Mời bạn thử lại')); die; } } } else { echo json_encode(array('result' => 'false', 'html' => 'Lỗi thao tác 02. Mời bạn thử lại')); die; } } else { echo json_encode(array('result' => 'false', 'html' => 'Lỗi thao tác 01. Mời bạn thử lại')); die; } } else { echo json_encode(array('result' => 'false', 'html' => 'Không có User nào cần gửi')); } }
public function actionEndLectureText() { $course_lecture_id = $_POST['course_lecture_id']; $idtraininglog = $_POST['idtraininglog']; $totalText = $_POST['totalText']; $totalViewText = $_POST['totalViewText']; $viewListText = $_POST['viewListText']; $user_id = Yii::app()->user->id; $timeOK = $totalViewText / $totalText * 100; $viewText = $totalViewText . ' / ' . $totalText; $check = 'NOK'; if ($timeOK >= 90) { $check = 'OK'; } //$des = ' View : ('. number_format($timeOK,2,',','.') .'% View pages '.$viewText.')'; $des = ' Hoàn thành : (' . number_format($timeOK, 2, ',', '.') . '% Xem ' . $viewText . ')'; $desNotifi = 'Học viên hoàn thành : (' . number_format($timeOK, 2, ',', '.') . '% Xem ' . $viewText . ')'; $modelTrainingLog = WTrainingLog::model()->findByPk($idtraininglog); $modelTrainingLog->user_id = $user_id; $modelTrainingLog->description = $des; $modelTrainingLog->result = $check; $modelTrainingLog->data = $viewListText; if ($modelTrainingLog->save()) { if ($modelTrainingLog->result == 'OK') { $userinfo = WUser::getFullNameUser(Yii::app()->user->id); $couseDetails = WCourseLecture::getInfoCourse($course_lecture_id); $trainer = WUser::getFullNameUser($couseDetails["created_by"]); $title = "Học viên " . $userinfo . " hoàn thành bài giảng:" . $couseDetails["course_name"]; $content = "Dear <strong>" . $trainer . "</strong>"; $content .= "<br/>Học viên <strong>" . $userinfo . '</strong> hoàn thành Bài giảng: <a href="' . Yii::app()->createUrl("wCourse/view", array("id" => $couseDetails["id"])) . '"><strong>' . $couseDetails["course_name"] . " (" . date('H:i d/m/Y') . ")</strong></a>"; //$content .="<br/>==> <a href='".Yii::app()->createUrl("wCourse/view",array("id" => $couseDetails["id"]))."'>".$couseDetails["course_name"]."</a>"; //$content .="<br />Congratulations, you have completed the lesson. "; //$content .="<br />Xin chúc mừng, Bạn đã hoàn thành bài học. "; $content .= "<br />" . $modelTrainingLog->description; WMessage::SendMessage($title, $content, "notifi", WUser::getIDMinUser(), $couseDetails["created_by"]); $mess = 'Xin chúc mừng, Bạn đã hoàn thành bài học. <br />' . $modelTrainingLog->description; // Chúc mừng bạn đã hoàn thành bài học } else { //$mess = 'You need to learn the lesson. <br />'.$modelTrainingLog->description;//Bạn cần phải học lại bài học. $mess = 'Bạn chưa hoàn thành bài học. <br />' . $modelTrainingLog->description; //Bạn cần phải học lại bài học. } echo json_encode(array('status' => 'true', 'result' => $modelTrainingLog->result, 'mess' => $mess)); } else { echo json_encode(array('status' => 'false')); } }