function Certificate($STUDENT_ID, $COURSE_ID, $checkPerms = true) { global $DB; $STUDENT_ID = intval($STUDENT_ID); $COURSE_ID = intval($COURSE_ID); if ($STUDENT_ID < 1 || $COURSE_ID < 1) { return false; } if (CCertification::IsCourseCompleted($STUDENT_ID, $COURSE_ID)) { $strSql = "SELECT SUM(G.RESULT) CNT, SUM(G.MAX_RESULT) MAX_CNT FROM b_learn_gradebook G\n\t\t\tINNER JOIN b_learn_test T ON T.ID = G.TEST_ID\n\t\t\tWHERE G.COMPLETED = 'Y' AND G.STUDENT_ID = '" . $STUDENT_ID . "' AND T.COURSE_ID = '" . $COURSE_ID . "'"; $res = $DB->Query($strSql, false, "File: " . __FILE__ . "<br>Line: " . __LINE__); $SUMMARY = $MAX_SUMMARY = 0; if ($ar = $res->Fetch()) { $SUMMARY = $ar["CNT"]; $MAX_SUMMARY = $ar["MAX_CNT"]; } $arFields = array('STUDENT_ID' => $STUDENT_ID, 'COURSE_ID' => $COURSE_ID, 'SUMMARY' => &$SUMMARY, 'MAX_SUMMARY' => &$MAX_SUMMARY); foreach (GetModuleEvents('learning', 'OnBeforeCertificate', true) as $arEvent) { if (ExecuteModuleEventEx($arEvent, array(&$arFields)) === false) { return false; } } $arParams = array(); if (!$checkPerms) { $arParams['CHECK_PERMISSIONS'] = 'N'; } $strSql = "SELECT ID FROM b_learn_certification WHERE STUDENT_ID = '" . $STUDENT_ID . "' AND COURSE_ID = '" . $COURSE_ID . "'"; $res = $DB->Query($strSql, false, "File: " . __FILE__ . "<br>Line: " . __LINE__); if ($ar = $res->Fetch()) { return CCertification::Update($ar["ID"], array("SUMMARY" => $SUMMARY, "MAX_SUMMARY" => $MAX_SUMMARY, "ACTIVE" => "Y"), $arParams); } else { $arFields = array("STUDENT_ID" => $STUDENT_ID, "COURSE_ID" => $COURSE_ID, "SUMMARY" => $SUMMARY, "MAX_SUMMARY" => $MAX_SUMMARY, "~DATE_CREATE" => CDatabase::CurrentTimeFunction()); $ID = CCertification::Add($arFields, $arParams); return $ID > 0; } } return false; }
public static function GetNowFunction() { return CDatabase::CurrentTimeFunction(); }
function AttemptFinished($ATTEMPT_ID) { global $DB; $ATTEMPT_ID = intval($ATTEMPT_ID); if ($ATTEMPT_ID < 1) { return false; } $strSql = "SELECT SUM(TR.POINT) as SCORE, SUM(Q.POINT) MAX_SCORE " . "FROM b_learn_test_result TR " . "INNER JOIN b_learn_question Q ON TR.QUESTION_ID = Q.ID " . "WHERE ATTEMPT_ID = '" . $ATTEMPT_ID . "' "; $res = $DB->Query($strSql, false, "File: " . __FILE__ . "<br>Line: " . __LINE__); if (!($ar = $res->Fetch())) { return false; } $res = $this->Update($ATTEMPT_ID, array("SCORE" => $ar["SCORE"], "MAX_SCORE" => $ar["MAX_SCORE"], "STATUS" => "F", "~DATE_END" => CDatabase::CurrentTimeFunction())); if ($res) { return CTestAttempt::OnAttemptChange($ATTEMPT_ID); } else { return false; } }
} } if ($strError == '') { if (CModule::IncludeModule("blog")) { $APPLICATION->ResetException(); $arblogFields = array("ALIAS" => $_REQUEST["blog_ALIAS"], "DESCRIPTION" => $_REQUEST["blog_DESCRIPTION"], "INTERESTS" => $_REQUEST["blog_INTERESTS"], "AVATAR" => $_FILES["blog_AVATAR"]); $arblogFields["AVATAR"]["del"] = $_REQUEST["blog_AVATAR_del"]; $ar_res = CBlogUser::GetByID($arResult["ID"], BLOG_BY_USER_ID); if ($ar_res) { $arblogFields["AVATAR"]["old_file"] = $ar_res["AVATAR"]; $BLOG_USER_ID = intval($ar_res["ID"]); $BLOG_USER_ID1 = CBlogUser::Update($BLOG_USER_ID, $arblogFields); $blog_res = intval($BLOG_USER_ID1) > 0; } else { $arblogFields["USER_ID"] = $arResult["ID"]; $arblogFields["~DATE_REG"] = CDatabase::CurrentTimeFunction(); $BLOG_USER_ID = CBlogUser::Add($arblogFields); $blog_res = intval($BLOG_USER_ID) > 0; } if ($ex = $APPLICATION->GetException()) { $strError = $ex->GetString(); } } } if (CModule::IncludeModule("learning") && $strError == '') { $arStudentFields = array("RESUME" => $_REQUEST["student_RESUME"], "PUBLIC_PROFILE" => $_REQUEST["student_PUBLIC_PROFILE"] == "Y" ? "Y" : "N"); $ar_res = CStudent::GetList(array(), array("USER_ID" => $arResult["ID"])); if ($arStudent = $ar_res->Fetch()) { $learning_res = CStudent::Update($arResult["ID"], $arStudentFields); } else { $arStudentFields["USER_ID"] = $arResult["ID"];
public static function Add($arFields) { global $DB; if (!is_set($arFields, "CODE") || strlen($arFields["CODE"]) <= 0) { return false; } if (!is_set($arFields, "ID") || strlen($arFields["ID"]) <= 0) { $arFields["ID"] = $this->Generate32RandomString(); } if (!is_set($arFields, "IP") || strlen($arFields["IP"]) <= 0) { $arFields["IP"] = $_SERVER["REMOTE_ADDR"]; } if (!is_set($arFields, "DATE_CREATE") || strlen($arFields["DATE_CREATE"]) <= 0 || !$DB->IsDate($arFields["DATE_CREATE"], false, LANG, "FULL")) { unset($arFields["DATE_CREATE"]); $arFields["~DATE_CREATE"] = CDatabase::CurrentTimeFunction(); } $arInsert = $DB->PrepareInsert("b_captcha", $arFields); if (!$DB->Query("INSERT INTO b_captcha (" . $arInsert[0] . ") VALUES (" . $arInsert[1] . ")", true)) { } return false; return $arFields["ID"]; }
$bPostAnswer = $_SERVER["REQUEST_METHOD"] == "POST" && isset($sessAttemptID) && $_POST["ANSWERED"] == "Y"; $arResult["COMPLETE_PERCENT"] = 0; $arResult["CURRENT_MARK"] = ""; if (isset($sessAttemptID) && intval($sessAttemptID) > 0) { $arResult["COMPLETE_PERCENT"] = CTestResult::GetPercent(@$sessAttemptID); if ($arResult["COMPLETE_PERCENT"]) { $arResult["CURRENT_MARK"] = CLTestMark::GetByPercent($arTest["ID"], $arResult["COMPLETE_PERCENT"]); } } if ($bTestCreate) { $sessIncorrectMessage = null; //If old attempt exists? if ($arAttempt = _AttemptExists($arParams["TEST_ID"])) { $sessAttemptID = $arAttempt["ID"]; if ($arAttempt["STATUS"] == "N") { $arFields = array("~DATE_START" => CDatabase::CurrentTimeFunction(), "DATE_END" => false, "STATUS" => "B"); $ta = new CTestAttempt(); $res = $ta->Update($arAttempt["ID"], $arFields); } LocalRedirect($arResult["REDIRECT_PAGE"]); } //Check attempt limit if ($arTest["ATTEMPT_LIMIT"] > 0 && $arTest["ATTEMPT_LIMIT"] <= CTestAttempt::GetCount($arParams["TEST_ID"], $USER->GetID())) { $sessAttemptError = GetMessage("LEARNING_LIMIT_ERROR"); LocalRedirect($arResult["REDIRECT_PAGE"]); } //Check min time between attempts if ($arTest["MIN_TIME_BETWEEN_ATTEMPTS"] > 0) { CTimeZone::Disable(); $rsPrevAttempt = CTestAttempt::GetList(array("DATE_END" => "DESC"), array("TEST_ID" => $arParams["TEST_ID"], "STUDENT_ID" => $USER->GetID())); CTimeZone::Enable();
/** * <p>Добавляет или изменяет сертификат, если курс был пройден.</p> * * * * * @param int $STUDENT_ID Идентификатор студента. * * * * @param int $COURSE_ID Идентификатор курса. * * * * @return bool <p>Метод возвращает <i>true</i>, если сертификация прошла успешно, * иначе - <i>false</i>.</p> * * * <h4>Example</h4> * <pre> * <?<br>if (CModule::IncludeModule("learning"))<br>{<br> $STUDENT_ID = 1;<br> $COURSE_ID = 92;<br><br> $done = CCertification::Certificate($STUDENT_ID, $COURSE_ID);<br><br> if ($done)<br> echo "Success!";<br> else<br> echo "Course is not completed";<br>}<br>?> * </pre> * * * * <h4>See Also</h4> * <ul> <li> <a href="http://dev.1c-bitrix.ru/api_help/learning/classes/ccertification/index.php">CCertification</a>::<a * href="http://dev.1c-bitrix.ru/api_help/learning/classes/ccertification/add.php">Add</a> </li> <li> <a * href="http://dev.1c-bitrix.ru/api_help/learning/classes/ccertification/index.php">CCertification</a>::<a * href="http://dev.1c-bitrix.ru/api_help/learning/classes/ccertification/update.php">Update</a> </li> <li> <a * href="http://dev.1c-bitrix.ru/api_help/learning/classes/ctest/index.php">CTest</a>::<a * href="http://dev.1c-bitrix.ru/api_help/learning/classes/ctest/getlist.php">GetList</a> </li> <li> <a * href="http://dev.1c-bitrix.ru/api_help/learning/classes/cgradebook/index.php">CGradeBook</a>::<a * href="http://dev.1c-bitrix.ru/api_help/learning/classes/cgradebook/getlist.php">GetList</a> </li> </ul><a * name="examples"></a> * * * @static * @link http://dev.1c-bitrix.ru/api_help/learning/classes/ccertification/certificate.php * @author Bitrix */ public static function Certificate($STUDENT_ID, $COURSE_ID) { global $DB; $STUDENT_ID = intval($STUDENT_ID); $COURSE_ID = intval($COURSE_ID); if ($STUDENT_ID < 1 || $COURSE_ID < 1) return false; if (CCertification::IsCourseCompleted($STUDENT_ID, $COURSE_ID)) { $strSql = "SELECT SUM(G.RESULT) CNT, SUM(G.MAX_RESULT) MAX_CNT FROM b_learn_gradebook G INNER JOIN b_learn_test T ON T.ID = G.TEST_ID WHERE G.COMPLETED = 'Y' AND G.STUDENT_ID = '".$STUDENT_ID."' AND T.COURSE_ID = '".$COURSE_ID."'"; $res = $DB->Query($strSql, false, "File: ".__FILE__."<br>Line: ".__LINE__); $SUMMARY = $MAX_SUMMARY = 0; if ($ar = $res->Fetch()) { $SUMMARY = $ar["CNT"]; $MAX_SUMMARY = $ar["MAX_CNT"]; } $strSql = "SELECT ID FROM b_learn_certification WHERE STUDENT_ID = '".$STUDENT_ID."' AND COURSE_ID = '".$COURSE_ID."'"; $res = $DB->Query($strSql, false, "File: ".__FILE__."<br>Line: ".__LINE__); if ($ar = $res->Fetch()) { return CCertification::Update($ar["ID"], Array("SUMMARY" => $SUMMARY, "MAX_SUMMARY" => $MAX_SUMMARY, "ACTIVE" => "Y") ); } else { $arFields = Array( "STUDENT_ID" => $STUDENT_ID, "COURSE_ID" => $COURSE_ID, "SUMMARY" => $SUMMARY, "MAX_SUMMARY" => $MAX_SUMMARY, "~DATE_CREATE" => CDatabase::CurrentTimeFunction(), ); $ID = CCertification::Add($arFields); return ($ID > 0); } } return false; }
if (intval($arLogComment["SOURCE_ID"]) > 0) { $log_tmp_id = false; $arBlogComment = CBlogComment::GetByID($arLogComment["SOURCE_ID"]); if ($arBlogComment) { $dbLog = CSocNetLog::GetList(array("ID" => "DESC"), array("EVENT_ID" => "blog_post", "SOURCE_ID" => $arBlogComment["POST_ID"]), false, array("nTopCount" => 1), array("ID", "TMP_ID")); if ($arLog = $dbLog->Fetch()) { $log_tmp_id = $arLog["TMP_ID"]; } } if (intval($log_tmp_id) > 0) { $arFields = array("ENTITY_TYPE" => $arLogComment["ENTITY_TYPE"], "ENTITY_ID" => $arLogComment["ENTITY_ID"], "EVENT_ID" => "blog_comment", "LOG_DATE" => $arLogComment["LOG_DATE"], "MESSAGE" => $arLogComment["MESSAGE"], "TEXT_MESSAGE" => $arLogComment["TEXT_MESSAGE"], "URL" => $arLogComment["URL"], "MODULE_ID" => false, "SOURCE_ID" => $arLogComment["SOURCE_ID"], "LOG_ID" => $log_tmp_id, "USER_ID" => $arLogComment["USER_ID"]); CSocNetLogComments::Add($arFields, false, false, false); CSocNetLog::Delete($arLogComment["ID"]); } } } } $dbLog = CSocNetLog::GetList(array("LOG_DATE" => "ASC"), array("COMMENTS_COUNT" => false), false, false, array("ID", "ENTITY_TYPE", "ENTITY_ID", "LOG_DATE", "MESSAGE", "TEXT_MESSAGE", "URL", "SOURCE_ID", "USER_ID")); while ($arLog = $dbLog->Fetch()) { CSocNetLog::Update($arLog["ID"], array("LOG_UPDATE" => $arLog["LOG_DATE"])); } if (IsModuleInstalled("intranet")) { $dbResult = CSocNetEventUserView::GetList(array("ENTITY_ID" => "ASC"), array("ENTITY_TYPE" => "N")); $arResult = $dbResult->Fetch(); if (!$arResult) { CSocNetEventUserView::Add(array("ENTITY_TYPE" => "N", "ENTITY_ID" => 0, "EVENT_ID" => "news", "USER_ID" => 0, "USER_ANONYMOUS" => "N")); CSocNetEventUserView::Add(array("ENTITY_TYPE" => "N", "ENTITY_ID" => 0, "EVENT_ID" => "news_comment", "USER_ID" => 0, "USER_ANONYMOUS" => "N")); } } $GLOBALS["DB"]->Query("UPDATE b_sonet_log SET LOG_UPDATE = " . CDatabase::IsNull("(SELECT MAX(LOG_DATE) FROM b_sonet_log_comment LC WHERE LC.LOG_ID=b_sonet_log.TMP_ID)", CDatabase::CurrentTimeFunction()), false, $err_mess . __LINE__); $GLOBALS["DB"]->Query("UPDATE b_sonet_log SET LOG_UPDATE = LOG_DATE WHERE NOT EXISTS (SELECT LC.ID FROM b_sonet_log_comment LC WHERE LC.LOG_ID = b_sonet_log.TMP_ID)", false, $err_mess . __LINE__);
$arResult["CURRENT_MARK"] = CLTestMark::GetByPercent($arTest["ID"], $arResult["COMPLETE_PERCENT"]); } } if ($bTestCreate) { $sessIncorrectMessage = null; //If old attempt exists? if ($arAttempt = _AttemptExists($arParams["TEST_ID"])) { $sessAttemptID = $arAttempt["ID"]; if ($arAttempt["STATUS"] == "N") { $arFields = array( "~DATE_START" => CDatabase::CurrentTimeFunction(), "DATE_END" => false, "STATUS" => "B" ); $ta = new CTestAttempt; $res = $ta->Update($arAttempt["ID"], $arFields); } LocalRedirect($arResult["REDIRECT_PAGE"]); } //Check attempt limit if ($arTest["ATTEMPT_LIMIT"] > 0 && $arTest["ATTEMPT_LIMIT"] <= CTestAttempt::GetCount($arParams["TEST_ID"], $USER->GetID())) { $sessAttemptError = GetMessage("LEARNING_LIMIT_ERROR");