| @@ 177-195 (lines=19) @@ | ||
| 174 | * @param string $directory The course directory/path that appears in the URL |
|
| 175 | * @return int |
|
| 176 | */ |
|
| 177 | public static function getCourseIdByDirectory($directory = null) |
|
| 178 | { |
|
| 179 | if (!empty($directory)) { |
|
| 180 | $directory = \Database::escape_string($directory); |
|
| 181 | $row = \Database::select( |
|
| 182 | 'id', |
|
| 183 | \Database::get_main_table(TABLE_MAIN_COURSE), |
|
| 184 | array('where'=> array('directory = ?' => array($directory))), |
|
| 185 | 'first' |
|
| 186 | ); |
|
| 187 | ||
| 188 | if (is_array($row) && isset($row['id'])) { |
|
| 189 | return $row['id']; |
|
| 190 | } else { |
|
| 191 | return false; |
|
| 192 | } |
|
| 193 | } |
|
| 194 | return Session::read('_real_cid', 0); |
|
| 195 | } |
|
| 196 | ||
| 197 | /** |
|
| 198 | * Check if the current HTTP request is by AJAX |
|
| @@ 1542-1560 (lines=19) @@ | ||
| 1539 | * @param string $code Optional course code |
|
| 1540 | * @return int |
|
| 1541 | */ |
|
| 1542 | function api_get_course_int_id($code = null) |
|
| 1543 | { |
|
| 1544 | if (!empty($code)) { |
|
| 1545 | $code = Database::escape_string($code); |
|
| 1546 | $row = Database::select( |
|
| 1547 | 'id', |
|
| 1548 | Database::get_main_table(TABLE_MAIN_COURSE), |
|
| 1549 | array('where'=> array('code = ?' => array($code))), |
|
| 1550 | 'first' |
|
| 1551 | ); |
|
| 1552 | ||
| 1553 | if (is_array($row) && isset($row['id'])) { |
|
| 1554 | return $row['id']; |
|
| 1555 | } else { |
|
| 1556 | return false; |
|
| 1557 | } |
|
| 1558 | } |
|
| 1559 | return Session::read('_real_cid', 0); |
|
| 1560 | } |
|
| 1561 | ||
| 1562 | /** |
|
| 1563 | * Returns the current course directory |
|