| @@ 151-176 (lines=26) @@ | ||
| 148 | * @param int $ref_id representative id inside one tool item |
|
| 149 | * @return array |
|
| 150 | */ |
|
| 151 | function get_specific_field_values_list_by_prefix( |
|
| 152 | $prefix, |
|
| 153 | $course_code, |
|
| 154 | $tool_id, |
|
| 155 | $ref_id |
|
| 156 | ) { |
|
| 157 | $table_sf = Database::get_main_table(TABLE_MAIN_SPECIFIC_FIELD); |
|
| 158 | $table_sfv = Database::get_main_table(TABLE_MAIN_SPECIFIC_FIELD_VALUES); |
|
| 159 | $sql = 'SELECT sfv.value FROM %s sf LEFT JOIN %s sfv ON sf.id = sfv.field_id'. |
|
| 160 | ' WHERE sf.code = \'%s\' AND sfv.c_id = \'%s\' AND tool_id = \'%s\' AND sfv.ref_id = %s'; |
|
| 161 | $sql = sprintf( |
|
| 162 | $sql, |
|
| 163 | $table_sf, |
|
| 164 | $table_sfv, |
|
| 165 | $prefix, |
|
| 166 | $course_code, |
|
| 167 | $tool_id, |
|
| 168 | $ref_id |
|
| 169 | ); |
|
| 170 | $sql_result = Database::query($sql); |
|
| 171 | while ($result = Database::fetch_array($sql_result)) { |
|
| 172 | $return_array[] = $result; |
|
| 173 | } |
|
| 174 | ||
| 175 | return $return_array; |
|
| 176 | } |
|
| 177 | ||
| 178 | /** |
|
| 179 | * Add a specific field value |
|
| @@ 1622-1647 (lines=26) @@ | ||
| 1619 | * |
|
| 1620 | * @return array |
|
| 1621 | */ |
|
| 1622 | public static function getLatestHotPotatoResult( |
|
| 1623 | $exercisePath, |
|
| 1624 | $userId, |
|
| 1625 | $courseId, |
|
| 1626 | $sessionId |
|
| 1627 | ) { |
|
| 1628 | $table = Database::get_main_table( |
|
| 1629 | TABLE_STATISTIC_TRACK_E_HOTPOTATOES |
|
| 1630 | ); |
|
| 1631 | $exercisePath = Database::escape_string($exercisePath); |
|
| 1632 | $userId = intval($userId); |
|
| 1633 | ||
| 1634 | $sql = "SELECT * FROM $table |
|
| 1635 | WHERE |
|
| 1636 | c_id = $courseId AND |
|
| 1637 | exe_name LIKE '$exercisePath%' AND |
|
| 1638 | exe_user_id = $userId |
|
| 1639 | ORDER BY id |
|
| 1640 | LIMIT 1"; |
|
| 1641 | $result = Database::query($sql); |
|
| 1642 | $attempt = array(); |
|
| 1643 | if (Database::num_rows($result)) { |
|
| 1644 | $attempt = Database::fetch_array($result, 'ASSOC'); |
|
| 1645 | } |
|
| 1646 | return $attempt; |
|
| 1647 | } |
|
| 1648 | ||
| 1649 | /** |
|
| 1650 | * Gets the exam'data results |
|
| @@ 3582-3604 (lines=23) @@ | ||
| 3579 | * @param int Session id |
|
| 3580 | * @return array Courses list |
|
| 3581 | */ |
|
| 3582 | public static function get_courses_list_from_session($session_id) |
|
| 3583 | { |
|
| 3584 | $session_id = intval($session_id); |
|
| 3585 | ||
| 3586 | // table definition |
|
| 3587 | $tbl_session_course = Database::get_main_table(TABLE_MAIN_SESSION_COURSE); |
|
| 3588 | $courseTable = Database::get_main_table(TABLE_MAIN_COURSE); |
|
| 3589 | ||
| 3590 | $sql = "SELECT DISTINCT code, c_id |
|
| 3591 | FROM $tbl_session_course sc |
|
| 3592 | INNER JOIN $courseTable c |
|
| 3593 | ON sc.c_id = c.id |
|
| 3594 | WHERE session_id= $session_id"; |
|
| 3595 | ||
| 3596 | $result = Database::query($sql); |
|
| 3597 | ||
| 3598 | $courses = array(); |
|
| 3599 | while ($row = Database::fetch_array($result)) { |
|
| 3600 | $courses[$row['code']] = $row; |
|
| 3601 | } |
|
| 3602 | ||
| 3603 | return $courses; |
|
| 3604 | } |
|
| 3605 | ||
| 3606 | /** |
|
| 3607 | * Count the number of documents that an user has uploaded to a course |
|
| @@ 5278-5301 (lines=24) @@ | ||
| 5275 | * @param string $lastname Lastname to search |
|
| 5276 | * @return array The user list |
|
| 5277 | */ |
|
| 5278 | public static function getUserByName($firstname, $lastname) |
|
| 5279 | { |
|
| 5280 | $firstname = Database::escape_string($firstname); |
|
| 5281 | $lastname = Database::escape_string($lastname); |
|
| 5282 | ||
| 5283 | $userTable = Database::get_main_table(TABLE_MAIN_USER); |
|
| 5284 | ||
| 5285 | $sql = <<<SQL |
|
| 5286 | SELECT id, username, lastname, firstname |
|
| 5287 | FROM $userTable |
|
| 5288 | WHERE |
|
| 5289 | firstname LIKE '$firstname%' AND |
|
| 5290 | lastname LIKE '$lastname%' |
|
| 5291 | SQL; |
|
| 5292 | ||
| 5293 | $result = Database::query($sql); |
|
| 5294 | ||
| 5295 | $users = []; |
|
| 5296 | while ($resultData = Database::fetch_object($result)) { |
|
| 5297 | $users[] = $resultData; |
|
| 5298 | } |
|
| 5299 | ||
| 5300 | return $users; |
|
| 5301 | } |
|
| 5302 | ||
| 5303 | /** |
|
| 5304 | * @param int $optionSelected |
|