|
@@ -1904,37 +1904,58 @@ function api_get_course_path($course_code = null)
|
|
|
/**
|
|
|
* Gets a course setting from the current course_setting table. Try always using integer values.
|
|
|
*
|
|
|
- * @param string $setting_name The name of the setting we want from the table
|
|
|
- * @param array $course_info
|
|
|
- *
|
|
|
+ * @param string $settingName The name of the setting we want from the table
|
|
|
+ * @param array $courseInfo
|
|
|
+ * @param bool $force force checking the value in the database
|
|
|
* @return mixed The value of that setting in that table. Return -1 if not found.
|
|
|
*/
|
|
|
-function api_get_course_setting($setting_name, $course_info = [])
|
|
|
+function api_get_course_setting($settingName, $courseInfo = [], $force = false)
|
|
|
{
|
|
|
- if (empty($course_info)) {
|
|
|
- $course_info = api_get_course_info();
|
|
|
+ if (empty($courseInfo)) {
|
|
|
+ $courseInfo = api_get_course_info();
|
|
|
+ }
|
|
|
+
|
|
|
+ if (empty($courseInfo) || empty($settingName)) {
|
|
|
+ return -1;
|
|
|
}
|
|
|
|
|
|
- if (isset($course_info['real_id']) && !empty($course_info['real_id']) && !empty($setting_name)) {
|
|
|
+ $courseId = isset($courseInfo['real_id']) && !empty($courseInfo['real_id']) ? $courseInfo['real_id'] : 0;
|
|
|
+
|
|
|
+ if (empty($courseId)) {
|
|
|
+ return -1;
|
|
|
+ }
|
|
|
+
|
|
|
+ static $courseSettingInfo = [];
|
|
|
+
|
|
|
+ if ($force) {
|
|
|
+ $courseSettingInfo = [];
|
|
|
+ }
|
|
|
+
|
|
|
+ if (!isset($courseSettingInfo[$courseId])) {
|
|
|
$table = Database::get_course_table(TABLE_COURSE_SETTING);
|
|
|
- $setting_name = Database::escape_string($setting_name);
|
|
|
+ $settingName = Database::escape_string($settingName);
|
|
|
|
|
|
- $sql = "SELECT value FROM $table
|
|
|
- WHERE c_id = {$course_info['real_id']} AND variable = '$setting_name'";
|
|
|
+ $sql = "SELECT variable, value FROM $table
|
|
|
+ WHERE c_id = $courseId ";
|
|
|
$res = Database::query($sql);
|
|
|
if (Database::num_rows($res) > 0) {
|
|
|
- $row = Database::fetch_array($res);
|
|
|
- if ($setting_name === 'email_alert_manager_on_new_quiz') {
|
|
|
- if (!is_null($row['value'])) {
|
|
|
- $result = explode(',', $row['value']);
|
|
|
- $row['value'] = $result;
|
|
|
+ $result = Database::store_result($res, 'ASSOC');
|
|
|
+ $courseSettingInfo[$courseId] = array_column($result, 'value', 'variable');
|
|
|
+
|
|
|
+ if (isset($courseSettingInfo[$courseId]['email_alert_manager_on_new_quiz'])) {
|
|
|
+ $value = $courseSettingInfo[$courseId]['email_alert_manager_on_new_quiz'];
|
|
|
+ if (!is_null($value)) {
|
|
|
+ $result = explode(',', $value);
|
|
|
+ $courseSettingInfo[$courseId]['email_alert_manager_on_new_quiz'] = $result;
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
- return $row['value'];
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ if (isset($courseSettingInfo[$courseId]) && isset($courseSettingInfo[$courseId][$settingName])) {
|
|
|
+ return $courseSettingInfo[$courseId][$settingName];
|
|
|
+ }
|
|
|
+
|
|
|
return -1;
|
|
|
}
|
|
|
|
|
@@ -4409,12 +4430,9 @@ function api_item_property_update(
|
|
|
/**
|
|
|
* Gets item property by tool.
|
|
|
*
|
|
|
- * @param string course code
|
|
|
- * @param string tool name, linked to 'rubrique' of the course tool_list (Warning: language sensitive !!)
|
|
|
- * @param int id of the item itself, linked to key of every tool ('id', ...), "*" = all items of the tool
|
|
|
- * @param int $session_id
|
|
|
- * @param string $tool
|
|
|
+ * @param string $tool tool name, linked to 'rubrique' of the course tool_list (Warning: language sensitive !!)
|
|
|
* @param string $course_code
|
|
|
+ * @param int $session_id
|
|
|
*
|
|
|
* @return array All fields from c_item_property (all rows found) or empty array
|
|
|
*/
|