Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
Complex classes like learnpath often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use learnpath, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 26 | class learnpath |
||
| 27 | { |
||
| 28 | public $attempt = 0; // The number for the current ID view. |
||
| 29 | public $cc; // Course (code) this learnpath is located in. @todo change name for something more comprensible ... |
||
| 30 | public $current; // Id of the current item the user is viewing. |
||
| 31 | public $current_score; // The score of the current item. |
||
| 32 | public $current_time_start; // The time the user loaded this resource (this does not mean he can see it yet). |
||
| 33 | public $current_time_stop; // The time the user closed this resource. |
||
| 34 | public $default_status = 'not attempted'; |
||
| 35 | public $encoding = 'UTF-8'; |
||
| 36 | public $error = ''; |
||
| 37 | public $extra_information = ''; // This string can be used by proprietary SCORM contents to store data about the current learnpath. |
||
| 38 | public $force_commit = false; // For SCORM only - if set to true, will send a scorm LMSCommit() request on each LMSSetValue(). |
||
| 39 | public $index; // The index of the active learnpath_item in $ordered_items array. |
||
| 40 | public $items = array(); |
||
| 41 | public $last; // item_id of last item viewed in the learning path. |
||
| 42 | public $last_item_seen = 0; // In case we have already come in this learnpath, reuse the last item seen if authorized. |
||
| 43 | public $license; // Which license this course has been given - not used yet on 20060522. |
||
| 44 | public $lp_id; // DB ID for this learnpath. |
||
| 45 | public $lp_view_id; // DB ID for lp_view |
||
| 46 | public $maker; // Which maker has conceived the content (ENI, Articulate, ...). |
||
| 47 | public $message = ''; |
||
| 48 | public $mode = 'embedded'; // Holds the video display mode (fullscreen or embedded). |
||
| 49 | public $name; // Learnpath name (they generally have one). |
||
| 50 | public $ordered_items = array(); // List of the learnpath items in the order they are to be read. |
||
| 51 | public $path = ''; // Path inside the scorm directory (if scorm). |
||
| 52 | public $theme; // The current theme of the learning path. |
||
| 53 | public $preview_image; // The current image of the learning path. |
||
| 54 | public $accumulateScormTime; // Flag to decide whether to accumulate SCORM time or not |
||
| 55 | |||
| 56 | // Tells if all the items of the learnpath can be tried again. Defaults to "no" (=1). |
||
| 57 | public $prevent_reinit = 1; |
||
| 58 | |||
| 59 | // Describes the mode of progress bar display. |
||
| 60 | public $seriousgame_mode = 0; |
||
| 61 | public $progress_bar_mode = '%'; |
||
| 62 | |||
| 63 | // Percentage progress as saved in the db. |
||
| 64 | public $progress_db = 0; |
||
| 65 | public $proximity; // Wether the content is distant or local or unknown. |
||
| 66 | public $refs_list = array(); //list of items by ref => db_id. Used only for prerequisites match. |
||
| 67 | // !!!This array (refs_list) is built differently depending on the nature of the LP. |
||
| 68 | // If SCORM, uses ref, if Chamilo, uses id to keep a unique value. |
||
| 69 | public $type; //type of learnpath. Could be 'chamilo', 'scorm', 'scorm2004', 'aicc', ... |
||
| 70 | // TODO: Check if this type variable is useful here (instead of just in the controller script). |
||
| 71 | public $user_id; //ID of the user that is viewing/using the course |
||
| 72 | public $update_queue = array(); |
||
| 73 | public $scorm_debug = 0; |
||
| 74 | public $arrMenu = array(); // Array for the menu items. |
||
| 75 | public $debug = 0; // Logging level. |
||
| 76 | public $lp_session_id = 0; |
||
| 77 | public $lp_view_session_id = 0; // The specific view might be bound to a session. |
||
| 78 | public $prerequisite = 0; |
||
| 79 | public $use_max_score = 1; // 1 or 0 |
||
| 80 | public $subscribeUsers = 0; // Subscribe users or not |
||
| 81 | public $created_on = ''; |
||
| 82 | public $modified_on = ''; |
||
| 83 | public $publicated_on = ''; |
||
| 84 | public $expired_on = ''; |
||
| 85 | public $ref = null; |
||
| 86 | public $course_int_id; |
||
| 87 | public $course_info = array(); |
||
| 88 | public $categoryId; |
||
| 89 | |||
| 90 | /** |
||
| 91 | * Constructor. |
||
| 92 | * Needs a database handler, a course code and a learnpath id from the database. |
||
| 93 | * Also builds the list of items into $this->items. |
||
| 94 | * @param string $course Course code |
||
| 95 | * @param integer $lp_id |
||
| 96 | * @param integer $user_id |
||
| 97 | * @return mixed True on success, false on error |
||
|
|
|||
| 98 | */ |
||
| 99 | public function __construct($course, $lp_id, $user_id) |
||
| 100 | { |
||
| 101 | $this->encoding = api_get_system_encoding(); |
||
| 102 | View Code Duplication | if ($this->debug > 0) { |
|
| 103 | error_log('New LP - In learnpath::__construct('.$course.','.$lp_id.','.$user_id.')', 0); |
||
| 104 | } |
||
| 105 | if (empty($course)) { |
||
| 106 | $course = api_get_course_id(); |
||
| 107 | } |
||
| 108 | $course_info = api_get_course_info($course); |
||
| 109 | if (!empty($course_info)) { |
||
| 110 | $this->cc = $course_info['code']; |
||
| 111 | $this->course_info = $course_info; |
||
| 112 | $course_id = $course_info['real_id']; |
||
| 113 | } else { |
||
| 114 | $this->error = 'Course code does not exist in database.'; |
||
| 115 | } |
||
| 116 | |||
| 117 | $lp_id = (int) $lp_id; |
||
| 118 | $course_id = (int) $course_id; |
||
| 119 | $this->set_course_int_id($course_id); |
||
| 120 | // Check learnpath ID. |
||
| 121 | if (empty($lp_id) || empty($course_id)) { |
||
| 122 | $this->error = "Parameter is empty: LpId:'$lp_id', courseId: '$lp_id'"; |
||
| 123 | } else { |
||
| 124 | // TODO: Make it flexible to use any course_code (still using env course code here). |
||
| 125 | $lp_table = Database::get_course_table(TABLE_LP_MAIN); |
||
| 126 | $sql = "SELECT * FROM $lp_table |
||
| 127 | WHERE id = '$lp_id' AND c_id = $course_id"; |
||
| 128 | if ($this->debug > 2) { |
||
| 129 | error_log('New LP - learnpath::__construct() '.__LINE__.' - Querying lp: '.$sql, 0); |
||
| 130 | } |
||
| 131 | $res = Database::query($sql); |
||
| 132 | if (Database::num_rows($res) > 0) { |
||
| 133 | $this->lp_id = $lp_id; |
||
| 134 | $row = Database::fetch_array($res); |
||
| 135 | $this->type = $row['lp_type']; |
||
| 136 | $this->name = stripslashes($row['name']); |
||
| 137 | $this->proximity = $row['content_local']; |
||
| 138 | $this->theme = $row['theme']; |
||
| 139 | $this->maker = $row['content_maker']; |
||
| 140 | $this->prevent_reinit = $row['prevent_reinit']; |
||
| 141 | $this->seriousgame_mode = $row['seriousgame_mode']; |
||
| 142 | $this->license = $row['content_license']; |
||
| 143 | $this->scorm_debug = $row['debug']; |
||
| 144 | $this->js_lib = $row['js_lib']; |
||
| 145 | $this->path = $row['path']; |
||
| 146 | $this->preview_image = $row['preview_image']; |
||
| 147 | $this->author = $row['author']; |
||
| 148 | $this->hide_toc_frame = $row['hide_toc_frame']; |
||
| 149 | $this->lp_session_id = $row['session_id']; |
||
| 150 | $this->use_max_score = $row['use_max_score']; |
||
| 151 | $this->subscribeUsers = $row['subscribe_users']; |
||
| 152 | $this->created_on = $row['created_on']; |
||
| 153 | $this->modified_on = $row['modified_on']; |
||
| 154 | $this->ref = $row['ref']; |
||
| 155 | $this->categoryId = $row['category_id']; |
||
| 156 | $this->accumulateScormTime = isset($row['accumulate_scorm_time']) ? $row['accumulate_scorm_time'] : 'true'; |
||
| 157 | |||
| 158 | if (!empty($row['publicated_on'])) { |
||
| 159 | $this->publicated_on = $row['publicated_on']; |
||
| 160 | } |
||
| 161 | |||
| 162 | if (!empty($row['expired_on'])) { |
||
| 163 | $this->expired_on = $row['expired_on']; |
||
| 164 | } |
||
| 165 | View Code Duplication | if ($this->type == 2) { |
|
| 166 | if ($row['force_commit'] == 1) { |
||
| 167 | $this->force_commit = true; |
||
| 168 | } |
||
| 169 | } |
||
| 170 | $this->mode = $row['default_view_mod']; |
||
| 171 | |||
| 172 | // Check user ID. |
||
| 173 | if (empty($user_id)) { |
||
| 174 | $this->error = 'User ID is empty'; |
||
| 175 | } else { |
||
| 176 | $user_info = api_get_user_info($user_id); |
||
| 177 | if (!empty($user_info)) { |
||
| 178 | $this->user_id = $user_info['user_id']; |
||
| 179 | } else { |
||
| 180 | $this->error = 'User ID does not exist in database ('.$sql.')'; |
||
| 181 | } |
||
| 182 | } |
||
| 183 | |||
| 184 | // End of variables checking. |
||
| 185 | $session_id = api_get_session_id(); |
||
| 186 | // Get the session condition for learning paths of the base + session. |
||
| 187 | $session = api_get_session_condition($session_id); |
||
| 188 | // Now get the latest attempt from this user on this LP, if available, otherwise create a new one. |
||
| 189 | $lp_table = Database::get_course_table(TABLE_LP_VIEW); |
||
| 190 | |||
| 191 | // Selecting by view_count descending allows to get the highest view_count first. |
||
| 192 | $sql = "SELECT * FROM $lp_table |
||
| 193 | WHERE |
||
| 194 | c_id = $course_id AND |
||
| 195 | lp_id = '$lp_id' AND |
||
| 196 | user_id = '$user_id' |
||
| 197 | $session |
||
| 198 | ORDER BY view_count DESC"; |
||
| 199 | $res = Database::query($sql); |
||
| 200 | if ($this->debug > 2) { |
||
| 201 | error_log('New LP - learnpath::__construct() '.__LINE__.' - querying lp_view: '.$sql, 0); |
||
| 202 | } |
||
| 203 | |||
| 204 | if (Database::num_rows($res) > 0) { |
||
| 205 | if ($this->debug > 2) { |
||
| 206 | error_log('New LP - learnpath::__construct() '.__LINE__.' - Found previous view', 0); |
||
| 207 | } |
||
| 208 | $row = Database::fetch_array($res); |
||
| 209 | $this->attempt = $row['view_count']; |
||
| 210 | $this->lp_view_id = $row['id']; |
||
| 211 | $this->last_item_seen = $row['last_item']; |
||
| 212 | $this->progress_db = $row['progress']; |
||
| 213 | $this->lp_view_session_id = $row['session_id']; |
||
| 214 | } elseif (!api_is_invitee()) { |
||
| 215 | if ($this->debug > 2) { |
||
| 216 | error_log('New LP - learnpath::__construct() '.__LINE__.' - NOT Found previous view', 0); |
||
| 217 | } |
||
| 218 | $this->attempt = 1; |
||
| 219 | $params = [ |
||
| 220 | 'c_id' => $course_id, |
||
| 221 | 'lp_id' => $lp_id, |
||
| 222 | 'user_id' => $user_id, |
||
| 223 | 'view_count' => 1, |
||
| 224 | 'session_id' => $session_id, |
||
| 225 | 'last_item' => 0 |
||
| 226 | ]; |
||
| 227 | $this->lp_view_id = Database::insert($lp_table, $params); |
||
| 228 | if (!empty($this->lp_view_id)) { |
||
| 229 | $sql = "UPDATE $lp_table SET id = iid |
||
| 230 | WHERE iid = ".$this->lp_view_id; |
||
| 231 | Database::query($sql); |
||
| 232 | } |
||
| 233 | } |
||
| 234 | |||
| 235 | // Initialise items. |
||
| 236 | $lp_item_table = Database::get_course_table(TABLE_LP_ITEM); |
||
| 237 | $sql = "SELECT * FROM $lp_item_table |
||
| 238 | WHERE c_id = $course_id AND lp_id = '".$this->lp_id."' |
||
| 239 | ORDER BY parent_item_id, display_order"; |
||
| 240 | $res = Database::query($sql); |
||
| 241 | |||
| 242 | if ($this->debug > 2) { |
||
| 243 | error_log('New LP - learnpath::__construct() '.__LINE__.' - query lp items: '.$sql, 0); |
||
| 244 | error_log('-- Start while--', 0); |
||
| 245 | } |
||
| 246 | |||
| 247 | $lp_item_id_list = array(); |
||
| 248 | while ($row = Database::fetch_array($res)) { |
||
| 249 | $lp_item_id_list[] = $row['id']; |
||
| 250 | switch ($this->type) { |
||
| 251 | View Code Duplication | case 3: //aicc |
|
| 252 | $oItem = new aiccItem('db', $row['id'], $course_id); |
||
| 253 | if (is_object($oItem)) { |
||
| 254 | $my_item_id = $oItem->get_id(); |
||
| 255 | $oItem->set_lp_view($this->lp_view_id, $course_id); |
||
| 256 | $oItem->set_prevent_reinit($this->prevent_reinit); |
||
| 257 | // Don't use reference here as the next loop will make the pointed object change. |
||
| 258 | $this->items[$my_item_id] = $oItem; |
||
| 259 | $this->refs_list[$oItem->ref] = $my_item_id; |
||
| 260 | if ($this->debug > 2) { |
||
| 261 | error_log( |
||
| 262 | 'New LP - learnpath::__construct() - '. |
||
| 263 | 'aicc object with id '.$my_item_id. |
||
| 264 | ' set in items[]', |
||
| 265 | 0 |
||
| 266 | ); |
||
| 267 | } |
||
| 268 | } |
||
| 269 | break; |
||
| 270 | View Code Duplication | case 2: |
|
| 271 | $oItem = new scormItem('db', $row['id'], $course_id); |
||
| 272 | if (is_object($oItem)) { |
||
| 273 | $my_item_id = $oItem->get_id(); |
||
| 274 | $oItem->set_lp_view($this->lp_view_id, $course_id); |
||
| 275 | $oItem->set_prevent_reinit($this->prevent_reinit); |
||
| 276 | // Don't use reference here as the next loop will make the pointed object change. |
||
| 277 | $this->items[$my_item_id] = $oItem; |
||
| 278 | $this->refs_list[$oItem->ref] = $my_item_id; |
||
| 279 | if ($this->debug > 2) { |
||
| 280 | error_log('New LP - object with id '.$my_item_id.' set in items[]', 0); |
||
| 281 | } |
||
| 282 | } |
||
| 283 | break; |
||
| 284 | case 1: |
||
| 285 | default: |
||
| 286 | if ($this->debug > 2) { |
||
| 287 | error_log('New LP - learnpath::__construct() '.__LINE__.' - calling learnpathItem', 0); |
||
| 288 | } |
||
| 289 | $oItem = new learnpathItem($row['id'], $user_id, $course_id, $row); |
||
| 290 | |||
| 291 | if ($this->debug > 2) { |
||
| 292 | error_log('New LP - learnpath::__construct() '.__LINE__.' - end calling learnpathItem', 0); |
||
| 293 | } |
||
| 294 | if (is_object($oItem)) { |
||
| 295 | $my_item_id = $oItem->get_id(); |
||
| 296 | //$oItem->set_lp_view($this->lp_view_id); // Moved down to when we are sure the item_view exists. |
||
| 297 | $oItem->set_prevent_reinit($this->prevent_reinit); |
||
| 298 | // Don't use reference here as the next loop will make the pointed object change. |
||
| 299 | $this->items[$my_item_id] = $oItem; |
||
| 300 | $this->refs_list[$my_item_id] = $my_item_id; |
||
| 301 | View Code Duplication | if ($this->debug > 2) { |
|
| 302 | error_log( |
||
| 303 | 'New LP - learnpath::__construct() '.__LINE__. |
||
| 304 | ' - object with id '.$my_item_id.' set in items[]', |
||
| 305 | 0 |
||
| 306 | ); |
||
| 307 | } |
||
| 308 | } |
||
| 309 | break; |
||
| 310 | } |
||
| 311 | |||
| 312 | // Setting the object level with variable $this->items[$i][parent] |
||
| 313 | foreach ($this->items as $itemLPObject) { |
||
| 314 | $level = self::get_level_for_item( |
||
| 315 | $this->items, |
||
| 316 | $itemLPObject->db_id |
||
| 317 | ); |
||
| 318 | $itemLPObject->level = $level; |
||
| 319 | } |
||
| 320 | |||
| 321 | // Setting the view in the item object. |
||
| 322 | if (is_object($this->items[$row['id']])) { |
||
| 323 | $this->items[$row['id']]->set_lp_view($this->lp_view_id, $course_id); |
||
| 324 | if ($this->items[$row['id']]->get_type() == TOOL_HOTPOTATOES) { |
||
| 325 | $this->items[$row['id']]->current_start_time = 0; |
||
| 326 | $this->items[$row['id']]->current_stop_time = 0; |
||
| 327 | } |
||
| 328 | } |
||
| 329 | } |
||
| 330 | |||
| 331 | if ($this->debug > 2) { |
||
| 332 | error_log('New LP - learnpath::__construct() '.__LINE__.' ----- end while ----', 0); |
||
| 333 | } |
||
| 334 | |||
| 335 | if (!empty($lp_item_id_list)) { |
||
| 336 | $lp_item_id_list_to_string = implode("','", $lp_item_id_list); |
||
| 337 | if (!empty($lp_item_id_list_to_string)) { |
||
| 338 | // Get last viewing vars. |
||
| 339 | $itemViewTable = Database::get_course_table(TABLE_LP_ITEM_VIEW); |
||
| 340 | // This query should only return one or zero result. |
||
| 341 | $sql = "SELECT lp_item_id, status |
||
| 342 | FROM $itemViewTable |
||
| 343 | WHERE |
||
| 344 | c_id = $course_id AND |
||
| 345 | lp_view_id = ".$this->lp_view_id." AND |
||
| 346 | lp_item_id IN ('".$lp_item_id_list_to_string."') |
||
| 347 | ORDER BY view_count DESC "; |
||
| 348 | |||
| 349 | if ($this->debug > 2) { |
||
| 350 | error_log( |
||
| 351 | 'New LP - learnpath::__construct() - Selecting item_views: '.$sql, |
||
| 352 | 0 |
||
| 353 | ); |
||
| 354 | } |
||
| 355 | |||
| 356 | $status_list = array(); |
||
| 357 | $res = Database::query($sql); |
||
| 358 | while ($row = Database:: fetch_array($res)) { |
||
| 359 | $status_list[$row['lp_item_id']] = $row['status']; |
||
| 360 | } |
||
| 361 | |||
| 362 | foreach ($lp_item_id_list as $item_id) { |
||
| 363 | if (isset($status_list[$item_id])) { |
||
| 364 | $status = $status_list[$item_id]; |
||
| 365 | if (is_object($this->items[$item_id])) { |
||
| 366 | $this->items[$item_id]->set_status($status); |
||
| 367 | if (empty($status)) { |
||
| 368 | $this->items[$item_id]->set_status( |
||
| 369 | $this->default_status |
||
| 370 | ); |
||
| 371 | } |
||
| 372 | } |
||
| 373 | } else { |
||
| 374 | if (!api_is_invitee()) { |
||
| 375 | if (is_object($this->items[$item_id])) { |
||
| 376 | $this->items[$item_id]->set_status( |
||
| 377 | $this->default_status |
||
| 378 | ); |
||
| 379 | } |
||
| 380 | |||
| 381 | if (!empty($this->lp_view_id)) { |
||
| 382 | // Add that row to the lp_item_view table so that we have something to show in the stats page. |
||
| 383 | $params = [ |
||
| 384 | 'c_id' => $course_id, |
||
| 385 | 'lp_item_id' => $item_id, |
||
| 386 | 'lp_view_id' => $this->lp_view_id, |
||
| 387 | 'view_count' => 1, |
||
| 388 | 'status' => 'not attempted', |
||
| 389 | 'start_time' => time(), |
||
| 390 | 'total_time' => 0, |
||
| 391 | 'score' => 0 |
||
| 392 | ]; |
||
| 393 | $insertId = Database::insert($itemViewTable, $params); |
||
| 394 | |||
| 395 | if ($insertId) { |
||
| 396 | $sql = "UPDATE $itemViewTable SET id = iid |
||
| 397 | WHERE iid = $insertId"; |
||
| 398 | Database::query($sql); |
||
| 399 | } |
||
| 400 | |||
| 401 | $this->items[$item_id]->set_lp_view( |
||
| 402 | $this->lp_view_id, |
||
| 403 | $course_id |
||
| 404 | ); |
||
| 405 | } |
||
| 406 | } |
||
| 407 | } |
||
| 408 | } |
||
| 409 | } |
||
| 410 | } |
||
| 411 | |||
| 412 | $this->ordered_items = self::get_flat_ordered_items_list( |
||
| 413 | $this->get_id(), |
||
| 414 | 0, |
||
| 415 | $course_id |
||
| 416 | ); |
||
| 417 | $this->max_ordered_items = 0; |
||
| 418 | foreach ($this->ordered_items as $index => $dummy) { |
||
| 419 | if ($index > $this->max_ordered_items && !empty($dummy)) { |
||
| 420 | $this->max_ordered_items = $index; |
||
| 421 | } |
||
| 422 | } |
||
| 423 | // TODO: Define the current item better. |
||
| 424 | $this->first(); |
||
| 425 | if ($this->debug > 2) { |
||
| 426 | error_log('New LP - learnpath::__construct() '.__LINE__.' - End of learnpath constructor for learnpath '.$this->get_id(), 0); |
||
| 427 | } |
||
| 428 | } else { |
||
| 429 | $this->error = 'Learnpath ID does not exist in database ('.$sql.')'; |
||
| 430 | } |
||
| 431 | } |
||
| 432 | } |
||
| 433 | |||
| 434 | /** |
||
| 435 | * @return string |
||
| 436 | */ |
||
| 437 | public function getCourseCode() |
||
| 438 | { |
||
| 439 | return $this->cc; |
||
| 440 | } |
||
| 441 | |||
| 442 | /** |
||
| 443 | * @return int |
||
| 444 | */ |
||
| 445 | public function get_course_int_id() |
||
| 446 | { |
||
| 447 | return isset($this->course_int_id) ? $this->course_int_id : api_get_course_int_id(); |
||
| 448 | } |
||
| 449 | |||
| 450 | /** |
||
| 451 | * @param $course_id |
||
| 452 | * @return int |
||
| 453 | */ |
||
| 454 | public function set_course_int_id($course_id) |
||
| 455 | { |
||
| 456 | return $this->course_int_id = (int) $course_id; |
||
| 457 | } |
||
| 458 | |||
| 459 | /** |
||
| 460 | * Get the depth level of LP item |
||
| 461 | * @param array $items |
||
| 462 | * @param int $currentItemId |
||
| 463 | * @return int |
||
| 464 | */ |
||
| 465 | private static function get_level_for_item($items, $currentItemId) |
||
| 466 | { |
||
| 467 | $parentItemId = $items[$currentItemId]->parent; |
||
| 468 | if ($parentItemId == 0) { |
||
| 469 | return 0; |
||
| 470 | } else { |
||
| 471 | return self::get_level_for_item($items, $parentItemId) + 1; |
||
| 472 | } |
||
| 473 | } |
||
| 474 | |||
| 475 | /** |
||
| 476 | * Function rewritten based on old_add_item() from Yannick Warnier. |
||
| 477 | * Due the fact that users can decide where the item should come, I had to overlook this function and |
||
| 478 | * I found it better to rewrite it. Old function is still available. |
||
| 479 | * Added also the possibility to add a description. |
||
| 480 | * |
||
| 481 | * @param int $parent |
||
| 482 | * @param int $previous |
||
| 483 | * @param string $type |
||
| 484 | * @param int $id resource ID (ref) |
||
| 485 | * @param string $title |
||
| 486 | * @param string $description |
||
| 487 | * @param int $prerequisites |
||
| 488 | * @param int $max_time_allowed |
||
| 489 | * @param int $userId |
||
| 490 | * |
||
| 491 | * @return int |
||
| 492 | */ |
||
| 493 | public function add_item( |
||
| 494 | $parent, |
||
| 495 | $previous, |
||
| 496 | $type = 'dir', |
||
| 497 | $id, |
||
| 498 | $title, |
||
| 499 | $description, |
||
| 500 | $prerequisites = 0, |
||
| 501 | $max_time_allowed = 0, |
||
| 502 | $userId = 0 |
||
| 503 | ) { |
||
| 504 | $course_id = $this->course_info['real_id']; |
||
| 505 | if ($this->debug > 0) { |
||
| 506 | error_log('New LP - In learnpath::add_item('.$parent.','.$previous.','.$type.','.$id.','.$title.')', 0); |
||
| 507 | } |
||
| 508 | if (empty($course_id)) { |
||
| 509 | // Sometimes Oogie doesn't catch the course info but sets $this->cc |
||
| 510 | $this->course_info = api_get_course_info($this->cc); |
||
| 511 | $course_id = $this->course_info['real_id']; |
||
| 512 | } |
||
| 513 | $userId = empty($userId) ? api_get_user_id() : $userId; |
||
| 514 | $sessionId = api_get_session_id(); |
||
| 515 | $tbl_lp_item = Database::get_course_table(TABLE_LP_ITEM); |
||
| 516 | $_course = $this->course_info; |
||
| 517 | $parent = intval($parent); |
||
| 518 | $previous = intval($previous); |
||
| 519 | $id = intval($id); |
||
| 520 | $max_time_allowed = htmlentities($max_time_allowed); |
||
| 521 | if (empty($max_time_allowed)) { |
||
| 522 | $max_time_allowed = 0; |
||
| 523 | } |
||
| 524 | $sql = "SELECT COUNT(id) AS num |
||
| 525 | FROM $tbl_lp_item |
||
| 526 | WHERE |
||
| 527 | c_id = $course_id AND |
||
| 528 | lp_id = ".$this->get_id()." AND |
||
| 529 | parent_item_id = ".$parent; |
||
| 530 | |||
| 531 | $res_count = Database::query($sql); |
||
| 532 | $row = Database::fetch_array($res_count); |
||
| 533 | $num = $row['num']; |
||
| 534 | |||
| 535 | if ($num > 0) { |
||
| 536 | if (empty($previous)) { |
||
| 537 | $sql = "SELECT id, next_item_id, display_order |
||
| 538 | FROM $tbl_lp_item |
||
| 539 | WHERE |
||
| 540 | c_id = $course_id AND |
||
| 541 | lp_id = ".$this->get_id()." AND |
||
| 542 | parent_item_id = ".$parent." AND |
||
| 543 | previous_item_id = 0 OR |
||
| 544 | previous_item_id= ".$parent; |
||
| 545 | $result = Database::query($sql); |
||
| 546 | $row = Database::fetch_array($result); |
||
| 547 | $tmp_previous = 0; |
||
| 548 | $next = $row['id']; |
||
| 549 | $display_order = 0; |
||
| 550 | } else { |
||
| 551 | $previous = (int) $previous; |
||
| 552 | $sql = "SELECT id, previous_item_id, next_item_id, display_order |
||
| 553 | FROM $tbl_lp_item |
||
| 554 | WHERE |
||
| 555 | c_id = $course_id AND |
||
| 556 | lp_id = ".$this->get_id()." AND |
||
| 557 | id = ".$previous; |
||
| 558 | |||
| 559 | $result = Database::query($sql); |
||
| 560 | $row = Database:: fetch_array($result); |
||
| 561 | |||
| 562 | $tmp_previous = $row['id']; |
||
| 563 | $next = $row['next_item_id']; |
||
| 564 | $display_order = $row['display_order']; |
||
| 565 | } |
||
| 566 | } else { |
||
| 567 | $tmp_previous = 0; |
||
| 568 | $next = 0; |
||
| 569 | $display_order = 0; |
||
| 570 | } |
||
| 571 | |||
| 572 | $id = intval($id); |
||
| 573 | $typeCleaned = Database::escape_string($type); |
||
| 574 | if ($type == 'quiz') { |
||
| 575 | $sql = 'SELECT SUM(ponderation) |
||
| 576 | FROM '.Database::get_course_table(TABLE_QUIZ_QUESTION).' as quiz_question |
||
| 577 | INNER JOIN '.Database::get_course_table(TABLE_QUIZ_TEST_QUESTION).' as quiz_rel_question |
||
| 578 | ON |
||
| 579 | quiz_question.id = quiz_rel_question.question_id AND |
||
| 580 | quiz_question.c_id = quiz_rel_question.c_id |
||
| 581 | WHERE |
||
| 582 | quiz_rel_question.exercice_id = '.$id." AND |
||
| 583 | quiz_question.c_id = $course_id AND |
||
| 584 | quiz_rel_question.c_id = $course_id "; |
||
| 585 | $rsQuiz = Database::query($sql); |
||
| 586 | $max_score = Database::result($rsQuiz, 0, 0); |
||
| 587 | |||
| 588 | // Disabling the exercise if we add it inside a LP |
||
| 589 | $exercise = new Exercise($course_id); |
||
| 590 | $exercise->read($id); |
||
| 591 | $exercise->disable(); |
||
| 592 | $exercise->save(); |
||
| 593 | } else { |
||
| 594 | $max_score = 100; |
||
| 595 | } |
||
| 596 | |||
| 597 | $params = array( |
||
| 598 | "c_id" => $course_id, |
||
| 599 | "lp_id" => $this->get_id(), |
||
| 600 | "item_type" => $typeCleaned, |
||
| 601 | "ref" => '', |
||
| 602 | "title" => $title, |
||
| 603 | "description" => $description, |
||
| 604 | "path" => $id, |
||
| 605 | "max_score" => $max_score, |
||
| 606 | "parent_item_id" => $parent, |
||
| 607 | "previous_item_id" => $previous, |
||
| 608 | "next_item_id" => intval($next), |
||
| 609 | "display_order" => $display_order + 1, |
||
| 610 | "prerequisite" => $prerequisites, |
||
| 611 | "max_time_allowed" => $max_time_allowed, |
||
| 612 | 'min_score' => 0, |
||
| 613 | 'launch_data' => '' |
||
| 614 | ); |
||
| 615 | |||
| 616 | if ($prerequisites != 0) { |
||
| 617 | $params['prerequisite'] = $prerequisites; |
||
| 618 | } |
||
| 619 | |||
| 620 | $new_item_id = Database::insert($tbl_lp_item, $params); |
||
| 621 | |||
| 622 | if ($this->debug > 2) { |
||
| 623 | error_log('New LP - Inserting dir/chapter: '.$new_item_id, 0); |
||
| 624 | } |
||
| 625 | |||
| 626 | if ($new_item_id) { |
||
| 627 | $sql = "UPDATE $tbl_lp_item SET id = iid WHERE iid = $new_item_id"; |
||
| 628 | Database::query($sql); |
||
| 629 | |||
| 630 | $sql = "UPDATE $tbl_lp_item |
||
| 631 | SET previous_item_id = $new_item_id |
||
| 632 | WHERE c_id = $course_id AND id = $next"; |
||
| 633 | Database::query($sql); |
||
| 634 | |||
| 635 | // Update the item that should be before the new item. |
||
| 636 | $sql = "UPDATE $tbl_lp_item |
||
| 637 | SET next_item_id = $new_item_id |
||
| 638 | WHERE c_id = $course_id AND id = $tmp_previous"; |
||
| 639 | Database::query($sql); |
||
| 640 | |||
| 641 | // Update all the items after the new item. |
||
| 642 | $sql = "UPDATE ".$tbl_lp_item." |
||
| 643 | SET display_order = display_order + 1 |
||
| 644 | WHERE |
||
| 645 | c_id = $course_id AND |
||
| 646 | lp_id = ".$this->get_id()." AND |
||
| 647 | id <> " . $new_item_id." AND |
||
| 648 | parent_item_id = " . $parent." AND |
||
| 649 | display_order > " . $display_order; |
||
| 650 | Database::query($sql); |
||
| 651 | |||
| 652 | // Update the item that should come after the new item. |
||
| 653 | $sql = "UPDATE ".$tbl_lp_item." |
||
| 654 | SET ref = " . $new_item_id." |
||
| 655 | WHERE c_id = $course_id AND id = ".$new_item_id; |
||
| 656 | Database::query($sql); |
||
| 657 | |||
| 658 | // Upload audio. |
||
| 659 | if (!empty($_FILES['mp3']['name'])) { |
||
| 660 | // Create the audio folder if it does not exist yet. |
||
| 661 | $filepath = api_get_path(SYS_COURSE_PATH).$_course['path'].'/document/'; |
||
| 662 | if (!is_dir($filepath.'audio')) { |
||
| 663 | mkdir($filepath.'audio', api_get_permissions_for_new_directories()); |
||
| 664 | $audio_id = add_document( |
||
| 665 | $_course, |
||
| 666 | '/audio', |
||
| 667 | 'folder', |
||
| 668 | 0, |
||
| 669 | 'audio', |
||
| 670 | '', |
||
| 671 | 0, |
||
| 672 | true, |
||
| 673 | null, |
||
| 674 | $sessionId, |
||
| 675 | $userId |
||
| 676 | ); |
||
| 677 | api_item_property_update( |
||
| 678 | $_course, |
||
| 679 | TOOL_DOCUMENT, |
||
| 680 | $audio_id, |
||
| 681 | 'FolderCreated', |
||
| 682 | $userId, |
||
| 683 | null, |
||
| 684 | null, |
||
| 685 | null, |
||
| 686 | null, |
||
| 687 | $sessionId |
||
| 688 | ); |
||
| 689 | api_item_property_update( |
||
| 690 | $_course, |
||
| 691 | TOOL_DOCUMENT, |
||
| 692 | $audio_id, |
||
| 693 | 'invisible', |
||
| 694 | $userId, |
||
| 695 | null, |
||
| 696 | null, |
||
| 697 | null, |
||
| 698 | null, |
||
| 699 | $sessionId |
||
| 700 | ); |
||
| 701 | } |
||
| 702 | |||
| 703 | $file_path = handle_uploaded_document( |
||
| 704 | $_course, |
||
| 705 | $_FILES['mp3'], |
||
| 706 | api_get_path(SYS_COURSE_PATH).$_course['path'].'/document', |
||
| 707 | '/audio', |
||
| 708 | $userId, |
||
| 709 | '', |
||
| 710 | '', |
||
| 711 | '', |
||
| 712 | '', |
||
| 713 | false |
||
| 714 | ); |
||
| 715 | |||
| 716 | // Getting the filename only. |
||
| 717 | $file_components = explode('/', $file_path); |
||
| 718 | $file = $file_components[count($file_components) - 1]; |
||
| 719 | |||
| 720 | // Store the mp3 file in the lp_item table. |
||
| 721 | $sql = "UPDATE $tbl_lp_item SET |
||
| 722 | audio = '".Database::escape_string($file)."' |
||
| 723 | WHERE id = '" . intval($new_item_id)."'"; |
||
| 724 | Database::query($sql); |
||
| 725 | } |
||
| 726 | } |
||
| 727 | |||
| 728 | return $new_item_id; |
||
| 729 | } |
||
| 730 | |||
| 731 | /** |
||
| 732 | * Static admin function allowing addition of a learnpath to a course. |
||
| 733 | * @param string Course code |
||
| 734 | * @param string Learnpath name |
||
| 735 | * @param string Learnpath description string, if provided |
||
| 736 | * @param string Type of learnpath (default = 'guess', others = 'dokeos', 'aicc',...) |
||
| 737 | * @param string Type of files origin (default = 'zip', others = 'dir','web_dir',...) |
||
| 738 | * @param string $zipname Zip file containing the learnpath or directory containing the learnpath |
||
| 739 | * @param string $publicated_on |
||
| 740 | * @param string $expired_on |
||
| 741 | * @param int $categoryId |
||
| 742 | * @param int $userId |
||
| 743 | * @return integer The new learnpath ID on success, 0 on failure |
||
| 744 | */ |
||
| 745 | public static function add_lp( |
||
| 746 | $courseCode, |
||
| 747 | $name, |
||
| 748 | $description = '', |
||
| 749 | $learnpath = 'guess', |
||
| 750 | $origin = 'zip', |
||
| 751 | $zipname = '', |
||
| 752 | $publicated_on = '', |
||
| 753 | $expired_on = '', |
||
| 754 | $categoryId = 0, |
||
| 755 | $userId = 0 |
||
| 756 | ) { |
||
| 757 | global $charset; |
||
| 758 | |||
| 759 | if (!empty($courseCode)) { |
||
| 760 | $courseInfo = api_get_course_info($courseCode); |
||
| 761 | $course_id = $courseInfo['real_id']; |
||
| 762 | } else { |
||
| 763 | $course_id = api_get_course_int_id(); |
||
| 764 | $courseInfo = api_get_course_info(); |
||
| 765 | } |
||
| 766 | |||
| 767 | $tbl_lp = Database::get_course_table(TABLE_LP_MAIN); |
||
| 768 | // Check course code exists. |
||
| 769 | // Check lp_name doesn't exist, otherwise append something. |
||
| 770 | $i = 0; |
||
| 771 | $name = Database::escape_string($name); |
||
| 772 | $categoryId = intval($categoryId); |
||
| 773 | |||
| 774 | // Session id. |
||
| 775 | $session_id = api_get_session_id(); |
||
| 776 | $userId = empty($userId) ? api_get_user_id() : $userId; |
||
| 777 | $check_name = "SELECT * FROM $tbl_lp |
||
| 778 | WHERE c_id = $course_id AND name = '$name'"; |
||
| 779 | |||
| 780 | $res_name = Database::query($check_name); |
||
| 781 | |||
| 782 | if (empty($publicated_on)) { |
||
| 783 | $publicated_on = null; |
||
| 784 | } else { |
||
| 785 | $publicated_on = Database::escape_string(api_get_utc_datetime($publicated_on)); |
||
| 786 | } |
||
| 787 | |||
| 788 | if (empty($expired_on)) { |
||
| 789 | $expired_on = null; |
||
| 790 | } else { |
||
| 791 | $expired_on = Database::escape_string(api_get_utc_datetime($expired_on)); |
||
| 792 | } |
||
| 793 | |||
| 794 | while (Database::num_rows($res_name)) { |
||
| 795 | // There is already one such name, update the current one a bit. |
||
| 796 | $i++; |
||
| 797 | $name = $name.' - '.$i; |
||
| 798 | $check_name = "SELECT * FROM $tbl_lp WHERE c_id = $course_id AND name = '$name'"; |
||
| 799 | $res_name = Database::query($check_name); |
||
| 800 | } |
||
| 801 | // New name does not exist yet; keep it. |
||
| 802 | // Escape description. |
||
| 803 | // Kevin: added htmlentities(). |
||
| 804 | $description = Database::escape_string(api_htmlentities($description, ENT_QUOTES, $charset)); |
||
| 805 | $type = 1; |
||
| 806 | switch ($learnpath) { |
||
| 807 | case 'guess': |
||
| 808 | break; |
||
| 809 | case 'dokeos': |
||
| 810 | case 'chamilo': |
||
| 811 | $type = 1; |
||
| 812 | break; |
||
| 813 | case 'aicc': |
||
| 814 | break; |
||
| 815 | } |
||
| 816 | |||
| 817 | switch ($origin) { |
||
| 818 | case 'zip': |
||
| 819 | // Check zip name string. If empty, we are currently creating a new Chamilo learnpath. |
||
| 820 | break; |
||
| 821 | case 'manual': |
||
| 822 | default: |
||
| 823 | $get_max = "SELECT MAX(display_order) FROM $tbl_lp WHERE c_id = $course_id"; |
||
| 824 | $res_max = Database::query($get_max); |
||
| 825 | if (Database::num_rows($res_max) < 1) { |
||
| 826 | $dsp = 1; |
||
| 827 | } else { |
||
| 828 | $row = Database::fetch_array($res_max); |
||
| 829 | $dsp = $row[0] + 1; |
||
| 830 | } |
||
| 831 | |||
| 832 | $params = [ |
||
| 833 | 'c_id' => $course_id, |
||
| 834 | 'lp_type' => $type, |
||
| 835 | 'name' => $name, |
||
| 836 | 'description' => $description, |
||
| 837 | 'path' => '', |
||
| 838 | 'default_view_mod' => 'embedded', |
||
| 839 | 'default_encoding' => 'UTF-8', |
||
| 840 | 'display_order' => $dsp, |
||
| 841 | 'content_maker' => 'Chamilo', |
||
| 842 | 'content_local' => 'local', |
||
| 843 | 'js_lib' => '', |
||
| 844 | 'session_id' => $session_id, |
||
| 845 | 'created_on' => api_get_utc_datetime(), |
||
| 846 | 'modified_on' => api_get_utc_datetime(), |
||
| 847 | 'publicated_on' => $publicated_on, |
||
| 848 | 'expired_on' => $expired_on, |
||
| 849 | 'category_id' => $categoryId, |
||
| 850 | 'force_commit' => 0, |
||
| 851 | 'content_license' => '', |
||
| 852 | 'debug' => 0, |
||
| 853 | 'theme' => '', |
||
| 854 | 'preview_image' => '', |
||
| 855 | 'author' => '', |
||
| 856 | 'prerequisite' => 0, |
||
| 857 | 'hide_toc_frame' => 0, |
||
| 858 | 'seriousgame_mode' => 0, |
||
| 859 | 'autolaunch' => 0, |
||
| 860 | 'max_attempts' => 0, |
||
| 861 | 'subscribe_users' => 0, |
||
| 862 | 'accumulate_scorm_time' => 1 |
||
| 863 | ]; |
||
| 864 | $id = Database::insert($tbl_lp, $params); |
||
| 865 | |||
| 866 | View Code Duplication | if ($id > 0) { |
|
| 867 | $sql = "UPDATE $tbl_lp SET id = iid WHERE iid = $id"; |
||
| 868 | Database::query($sql); |
||
| 869 | |||
| 870 | // Insert into item_property. |
||
| 871 | api_item_property_update( |
||
| 872 | $courseInfo, |
||
| 873 | TOOL_LEARNPATH, |
||
| 874 | $id, |
||
| 875 | 'LearnpathAdded', |
||
| 876 | $userId |
||
| 877 | ); |
||
| 878 | api_set_default_visibility($id, TOOL_LEARNPATH, 0, $courseInfo, $session_id, $userId); |
||
| 879 | return $id; |
||
| 880 | } |
||
| 881 | break; |
||
| 882 | } |
||
| 883 | } |
||
| 884 | |||
| 885 | /** |
||
| 886 | * Auto completes the parents of an item in case it's been completed or passed |
||
| 887 | * @param int $item Optional ID of the item from which to look for parents |
||
| 888 | */ |
||
| 889 | public function autocomplete_parents($item) |
||
| 890 | { |
||
| 891 | $debug = $this->debug; |
||
| 892 | |||
| 893 | if ($debug) { |
||
| 894 | error_log('Learnpath::autocomplete_parents()', 0); |
||
| 895 | } |
||
| 896 | |||
| 897 | if (empty($item)) { |
||
| 898 | $item = $this->current; |
||
| 899 | } |
||
| 900 | |||
| 901 | $currentItem = $this->getItem($item); |
||
| 902 | if ($currentItem) { |
||
| 903 | $parent_id = $currentItem->get_parent(); |
||
| 904 | $parent = $this->getItem($parent_id); |
||
| 905 | if ($parent) { |
||
| 906 | // if $item points to an object and there is a parent. |
||
| 907 | if ($debug) { |
||
| 908 | error_log( |
||
| 909 | 'Autocompleting parent of item '.$item.' "'.$currentItem->get_title().'" (item '.$parent_id.' "'.$parent->get_title().'") ', |
||
| 910 | 0 |
||
| 911 | ); |
||
| 912 | } |
||
| 913 | |||
| 914 | // New experiment including failed and browsed in completed status. |
||
| 915 | //$current_status = $currentItem->get_status(); |
||
| 916 | //if ($currentItem->is_done() || $current_status == 'browsed' || $current_status == 'failed') { |
||
| 917 | // Fixes chapter auto complete |
||
| 918 | if (true) { |
||
| 919 | // If the current item is completed or passes or succeeded. |
||
| 920 | $updateParentStatus = true; |
||
| 921 | if ($debug) { |
||
| 922 | error_log('Status of current item is alright', 0); |
||
| 923 | } |
||
| 924 | |||
| 925 | foreach ($parent->get_children() as $childItemId) { |
||
| 926 | $childItem = $this->getItem($childItemId); |
||
| 927 | |||
| 928 | // If children was not set try to get the info |
||
| 929 | if (empty($childItem->db_item_view_id)) { |
||
| 930 | $childItem->set_lp_view($this->lp_view_id, $this->course_int_id); |
||
| 931 | } |
||
| 932 | |||
| 933 | // Check all his brothers (parent's children) for completion status. |
||
| 934 | if ($childItemId != $item) { |
||
| 935 | if ($debug) { |
||
| 936 | error_log( |
||
| 937 | 'Looking at brother #'.$childItemId.' "'.$childItem->get_title().'", status is '.$childItem->get_status(), |
||
| 938 | 0 |
||
| 939 | ); |
||
| 940 | } |
||
| 941 | // Trying completing parents of failed and browsed items as well. |
||
| 942 | if ($childItem->status_is( |
||
| 943 | array( |
||
| 944 | 'completed', |
||
| 945 | 'passed', |
||
| 946 | 'succeeded', |
||
| 947 | 'browsed', |
||
| 948 | 'failed' |
||
| 949 | ) |
||
| 950 | ) |
||
| 951 | ) { |
||
| 952 | // Keep completion status to true. |
||
| 953 | continue; |
||
| 954 | } else { |
||
| 955 | if ($debug > 2) { |
||
| 956 | error_log( |
||
| 957 | 'Found one incomplete child of parent #'.$parent_id.': child #'.$childItemId.' "'.$childItem->get_title().'", is '.$childItem->get_status().' db_item_view_id:#'.$childItem->db_item_view_id, |
||
| 958 | 0 |
||
| 959 | ); |
||
| 960 | } |
||
| 961 | $updateParentStatus = false; |
||
| 962 | break; |
||
| 963 | } |
||
| 964 | } |
||
| 965 | } |
||
| 966 | |||
| 967 | if ($updateParentStatus) { |
||
| 968 | // If all the children were completed: |
||
| 969 | $parent->set_status('completed'); |
||
| 970 | $parent->save(false, $this->prerequisites_match($parent->get_id())); |
||
| 971 | // Force the status to "completed" |
||
| 972 | //$this->update_queue[$parent->get_id()] = $parent->get_status(); |
||
| 973 | $this->update_queue[$parent->get_id()] = 'completed'; |
||
| 974 | if ($debug) { |
||
| 975 | error_log( |
||
| 976 | 'Added parent #'.$parent->get_id().' "'.$parent->get_title().'" to update queue status: completed '. |
||
| 977 | print_r($this->update_queue, 1), |
||
| 978 | 0 |
||
| 979 | ); |
||
| 980 | } |
||
| 981 | // Recursive call. |
||
| 982 | $this->autocomplete_parents($parent->get_id()); |
||
| 983 | } |
||
| 984 | } |
||
| 985 | } else { |
||
| 986 | if ($debug) { |
||
| 987 | error_log("Parent #$parent_id does not exists"); |
||
| 988 | } |
||
| 989 | } |
||
| 990 | } else { |
||
| 991 | if ($debug) { |
||
| 992 | error_log("#$item is an item that doesn't have parents"); |
||
| 993 | } |
||
| 994 | } |
||
| 995 | } |
||
| 996 | |||
| 997 | /** |
||
| 998 | * Auto saves the current results into the database for the whole learnpath |
||
| 999 | * @todo: Add save operations for the learnpath itself. |
||
| 1000 | */ |
||
| 1001 | public function autosave() |
||
| 1002 | { |
||
| 1003 | if ($this->debug > 0) { |
||
| 1004 | error_log('New LP - In learnpath::autosave()', 0); |
||
| 1005 | } |
||
| 1006 | } |
||
| 1007 | |||
| 1008 | /** |
||
| 1009 | * Closes the current resource |
||
| 1010 | * |
||
| 1011 | * Stops the timer |
||
| 1012 | * Saves into the database if required |
||
| 1013 | * Clears the current resource data from this object |
||
| 1014 | * @return boolean True on success, false on failure |
||
| 1015 | */ |
||
| 1016 | public function close() |
||
| 1017 | { |
||
| 1018 | if ($this->debug > 0) { |
||
| 1019 | error_log('New LP - In learnpath::close()', 0); |
||
| 1020 | } |
||
| 1021 | if (empty($this->lp_id)) { |
||
| 1022 | $this->error = 'Trying to close this learnpath but no ID is set'; |
||
| 1023 | return false; |
||
| 1024 | } |
||
| 1025 | $this->current_time_stop = time(); |
||
| 1026 | $this->ordered_items = array(); |
||
| 1027 | $this->index = 0; |
||
| 1028 | unset($this->lp_id); |
||
| 1029 | //unset other stuff |
||
| 1030 | return true; |
||
| 1031 | } |
||
| 1032 | |||
| 1033 | /** |
||
| 1034 | * Static admin function allowing removal of a learnpath |
||
| 1035 | * @param array $courseInfo |
||
| 1036 | * @param integer $id Learnpath ID |
||
| 1037 | * @param string $delete Whether to delete data or keep it (default: 'keep', others: 'remove') |
||
| 1038 | * @return boolean True on success, false on failure (might change that to return number of elements deleted) |
||
| 1039 | */ |
||
| 1040 | public function delete($courseInfo = null, $id = null, $delete = 'keep') |
||
| 1041 | { |
||
| 1042 | $course_id = api_get_course_int_id(); |
||
| 1043 | if (!empty($courseInfo)) { |
||
| 1044 | $course_id = isset($courseInfo['real_id']) ? $courseInfo['real_id'] : $course_id; |
||
| 1045 | } |
||
| 1046 | |||
| 1047 | // TODO: Implement a way of getting this to work when the current object is not set. |
||
| 1048 | // In clear: implement this in the item class as well (abstract class) and use the given ID in queries. |
||
| 1049 | // If an ID is specifically given and the current LP is not the same, prevent delete. |
||
| 1050 | if (!empty($id) && ($id != $this->lp_id)) { |
||
| 1051 | return false; |
||
| 1052 | } |
||
| 1053 | |||
| 1054 | $lp = Database::get_course_table(TABLE_LP_MAIN); |
||
| 1055 | $lp_item = Database::get_course_table(TABLE_LP_ITEM); |
||
| 1056 | $lp_view = Database::get_course_table(TABLE_LP_VIEW); |
||
| 1057 | $lp_item_view = Database::get_course_table(TABLE_LP_ITEM_VIEW); |
||
| 1058 | |||
| 1059 | // Delete lp item id. |
||
| 1060 | foreach ($this->items as $id => $dummy) { |
||
| 1061 | $sql = "DELETE FROM $lp_item_view |
||
| 1062 | WHERE c_id = $course_id AND lp_item_id = '".$id."'"; |
||
| 1063 | Database::query($sql); |
||
| 1064 | } |
||
| 1065 | |||
| 1066 | // Proposed by Christophe (nickname: clefevre) |
||
| 1067 | $sql = "DELETE FROM $lp_item |
||
| 1068 | WHERE c_id = ".$course_id." AND lp_id = ".$this->lp_id; |
||
| 1069 | Database::query($sql); |
||
| 1070 | |||
| 1071 | $sql = "DELETE FROM $lp_view |
||
| 1072 | WHERE c_id = ".$course_id." AND lp_id = ".$this->lp_id; |
||
| 1073 | Database::query($sql); |
||
| 1074 | |||
| 1075 | self::toggle_publish($this->lp_id, 'i'); |
||
| 1076 | |||
| 1077 | if ($this->type == 2 || $this->type == 3) { |
||
| 1078 | // This is a scorm learning path, delete the files as well. |
||
| 1079 | $sql = "SELECT path FROM $lp |
||
| 1080 | WHERE c_id = ".$course_id." AND id = ".$this->lp_id; |
||
| 1081 | $res = Database::query($sql); |
||
| 1082 | if (Database::num_rows($res) > 0) { |
||
| 1083 | $row = Database::fetch_array($res); |
||
| 1084 | $path = $row['path']; |
||
| 1085 | $sql = "SELECT id FROM $lp |
||
| 1086 | WHERE |
||
| 1087 | c_id = ".$course_id." AND |
||
| 1088 | path = '$path' AND |
||
| 1089 | id != ".$this->lp_id; |
||
| 1090 | $res = Database::query($sql); |
||
| 1091 | if (Database::num_rows($res) > 0) { |
||
| 1092 | // Another learning path uses this directory, so don't delete it. |
||
| 1093 | if ($this->debug > 2) { |
||
| 1094 | error_log('New LP - In learnpath::delete(), found other LP using path '.$path.', keeping directory', 0); |
||
| 1095 | } |
||
| 1096 | } else { |
||
| 1097 | // No other LP uses that directory, delete it. |
||
| 1098 | $course_rel_dir = api_get_course_path().'/scorm/'; // scorm dir web path starting from /courses |
||
| 1099 | $course_scorm_dir = api_get_path(SYS_COURSE_PATH).$course_rel_dir; // The absolute system path for this course. |
||
| 1100 | if ($delete == 'remove' && is_dir($course_scorm_dir.$path) && !empty($course_scorm_dir)) { |
||
| 1101 | if ($this->debug > 2) { |
||
| 1102 | error_log('New LP - In learnpath::delete(), found SCORM, deleting directory: '.$course_scorm_dir.$path, 0); |
||
| 1103 | } |
||
| 1104 | // Proposed by Christophe (clefevre). |
||
| 1105 | if (strcmp(substr($path, -2), "/.") == 0) { |
||
| 1106 | $path = substr($path, 0, -1); // Remove "." at the end. |
||
| 1107 | } |
||
| 1108 | //exec('rm -rf ' . $course_scorm_dir . $path); // See Bug #5208, this is not OS-portable way. |
||
| 1109 | rmdirr($course_scorm_dir.$path); |
||
| 1110 | } |
||
| 1111 | } |
||
| 1112 | } |
||
| 1113 | } |
||
| 1114 | |||
| 1115 | $tbl_tool = Database::get_course_table(TABLE_TOOL_LIST); |
||
| 1116 | $link = 'lp/lp_controller.php?action=view&lp_id='.$this->lp_id; |
||
| 1117 | // Delete tools |
||
| 1118 | $sql = "DELETE FROM $tbl_tool |
||
| 1119 | WHERE c_id = ".$course_id." AND (link LIKE '$link%' AND image='scormbuilder.gif')"; |
||
| 1120 | Database::query($sql); |
||
| 1121 | |||
| 1122 | $sql = "DELETE FROM $lp WHERE c_id = ".$course_id." AND id = ".$this->lp_id; |
||
| 1123 | Database::query($sql); |
||
| 1124 | // Updates the display order of all lps. |
||
| 1125 | $this->update_display_order(); |
||
| 1126 | |||
| 1127 | api_item_property_update( |
||
| 1128 | api_get_course_info(), |
||
| 1129 | TOOL_LEARNPATH, |
||
| 1130 | $this->lp_id, |
||
| 1131 | 'delete', |
||
| 1132 | api_get_user_id() |
||
| 1133 | ); |
||
| 1134 | |||
| 1135 | $link_info = GradebookUtils::isResourceInCourseGradebook( |
||
| 1136 | api_get_course_int_id(), |
||
| 1137 | 4, |
||
| 1138 | $id, |
||
| 1139 | api_get_session_id() |
||
| 1140 | ); |
||
| 1141 | if ($link_info !== false) { |
||
| 1142 | GradebookUtils::remove_resource_from_course_gradebook($link_info['id']); |
||
| 1143 | } |
||
| 1144 | |||
| 1145 | if (api_get_setting('search_enabled') == 'true') { |
||
| 1146 | require_once api_get_path(LIBRARY_PATH).'specific_fields_manager.lib.php'; |
||
| 1147 | delete_all_values_for_item($this->cc, TOOL_LEARNPATH, $this->lp_id); |
||
| 1148 | } |
||
| 1149 | } |
||
| 1150 | |||
| 1151 | /** |
||
| 1152 | * Removes all the children of one item - dangerous! |
||
| 1153 | * @param integer $id Element ID of which children have to be removed |
||
| 1154 | * @return integer Total number of children removed |
||
| 1155 | */ |
||
| 1156 | public function delete_children_items($id) |
||
| 1157 | { |
||
| 1158 | $course_id = $this->course_info['real_id']; |
||
| 1159 | if ($this->debug > 0) { |
||
| 1160 | error_log('New LP - In learnpath::delete_children_items('.$id.')', 0); |
||
| 1161 | } |
||
| 1162 | $num = 0; |
||
| 1163 | if (empty($id) || $id != strval(intval($id))) { |
||
| 1164 | return false; |
||
| 1165 | } |
||
| 1166 | $lp_item = Database::get_course_table(TABLE_LP_ITEM); |
||
| 1167 | $sql = "SELECT * FROM $lp_item |
||
| 1168 | WHERE c_id = ".$course_id." AND parent_item_id = $id"; |
||
| 1169 | $res = Database::query($sql); |
||
| 1170 | View Code Duplication | while ($row = Database::fetch_array($res)) { |
|
| 1171 | $num += $this->delete_children_items($row['id']); |
||
| 1172 | $sql = "DELETE FROM $lp_item |
||
| 1173 | WHERE c_id = ".$course_id." AND id = ".$row['id']; |
||
| 1174 | Database::query($sql); |
||
| 1175 | $num++; |
||
| 1176 | } |
||
| 1177 | return $num; |
||
| 1178 | } |
||
| 1179 | |||
| 1180 | /** |
||
| 1181 | * Removes an item from the current learnpath |
||
| 1182 | * @param integer $id Elem ID (0 if first) |
||
| 1183 | * @param integer $remove Whether to remove the resource/data from the |
||
| 1184 | * system or leave it (default: 'keep', others 'remove') |
||
| 1185 | * @return integer Number of elements moved |
||
| 1186 | * @todo implement resource removal |
||
| 1187 | */ |
||
| 1188 | public function delete_item($id, $remove = 'keep') |
||
| 1255 | |||
| 1256 | /** |
||
| 1257 | * Updates an item's content in place |
||
| 1258 | * @param integer $id Element ID |
||
| 1259 | * @param integer $parent Parent item ID |
||
| 1260 | * @param integer $previous Previous item ID |
||
| 1261 | * @param string $title Item title |
||
| 1262 | * @param string $description Item description |
||
| 1263 | * @param string $prerequisites Prerequisites (optional) |
||
| 1264 | * @param array $audio The array resulting of the $_FILES[mp3] element |
||
| 1265 | * @param int $max_time_allowed |
||
| 1266 | * @param string $url |
||
| 1267 | * @return boolean True on success, false on error |
||
| 1268 | */ |
||
| 1269 | public function edit_item( |
||
| 1270 | $id, |
||
| 1271 | $parent, |
||
| 1272 | $previous, |
||
| 1273 | $title, |
||
| 1274 | $description, |
||
| 1275 | $prerequisites = '0', |
||
| 1276 | $audio = array(), |
||
| 1277 | $max_time_allowed = 0, |
||
| 1278 | $url = '' |
||
| 1279 | ) { |
||
| 1280 | $course_id = api_get_course_int_id(); |
||
| 1281 | $_course = api_get_course_info(); |
||
| 1282 | |||
| 1283 | if ($this->debug > 0) { |
||
| 1284 | error_log('New LP - In learnpath::edit_item()', 0); |
||
| 1285 | } |
||
| 1286 | if (empty($max_time_allowed)) { |
||
| 1287 | $max_time_allowed = 0; |
||
| 1288 | } |
||
| 1289 | if (empty($id) || ($id != strval(intval($id))) || empty($title)) { |
||
| 1290 | return false; |
||
| 1291 | } |
||
| 1292 | |||
| 1293 | $tbl_lp_item = Database::get_course_table(TABLE_LP_ITEM); |
||
| 1294 | $sql = "SELECT * FROM $tbl_lp_item |
||
| 1295 | WHERE c_id = ".$course_id." AND id = ".$id; |
||
| 1296 | $res_select = Database::query($sql); |
||
| 1297 | $row_select = Database::fetch_array($res_select); |
||
| 1298 | $audio_update_sql = ''; |
||
| 1299 | if (is_array($audio) && !empty($audio['tmp_name']) && $audio['error'] === 0) { |
||
| 1300 | // Create the audio folder if it does not exist yet. |
||
| 1301 | $filepath = api_get_path(SYS_COURSE_PATH).$_course['path'].'/document/'; |
||
| 1302 | View Code Duplication | if (!is_dir($filepath.'audio')) { |
|
| 1303 | mkdir($filepath.'audio', api_get_permissions_for_new_directories()); |
||
| 1304 | $audio_id = add_document( |
||
| 1305 | $_course, |
||
| 1306 | '/audio', |
||
| 1307 | 'folder', |
||
| 1308 | 0, |
||
| 1309 | 'audio' |
||
| 1310 | ); |
||
| 1311 | api_item_property_update( |
||
| 1312 | $_course, |
||
| 1313 | TOOL_DOCUMENT, |
||
| 1314 | $audio_id, |
||
| 1315 | 'FolderCreated', |
||
| 1316 | api_get_user_id(), |
||
| 1317 | null, |
||
| 1318 | null, |
||
| 1319 | null, |
||
| 1320 | null, |
||
| 1321 | api_get_session_id() |
||
| 1322 | ); |
||
| 1323 | api_item_property_update( |
||
| 1324 | $_course, |
||
| 1325 | TOOL_DOCUMENT, |
||
| 1326 | $audio_id, |
||
| 1327 | 'invisible', |
||
| 1328 | api_get_user_id(), |
||
| 1329 | null, |
||
| 1330 | null, |
||
| 1331 | null, |
||
| 1332 | null, |
||
| 1333 | api_get_session_id() |
||
| 1334 | ); |
||
| 1335 | } |
||
| 1336 | |||
| 1337 | // Upload file in documents. |
||
| 1338 | $pi = pathinfo($audio['name']); |
||
| 1339 | if ($pi['extension'] == 'mp3') { |
||
| 1340 | $c_det = api_get_course_info($this->cc); |
||
| 1341 | $bp = api_get_path(SYS_COURSE_PATH).$c_det['path'].'/document'; |
||
| 1342 | $path = handle_uploaded_document( |
||
| 1343 | $c_det, |
||
| 1344 | $audio, |
||
| 1345 | $bp, |
||
| 1346 | '/audio', |
||
| 1347 | api_get_user_id(), |
||
| 1348 | 0, |
||
| 1349 | null, |
||
| 1350 | 0, |
||
| 1351 | 'rename', |
||
| 1352 | false, |
||
| 1353 | 0 |
||
| 1354 | ); |
||
| 1355 | $path = substr($path, 7); |
||
| 1356 | // Update reference in lp_item - audio path is the path from inside de document/audio/ dir. |
||
| 1357 | $audio_update_sql = ", audio = '".Database::escape_string($path)."' "; |
||
| 1358 | } |
||
| 1359 | } |
||
| 1360 | |||
| 1361 | $same_parent = ($row_select['parent_item_id'] == $parent) ? true : false; |
||
| 1362 | $same_previous = ($row_select['previous_item_id'] == $previous) ? true : false; |
||
| 1363 | |||
| 1364 | // TODO: htmlspecialchars to be checked for encoding related problems. |
||
| 1365 | if ($same_parent && $same_previous) { |
||
| 1366 | // Only update title and description. |
||
| 1367 | $sql = "UPDATE ".$tbl_lp_item." |
||
| 1368 | SET title = '" . Database::escape_string($title)."', |
||
| 1369 | prerequisite = '".$prerequisites."', |
||
| 1370 | description = '".Database::escape_string($description)."' |
||
| 1371 | ".$audio_update_sql.", |
||
| 1372 | max_time_allowed = '".Database::escape_string($max_time_allowed)."' |
||
| 1373 | WHERE c_id = ".$course_id." AND id = ".$id; |
||
| 1374 | Database::query($sql); |
||
| 1375 | } else { |
||
| 1376 | $old_parent = $row_select['parent_item_id']; |
||
| 1377 | $old_previous = $row_select['previous_item_id']; |
||
| 1378 | $old_next = $row_select['next_item_id']; |
||
| 1379 | $old_order = $row_select['display_order']; |
||
| 1380 | $old_prerequisite = $row_select['prerequisite']; |
||
| 1381 | $old_max_time_allowed = $row_select['max_time_allowed']; |
||
| 1382 | |||
| 1383 | /* BEGIN -- virtually remove the current item id */ |
||
| 1384 | /* for the next and previous item it is like the current item doesn't exist anymore */ |
||
| 1385 | if ($old_previous != 0) { |
||
| 1386 | // Next |
||
| 1387 | $sql = "UPDATE ".$tbl_lp_item." |
||
| 1388 | SET next_item_id = " . $old_next." |
||
| 1389 | WHERE c_id = ".$course_id." AND id = ".$old_previous; |
||
| 1390 | Database::query($sql); |
||
| 1391 | } |
||
| 1392 | |||
| 1393 | if ($old_next != 0) { |
||
| 1394 | // Previous |
||
| 1395 | $sql = "UPDATE ".$tbl_lp_item." |
||
| 1396 | SET previous_item_id = " . $old_previous." |
||
| 1397 | WHERE c_id = ".$course_id." AND id = ".$old_next; |
||
| 1398 | Database::query($sql); |
||
| 1399 | } |
||
| 1400 | |||
| 1401 | // display_order - 1 for every item with a display_order |
||
| 1402 | // bigger then the display_order of the current item. |
||
| 1403 | $sql = "UPDATE ".$tbl_lp_item." |
||
| 1404 | SET display_order = display_order - 1 |
||
| 1405 | WHERE |
||
| 1406 | c_id = ".$course_id." AND |
||
| 1407 | display_order > " . $old_order." AND |
||
| 1408 | lp_id = " . $this->lp_id." AND |
||
| 1409 | parent_item_id = " . $old_parent; |
||
| 1410 | Database::query($sql); |
||
| 1411 | /* END -- virtually remove the current item id */ |
||
| 1412 | |||
| 1413 | /* BEGIN -- update the current item id to his new location */ |
||
| 1414 | if ($previous == 0) { |
||
| 1415 | // Select the data of the item that should come after the current item. |
||
| 1416 | $sql = "SELECT id, display_order |
||
| 1417 | FROM " . $tbl_lp_item." |
||
| 1418 | WHERE |
||
| 1419 | c_id = ".$course_id." AND |
||
| 1420 | lp_id = " . $this->lp_id." AND |
||
| 1421 | parent_item_id = " . $parent." AND |
||
| 1422 | previous_item_id = " . $previous; |
||
| 1423 | $res_select_old = Database::query($sql); |
||
| 1424 | $row_select_old = Database::fetch_array($res_select_old); |
||
| 1425 | |||
| 1426 | // If the new parent didn't have children before. |
||
| 1427 | if (Database::num_rows($res_select_old) == 0) { |
||
| 1428 | $new_next = 0; |
||
| 1429 | $new_order = 1; |
||
| 1430 | } else { |
||
| 1431 | $new_next = $row_select_old['id']; |
||
| 1432 | $new_order = $row_select_old['display_order']; |
||
| 1433 | } |
||
| 1434 | } else { |
||
| 1435 | // Select the data of the item that should come before the current item. |
||
| 1436 | $sql = "SELECT next_item_id, display_order |
||
| 1437 | FROM " . $tbl_lp_item." |
||
| 1438 | WHERE c_id = ".$course_id." AND id = ".$previous; |
||
| 1439 | $res_select_old = Database::query($sql); |
||
| 1440 | $row_select_old = Database::fetch_array($res_select_old); |
||
| 1441 | $new_next = $row_select_old['next_item_id']; |
||
| 1442 | $new_order = $row_select_old['display_order'] + 1; |
||
| 1443 | } |
||
| 1444 | |||
| 1445 | // TODO: htmlspecialchars to be checked for encoding related problems. |
||
| 1446 | // Update the current item with the new data. |
||
| 1447 | $sql = "UPDATE $tbl_lp_item |
||
| 1448 | SET |
||
| 1449 | title = '".Database::escape_string($title)."', |
||
| 1450 | description = '".Database::escape_string($description)."', |
||
| 1451 | parent_item_id = ".$parent.", |
||
| 1452 | previous_item_id = ".$previous.", |
||
| 1453 | next_item_id = ".$new_next.", |
||
| 1454 | display_order = ".$new_order." |
||
| 1455 | ".$audio_update_sql." |
||
| 1456 | WHERE c_id = ".$course_id." AND id = ".$id; |
||
| 1457 | Database::query($sql); |
||
| 1458 | |||
| 1459 | if ($previous != 0) { |
||
| 1460 | // Update the previous item's next_item_id. |
||
| 1461 | $sql = "UPDATE ".$tbl_lp_item." |
||
| 1462 | SET next_item_id = " . $id." |
||
| 1463 | WHERE c_id = ".$course_id." AND id = ".$previous; |
||
| 1464 | Database::query($sql); |
||
| 1465 | } |
||
| 1466 | |||
| 1467 | if ($new_next != 0) { |
||
| 1468 | // Update the next item's previous_item_id. |
||
| 1469 | $sql = "UPDATE ".$tbl_lp_item." |
||
| 1470 | SET previous_item_id = " . $id." |
||
| 1471 | WHERE c_id = ".$course_id." AND id = ".$new_next; |
||
| 1472 | Database::query($sql); |
||
| 1473 | } |
||
| 1474 | |||
| 1475 | if ($old_prerequisite != $prerequisites) { |
||
| 1476 | $sql = "UPDATE ".$tbl_lp_item." |
||
| 1477 | SET prerequisite = '" . $prerequisites."' |
||
| 1478 | WHERE c_id = ".$course_id." AND id = ".$id; |
||
| 1479 | Database::query($sql); |
||
| 1480 | } |
||
| 1481 | |||
| 1482 | if ($old_max_time_allowed != $max_time_allowed) { |
||
| 1483 | // update max time allowed |
||
| 1484 | $sql = "UPDATE ".$tbl_lp_item." |
||
| 1485 | SET max_time_allowed = " . $max_time_allowed." |
||
| 1486 | WHERE c_id = ".$course_id." AND id = ".$id; |
||
| 1487 | Database::query($sql); |
||
| 1488 | } |
||
| 1489 | |||
| 1490 | // Update all the items with the same or a bigger display_order than the current item. |
||
| 1491 | $sql = "UPDATE ".$tbl_lp_item." |
||
| 1492 | SET display_order = display_order + 1 |
||
| 1493 | WHERE |
||
| 1494 | c_id = ".$course_id." AND |
||
| 1495 | lp_id = " . $this->get_id()." AND |
||
| 1496 | id <> " . $id." AND |
||
| 1497 | parent_item_id = " . $parent." AND |
||
| 1498 | display_order >= " . $new_order; |
||
| 1499 | |||
| 1500 | Database::query($sql); |
||
| 1501 | } |
||
| 1502 | |||
| 1503 | if ($row_select['item_type'] == 'link') { |
||
| 1504 | $link = new Link(); |
||
| 1505 | $linkId = $row_select['path']; |
||
| 1506 | $link->updateLink($linkId, $url); |
||
| 1507 | } |
||
| 1508 | } |
||
| 1509 | |||
| 1510 | /** |
||
| 1511 | * Updates an item's prereq in place |
||
| 1512 | * @param integer $id Element ID |
||
| 1513 | * @param string $prerequisite_id Prerequisite Element ID |
||
| 1514 | * @param int $mastery_score Prerequisite min score |
||
| 1515 | * @param int $max_score Prerequisite max score |
||
| 1516 | * |
||
| 1517 | * @return boolean True on success, false on error |
||
| 1518 | */ |
||
| 1519 | public function edit_item_prereq( |
||
| 1520 | $id, |
||
| 1521 | $prerequisite_id, |
||
| 1522 | $mastery_score = 0, |
||
| 1523 | $max_score = 100 |
||
| 1524 | ) { |
||
| 1525 | $course_id = api_get_course_int_id(); |
||
| 1526 | if ($this->debug > 0) { |
||
| 1527 | error_log('New LP - In learnpath::edit_item_prereq('.$id.','.$prerequisite_id.','.$mastery_score.','.$max_score.')', 0); |
||
| 1528 | } |
||
| 1529 | |||
| 1530 | if (empty($id) || ($id != strval(intval($id))) || empty($prerequisite_id)) { |
||
| 1531 | return false; |
||
| 1532 | } |
||
| 1533 | |||
| 1534 | $prerequisite_id = intval($prerequisite_id); |
||
| 1535 | $tbl_lp_item = Database::get_course_table(TABLE_LP_ITEM); |
||
| 1536 | |||
| 1537 | if (!is_numeric($mastery_score) || $mastery_score < 0) { |
||
| 1538 | $mastery_score = 0; |
||
| 1539 | } |
||
| 1540 | |||
| 1541 | if (!is_numeric($max_score) || $max_score < 0) { |
||
| 1542 | $max_score = 100; |
||
| 1543 | } |
||
| 1544 | |||
| 1545 | /*if ($mastery_score > $max_score) { |
||
| 1546 | $max_score = $mastery_score; |
||
| 1547 | }*/ |
||
| 1548 | |||
| 1549 | if (!is_numeric($prerequisite_id)) { |
||
| 1550 | $prerequisite_id = 'NULL'; |
||
| 1551 | } |
||
| 1552 | |||
| 1553 | $mastery_score = floatval($mastery_score); |
||
| 1554 | $max_score = floatval($max_score); |
||
| 1555 | |||
| 1556 | $sql = " UPDATE $tbl_lp_item |
||
| 1557 | SET |
||
| 1558 | prerequisite = $prerequisite_id , |
||
| 1559 | prerequisite_min_score = $mastery_score , |
||
| 1560 | prerequisite_max_score = $max_score |
||
| 1561 | WHERE c_id = $course_id AND id = $id"; |
||
| 1562 | Database::query($sql); |
||
| 1563 | // TODO: Update the item object (can be ignored for now because refreshed). |
||
| 1564 | return true; |
||
| 1565 | } |
||
| 1566 | |||
| 1567 | /** |
||
| 1568 | * Static admin function exporting a learnpath into a zip file |
||
| 1569 | * @param string Export type (scorm, zip, cd) |
||
| 1570 | * @param string Course code |
||
| 1571 | * @param integer Learnpath ID |
||
| 1572 | * @param string Zip file name |
||
| 1573 | * @return string Zip file path (or false on error) |
||
| 1574 | */ |
||
| 1575 | public function export_lp($type, $course, $id, $zipname) |
||
| 1576 | { |
||
| 1577 | if (empty($type) || empty($course) || empty($id) || empty($zipname)) { |
||
| 1578 | return false; |
||
| 1579 | } |
||
| 1580 | $url = ''; |
||
| 1581 | switch ($type) { |
||
| 1582 | case 'scorm': |
||
| 1583 | break; |
||
| 1584 | case 'zip': |
||
| 1585 | break; |
||
| 1586 | case 'cdrom': |
||
| 1587 | break; |
||
| 1588 | } |
||
| 1589 | return $url; |
||
| 1590 | } |
||
| 1591 | |||
| 1592 | /** |
||
| 1593 | * Gets all the chapters belonging to the same parent as the item/chapter given |
||
| 1594 | * Can also be called as abstract method |
||
| 1595 | * @param integer $id Item ID |
||
| 1596 | * @return array A list of all the "brother items" (or an empty array on failure) |
||
| 1597 | */ |
||
| 1598 | View Code Duplication | public function getSiblingDirectories($id) |
|
| 1599 | { |
||
| 1600 | $course_id = api_get_course_int_id(); |
||
| 1601 | if ($this->debug > 0) { |
||
| 1602 | error_log('New LP - In learnpath::getSiblingDirectories()', 0); |
||
| 1603 | } |
||
| 1604 | |||
| 1605 | if (empty($id) || $id != strval(intval($id))) { |
||
| 1606 | return array(); |
||
| 1607 | } |
||
| 1608 | |||
| 1609 | $lp_item = Database::get_course_table(TABLE_LP_ITEM); |
||
| 1610 | $sql_parent = "SELECT * FROM $lp_item |
||
| 1611 | WHERE c_id = ".$course_id." AND id = $id AND item_type='dir'"; |
||
| 1612 | $res_parent = Database::query($sql_parent); |
||
| 1613 | if (Database::num_rows($res_parent) > 0) { |
||
| 1614 | $row_parent = Database::fetch_array($res_parent); |
||
| 1615 | $parent = $row_parent['parent_item_id']; |
||
| 1616 | $sql = "SELECT * FROM $lp_item |
||
| 1617 | WHERE |
||
| 1618 | c_id = ".$course_id." AND |
||
| 1619 | parent_item_id = $parent AND |
||
| 1620 | id = $id AND |
||
| 1621 | item_type='dir' |
||
| 1622 | ORDER BY display_order"; |
||
| 1623 | $res_bros = Database::query($sql); |
||
| 1624 | |||
| 1625 | $list = array(); |
||
| 1626 | while ($row_bro = Database::fetch_array($res_bros)) { |
||
| 1627 | $list[] = $row_bro; |
||
| 1628 | } |
||
| 1629 | |||
| 1630 | return $list; |
||
| 1631 | } |
||
| 1632 | |||
| 1633 | return array(); |
||
| 1634 | } |
||
| 1635 | |||
| 1636 | /** |
||
| 1637 | * Gets all the items belonging to the same parent as the item given |
||
| 1638 | * Can also be called as abstract method |
||
| 1639 | * @param integer $id Item ID |
||
| 1640 | * @return array A list of all the "brother items" (or an empty array on failure) |
||
| 1641 | */ |
||
| 1642 | View Code Duplication | public function get_brother_items($id) |
|
| 1643 | { |
||
| 1644 | $course_id = api_get_course_int_id(); |
||
| 1645 | if ($this->debug > 0) { |
||
| 1646 | error_log('New LP - In learnpath::get_brother_items('.$id.')', 0); |
||
| 1647 | } |
||
| 1648 | |||
| 1649 | if (empty($id) || $id != strval(intval($id))) { |
||
| 1650 | return array(); |
||
| 1651 | } |
||
| 1652 | |||
| 1653 | $lp_item = Database::get_course_table(TABLE_LP_ITEM); |
||
| 1654 | $sql_parent = "SELECT * FROM $lp_item WHERE c_id = $course_id AND id = $id"; |
||
| 1655 | $res_parent = Database::query($sql_parent); |
||
| 1656 | if (Database::num_rows($res_parent) > 0) { |
||
| 1657 | $row_parent = Database::fetch_array($res_parent); |
||
| 1658 | $parent = $row_parent['parent_item_id']; |
||
| 1659 | $sql_bros = "SELECT * FROM $lp_item WHERE c_id = ".$course_id." AND parent_item_id = $parent |
||
| 1660 | ORDER BY display_order"; |
||
| 1661 | $res_bros = Database::query($sql_bros); |
||
| 1662 | $list = []; |
||
| 1663 | while ($row_bro = Database::fetch_array($res_bros)) { |
||
| 1664 | $list[] = $row_bro; |
||
| 1665 | } |
||
| 1666 | return $list; |
||
| 1667 | } |
||
| 1668 | return []; |
||
| 1669 | } |
||
| 1670 | |||
| 1671 | /** |
||
| 1672 | * Get the specific prefix index terms of this learning path |
||
| 1673 | * @param string $prefix |
||
| 1674 | * @return array Array of terms |
||
| 1675 | */ |
||
| 1676 | public function get_common_index_terms_by_prefix($prefix) |
||
| 1677 | { |
||
| 1678 | require_once api_get_path(LIBRARY_PATH).'specific_fields_manager.lib.php'; |
||
| 1679 | $terms = get_specific_field_values_list_by_prefix( |
||
| 1680 | $prefix, |
||
| 1681 | $this->cc, |
||
| 1682 | TOOL_LEARNPATH, |
||
| 1683 | $this->lp_id |
||
| 1684 | ); |
||
| 1685 | $prefix_terms = array(); |
||
| 1686 | if (!empty($terms)) { |
||
| 1687 | foreach ($terms as $term) { |
||
| 1688 | $prefix_terms[] = $term['value']; |
||
| 1689 | } |
||
| 1690 | } |
||
| 1691 | return $prefix_terms; |
||
| 1692 | } |
||
| 1693 | |||
| 1694 | /** |
||
| 1695 | * Gets the number of items currently completed |
||
| 1696 | * @param bool $failedStatusException flag to determine the failed status is not considered progressed |
||
| 1697 | * @return integer The number of items currently completed |
||
| 1698 | */ |
||
| 1699 | public function get_complete_items_count($failedStatusException = false) |
||
| 1700 | { |
||
| 1701 | if ($this->debug > 0) { |
||
| 1702 | error_log('New LP - In learnpath::get_complete_items_count()', 0); |
||
| 1703 | } |
||
| 1704 | $i = 0; |
||
| 1705 | $completedStatusList = array( |
||
| 1706 | 'completed', |
||
| 1707 | 'passed', |
||
| 1708 | 'succeeded', |
||
| 1709 | 'browsed' |
||
| 1710 | ); |
||
| 1711 | |||
| 1712 | if (!$failedStatusException) { |
||
| 1713 | $completedStatusList[] = 'failed'; |
||
| 1714 | } |
||
| 1715 | |||
| 1716 | foreach ($this->items as $id => $dummy) { |
||
| 1717 | // Trying failed and browsed considered "progressed" as well. |
||
| 1718 | if ($this->items[$id]->status_is($completedStatusList) && |
||
| 1719 | $this->items[$id]->get_type() != 'dir' |
||
| 1720 | ) { |
||
| 1721 | $i++; |
||
| 1722 | } |
||
| 1723 | } |
||
| 1724 | return $i; |
||
| 1725 | } |
||
| 1726 | |||
| 1727 | /** |
||
| 1728 | * Gets the current item ID |
||
| 1729 | * @return integer The current learnpath item id |
||
| 1730 | */ |
||
| 1731 | public function get_current_item_id() |
||
| 1732 | { |
||
| 1733 | $current = 0; |
||
| 1734 | if ($this->debug > 0) { |
||
| 1735 | error_log('New LP - In learnpath::get_current_item_id()', 0); |
||
| 1736 | } |
||
| 1737 | if (!empty($this->current)) { |
||
| 1738 | $current = $this->current; |
||
| 1739 | } |
||
| 1740 | if ($this->debug > 2) { |
||
| 1741 | error_log('New LP - In learnpath::get_current_item_id() - Returning '.$current, 0); |
||
| 1742 | } |
||
| 1743 | return $current; |
||
| 1744 | } |
||
| 1745 | |||
| 1746 | /** |
||
| 1747 | * Force to get the first learnpath item id |
||
| 1748 | * @return integer The current learnpath item id |
||
| 1749 | */ |
||
| 1750 | public function get_first_item_id() |
||
| 1751 | { |
||
| 1752 | $current = 0; |
||
| 1753 | if (is_array($this->ordered_items)) { |
||
| 1754 | $current = $this->ordered_items[0]; |
||
| 1755 | } |
||
| 1756 | return $current; |
||
| 1757 | } |
||
| 1758 | |||
| 1759 | /** |
||
| 1760 | * Gets the total number of items available for viewing in this SCORM |
||
| 1761 | * @return integer The total number of items |
||
| 1762 | */ |
||
| 1763 | public function get_total_items_count() |
||
| 1764 | { |
||
| 1765 | if ($this->debug > 0) { |
||
| 1766 | error_log('New LP - In learnpath::get_total_items_count()', 0); |
||
| 1767 | } |
||
| 1768 | return count($this->items); |
||
| 1769 | } |
||
| 1770 | |||
| 1771 | /** |
||
| 1772 | * Gets the total number of items available for viewing in this SCORM but without chapters |
||
| 1773 | * @return integer The total no-chapters number of items |
||
| 1774 | */ |
||
| 1775 | public function getTotalItemsCountWithoutDirs() |
||
| 1776 | { |
||
| 1777 | if ($this->debug > 0) { |
||
| 1778 | error_log('New LP - In learnpath::getTotalItemsCountWithoutDirs()', 0); |
||
| 1779 | } |
||
| 1780 | $total = 0; |
||
| 1781 | $typeListNotToCount = self::getChapterTypes(); |
||
| 1782 | foreach ($this->items as $temp2) { |
||
| 1783 | if (!in_array($temp2->get_type(), $typeListNotToCount)) { |
||
| 1784 | $total++; |
||
| 1785 | } |
||
| 1786 | } |
||
| 1787 | return $total; |
||
| 1788 | } |
||
| 1789 | |||
| 1790 | /** |
||
| 1791 | * Gets the first element URL. |
||
| 1792 | * @return string URL to load into the viewer |
||
| 1793 | */ |
||
| 1794 | public function first() |
||
| 1795 | { |
||
| 1796 | if ($this->debug > 0) { |
||
| 1797 | error_log('New LP - In learnpath::first()', 0); |
||
| 1798 | error_log('$this->last_item_seen '.$this->last_item_seen); |
||
| 1799 | } |
||
| 1800 | |||
| 1801 | // Test if the last_item_seen exists and is not a dir. |
||
| 1802 | if (count($this->ordered_items) == 0) { |
||
| 1803 | $this->index = 0; |
||
| 1804 | } |
||
| 1805 | |||
| 1806 | if ($this->debug > 0) { |
||
| 1807 | if (isset($this->items[$this->last_item_seen])) { |
||
| 1808 | $status = $this->items[$this->last_item_seen]->get_status(); |
||
| 1809 | } |
||
| 1810 | error_log('status '.$status); |
||
| 1811 | } |
||
| 1812 | |||
| 1813 | if (!empty($this->last_item_seen) && |
||
| 1814 | !empty($this->items[$this->last_item_seen]) && |
||
| 1815 | $this->items[$this->last_item_seen]->get_type() != 'dir' |
||
| 1816 | //with this change (below) the LP will NOT go to the next item, it will take lp item we left |
||
| 1817 | //&& !$this->items[$this->last_item_seen]->is_done() |
||
| 1818 | ) { |
||
| 1819 | if ($this->debug > 2) { |
||
| 1820 | error_log('New LP - In learnpath::first() - Last item seen is '.$this->last_item_seen.' of type '.$this->items[$this->last_item_seen]->get_type(), 0); |
||
| 1821 | } |
||
| 1822 | $index = -1; |
||
| 1823 | foreach ($this->ordered_items as $myindex => $item_id) { |
||
| 1824 | if ($item_id == $this->last_item_seen) { |
||
| 1825 | $index = $myindex; |
||
| 1826 | break; |
||
| 1827 | } |
||
| 1828 | } |
||
| 1829 | if ($index == -1) { |
||
| 1830 | // Index hasn't changed, so item not found - panic (this shouldn't happen). |
||
| 1831 | if ($this->debug > 2) { |
||
| 1832 | error_log('New LP - Last item ('.$this->last_item_seen.') was found in items but not in ordered_items, panic!', 0); |
||
| 1833 | } |
||
| 1834 | return false; |
||
| 1835 | } else { |
||
| 1836 | $this->last = $this->last_item_seen; |
||
| 1837 | $this->current = $this->last_item_seen; |
||
| 1838 | $this->index = $index; |
||
| 1839 | } |
||
| 1840 | } else { |
||
| 1841 | if ($this->debug > 2) { |
||
| 1842 | error_log('New LP - In learnpath::first() - No last item seen', 0); |
||
| 1843 | } |
||
| 1844 | $index = 0; |
||
| 1845 | // Loop through all ordered items and stop at the first item that is |
||
| 1846 | // not a directory *and* that has not been completed yet. |
||
| 1847 | while (!empty($this->ordered_items[$index]) && |
||
| 1848 | is_a($this->items[$this->ordered_items[$index]], 'learnpathItem') && |
||
| 1849 | ( |
||
| 1850 | $this->items[$this->ordered_items[$index]]->get_type() == 'dir' || |
||
| 1851 | $this->items[$this->ordered_items[$index]]->is_done() === true |
||
| 1852 | ) && $index < $this->max_ordered_items) { |
||
| 1853 | $index++; |
||
| 1854 | } |
||
| 1855 | $this->last = $this->current; |
||
| 1856 | // current is |
||
| 1857 | $this->current = isset($this->ordered_items[$index]) ? $this->ordered_items[$index] : null; |
||
| 1858 | $this->index = $index; |
||
| 1859 | if ($this->debug > 2) { |
||
| 1860 | error_log('$index '.$index); |
||
| 1861 | } |
||
| 1862 | View Code Duplication | if ($this->debug > 2) { |
|
| 1863 | error_log('New LP - In learnpath::first() - No last item seen. New last = '.$this->last.'('.$this->ordered_items[$index].')', 0); |
||
| 1864 | } |
||
| 1865 | } |
||
| 1866 | if ($this->debug > 2) { |
||
| 1867 | error_log('New LP - In learnpath::first() - First item is '.$this->get_current_item_id()); |
||
| 1868 | } |
||
| 1869 | } |
||
| 1870 | |||
| 1871 | /** |
||
| 1872 | * Gets the information about an item in a format usable as JavaScript to update |
||
| 1873 | * the JS API by just printing this content into the <head> section of the message frame |
||
| 1874 | * @param int $item_id |
||
| 1875 | * @return string |
||
| 1876 | */ |
||
| 1877 | public function get_js_info($item_id = 0) |
||
| 1878 | { |
||
| 1879 | if ($this->debug > 0) { |
||
| 1880 | error_log('New LP - In learnpath::get_js_info('.$item_id.')', 0); |
||
| 1881 | } |
||
| 1882 | |||
| 1883 | $info = ''; |
||
| 1884 | $item_id = intval($item_id); |
||
| 1885 | |||
| 1886 | if (!empty($item_id) && is_object($this->items[$item_id])) { |
||
| 1887 | //if item is defined, return values from DB |
||
| 1888 | $oItem = $this->items[$item_id]; |
||
| 1889 | $info .= '<script language="javascript">'; |
||
| 1890 | $info .= "top.set_score(".$oItem->get_score().");\n"; |
||
| 1891 | $info .= "top.set_max(".$oItem->get_max().");\n"; |
||
| 1892 | $info .= "top.set_min(".$oItem->get_min().");\n"; |
||
| 1893 | $info .= "top.set_lesson_status('".$oItem->get_status()."');"; |
||
| 1894 | $info .= "top.set_session_time('".$oItem->get_scorm_time('js')."');"; |
||
| 1895 | $info .= "top.set_suspend_data('".$oItem->get_suspend_data()."');"; |
||
| 1896 | $info .= "top.set_saved_lesson_status('".$oItem->get_status()."');"; |
||
| 1897 | $info .= "top.set_flag_synchronized();"; |
||
| 1898 | $info .= '</script>'; |
||
| 1899 | if ($this->debug > 2) { |
||
| 1900 | error_log('New LP - in learnpath::get_js_info('.$item_id.') - returning: '.$info, 0); |
||
| 1901 | } |
||
| 1902 | return $info; |
||
| 1903 | |||
| 1904 | } else { |
||
| 1905 | // If item_id is empty, just update to default SCORM data. |
||
| 1906 | $info .= '<script language="javascript">'; |
||
| 1907 | $info .= "top.set_score(".learnpathItem::get_score().");\n"; |
||
| 1908 | $info .= "top.set_max(".learnpathItem::get_max().");\n"; |
||
| 1909 | $info .= "top.set_min(".learnpathItem::get_min().");\n"; |
||
| 1910 | $info .= "top.set_lesson_status('".learnpathItem::get_status()."');"; |
||
| 1911 | $info .= "top.set_session_time('".learnpathItem::getScormTimeFromParameter('js')."');"; |
||
| 1912 | $info .= "top.set_suspend_data('".learnpathItem::get_suspend_data()."');"; |
||
| 1913 | $info .= "top.set_saved_lesson_status('".learnpathItem::get_status()."');"; |
||
| 1914 | $info .= "top.set_flag_synchronized();"; |
||
| 1915 | $info .= '</script>'; |
||
| 1916 | if ($this->debug > 2) { |
||
| 1917 | error_log('New LP - in learnpath::get_js_info('.$item_id.') - returning: '.$info, 0); |
||
| 1918 | } |
||
| 1919 | return $info; |
||
| 1920 | } |
||
| 1921 | } |
||
| 1922 | |||
| 1923 | /** |
||
| 1924 | * Gets the js library from the database |
||
| 1925 | * @return string The name of the javascript library to be used |
||
| 1926 | */ |
||
| 1927 | public function get_js_lib() |
||
| 1928 | { |
||
| 1929 | $lib = ''; |
||
| 1930 | if (!empty($this->js_lib)) { |
||
| 1931 | $lib = $this->js_lib; |
||
| 1932 | } |
||
| 1933 | return $lib; |
||
| 1934 | } |
||
| 1935 | |||
| 1936 | /** |
||
| 1937 | * Gets the learnpath database ID |
||
| 1938 | * @return integer Learnpath ID in the lp table |
||
| 1939 | */ |
||
| 1940 | public function get_id() |
||
| 1941 | { |
||
| 1942 | if (!empty($this->lp_id)) { |
||
| 1943 | return $this->lp_id; |
||
| 1944 | } else { |
||
| 1945 | return 0; |
||
| 1946 | } |
||
| 1947 | } |
||
| 1948 | |||
| 1949 | /** |
||
| 1950 | * Gets the last element URL. |
||
| 1951 | * @return string URL to load into the viewer |
||
| 1952 | */ |
||
| 1953 | public function get_last() |
||
| 1954 | { |
||
| 1955 | if ($this->debug > 0) { |
||
| 1956 | error_log('New LP - In learnpath::get_last()', 0); |
||
| 1957 | } |
||
| 1958 | //This is just in case the lesson doesn't cointain a valid scheme, just to avoid "Notices" |
||
| 1959 | if (count($this->ordered_items) > 0) { |
||
| 1960 | $this->index = count($this->ordered_items) - 1; |
||
| 1961 | return $this->ordered_items[$this->index]; |
||
| 1962 | } |
||
| 1963 | |||
| 1964 | return false; |
||
| 1965 | } |
||
| 1966 | |||
| 1967 | /** |
||
| 1968 | * Gets the navigation bar for the learnpath display screen |
||
| 1969 | * @return string The HTML string to use as a navigation bar |
||
| 1970 | */ |
||
| 1971 | public function get_navigation_bar($idBar = null, $display = null) |
||
| 1972 | { |
||
| 1973 | if ($this->debug > 0) { |
||
| 1974 | error_log('New LP - In learnpath::get_navigation_bar()', 0); |
||
| 1975 | } |
||
| 1976 | if (empty($idBar)) { |
||
| 1977 | $idBar = 'control-top'; |
||
| 1978 | } |
||
| 1979 | |||
| 1980 | $navbar = null; |
||
| 1981 | $lp_id = $this->lp_id; |
||
| 1982 | $mycurrentitemid = $this->get_current_item_id(); |
||
| 1983 | |||
| 1984 | $reportingText = get_lang('Reporting'); |
||
| 1985 | $previousText = get_lang('ScormPrevious'); |
||
| 1986 | $nextText = get_lang('ScormNext'); |
||
| 1987 | $fullScreenText = get_lang('ScormExitFullScreen'); |
||
| 1988 | |||
| 1989 | if ($this->mode == 'fullscreen') { |
||
| 1990 | $navbar = ' |
||
| 1991 | <span id="'.$idBar.'" class="buttons"> |
||
| 1992 | <a class="icon-toolbar" href="lp_controller.php?action=stats&'.api_get_cidreq(true).'&lp_id='.$lp_id.'" onclick="window.parent.API.save_asset();return true;" target="content_name" title="'.$reportingText.'" id="stats_link"> |
||
| 1993 | <span class="fa fa-info"></span><span class="sr-only">' . $reportingText.'</span> |
||
| 1994 | </a> |
||
| 1995 | <a class="icon-toolbar" id="scorm-previous" href="#" onclick="switch_item(' . $mycurrentitemid.',\'previous\');return false;" title="'.$previousText.'"> |
||
| 1996 | <span class="fa fa-chevron-left"></span><span class="sr-only">' . $previousText.'</span> |
||
| 1997 | </a> |
||
| 1998 | <a class="icon-toolbar" id="scorm-next" href="#" onclick="switch_item(' . $mycurrentitemid.',\'next\');return false;" title="'.$nextText.'"> |
||
| 1999 | <span class="fa fa-chevron-right"></span><span class="sr-only">' . $nextText.'</span> |
||
| 2000 | </a> |
||
| 2001 | <a class="icon-toolbar" id="view-embedded" href="lp_controller.php?action=mode&mode=embedded" target="_top" title="'.$fullScreenText.'"> |
||
| 2002 | <span class="fa fa-columns"></span><span class="sr-only">' . $fullScreenText.'</span> |
||
| 2003 | </a> |
||
| 2004 | </span>'; |
||
| 2005 | } else { |
||
| 2006 | $navbar = ' |
||
| 2007 | <span id="'.$idBar.'" class="buttons text-right"> |
||
| 2008 | <a class="icon-toolbar" href="lp_controller.php?action=stats&'.api_get_cidreq(true).'&lp_id='.$lp_id.'" onclick="window.parent.API.save_asset();return true;" target="content_name" title="'.$reportingText.'" id="stats_link"> |
||
| 2009 | <span class="fa fa-info"></span><span class="sr-only">' . $reportingText.'</span> |
||
| 2010 | </a> |
||
| 2011 | <a class="icon-toolbar" id="scorm-previous" href="#" onclick="switch_item(' . $mycurrentitemid.',\'previous\');return false;" title="'.$previousText.'"> |
||
| 2012 | <span class="fa fa-chevron-left"></span><span class="sr-only">' . $previousText.'</span> |
||
| 2013 | </a> |
||
| 2014 | <a class="icon-toolbar" id="scorm-next" href="#" onclick="switch_item(' . $mycurrentitemid.',\'next\');return false;" title="'.$nextText.'"> |
||
| 2015 | <span class="fa fa-chevron-right"></span><span class="sr-only">' . $nextText.'</span> |
||
| 2016 | </a> |
||
| 2017 | </span>'; |
||
| 2018 | } |
||
| 2019 | |||
| 2020 | return $navbar; |
||
| 2021 | } |
||
| 2022 | |||
| 2023 | /** |
||
| 2024 | * Gets the next resource in queue (url). |
||
| 2025 | * @return string URL to load into the viewer |
||
| 2026 | */ |
||
| 2027 | public function get_next_index() |
||
| 2028 | { |
||
| 2029 | if ($this->debug > 0) { |
||
| 2030 | error_log('New LP - In learnpath::get_next_index()', 0); |
||
| 2031 | } |
||
| 2032 | // TODO |
||
| 2033 | $index = $this->index; |
||
| 2034 | $index++; |
||
| 2035 | View Code Duplication | if ($this->debug > 2) { |
|
| 2036 | error_log('New LP - Now looking at ordered_items['.($index).'] - type is '.$this->items[$this->ordered_items[$index]]->type, 0); |
||
| 2037 | } |
||
| 2038 | while (!empty ($this->ordered_items[$index]) AND ($this->items[$this->ordered_items[$index]]->get_type() == 'dir') AND $index < $this->max_ordered_items) { |
||
| 2039 | $index++; |
||
| 2040 | if ($index == $this->max_ordered_items) { |
||
| 2041 | if ($this->items[$this->ordered_items[$index]]->get_type() == 'dir') { |
||
| 2042 | return $this->index; |
||
| 2043 | } else { |
||
| 2044 | return $index; |
||
| 2045 | } |
||
| 2046 | } |
||
| 2047 | } |
||
| 2048 | if (empty ($this->ordered_items[$index])) { |
||
| 2049 | return $this->index; |
||
| 2050 | } |
||
| 2051 | if ($this->debug > 2) { |
||
| 2052 | error_log('New LP - index is now '.$index, 0); |
||
| 2053 | } |
||
| 2054 | return $index; |
||
| 2055 | } |
||
| 2056 | |||
| 2057 | /** |
||
| 2058 | * Gets item_id for the next element |
||
| 2059 | * @return integer Next item (DB) ID |
||
| 2060 | */ |
||
| 2061 | public function get_next_item_id() |
||
| 2062 | { |
||
| 2063 | if ($this->debug > 0) { |
||
| 2064 | error_log('New LP - In learnpath::get_next_item_id()', 0); |
||
| 2065 | } |
||
| 2066 | $new_index = $this->get_next_index(); |
||
| 2067 | if (!empty ($new_index)) { |
||
| 2068 | if (isset ($this->ordered_items[$new_index])) { |
||
| 2069 | if ($this->debug > 2) { |
||
| 2070 | error_log('New LP - In learnpath::get_next_index() - Returning '.$this->ordered_items[$new_index], 0); |
||
| 2071 | } |
||
| 2072 | return $this->ordered_items[$new_index]; |
||
| 2073 | } |
||
| 2074 | } |
||
| 2075 | if ($this->debug > 2) { |
||
| 2076 | error_log('New LP - In learnpath::get_next_index() - Problem - Returning 0', 0); |
||
| 2077 | } |
||
| 2078 | return 0; |
||
| 2079 | } |
||
| 2080 | |||
| 2081 | /** |
||
| 2082 | * Returns the package type ('scorm','aicc','scorm2004','dokeos','ppt'...) |
||
| 2083 | * |
||
| 2084 | * Generally, the package provided is in the form of a zip file, so the function |
||
| 2085 | * has been written to test a zip file. If not a zip, the function will return the |
||
| 2086 | * default return value: '' |
||
| 2087 | * @param string the path to the file |
||
| 2088 | * @param string the original name of the file |
||
| 2089 | * @return string 'scorm','aicc','scorm2004','dokeos' or '' if the package cannot be recognized |
||
| 2090 | */ |
||
| 2091 | public static function get_package_type($file_path, $file_name) |
||
| 2092 | { |
||
| 2093 | // Get name of the zip file without the extension. |
||
| 2094 | $file_info = pathinfo($file_name); |
||
| 2095 | $filename = $file_info['basename']; // Name including extension. |
||
| 2096 | $extension = $file_info['extension']; // Extension only. |
||
| 2097 | |||
| 2098 | if (!empty($_POST['ppt2lp']) && !in_array(strtolower($extension), array( |
||
| 2099 | 'dll', |
||
| 2100 | 'exe' |
||
| 2101 | ))) { |
||
| 2102 | return 'oogie'; |
||
| 2103 | } |
||
| 2104 | if (!empty($_POST['woogie']) && !in_array(strtolower($extension), array( |
||
| 2105 | 'dll', |
||
| 2106 | 'exe' |
||
| 2107 | ))) { |
||
| 2108 | return 'woogie'; |
||
| 2109 | } |
||
| 2110 | |||
| 2111 | $zipFile = new PclZip($file_path); |
||
| 2112 | // Check the zip content (real size and file extension). |
||
| 2113 | $zipContentArray = $zipFile->listContent(); |
||
| 2114 | $package_type = ''; |
||
| 2115 | $at_root = false; |
||
| 2116 | $manifest = ''; |
||
| 2117 | $aicc_match_crs = 0; |
||
| 2118 | $aicc_match_au = 0; |
||
| 2119 | $aicc_match_des = 0; |
||
| 2120 | $aicc_match_cst = 0; |
||
| 2121 | |||
| 2122 | // The following loop should be stopped as soon as we found the right imsmanifest.xml (how to recognize it?). |
||
| 2123 | if (is_array($zipContentArray) && count($zipContentArray) > 0) { |
||
| 2124 | foreach ($zipContentArray as $thisContent) { |
||
| 2125 | if (preg_match('~.(php.*|phtml)$~i', $thisContent['filename'])) { |
||
| 2126 | // New behaviour: Don't do anything. These files will be removed in scorm::import_package. |
||
| 2127 | } elseif (stristr($thisContent['filename'], 'imsmanifest.xml') !== false) { |
||
| 2128 | $manifest = $thisContent['filename']; // Just the relative directory inside scorm/ |
||
| 2129 | $package_type = 'scorm'; |
||
| 2130 | break; // Exit the foreach loop. |
||
| 2131 | } elseif ( |
||
| 2132 | preg_match('/aicc\//i', $thisContent['filename']) || |
||
| 2133 | in_array(strtolower(pathinfo($thisContent['filename'], PATHINFO_EXTENSION)), array('crs', 'au', 'des', 'cst')) |
||
| 2134 | ) { |
||
| 2135 | $ext = strtolower(pathinfo($thisContent['filename'], PATHINFO_EXTENSION)); |
||
| 2136 | switch ($ext) { |
||
| 2137 | case 'crs': |
||
| 2138 | $aicc_match_crs = 1; |
||
| 2139 | break; |
||
| 2140 | case 'au': |
||
| 2141 | $aicc_match_au = 1; |
||
| 2142 | break; |
||
| 2143 | case 'des': |
||
| 2144 | $aicc_match_des = 1; |
||
| 2145 | break; |
||
| 2146 | case 'cst': |
||
| 2147 | $aicc_match_cst = 1; |
||
| 2148 | break; |
||
| 2149 | default: |
||
| 2150 | break; |
||
| 2151 | } |
||
| 2152 | //break; // Don't exit the loop, because if we find an imsmanifest afterwards, we want it, not the AICC. |
||
| 2153 | } else { |
||
| 2154 | $package_type = ''; |
||
| 2155 | } |
||
| 2156 | } |
||
| 2157 | } |
||
| 2158 | if (empty($package_type) && 4 == ($aicc_match_crs + $aicc_match_au + $aicc_match_des + $aicc_match_cst)) { |
||
| 2159 | // If found an aicc directory... (!= false means it cannot be false (error) or 0 (no match)). |
||
| 2160 | $package_type = 'aicc'; |
||
| 2161 | } |
||
| 2162 | return $package_type; |
||
| 2163 | } |
||
| 2164 | |||
| 2165 | /** |
||
| 2166 | * Gets the previous resource in queue (url). Also initialises time values for this viewing |
||
| 2167 | * @return string URL to load into the viewer |
||
| 2168 | */ |
||
| 2169 | public function get_previous_index() |
||
| 2170 | { |
||
| 2171 | if ($this->debug > 0) { |
||
| 2172 | error_log('New LP - In learnpath::get_previous_index()', 0); |
||
| 2173 | } |
||
| 2174 | $index = $this->index; |
||
| 2175 | if (isset ($this->ordered_items[$index - 1])) { |
||
| 2176 | $index--; |
||
| 2177 | while (isset($this->ordered_items[$index]) && ($this->items[$this->ordered_items[$index]]->get_type() == 'dir')) { |
||
| 2178 | $index--; |
||
| 2179 | if ($index < 0) { |
||
| 2180 | return $this->index; |
||
| 2181 | } |
||
| 2182 | } |
||
| 2183 | } else { |
||
| 2184 | if ($this->debug > 2) { |
||
| 2185 | error_log('New LP - get_previous_index() - there was no previous index available, reusing '.$index, 0); |
||
| 2186 | } |
||
| 2187 | // There is no previous item. |
||
| 2188 | } |
||
| 2189 | return $index; |
||
| 2190 | } |
||
| 2191 | |||
| 2192 | /** |
||
| 2193 | * Gets item_id for the next element |
||
| 2194 | * @return integer Previous item (DB) ID |
||
| 2195 | */ |
||
| 2196 | public function get_previous_item_id() |
||
| 2197 | { |
||
| 2198 | if ($this->debug > 0) { |
||
| 2199 | error_log('New LP - In learnpath::get_previous_item_id()', 0); |
||
| 2200 | } |
||
| 2201 | $new_index = $this->get_previous_index(); |
||
| 2202 | return $this->ordered_items[$new_index]; |
||
| 2203 | } |
||
| 2204 | |||
| 2205 | /** |
||
| 2206 | * Gets the progress value from the progress_db attribute |
||
| 2207 | * @return integer Current progress value |
||
| 2208 | * @deprecated This method does not seem to be used as of 20170514 |
||
| 2209 | */ |
||
| 2210 | public function get_progress() |
||
| 2211 | { |
||
| 2212 | if ($this->debug > 0) { |
||
| 2213 | error_log('New LP - In learnpath::get_progress()', 0); |
||
| 2214 | } |
||
| 2215 | if (!empty ($this->progress_db)) { |
||
| 2216 | return $this->progress_db; |
||
| 2217 | } |
||
| 2218 | return 0; |
||
| 2219 | } |
||
| 2220 | |||
| 2221 | /** |
||
| 2222 | * Returns the HTML necessary to print a mediaplayer block inside a page |
||
| 2223 | * @return string The mediaplayer HTML |
||
| 2224 | */ |
||
| 2225 | public function get_mediaplayer($lpItemId, $autostart = 'true') |
||
| 2226 | { |
||
| 2227 | $course_id = api_get_course_int_id(); |
||
| 2228 | $_course = api_get_course_info(); |
||
| 2229 | if (empty($_course)) { |
||
| 2230 | return ''; |
||
| 2231 | } |
||
| 2232 | $tbl_lp_item = Database::get_course_table(TABLE_LP_ITEM); |
||
| 2233 | $tbl_lp_item_view = Database::get_course_table(TABLE_LP_ITEM_VIEW); |
||
| 2234 | |||
| 2235 | // Getting all the information about the item. |
||
| 2236 | $sql = "SELECT * FROM $tbl_lp_item as lp |
||
| 2237 | INNER JOIN $tbl_lp_item_view as lp_view |
||
| 2238 | ON (lp.id = lp_view.lp_item_id AND lp.c_id = lp_view.c_id) |
||
| 2239 | WHERE |
||
| 2240 | lp.id = '$lpItemId' AND |
||
| 2241 | lp.c_id = $course_id AND |
||
| 2242 | lp_view.c_id = $course_id"; |
||
| 2243 | $result = Database::query($sql); |
||
| 2244 | $row = Database::fetch_assoc($result); |
||
| 2245 | $output = ''; |
||
| 2246 | |||
| 2247 | if (!empty ($row['audio'])) { |
||
| 2248 | $list = $_SESSION['oLP']->get_toc(); |
||
| 2249 | $type_quiz = false; |
||
| 2250 | |||
| 2251 | foreach ($list as $toc) { |
||
| 2252 | if ($toc['id'] == $_SESSION['oLP']->current && ($toc['type'] == 'quiz')) { |
||
| 2253 | $type_quiz = true; |
||
| 2254 | } |
||
| 2255 | } |
||
| 2256 | |||
| 2257 | if ($type_quiz) { |
||
| 2258 | if ($_SESSION['oLP']->prevent_reinit == 1) { |
||
| 2259 | $autostart_audio = $row['status'] === 'completed' ? 'false' : 'true'; |
||
| 2260 | } else { |
||
| 2261 | $autostart_audio = $autostart; |
||
| 2262 | } |
||
| 2263 | } else { |
||
| 2264 | $autostart_audio = 'true'; |
||
| 2265 | } |
||
| 2266 | |||
| 2267 | $courseInfo = api_get_course_info(); |
||
| 2268 | $audio = $row['audio']; |
||
| 2269 | |||
| 2270 | $file = api_get_path(SYS_COURSE_PATH).$courseInfo['path'].'/document/audio/'.$audio; |
||
| 2271 | $url = api_get_path(WEB_COURSE_PATH).$courseInfo['path'].'/document/audio/'.$audio.'?'.api_get_cidreq(); |
||
| 2272 | |||
| 2273 | if (!file_exists($file)) { |
||
| 2274 | $lpPathInfo = $_SESSION['oLP']->generate_lp_folder(api_get_course_info()); |
||
| 2275 | $file = api_get_path(SYS_COURSE_PATH).$_course['path'].'/document'.$lpPathInfo['dir'].$audio; |
||
| 2276 | $url = api_get_path(WEB_COURSE_PATH).$_course['path'].'/document'.$lpPathInfo['dir'].$audio.'?'.api_get_cidreq(); |
||
| 2277 | } |
||
| 2278 | |||
| 2279 | $player = Display::getMediaPlayer( |
||
| 2280 | $file, |
||
| 2281 | array( |
||
| 2282 | 'id' => 'lp_audio_media_player', |
||
| 2283 | 'url' => $url, |
||
| 2284 | 'autoplay' => $autostart_audio, |
||
| 2285 | 'width' => '100%' |
||
| 2286 | ) |
||
| 2287 | ); |
||
| 2288 | |||
| 2289 | // The mp3 player. |
||
| 2290 | $output = '<div id="container">'; |
||
| 2291 | $output .= $player; |
||
| 2292 | $output .= '</div>'; |
||
| 2293 | } |
||
| 2294 | |||
| 2295 | return $output; |
||
| 2296 | } |
||
| 2297 | |||
| 2298 | /** |
||
| 2299 | * @param int $studentId |
||
| 2300 | * @param int $prerequisite |
||
| 2301 | * @param array $courseInfo |
||
| 2302 | * @return bool |
||
| 2303 | * |
||
| 2304 | */ |
||
| 2305 | public static function isBlockedByPrerequisite( |
||
| 2306 | $studentId, |
||
| 2307 | $prerequisite, |
||
| 2308 | $courseInfo, |
||
| 2309 | $sessionId |
||
| 2310 | ) { |
||
| 2311 | $isBlocked = false; |
||
| 2312 | |||
| 2313 | if (!empty($prerequisite)) { |
||
| 2314 | $progress = self::getProgress( |
||
| 2315 | $prerequisite, |
||
| 2316 | $studentId, |
||
| 2317 | $courseInfo['real_id'], |
||
| 2318 | $sessionId |
||
| 2319 | ); |
||
| 2320 | if ($progress < 100) { |
||
| 2321 | $isBlocked = true; |
||
| 2322 | } |
||
| 2323 | } |
||
| 2324 | |||
| 2325 | return $isBlocked; |
||
| 2326 | } |
||
| 2327 | |||
| 2328 | /** |
||
| 2329 | * Checks if the learning path is visible for student after the progress |
||
| 2330 | * of its prerequisite is completed, considering the time availability and |
||
| 2331 | * the LP visibility. |
||
| 2332 | * @param int $lp_id |
||
| 2333 | * @param int $student_id |
||
| 2334 | * @param string Course code (optional) |
||
| 2335 | * @param int $sessionId |
||
| 2336 | * @return bool |
||
| 2337 | */ |
||
| 2338 | public static function is_lp_visible_for_student( |
||
| 2339 | $lp_id, |
||
| 2340 | $student_id, |
||
| 2341 | $courseCode = null, |
||
| 2342 | $sessionId = 0 |
||
| 2343 | ) { |
||
| 2344 | $courseInfo = api_get_course_info($courseCode); |
||
| 2345 | $lp_id = (int) $lp_id; |
||
| 2346 | $sessionId = (int) $sessionId; |
||
| 2347 | |||
| 2348 | if (empty($sessionId)) { |
||
| 2349 | $sessionId = api_get_session_id(); |
||
| 2350 | } |
||
| 2351 | |||
| 2352 | if (empty($courseInfo)) { |
||
| 2353 | return false; |
||
| 2354 | } |
||
| 2355 | |||
| 2356 | $itemInfo = api_get_item_property_info( |
||
| 2357 | $courseInfo['real_id'], |
||
| 2358 | TOOL_LEARNPATH, |
||
| 2359 | $lp_id, |
||
| 2360 | $sessionId |
||
| 2361 | ); |
||
| 2362 | |||
| 2363 | // If the item was deleted. |
||
| 2364 | if (isset($itemInfo['visibility']) && $itemInfo['visibility'] == 2) { |
||
| 2365 | return false; |
||
| 2366 | } |
||
| 2367 | |||
| 2368 | // @todo remove this query and load the row info as a parameter |
||
| 2369 | $tbl_learnpath = Database::get_course_table(TABLE_LP_MAIN); |
||
| 2370 | // Get current prerequisite |
||
| 2371 | $sql = "SELECT id, prerequisite, subscribe_users, publicated_on, expired_on |
||
| 2372 | FROM $tbl_learnpath |
||
| 2373 | WHERE c_id = ".$courseInfo['real_id']." AND id = $lp_id"; |
||
| 2374 | |||
| 2375 | $rs = Database::query($sql); |
||
| 2376 | $now = time(); |
||
| 2377 | if (Database::num_rows($rs) > 0) { |
||
| 2378 | $row = Database::fetch_array($rs, 'ASSOC'); |
||
| 2379 | $prerequisite = $row['prerequisite']; |
||
| 2380 | $is_visible = true; |
||
| 2381 | |||
| 2382 | $isBlocked = self::isBlockedByPrerequisite( |
||
| 2383 | $student_id, |
||
| 2384 | $prerequisite, |
||
| 2385 | $courseInfo, |
||
| 2386 | $sessionId |
||
| 2387 | ); |
||
| 2388 | |||
| 2389 | if ($isBlocked) { |
||
| 2390 | $is_visible = false; |
||
| 2391 | } |
||
| 2392 | |||
| 2393 | // Also check the time availability of the LP |
||
| 2394 | if ($is_visible) { |
||
| 2395 | // Adding visibility restrictions |
||
| 2396 | if (!empty($row['publicated_on'])) { |
||
| 2397 | if ($now < api_strtotime($row['publicated_on'], 'UTC')) { |
||
| 2398 | $is_visible = false; |
||
| 2399 | } |
||
| 2400 | } |
||
| 2401 | |||
| 2402 | // Blocking empty start times see BT#2800 |
||
| 2403 | global $_custom; |
||
| 2404 | if (isset($_custom['lps_hidden_when_no_start_date']) && |
||
| 2405 | $_custom['lps_hidden_when_no_start_date'] |
||
| 2406 | ) { |
||
| 2407 | if (empty($row['publicated_on'])) { |
||
| 2408 | $is_visible = false; |
||
| 2409 | } |
||
| 2410 | } |
||
| 2411 | |||
| 2412 | if (!empty($row['expired_on'])) { |
||
| 2413 | if ($now > api_strtotime($row['expired_on'], 'UTC')) { |
||
| 2414 | $is_visible = false; |
||
| 2415 | } |
||
| 2416 | } |
||
| 2417 | } |
||
| 2418 | |||
| 2419 | // Check if the subscription users/group to a LP is ON |
||
| 2420 | if (isset($row['subscribe_users']) && $row['subscribe_users'] == 1) { |
||
| 2421 | // Try group |
||
| 2422 | $is_visible = false; |
||
| 2423 | |||
| 2424 | // Checking only the user visibility |
||
| 2425 | $userVisibility = api_get_item_visibility( |
||
| 2426 | $courseInfo, |
||
| 2427 | 'learnpath', |
||
| 2428 | $row['id'], |
||
| 2429 | $sessionId, |
||
| 2430 | $student_id, |
||
| 2431 | 'LearnpathSubscription' |
||
| 2432 | ); |
||
| 2433 | |||
| 2434 | if ($userVisibility == 1) { |
||
| 2435 | $is_visible = true; |
||
| 2436 | } else { |
||
| 2437 | $userGroups = GroupManager::getAllGroupPerUserSubscription($student_id); |
||
| 2438 | if (!empty($userGroups)) { |
||
| 2439 | foreach ($userGroups as $groupInfo) { |
||
| 2440 | $groupId = $groupInfo['iid']; |
||
| 2441 | $userVisibility = api_get_item_visibility( |
||
| 2442 | $courseInfo, |
||
| 2443 | 'learnpath', |
||
| 2444 | $row['id'], |
||
| 2445 | $sessionId, |
||
| 2446 | null, |
||
| 2447 | 'LearnpathSubscription', |
||
| 2448 | $groupId |
||
| 2449 | ); |
||
| 2450 | |||
| 2451 | if ($userVisibility == 1) { |
||
| 2452 | $is_visible = true; |
||
| 2453 | break; |
||
| 2454 | } |
||
| 2455 | } |
||
| 2456 | } |
||
| 2457 | } |
||
| 2458 | } |
||
| 2459 | |||
| 2460 | return $is_visible; |
||
| 2461 | } |
||
| 2462 | |||
| 2463 | return false; |
||
| 2464 | } |
||
| 2465 | |||
| 2466 | /** |
||
| 2467 | * @param int $lpId |
||
| 2468 | * @param int $userId |
||
| 2469 | * @param int $courseId |
||
| 2470 | * @param int $sessionId |
||
| 2471 | * @return int |
||
| 2472 | */ |
||
| 2473 | public static function getProgress($lpId, $userId, $courseId, $sessionId = 0) |
||
| 2474 | { |
||
| 2475 | $lpId = intval($lpId); |
||
| 2476 | $userId = intval($userId); |
||
| 2477 | $courseId = intval($courseId); |
||
| 2478 | $sessionId = intval($sessionId); |
||
| 2479 | $progress = 0; |
||
| 2480 | |||
| 2481 | $sessionCondition = api_get_session_condition($sessionId); |
||
| 2482 | $table = Database::get_course_table(TABLE_LP_VIEW); |
||
| 2483 | $sql = "SELECT * FROM $table |
||
| 2484 | WHERE |
||
| 2485 | c_id = ".$courseId." AND |
||
| 2486 | lp_id = $lpId AND |
||
| 2487 | user_id = $userId $sessionCondition"; |
||
| 2488 | $res = Database::query($sql); |
||
| 2489 | if (Database::num_rows($res) > 0) { |
||
| 2490 | $row = Database:: fetch_array($res); |
||
| 2491 | $progress = $row['progress']; |
||
| 2492 | } |
||
| 2493 | |||
| 2494 | return (int) $progress; |
||
| 2495 | } |
||
| 2496 | |||
| 2497 | /** |
||
| 2498 | * Displays a progress bar |
||
| 2499 | * completed so far. |
||
| 2500 | * @param integer $percentage Progress value to display |
||
| 2501 | * @param string $text_add Text to display near the progress value |
||
| 2502 | * @return string HTML string containing the progress bar |
||
| 2503 | */ |
||
| 2504 | public static function get_progress_bar($percentage = -1, $text_add = '') |
||
| 2505 | { |
||
| 2506 | $text = $percentage.$text_add; |
||
| 2507 | $output = '<div class="progress"> |
||
| 2508 | <div id="progress_bar_value" class="progress-bar progress-bar-success" role="progressbar" aria-valuenow="' .$percentage.'" aria-valuemin="0" aria-valuemax="100" style="width: '.$text.';"> |
||
| 2509 | '. $text.' |
||
| 2510 | </div> |
||
| 2511 | </div>'; |
||
| 2512 | |||
| 2513 | return $output; |
||
| 2514 | } |
||
| 2515 | |||
| 2516 | /** |
||
| 2517 | * @param string $mode can be '%' or 'abs' |
||
| 2518 | * otherwise this value will be used $this->progress_bar_mode |
||
| 2519 | * @return string |
||
| 2520 | */ |
||
| 2521 | public function getProgressBar($mode = null) |
||
| 2522 | { |
||
| 2523 | list($percentage, $text_add) = $this->get_progress_bar_text($mode); |
||
| 2524 | return self::get_progress_bar($percentage, $text_add); |
||
| 2525 | } |
||
| 2526 | |||
| 2527 | /** |
||
| 2528 | * Gets the progress bar info to display inside the progress bar. |
||
| 2529 | * Also used by scorm_api.php |
||
| 2530 | * @param string $mode Mode of display (can be '%' or 'abs').abs means |
||
| 2531 | * we display a number of completed elements per total elements |
||
| 2532 | * @param integer $add Additional steps to fake as completed |
||
| 2533 | * @return list array Percentage or number and symbol (% or /xx) |
||
| 2534 | */ |
||
| 2535 | public function get_progress_bar_text($mode = '', $add = 0) |
||
| 2536 | { |
||
| 2537 | if ($this->debug > 0) { |
||
| 2538 | error_log('New LP - In learnpath::get_progress_bar_text()', 0); |
||
| 2539 | } |
||
| 2540 | if (empty($mode)) { |
||
| 2541 | $mode = $this->progress_bar_mode; |
||
| 2542 | } |
||
| 2543 | $total_items = $this->getTotalItemsCountWithoutDirs(); |
||
| 2544 | if ($this->debug > 2) { |
||
| 2545 | error_log('New LP - Total items available in this learnpath: '.$total_items, 0); |
||
| 2546 | } |
||
| 2547 | $completeItems = $this->get_complete_items_count(); |
||
| 2548 | if ($this->debug > 2) { |
||
| 2549 | error_log('New LP - Items completed so far: '.$completeItems, 0); |
||
| 2550 | } |
||
| 2551 | if ($add != 0) { |
||
| 2552 | $completeItems += $add; |
||
| 2553 | if ($this->debug > 2) { |
||
| 2554 | error_log('New LP - Items completed so far (+modifier): '.$completeItems, 0); |
||
| 2555 | } |
||
| 2556 | } |
||
| 2557 | $text = ''; |
||
| 2558 | if ($completeItems > $total_items) { |
||
| 2559 | $completeItems = $total_items; |
||
| 2560 | } |
||
| 2561 | $percentage = 0; |
||
| 2562 | if ($mode == '%') { |
||
| 2563 | if ($total_items > 0) { |
||
| 2564 | $percentage = ((float) $completeItems / (float) $total_items) * 100; |
||
| 2565 | } else { |
||
| 2566 | $percentage = 0; |
||
| 2567 | } |
||
| 2568 | $percentage = number_format($percentage, 0); |
||
| 2569 | $text = '%'; |
||
| 2570 | } elseif ($mode == 'abs') { |
||
| 2571 | $percentage = $completeItems; |
||
| 2572 | $text = '/'.$total_items; |
||
| 2573 | } |
||
| 2574 | |||
| 2575 | return array( |
||
| 2576 | $percentage, |
||
| 2577 | $text |
||
| 2578 | ); |
||
| 2579 | } |
||
| 2580 | |||
| 2581 | /** |
||
| 2582 | * Gets the progress bar mode |
||
| 2583 | * @return string The progress bar mode attribute |
||
| 2584 | */ |
||
| 2585 | public function get_progress_bar_mode() |
||
| 2586 | { |
||
| 2587 | if ($this->debug > 0) { |
||
| 2588 | error_log('New LP - In learnpath::get_progress_bar_mode()', 0); |
||
| 2589 | } |
||
| 2590 | if (!empty ($this->progress_bar_mode)) { |
||
| 2591 | return $this->progress_bar_mode; |
||
| 2592 | } else { |
||
| 2593 | return '%'; |
||
| 2594 | } |
||
| 2595 | } |
||
| 2596 | |||
| 2597 | /** |
||
| 2598 | * Gets the learnpath proximity (remote or local) |
||
| 2599 | * @return string Learnpath proximity |
||
| 2600 | */ |
||
| 2601 | public function get_proximity() |
||
| 2602 | { |
||
| 2603 | if ($this->debug > 0) { |
||
| 2604 | error_log('New LP - In learnpath::get_proximity()', 0); |
||
| 2605 | } |
||
| 2606 | if (!empty ($this->proximity)) { |
||
| 2607 | return $this->proximity; |
||
| 2608 | } else { |
||
| 2609 | return ''; |
||
| 2610 | } |
||
| 2611 | } |
||
| 2612 | |||
| 2613 | /** |
||
| 2614 | * Gets the learnpath theme (remote or local) |
||
| 2615 | * @return string Learnpath theme |
||
| 2616 | */ |
||
| 2617 | public function get_theme() |
||
| 2618 | { |
||
| 2619 | if ($this->debug > 0) { |
||
| 2620 | error_log('New LP - In learnpath::get_theme()', 0); |
||
| 2621 | } |
||
| 2622 | if (!empty ($this->theme)) { |
||
| 2623 | return $this->theme; |
||
| 2624 | } else { |
||
| 2625 | return ''; |
||
| 2626 | } |
||
| 2627 | } |
||
| 2628 | |||
| 2629 | /** |
||
| 2630 | * Gets the learnpath session id |
||
| 2631 | * @return int |
||
| 2632 | */ |
||
| 2633 | View Code Duplication | public function get_lp_session_id() |
|
| 2634 | { |
||
| 2635 | if ($this->debug > 0) { |
||
| 2636 | error_log('New LP - In learnpath::get_lp_session_id()', 0); |
||
| 2637 | } |
||
| 2638 | if (!empty ($this->lp_session_id)) { |
||
| 2639 | return (int) $this->lp_session_id; |
||
| 2640 | } else { |
||
| 2641 | return 0; |
||
| 2642 | } |
||
| 2643 | } |
||
| 2644 | |||
| 2645 | /** |
||
| 2646 | * Gets the learnpath image |
||
| 2647 | * @return string Web URL of the LP image |
||
| 2648 | */ |
||
| 2649 | public function get_preview_image() |
||
| 2650 | { |
||
| 2651 | if ($this->debug > 0) { |
||
| 2652 | error_log('New LP - In learnpath::get_preview_image()', 0); |
||
| 2653 | } |
||
| 2654 | if (!empty($this->preview_image)) { |
||
| 2655 | return $this->preview_image; |
||
| 2656 | } else { |
||
| 2657 | return ''; |
||
| 2658 | } |
||
| 2659 | } |
||
| 2660 | |||
| 2661 | /** |
||
| 2662 | * @param string $size |
||
| 2663 | * @param string $path_type |
||
| 2664 | * @return bool|string |
||
| 2665 | */ |
||
| 2666 | public function get_preview_image_path($size = null, $path_type = 'web') |
||
| 2667 | { |
||
| 2668 | $preview_image = $this->get_preview_image(); |
||
| 2669 | if (isset($preview_image) && !empty($preview_image)) { |
||
| 2670 | $image_sys_path = api_get_path(SYS_COURSE_PATH).$this->course_info['path'].'/upload/learning_path/images/'; |
||
| 2671 | $image_path = api_get_path(WEB_COURSE_PATH).$this->course_info['path'].'/upload/learning_path/images/'; |
||
| 2672 | |||
| 2673 | if (isset($size)) { |
||
| 2674 | $info = pathinfo($preview_image); |
||
| 2675 | $image_custom_size = $info['filename'].'.'.$size.'.'.$info['extension']; |
||
| 2676 | |||
| 2677 | if (file_exists($image_sys_path.$image_custom_size)) { |
||
| 2678 | if ($path_type == 'web') { |
||
| 2679 | return $image_path.$image_custom_size; |
||
| 2680 | } else { |
||
| 2681 | return $image_sys_path.$image_custom_size; |
||
| 2682 | } |
||
| 2683 | } |
||
| 2684 | } else { |
||
| 2685 | if ($path_type == 'web') { |
||
| 2686 | return $image_path.$preview_image; |
||
| 2687 | } else { |
||
| 2688 | return $image_sys_path.$preview_image; |
||
| 2689 | } |
||
| 2690 | } |
||
| 2691 | } |
||
| 2692 | |||
| 2693 | return false; |
||
| 2694 | } |
||
| 2695 | |||
| 2696 | /** |
||
| 2697 | * Gets the learnpath author |
||
| 2698 | * @return string LP's author |
||
| 2699 | */ |
||
| 2700 | public function get_author() |
||
| 2701 | { |
||
| 2702 | if ($this->debug > 0) { |
||
| 2703 | error_log('New LP - In learnpath::get_author()', 0); |
||
| 2704 | } |
||
| 2705 | if (!empty ($this->author)) { |
||
| 2706 | return $this->author; |
||
| 2707 | } else { |
||
| 2708 | return ''; |
||
| 2709 | } |
||
| 2710 | } |
||
| 2711 | |||
| 2712 | /** |
||
| 2713 | * Gets the learnpath author |
||
| 2714 | * @return string LP's author |
||
| 2715 | */ |
||
| 2716 | public function get_hide_toc_frame() |
||
| 2717 | { |
||
| 2718 | if ($this->debug > 0) { |
||
| 2719 | error_log('New LP - In learnpath::get_author()', 0); |
||
| 2720 | } |
||
| 2721 | if (!empty ($this->hide_toc_frame)) { |
||
| 2722 | return $this->hide_toc_frame; |
||
| 2723 | } else { |
||
| 2724 | return ''; |
||
| 2725 | } |
||
| 2726 | } |
||
| 2727 | |||
| 2728 | /** |
||
| 2729 | * Generate a new prerequisites string for a given item. If this item was a sco and |
||
| 2730 | * its prerequisites were strings (instead of IDs), then transform those strings into |
||
| 2731 | * IDs, knowing that SCORM IDs are kept in the "ref" field of the lp_item table. |
||
| 2732 | * Prefix all item IDs that end-up in the prerequisites string by "ITEM_" to use the |
||
| 2733 | * same rule as the scorm_export() method |
||
| 2734 | * @param integer Item ID |
||
| 2735 | * @return string Prerequisites string ready for the export as SCORM |
||
| 2736 | */ |
||
| 2737 | public function get_scorm_prereq_string($item_id) |
||
| 2738 | { |
||
| 2739 | if ($this->debug > 0) { |
||
| 2740 | error_log('New LP - In learnpath::get_scorm_prereq_string()', 0); |
||
| 2741 | } |
||
| 2742 | if (!is_object($this->items[$item_id])) { |
||
| 2743 | return false; |
||
| 2744 | } |
||
| 2745 | /** @var learnpathItem $oItem */ |
||
| 2746 | $oItem = $this->items[$item_id]; |
||
| 2747 | $prereq = $oItem->get_prereq_string(); |
||
| 2748 | |||
| 2749 | if (empty($prereq)) { |
||
| 2750 | return ''; |
||
| 2751 | } |
||
| 2752 | if (preg_match('/^\d+$/', $prereq) && is_object($this->items[$prereq])) { |
||
| 2753 | // If the prerequisite is a simple integer ID and this ID exists as an item ID, |
||
| 2754 | // then simply return it (with the ITEM_ prefix). |
||
| 2755 | //return 'ITEM_' . $prereq; |
||
| 2756 | return $this->items[$prereq]->ref; |
||
| 2757 | } else { |
||
| 2758 | if (isset($this->refs_list[$prereq])) { |
||
| 2759 | // It's a simple string item from which the ID can be found in the refs list, |
||
| 2760 | // so we can transform it directly to an ID for export. |
||
| 2761 | return $this->items[$this->refs_list[$prereq]]->ref; |
||
| 2762 | } elseif (isset($this->refs_list['ITEM_'.$prereq])) { |
||
| 2763 | return $this->items[$this->refs_list['ITEM_'.$prereq]]->ref; |
||
| 2764 | } else { |
||
| 2765 | // The last case, if it's a complex form, then find all the IDs (SCORM strings) |
||
| 2766 | // and replace them, one by one, by the internal IDs (chamilo db) |
||
| 2767 | // TODO: Modify the '*' replacement to replace the multiplier in front of it |
||
| 2768 | // by a space as well. |
||
| 2769 | $find = array( |
||
| 2770 | '&', |
||
| 2771 | '|', |
||
| 2772 | '~', |
||
| 2773 | '=', |
||
| 2774 | '<>', |
||
| 2775 | '{', |
||
| 2776 | '}', |
||
| 2777 | '*', |
||
| 2778 | '(', |
||
| 2779 | ')' |
||
| 2780 | ); |
||
| 2781 | $replace = array( |
||
| 2782 | ' ', |
||
| 2783 | ' ', |
||
| 2784 | ' ', |
||
| 2785 | ' ', |
||
| 2786 | ' ', |
||
| 2787 | ' ', |
||
| 2788 | ' ', |
||
| 2789 | ' ', |
||
| 2790 | ' ', |
||
| 2791 | ' ' |
||
| 2792 | ); |
||
| 2793 | $prereq_mod = str_replace($find, $replace, $prereq); |
||
| 2794 | $ids = explode(' ', $prereq_mod); |
||
| 2795 | foreach ($ids as $id) { |
||
| 2796 | $id = trim($id); |
||
| 2797 | if (isset ($this->refs_list[$id])) { |
||
| 2798 | $prereq = preg_replace('/[^a-zA-Z_0-9]('.$id.')[^a-zA-Z_0-9]/', 'ITEM_'.$this->refs_list[$id], $prereq); |
||
| 2799 | } |
||
| 2800 | } |
||
| 2801 | |||
| 2802 | return $prereq; |
||
| 2803 | } |
||
| 2804 | } |
||
| 2805 | } |
||
| 2806 | |||
| 2807 | /** |
||
| 2808 | * Returns the XML DOM document's node |
||
| 2809 | * @param resource Reference to a list of objects to search for the given ITEM_* |
||
| 2810 | * @param string The identifier to look for |
||
| 2811 | * @return mixed The reference to the element found with that identifier. False if not found |
||
| 2812 | */ |
||
| 2813 | public function get_scorm_xml_node(& $children, $id) |
||
| 2814 | { |
||
| 2815 | for ($i = 0; $i < $children->length; $i++) { |
||
| 2816 | $item_temp = $children->item($i); |
||
| 2817 | if ($item_temp->nodeName == 'item') { |
||
| 2818 | if ($item_temp->getAttribute('identifier') == $id) { |
||
| 2819 | return $item_temp; |
||
| 2820 | } |
||
| 2821 | } |
||
| 2822 | $subchildren = $item_temp->childNodes; |
||
| 2823 | if ($subchildren && $subchildren->length > 0) { |
||
| 2824 | $val = $this->get_scorm_xml_node($subchildren, $id); |
||
| 2825 | if (is_object($val)) { |
||
| 2826 | |||
| 2827 | return $val; |
||
| 2828 | } |
||
| 2829 | } |
||
| 2830 | } |
||
| 2831 | |||
| 2832 | return false; |
||
| 2833 | } |
||
| 2834 | |||
| 2835 | /** |
||
| 2836 | * Gets the status list for all LP's items |
||
| 2837 | * @return array Array of [index] => [item ID => current status] |
||
| 2838 | */ |
||
| 2839 | public function get_items_status_list() |
||
| 2840 | { |
||
| 2841 | if ($this->debug > 0) { |
||
| 2842 | error_log('New LP - In learnpath::get_items_status_list()', 0); |
||
| 2843 | } |
||
| 2844 | $list = array(); |
||
| 2845 | foreach ($this->ordered_items as $item_id) { |
||
| 2846 | $list[] = array( |
||
| 2847 | $item_id => $this->items[$item_id]->get_status() |
||
| 2848 | ); |
||
| 2849 | } |
||
| 2850 | return $list; |
||
| 2851 | } |
||
| 2852 | |||
| 2853 | /** |
||
| 2854 | * Return the number of interactions for the given learnpath Item View ID. |
||
| 2855 | * This method can be used as static. |
||
| 2856 | * @param integer Item View ID |
||
| 2857 | * @param integer course id |
||
| 2858 | * @return integer Number of interactions |
||
| 2859 | */ |
||
| 2860 | View Code Duplication | public static function get_interactions_count_from_db($lp_iv_id, $course_id) |
|
| 2861 | { |
||
| 2862 | $table = Database::get_course_table(TABLE_LP_IV_INTERACTION); |
||
| 2863 | $lp_iv_id = intval($lp_iv_id); |
||
| 2864 | $course_id = intval($course_id); |
||
| 2865 | |||
| 2866 | $sql = "SELECT count(*) FROM $table |
||
| 2867 | WHERE c_id = $course_id AND lp_iv_id = $lp_iv_id"; |
||
| 2868 | $res = Database::query($sql); |
||
| 2869 | $num = 0; |
||
| 2870 | if (Database::num_rows($res)) { |
||
| 2871 | $row = Database::fetch_array($res); |
||
| 2872 | $num = $row[0]; |
||
| 2873 | } |
||
| 2874 | return $num; |
||
| 2875 | } |
||
| 2876 | |||
| 2877 | /** |
||
| 2878 | * Return the interactions as an array for the given lp_iv_id. |
||
| 2879 | * This method can be used as static. |
||
| 2880 | * @param integer Learnpath Item View ID |
||
| 2881 | * @return array |
||
| 2882 | * @todo Transcode labels instead of switching to HTML (which requires to know the encoding of the LP) |
||
| 2883 | */ |
||
| 2884 | public static function get_iv_interactions_array($lp_iv_id) |
||
| 2885 | { |
||
| 2886 | $course_id = api_get_course_int_id(); |
||
| 2887 | $list = array(); |
||
| 2888 | $table = Database::get_course_table(TABLE_LP_IV_INTERACTION); |
||
| 2889 | |||
| 2890 | if (empty($lp_iv_id)) { |
||
| 2891 | return array(); |
||
| 2892 | } |
||
| 2893 | |||
| 2894 | $sql = "SELECT * FROM $table |
||
| 2895 | WHERE c_id = ".$course_id." AND lp_iv_id = $lp_iv_id |
||
| 2896 | ORDER BY order_id ASC"; |
||
| 2897 | $res = Database::query($sql); |
||
| 2898 | $num = Database::num_rows($res); |
||
| 2899 | if ($num > 0) { |
||
| 2900 | $list[] = array( |
||
| 2901 | 'order_id' => api_htmlentities(get_lang('Order'), ENT_QUOTES), |
||
| 2902 | 'id' => api_htmlentities(get_lang('InteractionID'), ENT_QUOTES), |
||
| 2903 | 'type' => api_htmlentities(get_lang('Type'), ENT_QUOTES), |
||
| 2904 | 'time' => api_htmlentities(get_lang('TimeFinished'), ENT_QUOTES), |
||
| 2905 | 'correct_responses' => api_htmlentities(get_lang('CorrectAnswers'), ENT_QUOTES), |
||
| 2906 | 'student_response' => api_htmlentities(get_lang('StudentResponse'), ENT_QUOTES), |
||
| 2907 | 'result' => api_htmlentities(get_lang('Result'), ENT_QUOTES), |
||
| 2908 | 'latency' => api_htmlentities(get_lang('LatencyTimeSpent'), ENT_QUOTES) |
||
| 2909 | ); |
||
| 2910 | while ($row = Database::fetch_array($res)) { |
||
| 2911 | $list[] = array( |
||
| 2912 | 'order_id' => ($row['order_id'] + 1), |
||
| 2913 | 'id' => urldecode($row['interaction_id']), //urldecode because they often have %2F or stuff like that |
||
| 2914 | 'type' => $row['interaction_type'], |
||
| 2915 | 'time' => $row['completion_time'], |
||
| 2916 | //'correct_responses' => $row['correct_responses'], |
||
| 2917 | 'correct_responses' => '', // Hide correct responses from students. |
||
| 2918 | 'student_response' => $row['student_response'], |
||
| 2919 | 'result' => $row['result'], |
||
| 2920 | 'latency' => $row['latency'] |
||
| 2921 | ); |
||
| 2922 | } |
||
| 2923 | } |
||
| 2924 | |||
| 2925 | return $list; |
||
| 2926 | } |
||
| 2927 | |||
| 2928 | /** |
||
| 2929 | * Return the number of objectives for the given learnpath Item View ID. |
||
| 2930 | * This method can be used as static. |
||
| 2931 | * @param integer Item View ID |
||
| 2932 | * @return integer Number of objectives |
||
| 2933 | */ |
||
| 2934 | View Code Duplication | public static function get_objectives_count_from_db($lp_iv_id, $course_id) |
|
| 2935 | { |
||
| 2936 | $table = Database::get_course_table(TABLE_LP_IV_OBJECTIVE); |
||
| 2937 | $course_id = intval($course_id); |
||
| 2938 | $lp_iv_id = intval($lp_iv_id); |
||
| 2939 | $sql = "SELECT count(*) FROM $table |
||
| 2940 | WHERE c_id = $course_id AND lp_iv_id = $lp_iv_id"; |
||
| 2941 | //@todo seems that this always returns 0 |
||
| 2942 | $res = Database::query($sql); |
||
| 2943 | $num = 0; |
||
| 2944 | if (Database::num_rows($res)) { |
||
| 2945 | $row = Database::fetch_array($res); |
||
| 2946 | $num = $row[0]; |
||
| 2947 | } |
||
| 2948 | |||
| 2949 | return $num; |
||
| 2950 | } |
||
| 2951 | |||
| 2952 | /** |
||
| 2953 | * Return the objectives as an array for the given lp_iv_id. |
||
| 2954 | * This method can be used as static. |
||
| 2955 | * @param integer Learnpath Item View ID |
||
| 2956 | * @return array |
||
| 2957 | * @todo Translate labels |
||
| 2958 | */ |
||
| 2959 | public static function get_iv_objectives_array($lp_iv_id = 0) |
||
| 2960 | { |
||
| 2961 | $course_id = api_get_course_int_id(); |
||
| 2962 | $table = Database::get_course_table(TABLE_LP_IV_OBJECTIVE); |
||
| 2963 | $sql = "SELECT * FROM $table |
||
| 2964 | WHERE c_id = $course_id AND lp_iv_id = $lp_iv_id |
||
| 2965 | ORDER BY order_id ASC"; |
||
| 2966 | $res = Database::query($sql); |
||
| 2967 | $num = Database::num_rows($res); |
||
| 2968 | $list = array(); |
||
| 2969 | if ($num > 0) { |
||
| 2970 | $list[] = array( |
||
| 2971 | 'order_id' => api_htmlentities(get_lang('Order'), ENT_QUOTES), |
||
| 2972 | 'objective_id' => api_htmlentities(get_lang('ObjectiveID'), ENT_QUOTES), |
||
| 2973 | 'score_raw' => api_htmlentities(get_lang('ObjectiveRawScore'), ENT_QUOTES), |
||
| 2974 | 'score_max' => api_htmlentities(get_lang('ObjectiveMaxScore'), ENT_QUOTES), |
||
| 2975 | 'score_min' => api_htmlentities(get_lang('ObjectiveMinScore'), ENT_QUOTES), |
||
| 2976 | 'status' => api_htmlentities(get_lang('ObjectiveStatus'), ENT_QUOTES) |
||
| 2977 | ); |
||
| 2978 | while ($row = Database::fetch_array($res)) { |
||
| 2979 | $list[] = array( |
||
| 2980 | 'order_id' => ($row['order_id'] + 1), |
||
| 2981 | 'objective_id' => urldecode($row['objective_id']), // urldecode() because they often have %2F or stuff like that. |
||
| 2982 | 'score_raw' => $row['score_raw'], |
||
| 2983 | 'score_max' => $row['score_max'], |
||
| 2984 | 'score_min' => $row['score_min'], |
||
| 2985 | 'status' => $row['status'] |
||
| 2986 | ); |
||
| 2987 | } |
||
| 2988 | } |
||
| 2989 | |||
| 2990 | return $list; |
||
| 2991 | } |
||
| 2992 | |||
| 2993 | /** |
||
| 2994 | * Generate and return the table of contents for this learnpath. The (flat) table returned can be |
||
| 2995 | * used by get_html_toc() to be ready to display |
||
| 2996 | * @return array TOC as a table with 4 elements per row: title, link, status and level |
||
| 2997 | */ |
||
| 2998 | public function get_toc() |
||
| 2999 | { |
||
| 3000 | if ($this->debug > 0) { |
||
| 3001 | error_log('learnpath::get_toc()', 0); |
||
| 3002 | } |
||
| 3003 | $toc = array(); |
||
| 3004 | foreach ($this->ordered_items as $item_id) { |
||
| 3005 | if ($this->debug > 2) { |
||
| 3006 | error_log('learnpath::get_toc(): getting info for item '.$item_id, 0); |
||
| 3007 | } |
||
| 3008 | // TODO: Change this link generation and use new function instead. |
||
| 3009 | $toc[] = array( |
||
| 3010 | 'id' => $item_id, |
||
| 3011 | 'title' => $this->items[$item_id]->get_title(), |
||
| 3012 | 'status' => $this->items[$item_id]->get_status(), |
||
| 3013 | 'level' => $this->items[$item_id]->get_level(), |
||
| 3014 | 'type' => $this->items[$item_id]->get_type(), |
||
| 3015 | 'description' => $this->items[$item_id]->get_description(), |
||
| 3016 | 'path' => $this->items[$item_id]->get_path(), |
||
| 3017 | ); |
||
| 3018 | } |
||
| 3019 | if ($this->debug > 2) { |
||
| 3020 | error_log('New LP - In learnpath::get_toc() - TOC array: '.print_r($toc, true), 0); |
||
| 3021 | } |
||
| 3022 | return $toc; |
||
| 3023 | } |
||
| 3024 | |||
| 3025 | /** |
||
| 3026 | * Generate and return the table of contents for this learnpath. The JS |
||
| 3027 | * table returned is used inside of scorm_api.php |
||
| 3028 | * @return string A JS array vairiable construction |
||
| 3029 | */ |
||
| 3030 | public function get_items_details_as_js($varname = 'olms.lms_item_types') |
||
| 3031 | { |
||
| 3032 | if ($this->debug > 0) { |
||
| 3033 | error_log('New LP - In learnpath::get_items_details_as_js()', 0); |
||
| 3034 | } |
||
| 3035 | $toc = $varname.' = new Array();'; |
||
| 3036 | foreach ($this->ordered_items as $item_id) { |
||
| 3037 | $toc .= $varname."['i$item_id'] = '".$this->items[$item_id]->get_type()."';"; |
||
| 3038 | } |
||
| 3039 | if ($this->debug > 2) { |
||
| 3040 | error_log('New LP - In learnpath::get_items_details_as_js() - TOC array: '.print_r($toc, true), 0); |
||
| 3041 | } |
||
| 3042 | return $toc; |
||
| 3043 | } |
||
| 3044 | |||
| 3045 | /** |
||
| 3046 | * Gets the learning path type |
||
| 3047 | * @param boolean Return the name? If false, return the ID. Default is false. |
||
| 3048 | * @return mixed Type ID or name, depending on the parameter |
||
| 3049 | */ |
||
| 3050 | public function get_type($get_name = false) |
||
| 3051 | { |
||
| 3052 | $res = false; |
||
| 3053 | if ($this->debug > 0) { |
||
| 3054 | error_log('New LP - In learnpath::get_type()', 0); |
||
| 3055 | } |
||
| 3056 | if (!empty($this->type)) { |
||
| 3057 | if ($get_name) { |
||
| 3058 | // Get it from the lp_type table in main db. |
||
| 3059 | } else { |
||
| 3060 | $res = $this->type; |
||
| 3061 | } |
||
| 3062 | } |
||
| 3063 | if ($this->debug > 2) { |
||
| 3064 | error_log('New LP - In learnpath::get_type() - Returning '.($res ? $res : 'false'), 0); |
||
| 3065 | } |
||
| 3066 | return $res; |
||
| 3067 | } |
||
| 3068 | |||
| 3069 | /** |
||
| 3070 | * Gets the learning path type as static method |
||
| 3071 | * @param boolean Return the name? If false, return the ID. Default is false. |
||
| 3072 | * @return mixed Type ID or name, depending on the parameter |
||
| 3073 | */ |
||
| 3074 | public static function get_type_static($lp_id = 0) |
||
| 3075 | { |
||
| 3076 | $course_id = api_get_course_int_id(); |
||
| 3077 | $tbl_lp = Database::get_course_table(TABLE_LP_MAIN); |
||
| 3078 | $lp_id = intval($lp_id); |
||
| 3079 | $sql = "SELECT lp_type FROM $tbl_lp |
||
| 3080 | WHERE c_id = $course_id AND id = '".$lp_id."'"; |
||
| 3081 | $res = Database::query($sql); |
||
| 3082 | if ($res === false) { |
||
| 3083 | return null; |
||
| 3084 | } |
||
| 3085 | if (Database::num_rows($res) <= 0) { |
||
| 3086 | return null; |
||
| 3087 | } |
||
| 3088 | $row = Database::fetch_array($res); |
||
| 3089 | return $row['lp_type']; |
||
| 3090 | } |
||
| 3091 | |||
| 3092 | /** |
||
| 3093 | * Gets a flat list of item IDs ordered for display (level by level ordered by order_display) |
||
| 3094 | * This method can be used as abstract and is recursive |
||
| 3095 | * @param integer Learnpath ID |
||
| 3096 | * @param integer Parent ID of the items to look for |
||
| 3097 | * @return array Ordered list of item IDs (empty array on error) |
||
| 3098 | */ |
||
| 3099 | public static function get_flat_ordered_items_list($lp, $parent = 0, $course_id = null) |
||
| 3100 | { |
||
| 3101 | if (empty($course_id)) { |
||
| 3102 | $course_id = api_get_course_int_id(); |
||
| 3103 | } else { |
||
| 3104 | $course_id = intval($course_id); |
||
| 3105 | } |
||
| 3106 | $list = array(); |
||
| 3107 | |||
| 3108 | if (empty($lp)) { |
||
| 3109 | return $list; |
||
| 3110 | } |
||
| 3111 | |||
| 3112 | $lp = intval($lp); |
||
| 3113 | $parent = intval($parent); |
||
| 3114 | |||
| 3115 | $tbl_lp_item = Database::get_course_table(TABLE_LP_ITEM); |
||
| 3116 | $sql = "SELECT id FROM $tbl_lp_item |
||
| 3117 | WHERE c_id = $course_id AND lp_id = $lp AND parent_item_id = $parent |
||
| 3118 | ORDER BY display_order"; |
||
| 3119 | |||
| 3120 | $res = Database::query($sql); |
||
| 3121 | while ($row = Database::fetch_array($res)) { |
||
| 3122 | $sublist = self::get_flat_ordered_items_list($lp, $row['id'], $course_id); |
||
| 3123 | $list[] = $row['id']; |
||
| 3124 | foreach ($sublist as $item) { |
||
| 3125 | $list[] = $item; |
||
| 3126 | } |
||
| 3127 | } |
||
| 3128 | return $list; |
||
| 3129 | } |
||
| 3130 | |||
| 3131 | /** |
||
| 3132 | * @return array |
||
| 3133 | */ |
||
| 3134 | public static function getChapterTypes() |
||
| 3135 | { |
||
| 3136 | return array( |
||
| 3137 | 'dir' |
||
| 3138 | ); |
||
| 3139 | } |
||
| 3140 | /** |
||
| 3141 | * Uses the table generated by get_toc() and returns an HTML-formatted string ready to display |
||
| 3142 | * @return string HTML TOC ready to display |
||
| 3143 | */ |
||
| 3144 | public function getListArrayToc($toc_list = null) |
||
| 3145 | { |
||
| 3146 | if ($this->debug > 0) { |
||
| 3147 | error_log('In learnpath::get_html_toc()', 0); |
||
| 3148 | } |
||
| 3149 | if (empty($toc_list)) { |
||
| 3150 | $toc_list = $this->get_toc(); |
||
| 3151 | } |
||
| 3152 | // Temporary variables. |
||
| 3153 | $mycurrentitemid = $this->get_current_item_id(); |
||
| 3154 | $list = []; |
||
| 3155 | $arrayList = []; |
||
| 3156 | $classStatus = [ |
||
| 3157 | 'not attempted' => 'scorm_not_attempted', |
||
| 3158 | 'incomplete' => 'scorm_not_attempted', |
||
| 3159 | 'failed' => 'scorm_failed', |
||
| 3160 | 'completed' => 'scorm_completed', |
||
| 3161 | 'passed' => 'scorm_completed', |
||
| 3162 | 'succeeded' => 'scorm_completed', |
||
| 3163 | 'browsed' => 'scorm_completed', |
||
| 3164 | ]; |
||
| 3165 | foreach ($toc_list as $item) { |
||
| 3166 | |||
| 3167 | $list['id'] = $item['id']; |
||
| 3168 | $list['status'] = $item['status']; |
||
| 3169 | $cssStatus = null; |
||
| 3170 | |||
| 3171 | if (isset($classStatus[$item['status']])) { |
||
| 3172 | $cssStatus = $classStatus[$item['status']]; |
||
| 3173 | } |
||
| 3174 | |||
| 3175 | $classStyle = ' '; |
||
| 3176 | $dirTypes = self::getChapterTypes(); |
||
| 3177 | |||
| 3178 | if (in_array($item['type'], $dirTypes)) { |
||
| 3179 | $classStyle = 'scorm_item_section '; |
||
| 3180 | } |
||
| 3181 | if ($item['id'] == $this->current) { |
||
| 3182 | $classStyle = 'scorm_item_normal '.$classStyle.'scorm_highlight'; |
||
| 3183 | } elseif (!in_array($item['type'], $dirTypes)) { |
||
| 3184 | $classStyle = 'scorm_item_normal '.$classStyle.' '; |
||
| 3185 | } |
||
| 3186 | $title = $item['title']; |
||
| 3187 | if (empty($title)) { |
||
| 3188 | $title = self::rl_get_resource_name(api_get_course_id(), $this->get_id(), $item['id']); |
||
| 3189 | } |
||
| 3190 | $title = Security::remove_XSS($item['title']); |
||
| 3191 | |||
| 3192 | if (empty($item['description'])) { |
||
| 3193 | $list['description'] = $title; |
||
| 3194 | } else { |
||
| 3195 | $list['description'] = $item['description']; |
||
| 3196 | } |
||
| 3197 | |||
| 3198 | $list['class'] = $classStyle.' '.$cssStatus; |
||
| 3199 | $list['level'] = $item['level']; |
||
| 3200 | $list['type'] = $item['type']; |
||
| 3201 | |||
| 3202 | if (in_array($item['type'], $dirTypes)) { |
||
| 3203 | $list['css_level'] = 'level_'.$item['level']; |
||
| 3204 | } else { |
||
| 3205 | $list['css_level'] = 'level_'.$item['level'] |
||
| 3206 | .' scorm_type_' |
||
| 3207 | .learnpath::format_scorm_type_item($item['type']); |
||
| 3208 | } |
||
| 3209 | |||
| 3210 | if (in_array($item['type'], $dirTypes)) { |
||
| 3211 | $list['title'] = stripslashes($title); |
||
| 3212 | } else { |
||
| 3213 | $list['title'] = stripslashes($title); |
||
| 3214 | $list['url'] = $this->get_link('http', $item['id'], $toc_list); |
||
| 3215 | $list['current_id'] = $mycurrentitemid; |
||
| 3216 | } |
||
| 3217 | $arrayList[] = $list; |
||
| 3218 | } |
||
| 3219 | |||
| 3220 | return $arrayList; |
||
| 3221 | } |
||
| 3222 | |||
| 3223 | /** |
||
| 3224 | * Returns an HTML-formatted string ready to display with teacher buttons |
||
| 3225 | * in LP view menu |
||
| 3226 | * @return string HTML TOC ready to display |
||
| 3227 | */ |
||
| 3228 | public function get_teacher_toc_buttons() |
||
| 3229 | { |
||
| 3230 | $is_allowed_to_edit = api_is_allowed_to_edit(null, true, false, false); |
||
| 3231 | $hide_teacher_icons_lp = api_get_configuration_value('hide_teacher_icons_lp'); |
||
| 3232 | $html = ''; |
||
| 3233 | if ($is_allowed_to_edit && $hide_teacher_icons_lp == false) { |
||
| 3234 | $gradebook = ''; |
||
| 3235 | if (!empty($_GET['gradebook'])) { |
||
| 3236 | $gradebook = Security::remove_XSS($_GET['gradebook']); |
||
| 3237 | } |
||
| 3238 | if ($this->get_lp_session_id() == api_get_session_id()) { |
||
| 3239 | $html .= '<div id="actions_lp" class="actions_lp"><hr>'; |
||
| 3240 | $html .= '<div class="btn-group">'; |
||
| 3241 | $html .= "<a class='btn btn-sm btn-default' href='lp_controller.php?".api_get_cidreq()."&gradebook=$gradebook&action=build&lp_id=".$this->lp_id."&isStudentView=false' target='_parent'>". |
||
| 3242 | Display::returnFontAwesomeIcon('street-view').get_lang('Overview')."</a>"; |
||
| 3243 | $html .= "<a class='btn btn-sm btn-default' href='lp_controller.php?".api_get_cidreq()."&action=add_item&type=step&lp_id=".$this->lp_id."&isStudentView=false' target='_parent'>". |
||
| 3244 | Display::returnFontAwesomeIcon('pencil').get_lang('Edit')."</a>"; |
||
| 3245 | $html .= '<a class="btn btn-sm btn-default" href="lp_controller.php?'.api_get_cidreq()."&gradebook=$gradebook&action=edit&lp_id=".$this->lp_id.'&isStudentView=false">'. |
||
| 3246 | Display::returnFontAwesomeIcon('cog').get_lang('Settings').'</a>'; |
||
| 3247 | $html .= '</div>'; |
||
| 3248 | $html .= '</div>'; |
||
| 3249 | } |
||
| 3250 | } |
||
| 3251 | |||
| 3252 | return $html; |
||
| 3253 | |||
| 3254 | } |
||
| 3255 | /** |
||
| 3256 | * Gets the learnpath maker name - generally the editor's name |
||
| 3257 | * @return string Learnpath maker name |
||
| 3258 | */ |
||
| 3259 | public function get_maker() |
||
| 3260 | { |
||
| 3261 | if ($this->debug > 0) { |
||
| 3262 | error_log('New LP - In learnpath::get_maker()', 0); |
||
| 3263 | } |
||
| 3264 | if (!empty ($this->maker)) { |
||
| 3265 | return $this->maker; |
||
| 3266 | } else { |
||
| 3267 | return ''; |
||
| 3268 | } |
||
| 3269 | } |
||
| 3270 | |||
| 3271 | /** |
||
| 3272 | * Gets the learnpath name/title |
||
| 3273 | * @return string Learnpath name/title |
||
| 3274 | */ |
||
| 3275 | View Code Duplication | public function get_name() |
|
| 3276 | { |
||
| 3277 | if ($this->debug > 0) { |
||
| 3278 | error_log('New LP - In learnpath::get_name()', 0); |
||
| 3279 | } |
||
| 3280 | if (!empty ($this->name)) { |
||
| 3281 | return $this->name; |
||
| 3282 | } else { |
||
| 3283 | return 'N/A'; |
||
| 3284 | } |
||
| 3285 | } |
||
| 3286 | |||
| 3287 | /** |
||
| 3288 | * Gets a link to the resource from the present location, depending on item ID. |
||
| 3289 | * @param string $type Type of link expected |
||
| 3290 | * @param integer $item_id Learnpath item ID |
||
| 3291 | * @return string $provided_toc Link to the lp_item resource |
||
| 3292 | */ |
||
| 3293 | public function get_link($type = 'http', $item_id = null, $provided_toc = false) |
||
| 3294 | { |
||
| 3295 | $course_id = $this->get_course_int_id(); |
||
| 3296 | |||
| 3297 | View Code Duplication | if ($this->debug > 0) { |
|
| 3298 | error_log('New LP - In learnpath::get_link('.$type.','.$item_id.')', 0); |
||
| 3299 | } |
||
| 3300 | View Code Duplication | if (empty($item_id)) { |
|
| 3301 | if ($this->debug > 2) { |
||
| 3302 | error_log('New LP - In learnpath::get_link() - no item id given in learnpath::get_link(), using current: '.$this->get_current_item_id(), 0); |
||
| 3303 | } |
||
| 3304 | $item_id = $this->get_current_item_id(); |
||
| 3305 | } |
||
| 3306 | |||
| 3307 | View Code Duplication | if (empty($item_id)) { |
|
| 3308 | if ($this->debug > 2) { |
||
| 3309 | error_log('New LP - In learnpath::get_link() - no current item id found in learnpath object', 0); |
||
| 3310 | } |
||
| 3311 | //still empty, this means there was no item_id given and we are not in an object context or |
||
| 3312 | //the object property is empty, return empty link |
||
| 3313 | $item_id = $this->first(); |
||
| 3314 | return ''; |
||
| 3315 | } |
||
| 3316 | |||
| 3317 | $file = ''; |
||
| 3318 | $lp_table = Database::get_course_table(TABLE_LP_MAIN); |
||
| 3319 | $lp_item_table = Database::get_course_table(TABLE_LP_ITEM); |
||
| 3320 | $lp_item_view_table = Database::get_course_table(TABLE_LP_ITEM_VIEW); |
||
| 3321 | $item_id = intval($item_id); |
||
| 3322 | |||
| 3323 | $sql = "SELECT |
||
| 3324 | l.lp_type as ltype, |
||
| 3325 | l.path as lpath, |
||
| 3326 | li.item_type as litype, |
||
| 3327 | li.path as lipath, |
||
| 3328 | li.parameters as liparams |
||
| 3329 | FROM $lp_table l |
||
| 3330 | INNER JOIN $lp_item_table li |
||
| 3331 | ON (li.lp_id = l.id AND l.c_id = $course_id AND li.c_id = $course_id ) |
||
| 3332 | WHERE li.id = $item_id "; |
||
| 3333 | if ($this->debug > 2) { |
||
| 3334 | error_log('New LP - In learnpath::get_link() - selecting item '.$sql, 0); |
||
| 3335 | } |
||
| 3336 | $res = Database::query($sql); |
||
| 3337 | if (Database::num_rows($res) > 0) { |
||
| 3338 | $row = Database::fetch_array($res); |
||
| 3339 | $lp_type = $row['ltype']; |
||
| 3340 | $lp_path = $row['lpath']; |
||
| 3341 | $lp_item_type = $row['litype']; |
||
| 3342 | $lp_item_path = $row['lipath']; |
||
| 3343 | $lp_item_params = $row['liparams']; |
||
| 3344 | |||
| 3345 | if (empty($lp_item_params) && strpos($lp_item_path, '?') !== false) { |
||
| 3346 | list($lp_item_path, $lp_item_params) = explode('?', $lp_item_path); |
||
| 3347 | } |
||
| 3348 | $sys_course_path = api_get_path(SYS_COURSE_PATH).api_get_course_path(); |
||
| 3349 | if ($type == 'http') { |
||
| 3350 | $course_path = api_get_path(WEB_COURSE_PATH).api_get_course_path(); //web path |
||
| 3351 | } else { |
||
| 3352 | $course_path = $sys_course_path; //system path |
||
| 3353 | } |
||
| 3354 | |||
| 3355 | // Fixed issue BT#1272 - If the item type is a Chamilo Item (quiz, link, etc), then change the lp type to thread it as a normal Chamilo LP not a SCO. |
||
| 3356 | if (in_array($lp_item_type, array('quiz', 'document', 'final_item', 'link', 'forum', 'thread', 'student_publication'))) { |
||
| 3357 | $lp_type = 1; |
||
| 3358 | } |
||
| 3359 | |||
| 3360 | if ($this->debug > 2) { |
||
| 3361 | error_log('New LP - In learnpath::get_link() - $lp_type '.$lp_type, 0); |
||
| 3362 | error_log('New LP - In learnpath::get_link() - $lp_item_type '.$lp_item_type, 0); |
||
| 3363 | } |
||
| 3364 | |||
| 3365 | // Now go through the specific cases to get the end of the path |
||
| 3366 | // @todo Use constants instead of int values. |
||
| 3367 | switch ($lp_type) { |
||
| 3368 | case 1 : |
||
| 3369 | $file = self::rl_get_resource_link_for_learnpath( |
||
| 3370 | $course_id, |
||
| 3371 | $this->get_id(), |
||
| 3372 | $item_id, |
||
| 3373 | $this->get_view_id() |
||
| 3374 | ); |
||
| 3375 | if ($this->debug > 0) { |
||
| 3376 | error_log('rl_get_resource_link_for_learnpath - file: '.$file, 0); |
||
| 3377 | } |
||
| 3378 | |||
| 3379 | switch ($lp_item_type) { |
||
| 3380 | case 'dir': |
||
| 3381 | $file = 'lp_content.php?type=dir'; |
||
| 3382 | break; |
||
| 3383 | case 'link': |
||
| 3384 | if (Link::is_youtube_link($file)) { |
||
| 3385 | $src = Link::get_youtube_video_id($file); |
||
| 3386 | $file = api_get_path(WEB_CODE_PATH).'lp/embed.php?type=youtube&source='.$src; |
||
| 3387 | } elseif (Link::isVimeoLink($file)) { |
||
| 3388 | $src = Link::getVimeoLinkId($file); |
||
| 3389 | $file = api_get_path(WEB_CODE_PATH).'lp/embed.php?type=vimeo&source='.$src; |
||
| 3390 | } else { |
||
| 3391 | // If the current site is HTTPS and the link is |
||
| 3392 | // HTTP, browsers will refuse opening the link |
||
| 3393 | $urlId = api_get_current_access_url_id(); |
||
| 3394 | $url = api_get_access_url($urlId, false); |
||
| 3395 | $protocol = substr($url['url'], 0, 5); |
||
| 3396 | if ($protocol === 'https') { |
||
| 3397 | $linkProtocol = substr($file, 0, 5); |
||
| 3398 | if ($linkProtocol === 'http:') { |
||
| 3399 | //this is the special intervention case |
||
| 3400 | $file = api_get_path(WEB_CODE_PATH).'lp/embed.php?type=nonhttps&source='.urlencode($file); |
||
| 3401 | } |
||
| 3402 | } |
||
| 3403 | } |
||
| 3404 | break; |
||
| 3405 | case 'quiz': |
||
| 3406 | // Check how much attempts of a exercise exits in lp |
||
| 3407 | $lp_item_id = $this->get_current_item_id(); |
||
| 3408 | $lp_view_id = $this->get_view_id(); |
||
| 3409 | |||
| 3410 | $prevent_reinit = null; |
||
| 3411 | if (isset($this->items[$this->current])) { |
||
| 3412 | $prevent_reinit = $this->items[$this->current]->get_prevent_reinit(); |
||
| 3413 | } |
||
| 3414 | |||
| 3415 | if (empty($provided_toc)) { |
||
| 3416 | if ($this->debug > 0) { |
||
| 3417 | error_log('In learnpath::get_link() Loading get_toc ', 0); |
||
| 3418 | } |
||
| 3419 | $list = $this->get_toc(); |
||
| 3420 | } else { |
||
| 3421 | if ($this->debug > 0) { |
||
| 3422 | error_log('In learnpath::get_link() Loading get_toc from "cache" ', 0); |
||
| 3423 | } |
||
| 3424 | $list = $provided_toc; |
||
| 3425 | } |
||
| 3426 | |||
| 3427 | $type_quiz = false; |
||
| 3428 | |||
| 3429 | View Code Duplication | foreach ($list as $toc) { |
|
| 3430 | if ($toc['id'] == $lp_item_id && ($toc['type'] == 'quiz')) { |
||
| 3431 | $type_quiz = true; |
||
| 3432 | } |
||
| 3433 | } |
||
| 3434 | |||
| 3435 | if ($type_quiz) { |
||
| 3436 | $lp_item_id = intval($lp_item_id); |
||
| 3437 | $lp_view_id = intval($lp_view_id); |
||
| 3438 | $sql = "SELECT count(*) FROM $lp_item_view_table |
||
| 3439 | WHERE |
||
| 3440 | c_id = $course_id AND |
||
| 3441 | lp_item_id='".$lp_item_id."' AND |
||
| 3442 | lp_view_id ='".$lp_view_id."' AND |
||
| 3443 | status='completed'"; |
||
| 3444 | $result = Database::query($sql); |
||
| 3445 | $row_count = Database:: fetch_row($result); |
||
| 3446 | $count_item_view = (int) $row_count[0]; |
||
| 3447 | $not_multiple_attempt = 0; |
||
| 3448 | if ($prevent_reinit === 1 && $count_item_view > 0) { |
||
| 3449 | $not_multiple_attempt = 1; |
||
| 3450 | } |
||
| 3451 | $file .= '¬_multiple_attempt='.$not_multiple_attempt; |
||
| 3452 | } |
||
| 3453 | break; |
||
| 3454 | } |
||
| 3455 | |||
| 3456 | $tmp_array = explode('/', $file); |
||
| 3457 | $document_name = $tmp_array[count($tmp_array) - 1]; |
||
| 3458 | if (strpos($document_name, '_DELETED_')) { |
||
| 3459 | $file = 'blank.php?error=document_deleted'; |
||
| 3460 | } |
||
| 3461 | |||
| 3462 | break; |
||
| 3463 | case 2 : |
||
| 3464 | if ($this->debug > 2) { |
||
| 3465 | error_log('New LP - In learnpath::get_link() '.__LINE__.' - Item type: '.$lp_item_type, 0); |
||
| 3466 | } |
||
| 3467 | |||
| 3468 | if ($lp_item_type != 'dir') { |
||
| 3469 | // Quite complex here: |
||
| 3470 | // We want to make sure 'http://' (and similar) links can |
||
| 3471 | // be loaded as is (withouth the Chamilo path in front) but |
||
| 3472 | // some contents use this form: resource.htm?resource=http://blablabla |
||
| 3473 | // which means we have to find a protocol at the path's start, otherwise |
||
| 3474 | // it should not be considered as an external URL. |
||
| 3475 | |||
| 3476 | //if ($this->prerequisites_match($item_id)) { |
||
| 3477 | if (preg_match('#^[a-zA-Z]{2,5}://#', $lp_item_path) != 0) { |
||
| 3478 | if ($this->debug > 2) { |
||
| 3479 | error_log('New LP - In learnpath::get_link() '.__LINE__.' - Found match for protocol in '.$lp_item_path, 0); |
||
| 3480 | } |
||
| 3481 | // Distant url, return as is. |
||
| 3482 | $file = $lp_item_path; |
||
| 3483 | } else { |
||
| 3484 | if ($this->debug > 2) { |
||
| 3485 | error_log('New LP - In learnpath::get_link() '.__LINE__.' - No starting protocol in '.$lp_item_path, 0); |
||
| 3486 | } |
||
| 3487 | // Prevent getting untranslatable urls. |
||
| 3488 | $lp_item_path = preg_replace('/%2F/', '/', $lp_item_path); |
||
| 3489 | $lp_item_path = preg_replace('/%3A/', ':', $lp_item_path); |
||
| 3490 | // Prepare the path. |
||
| 3491 | $file = $course_path.'/scorm/'.$lp_path.'/'.$lp_item_path; |
||
| 3492 | // TODO: Fix this for urls with protocol header. |
||
| 3493 | $file = str_replace('//', '/', $file); |
||
| 3494 | $file = str_replace(':/', '://', $file); |
||
| 3495 | if (substr($lp_path, -1) == '/') { |
||
| 3496 | $lp_path = substr($lp_path, 0, -1); |
||
| 3497 | } |
||
| 3498 | |||
| 3499 | if (!is_file(realpath($sys_course_path.'/scorm/'.$lp_path.'/'.$lp_item_path))) { |
||
| 3500 | // if file not found. |
||
| 3501 | $decoded = html_entity_decode($lp_item_path); |
||
| 3502 | list ($decoded) = explode('?', $decoded); |
||
| 3503 | if (!is_file(realpath($sys_course_path.'/scorm/'.$lp_path.'/'.$decoded))) { |
||
| 3504 | $file = self::rl_get_resource_link_for_learnpath( |
||
| 3505 | $course_id, |
||
| 3506 | $this->get_id(), |
||
| 3507 | $item_id, |
||
| 3508 | $this->get_view_id() |
||
| 3509 | ); |
||
| 3510 | if (empty($file)) { |
||
| 3511 | $file = 'blank.php?error=document_not_found'; |
||
| 3512 | } else { |
||
| 3513 | $tmp_array = explode('/', $file); |
||
| 3514 | $document_name = $tmp_array[count($tmp_array) - 1]; |
||
| 3515 | if (strpos($document_name, '_DELETED_')) { |
||
| 3516 | $file = 'blank.php?error=document_deleted'; |
||
| 3517 | } else { |
||
| 3518 | $file = 'blank.php?error=document_not_found'; |
||
| 3519 | } |
||
| 3520 | } |
||
| 3521 | } else { |
||
| 3522 | $file = $course_path.'/scorm/'.$lp_path.'/'.$decoded; |
||
| 3523 | } |
||
| 3524 | } |
||
| 3525 | } |
||
| 3526 | |||
| 3527 | // We want to use parameters if they were defined in the imsmanifest |
||
| 3528 | if (strpos($file, 'blank.php') === false) { |
||
| 3529 | $lp_item_params = ltrim($lp_item_params, '?'); |
||
| 3530 | $file .= (strstr($file, '?') === false ? '?' : '').$lp_item_params; |
||
| 3531 | } |
||
| 3532 | } else { |
||
| 3533 | $file = 'lp_content.php?type=dir'; |
||
| 3534 | } |
||
| 3535 | break; |
||
| 3536 | case 3 : |
||
| 3537 | if ($this->debug > 2) { |
||
| 3538 | error_log('New LP - In learnpath::get_link() '.__LINE__.' - Item type: '.$lp_item_type, 0); |
||
| 3539 | } |
||
| 3540 | // Formatting AICC HACP append URL. |
||
| 3541 | $aicc_append = '?aicc_sid='.urlencode(session_id()).'&aicc_url='.urlencode(api_get_path(WEB_CODE_PATH).'lp/aicc_hacp.php').'&'; |
||
| 3542 | if (!empty($lp_item_params)) { |
||
| 3543 | $aicc_append .= $lp_item_params.'&'; |
||
| 3544 | } |
||
| 3545 | if ($lp_item_type != 'dir') { |
||
| 3546 | // Quite complex here: |
||
| 3547 | // We want to make sure 'http://' (and similar) links can |
||
| 3548 | // be loaded as is (withouth the Chamilo path in front) but |
||
| 3549 | // some contents use this form: resource.htm?resource=http://blablabla |
||
| 3550 | // which means we have to find a protocol at the path's start, otherwise |
||
| 3551 | // it should not be considered as an external URL. |
||
| 3552 | |||
| 3553 | if (preg_match('#^[a-zA-Z]{2,5}://#', $lp_item_path) != 0) { |
||
| 3554 | if ($this->debug > 2) { |
||
| 3555 | error_log('New LP - In learnpath::get_link() '.__LINE__.' - Found match for protocol in '.$lp_item_path, 0); |
||
| 3556 | } |
||
| 3557 | // Distant url, return as is. |
||
| 3558 | $file = $lp_item_path; |
||
| 3559 | // Enabled and modified by Ivan Tcholakov, 16-OCT-2008. |
||
| 3560 | /* |
||
| 3561 | if (stristr($file,'<servername>') !== false) { |
||
| 3562 | $file = str_replace('<servername>', $course_path.'/scorm/'.$lp_path.'/', $lp_item_path); |
||
| 3563 | } |
||
| 3564 | */ |
||
| 3565 | if (stripos($file, '<servername>') !== false) { |
||
| 3566 | //$file = str_replace('<servername>',$course_path.'/scorm/'.$lp_path.'/',$lp_item_path); |
||
| 3567 | $web_course_path = str_replace('https://', '', str_replace('http://', '', $course_path)); |
||
| 3568 | $file = str_replace('<servername>', $web_course_path.'/scorm/'.$lp_path, $lp_item_path); |
||
| 3569 | } |
||
| 3570 | // |
||
| 3571 | $file .= $aicc_append; |
||
| 3572 | } else { |
||
| 3573 | if ($this->debug > 2) { |
||
| 3574 | error_log('New LP - In learnpath::get_link() '.__LINE__.' - No starting protocol in '.$lp_item_path, 0); |
||
| 3575 | } |
||
| 3576 | // Prevent getting untranslatable urls. |
||
| 3577 | $lp_item_path = preg_replace('/%2F/', '/', $lp_item_path); |
||
| 3578 | $lp_item_path = preg_replace('/%3A/', ':', $lp_item_path); |
||
| 3579 | // Prepare the path - lp_path might be unusable because it includes the "aicc" subdir name. |
||
| 3580 | $file = $course_path.'/scorm/'.$lp_path.'/'.$lp_item_path; |
||
| 3581 | // TODO: Fix this for urls with protocol header. |
||
| 3582 | $file = str_replace('//', '/', $file); |
||
| 3583 | $file = str_replace(':/', '://', $file); |
||
| 3584 | $file .= $aicc_append; |
||
| 3585 | } |
||
| 3586 | } else { |
||
| 3587 | $file = 'lp_content.php?type=dir'; |
||
| 3588 | } |
||
| 3589 | break; |
||
| 3590 | case 4 : |
||
| 3591 | break; |
||
| 3592 | default: |
||
| 3593 | break; |
||
| 3594 | } |
||
| 3595 | // Replace & by & because & will break URL with params |
||
| 3596 | $file = !empty($file) ? str_replace('&', '&', $file) : ''; |
||
| 3597 | } |
||
| 3598 | if ($this->debug > 2) { |
||
| 3599 | error_log('New LP - In learnpath::get_link() - returning "'.$file.'" from get_link', 0); |
||
| 3600 | } |
||
| 3601 | return $file; |
||
| 3602 | } |
||
| 3603 | |||
| 3604 | /** |
||
| 3605 | * Gets the latest usable view or generate a new one |
||
| 3606 | * @param integer Optional attempt number. If none given, takes the highest from the lp_view table |
||
| 3607 | * @return integer DB lp_view id |
||
| 3608 | */ |
||
| 3609 | public function get_view($attempt_num = 0) |
||
| 3651 | |||
| 3652 | /** |
||
| 3653 | * Gets the current view id |
||
| 3654 | * @return integer View ID (from lp_view) |
||
| 3655 | */ |
||
| 3656 | public function get_view_id() |
||
| 3667 | |||
| 3668 | /** |
||
| 3669 | * Gets the update queue |
||
| 3670 | * @return array Array containing IDs of items to be updated by JavaScript |
||
| 3671 | */ |
||
| 3672 | public function get_update_queue() |
||
| 3679 | |||
| 3680 | /** |
||
| 3681 | * Gets the user ID |
||
| 3682 | * @return integer User ID |
||
| 3683 | */ |
||
| 3684 | View Code Duplication | public function get_user_id() |
|
| 3695 | |||
| 3696 | /** |
||
| 3697 | * Checks if any of the items has an audio element attached |
||
| 3698 | * @return bool True or false |
||
| 3699 | */ |
||
| 3700 | public function has_audio() |
||
| 3714 | |||
| 3715 | /** |
||
| 3716 | * Logs a message into a file |
||
| 3717 | * @param string Message to log |
||
| 3718 | * @return boolean True on success, false on error or if msg empty |
||
| 3719 | */ |
||
| 3720 | public function log($msg) |
||
| 3729 | |||
| 3730 | /** |
||
| 3731 | * Moves an item up and down at its level |
||
| 3732 | * @param integer Item to move up and down |
||
| 3733 | * @param string Direction 'up' or 'down' |
||
| 3734 | * @return integer New display order, or false on error |
||
| 3735 | */ |
||
| 3736 | public function move_item($id, $direction) |
||
| 3737 | { |
||
| 3738 | $course_id = api_get_course_int_id(); |
||
| 3739 | if ($this->debug > 0) { |
||
| 3740 | error_log('New LP - In learnpath::move_item('.$id.','.$direction.')', 0); |
||
| 3741 | } |
||
| 3742 | if (empty($id) || empty($direction)) { |
||
| 3743 | return false; |
||
| 3744 | } |
||
| 3745 | $tbl_lp_item = Database::get_course_table(TABLE_LP_ITEM); |
||
| 3746 | $sql_sel = "SELECT * |
||
| 3747 | FROM " . $tbl_lp_item." |
||
| 3748 | WHERE c_id = ".$course_id." AND id = ".$id; |
||
| 3749 | $res_sel = Database::query($sql_sel); |
||
| 3750 | // Check if elem exists. |
||
| 3751 | if (Database::num_rows($res_sel) < 1) { |
||
| 3752 | return false; |
||
| 3753 | } |
||
| 3754 | // Gather data. |
||
| 3755 | $row = Database::fetch_array($res_sel); |
||
| 3756 | $previous = $row['previous_item_id']; |
||
| 3757 | $next = $row['next_item_id']; |
||
| 3758 | $display = $row['display_order']; |
||
| 3759 | $parent = $row['parent_item_id']; |
||
| 3760 | $lp = $row['lp_id']; |
||
| 3761 | // Update the item (switch with previous/next one). |
||
| 3762 | switch ($direction) { |
||
| 3763 | case 'up': |
||
| 3764 | if ($this->debug > 2) { |
||
| 3765 | error_log('Movement up detected', 0); |
||
| 3766 | } |
||
| 3767 | if ($display > 1) { |
||
| 3768 | $sql_sel2 = "SELECT * FROM $tbl_lp_item |
||
| 3769 | WHERE c_id = ".$course_id." AND id = $previous"; |
||
| 3770 | |||
| 3771 | if ($this->debug > 2) { |
||
| 3772 | error_log('Selecting previous: '.$sql_sel2, 0); |
||
| 3773 | } |
||
| 3774 | $res_sel2 = Database::query($sql_sel2); |
||
| 3775 | if (Database::num_rows($res_sel2) < 1) { |
||
| 3776 | $previous_previous = 0; |
||
| 3777 | } |
||
| 3778 | // Gather data. |
||
| 3779 | $row2 = Database::fetch_array($res_sel2); |
||
| 3780 | $previous_previous = $row2['previous_item_id']; |
||
| 3781 | // Update previous_previous item (switch "next" with current). |
||
| 3782 | View Code Duplication | if ($previous_previous != 0) { |
|
| 3783 | $sql_upd2 = "UPDATE $tbl_lp_item SET |
||
| 3784 | next_item_id = $id |
||
| 3785 | WHERE c_id = ".$course_id." AND id = $previous_previous"; |
||
| 3786 | if ($this->debug > 2) { |
||
| 3787 | error_log($sql_upd2, 0); |
||
| 3788 | } |
||
| 3789 | Database::query($sql_upd2); |
||
| 3790 | } |
||
| 3791 | // Update previous item (switch with current). |
||
| 3792 | View Code Duplication | if ($previous != 0) { |
|
| 3793 | $sql_upd2 = "UPDATE $tbl_lp_item SET |
||
| 3794 | next_item_id = $next, |
||
| 3795 | previous_item_id = $id, |
||
| 3796 | display_order = display_order +1 |
||
| 3797 | WHERE c_id = ".$course_id." AND id = $previous"; |
||
| 3881 | |||
| 3882 | /** |
||
| 3883 | * Move a LP up (display_order) |
||
| 3884 | * @param int $lp_id Learnpath ID |
||
| 3885 | * @param int $categoryId |
||
| 3886 | * @return bool |
||
| 3887 | */ |
||
| 3888 | public static function move_up($lp_id, $categoryId = 0) |
||
| 3940 | |||
| 3941 | /** |
||
| 3942 | * Move a learnpath down (display_order) |
||
| 3943 | * @param int $lp_id Learnpath ID |
||
| 3944 | * @param int $categoryId |
||
| 3945 | * @return bool |
||
| 3946 | */ |
||
| 3947 | public static function move_down($lp_id, $categoryId = 0) |
||
| 4002 | |||
| 4003 | /** |
||
| 4004 | * Updates learnpath attributes to point to the next element |
||
| 4005 | * The last part is similar to set_current_item but processing the other way around |
||
| 4006 | */ |
||
| 4007 | public function next() |
||
| 4031 | |||
| 4032 | /** |
||
| 4033 | * Open a resource = initialise all local variables relative to this resource. Depending on the child |
||
| 4034 | * class, this might be redefined to allow several behaviours depending on the document type. |
||
| 4035 | * @param integer Resource ID |
||
| 4036 | * @return boolean True on success, false otherwise |
||
| 4037 | */ |
||
| 4038 | public function open($id) |
||
| 4051 | |||
| 4052 | /** |
||
| 4053 | * Check that all prerequisites are fulfilled. Returns true and an |
||
| 4054 | * empty string on success, returns false |
||
| 4055 | * and the prerequisite string on error. |
||
| 4056 | * This function is based on the rules for aicc_script language as |
||
| 4057 | * described in the SCORM 1.2 CAM documentation page 108. |
||
| 4058 | * @param integer $itemId Optional item ID. If none given, uses the current open item. |
||
| 4059 | * @return boolean True if prerequisites are matched, false otherwise - |
||
| 4060 | * Empty string if true returned, prerequisites string otherwise. |
||
| 4061 | */ |
||
| 4062 | public function prerequisites_match($itemId = null) |
||
| 4117 | |||
| 4118 | /** |
||
| 4119 | * Updates learnpath attributes to point to the previous element |
||
| 4120 | * The last part is similar to set_current_item but processing the other way around |
||
| 4121 | */ |
||
| 4122 | public function previous() |
||
| 4134 | |||
| 4135 | /** |
||
| 4136 | * Publishes a learnpath. This basically means show or hide the learnpath |
||
| 4137 | * to normal users. |
||
| 4138 | * Can be used as abstract |
||
| 4139 | * @param integer Learnpath ID |
||
| 4140 | * @param string New visibility |
||
| 4141 | * @return bool |
||
| 4142 | */ |
||
| 4143 | public static function toggle_visibility($lp_id, $set_visibility = 1) |
||
| 4159 | |||
| 4160 | /** |
||
| 4161 | * Publishes a learnpath category. |
||
| 4162 | * This basically means show or hide the learnpath category to normal users. |
||
| 4163 | * @param int $id |
||
| 4164 | * @param int $visibility |
||
| 4165 | * @return bool |
||
| 4166 | */ |
||
| 4167 | public static function toggleCategoryVisibility($id, $visibility = 1) |
||
| 4198 | |||
| 4199 | /** |
||
| 4200 | * Publishes a learnpath. This basically means show or hide the learnpath |
||
| 4201 | * on the course homepage |
||
| 4202 | * Can be used as abstract |
||
| 4203 | * @param integer $lp_id Learnpath id |
||
| 4204 | * @param string $set_visibility New visibility (v/i - visible/invisible) |
||
| 4205 | * @return bool |
||
| 4206 | */ |
||
| 4207 | public static function toggle_publish($lp_id, $set_visibility = 'v') |
||
| 4289 | |||
| 4290 | /** |
||
| 4291 | * Generate the link for a learnpath category as course tool |
||
| 4292 | * @param int $categoryId |
||
| 4293 | * @return string |
||
| 4294 | */ |
||
| 4295 | private static function getCategoryLinkForTool($categoryId) |
||
| 4307 | |||
| 4308 | /** |
||
| 4309 | * Publishes a learnpath. |
||
| 4310 | * Show or hide the learnpath category on the course homepage |
||
| 4311 | * @param int $id |
||
| 4312 | * @param int $setVisibility |
||
| 4313 | * @return bool |
||
| 4314 | */ |
||
| 4315 | public static function toggleCategoryPublish($id, $setVisibility = 1) |
||
| 4401 | |||
| 4402 | /** |
||
| 4403 | * Check if the learnpath category is visible for a user |
||
| 4404 | * @param CLpCategory $category |
||
| 4405 | * @param User $user |
||
| 4406 | * @return bool |
||
| 4407 | */ |
||
| 4408 | public static function categoryIsVisibleForStudent( |
||
| 4430 | |||
| 4431 | /** |
||
| 4432 | * Check if a learnpath category is published as course tool |
||
| 4433 | * @param CLpCategory $category |
||
| 4434 | * @param int $courseId |
||
| 4435 | * @return bool |
||
| 4436 | */ |
||
| 4437 | public static function categoryIsPublished( |
||
| 4464 | |||
| 4465 | /** |
||
| 4466 | * Restart the whole learnpath. Return the URL of the first element. |
||
| 4467 | * Make sure the results are saved with anoter method. This method should probably be |
||
| 4468 | * redefined in children classes. |
||
| 4469 | * To use a similar method statically, use the create_new_attempt() method |
||
| 4470 | * @return string URL to load in the viewer |
||
| 4471 | */ |
||
| 4472 | public function restart() |
||
| 4512 | |||
| 4513 | /** |
||
| 4514 | * Saves the current item |
||
| 4515 | * @return boolean |
||
| 4516 | */ |
||
| 4517 | public function save_current() |
||
| 4541 | |||
| 4542 | /** |
||
| 4543 | * Saves the given item |
||
| 4544 | * @param integer $item_id Optional (will take from $_REQUEST if null) |
||
| 4545 | * @param boolean $from_outside Save from url params (true) or from current attributes (false). Optional. Defaults to true |
||
| 4546 | * @return boolean |
||
| 4547 | */ |
||
| 4548 | public function save_item($item_id = null, $from_outside = true) |
||
| 4591 | |||
| 4592 | /** |
||
| 4593 | * Saves the last item seen's ID only in case |
||
| 4594 | */ |
||
| 4595 | public function save_last() |
||
| 4642 | |||
| 4643 | /** |
||
| 4644 | * Sets the current item ID (checks if valid and authorized first) |
||
| 4645 | * @param integer $item_id New item ID. If not given or not authorized, defaults to current |
||
| 4646 | */ |
||
| 4647 | public function set_current_item($item_id = null) |
||
| 4681 | |||
| 4682 | /** |
||
| 4683 | * Sets the encoding |
||
| 4684 | * @param string New encoding |
||
| 4685 | * @return bool |
||
| 4686 | * TODO (as of Chamilo 1.8.8): Check in the future whether this method is needed. |
||
| 4687 | */ |
||
| 4688 | public function set_encoding($enc = 'UTF-8') |
||
| 4711 | |||
| 4712 | /** |
||
| 4713 | * Sets the JS lib setting in the database directly. |
||
| 4714 | * This is the JavaScript library file this lp needs to load on startup |
||
| 4715 | * @param string Proximity setting |
||
| 4716 | * @return boolean True on update success. False otherwise. |
||
| 4717 | */ |
||
| 4718 | View Code Duplication | public function set_jslib($lib = '') |
|
| 4736 | |||
| 4737 | /** |
||
| 4738 | * Sets the name of the LP maker (publisher) (and save) |
||
| 4739 | * @param string Optional string giving the new content_maker of this learnpath |
||
| 4740 | * @return boolean True |
||
| 4741 | */ |
||
| 4742 | public function set_maker($name = '') |
||
| 4762 | |||
| 4763 | /** |
||
| 4764 | * Sets the name of the current learnpath (and save) |
||
| 4765 | * @param string $name Optional string giving the new name of this learnpath |
||
| 4766 | * @return boolean True/False |
||
| 4767 | */ |
||
| 4768 | public function set_name($name = null) |
||
| 4803 | |||
| 4804 | /** |
||
| 4805 | * Set index specified prefix terms for all items in this path |
||
| 4806 | * @param string Comma-separated list of terms |
||
| 4807 | * @param char Xapian term prefix |
||
| 4808 | * @return boolean False on error, true otherwise |
||
| 4809 | */ |
||
| 4810 | public function set_terms_by_prefix($terms_string, $prefix) |
||
| 4880 | |||
| 4881 | /** |
||
| 4882 | * Sets the theme of the LP (local/remote) (and save) |
||
| 4883 | * @param string Optional string giving the new theme of this learnpath |
||
| 4884 | * @return bool Returns true if theme name is not empty |
||
| 4885 | */ |
||
| 4886 | View Code Duplication | public function set_theme($name = '') |
|
| 4904 | |||
| 4905 | /** |
||
| 4906 | * Sets the image of an LP (and save) |
||
| 4907 | * @param string Optional string giving the new image of this learnpath |
||
| 4908 | * @return bool Returns true if theme name is not empty |
||
| 4909 | */ |
||
| 4910 | View Code Duplication | public function set_preview_image($name = '') |
|
| 4929 | |||
| 4930 | /** |
||
| 4931 | * Sets the author of a LP (and save) |
||
| 4932 | * @param string Optional string giving the new author of this learnpath |
||
| 4933 | * @return bool Returns true if author's name is not empty |
||
| 4934 | */ |
||
| 4935 | View Code Duplication | public function set_author($name = '') |
|
| 4953 | |||
| 4954 | /** |
||
| 4955 | * Sets the hide_toc_frame parameter of a LP (and save) |
||
| 4956 | * @param int 1 if frame is hidden 0 then else |
||
| 4957 | * @return bool Returns true if author's name is not empty |
||
| 4958 | */ |
||
| 4959 | public function set_hide_toc_frame($hide) |
||
| 4982 | |||
| 4983 | /** |
||
| 4984 | * Sets the prerequisite of a LP (and save) |
||
| 4985 | * @param int integer giving the new prerequisite of this learnpath |
||
| 4986 | * @return bool returns true if prerequisite is not empty |
||
| 4987 | */ |
||
| 4988 | View Code Duplication | public function set_prerequisite($prerequisite) |
|
| 5005 | |||
| 5006 | /** |
||
| 5007 | * Sets the location/proximity of the LP (local/remote) (and save) |
||
| 5008 | * @param string Optional string giving the new location of this learnpath |
||
| 5009 | * @return boolean True on success / False on error |
||
| 5010 | */ |
||
| 5011 | public function set_proximity($name = '') |
||
| 5032 | |||
| 5033 | /** |
||
| 5034 | * Sets the previous item ID to a given ID. Generally, this should be set to the previous 'current' item |
||
| 5035 | * @param integer DB ID of the item |
||
| 5036 | */ |
||
| 5037 | public function set_previous_item($id) |
||
| 5044 | |||
| 5045 | /** |
||
| 5046 | * Sets use_max_score |
||
| 5047 | * @param string $use_max_score Optional string giving the new location of this learnpath |
||
| 5048 | * @return boolean True on success / False on error |
||
| 5049 | */ |
||
| 5050 | public function set_use_max_score($use_max_score = 1) |
||
| 5071 | |||
| 5072 | /** |
||
| 5073 | * Sets and saves the expired_on date |
||
| 5074 | * @param string $expired_on Optional string giving the new author of this learnpath |
||
| 5075 | * @return bool Returns true if author's name is not empty |
||
| 5076 | */ |
||
| 5077 | View Code Duplication | public function set_expired_on($expired_on) |
|
| 5110 | |||
| 5111 | /** |
||
| 5112 | * Sets and saves the publicated_on date |
||
| 5113 | * @param string $publicated_on Optional string giving the new author of this learnpath |
||
| 5114 | * @return bool Returns true if author's name is not empty |
||
| 5115 | */ |
||
| 5116 | View Code Duplication | public function set_publicated_on($publicated_on) |
|
| 5148 | |||
| 5149 | /** |
||
| 5150 | * Sets and saves the expired_on date |
||
| 5151 | * @return bool Returns true if author's name is not empty |
||
| 5152 | */ |
||
| 5153 | View Code Duplication | public function set_modified_on() |
|
| 5171 | |||
| 5172 | /** |
||
| 5173 | * Sets the object's error message |
||
| 5174 | * @param string Error message. If empty, reinits the error string |
||
| 5175 | * @return void |
||
| 5176 | */ |
||
| 5177 | public function set_error_msg($error = '') |
||
| 5188 | |||
| 5189 | /** |
||
| 5190 | * Launches the current item if not 'sco' |
||
| 5191 | * (starts timer and make sure there is a record ready in the DB) |
||
| 5192 | * @param boolean $allow_new_attempt Whether to allow a new attempt or not |
||
| 5193 | * @return boolean |
||
| 5194 | */ |
||
| 5195 | public function start_current_item($allow_new_attempt = false) |
||
| 5223 | |||
| 5224 | /** |
||
| 5225 | * Stops the processing and counters for the old item (as held in $this->last) |
||
| 5226 | * @return boolean True/False |
||
| 5227 | */ |
||
| 5228 | public function stop_previous_item() |
||
| 5283 | |||
| 5284 | /** |
||
| 5285 | * Updates the default view mode from fullscreen to embedded and inversely |
||
| 5286 | * @return string The current default view mode ('fullscreen' or 'embedded') |
||
| 5287 | */ |
||
| 5288 | public function update_default_view_mode() |
||
| 5329 | |||
| 5330 | /** |
||
| 5331 | * Updates the default behaviour about auto-commiting SCORM updates |
||
| 5332 | * @return boolean True if auto-commit has been set to 'on', false otherwise |
||
| 5333 | */ |
||
| 5334 | public function update_default_scorm_commit() |
||
| 5367 | |||
| 5368 | /** |
||
| 5369 | * Updates the order of learning paths (goes through all of them by order and fills the gaps) |
||
| 5370 | * @return bool True on success, false on failure |
||
| 5371 | */ |
||
| 5372 | public function update_display_order() |
||
| 5400 | |||
| 5401 | /** |
||
| 5402 | * Updates the "prevent_reinit" value that enables control on reinitialising items on second view |
||
| 5403 | * @return boolean True if prevent_reinit has been set to 'on', false otherwise (or 1 or 0 in this case) |
||
| 5404 | */ |
||
| 5405 | View Code Duplication | public function update_reinit() |
|
| 5435 | |||
| 5436 | /** |
||
| 5437 | * Determine the attempt_mode thanks to prevent_reinit and seriousgame_mode db flag |
||
| 5438 | * |
||
| 5439 | * @return string 'single', 'multi' or 'seriousgame' |
||
| 5440 | * @author ndiechburg <[email protected]> |
||
| 5441 | **/ |
||
| 5442 | public function get_attempt_mode() |
||
| 5463 | |||
| 5464 | /** |
||
| 5465 | * Register the attempt mode into db thanks to flags prevent_reinit and seriousgame_mode flags |
||
| 5466 | * |
||
| 5467 | * @param string 'seriousgame', 'single' or 'multiple' |
||
| 5468 | * @return boolean |
||
| 5469 | * @author ndiechburg <[email protected]> |
||
| 5470 | **/ |
||
| 5471 | public function set_attempt_mode($mode) |
||
| 5506 | |||
| 5507 | /** |
||
| 5508 | * Switch between multiple attempt, single attempt or serious_game mode (only for scorm) |
||
| 5509 | * |
||
| 5510 | * @return boolean |
||
| 5511 | * @author ndiechburg <[email protected]> |
||
| 5512 | **/ |
||
| 5513 | public function switch_attempt_mode() |
||
| 5535 | |||
| 5536 | /** |
||
| 5537 | * Switch the lp in ktm mode. This is a special scorm mode with unique attempt |
||
| 5538 | * but possibility to do again a completed item. |
||
| 5539 | * |
||
| 5540 | * @return boolean true if seriousgame_mode has been set to 1, false otherwise |
||
| 5541 | * @author ndiechburg <[email protected]> |
||
| 5542 | **/ |
||
| 5543 | View Code Duplication | public function set_seriousgame_mode() |
|
| 5572 | |||
| 5573 | /** |
||
| 5574 | * Updates the "scorm_debug" value that shows or hide the debug window |
||
| 5575 | * @return boolean True if scorm_debug has been set to 'on', false otherwise (or 1 or 0 in this case) |
||
| 5576 | */ |
||
| 5577 | View Code Duplication | public function update_scorm_debug() |
|
| 5607 | |||
| 5608 | /** |
||
| 5609 | * Function that makes a call to the function sort_tree_array and create_tree_array |
||
| 5610 | * @author Kevin Van Den Haute |
||
| 5611 | * @param array |
||
| 5612 | */ |
||
| 5613 | public function tree_array($array) |
||
| 5621 | |||
| 5622 | /** |
||
| 5623 | * Creates an array with the elements of the learning path tree in it |
||
| 5624 | * |
||
| 5625 | * @author Kevin Van Den Haute |
||
| 5626 | * @param array $array |
||
| 5627 | * @param int $parent |
||
| 5628 | * @param int $depth |
||
| 5629 | * @param array $tmp |
||
| 5630 | */ |
||
| 5631 | public function create_tree_array($array, $parent = 0, $depth = -1, $tmp = array()) |
||
| 5677 | |||
| 5678 | /** |
||
| 5679 | * Sorts a multi dimensional array by parent id and display order |
||
| 5680 | * @author Kevin Van Den Haute |
||
| 5681 | * |
||
| 5682 | * @param array $array (array with al the learning path items in it) |
||
| 5683 | * |
||
| 5684 | * @return array |
||
| 5685 | */ |
||
| 5686 | public function sort_tree_array($array) |
||
| 5699 | |||
| 5700 | /** |
||
| 5701 | * Function that creates a html list of learning path items so that we can add audio files to them |
||
| 5702 | * @author Kevin Van Den Haute |
||
| 5703 | * @return string |
||
| 5704 | */ |
||
| 5705 | public function overview() |
||
| 5762 | |||
| 5763 | /** |
||
| 5764 | * @param string string $update_audio |
||
| 5765 | * @param bool $drop_element_here |
||
| 5766 | * @return string |
||
| 5767 | */ |
||
| 5768 | public function return_new_tree($update_audio = 'false', $drop_element_here = false) |
||
| 6131 | |||
| 6132 | /** |
||
| 6133 | * @param array $elements |
||
| 6134 | * @param array $default_data |
||
| 6135 | * @param array $default_content |
||
| 6136 | * @return string |
||
| 6137 | */ |
||
| 6138 | public function print_recursive($elements, $default_data, $default_content) |
||
| 6177 | |||
| 6178 | /** |
||
| 6179 | * This function builds the action menu |
||
| 6180 | * @param bool $returnContent Optional |
||
| 6181 | * @param bool $showRequirementButtons Optional. Allow show the requirements button |
||
| 6182 | * @param bool $isConfigPage Optional. If is the config page, show the edit button |
||
| 6183 | * @param bool $allowExpand Optional. Allow show the expand/contract button |
||
| 6184 | * @return string |
||
| 6185 | */ |
||
| 6186 | public function build_action_menu($returnContent = false, $showRequirementButtons = true, $isConfigPage = false, $allowExpand = true) |
||
| 6266 | |||
| 6267 | /** |
||
| 6268 | * Creates the default learning path folder |
||
| 6269 | * @param array $course |
||
| 6270 | * @param int $creatorId |
||
| 6271 | * |
||
| 6272 | * @return bool |
||
| 6273 | */ |
||
| 6274 | public static function generate_learning_path_folder($course, $creatorId = 0) |
||
| 6303 | |||
| 6304 | /** |
||
| 6305 | * @param array $course |
||
| 6306 | * @param string $lp_name |
||
| 6307 | * @param int $creatorId |
||
| 6308 | * |
||
| 6309 | * @return array |
||
| 6310 | */ |
||
| 6311 | public function generate_lp_folder($course, $lp_name = '', $creatorId = 0) |
||
| 6371 | |||
| 6372 | /** |
||
| 6373 | * Create a new document //still needs some finetuning |
||
| 6374 | * @param array $courseInfo |
||
| 6375 | * @param string $content |
||
| 6376 | * @param string $title |
||
| 6377 | * @param string $extension |
||
| 6378 | * @param int $parentId |
||
| 6379 | * @param int $creatorId creator id |
||
| 6380 | * |
||
| 6381 | * @return string |
||
| 6382 | */ |
||
| 6383 | public function create_document( |
||
| 6550 | |||
| 6551 | /** |
||
| 6552 | * Edit a document based on $_POST and $_GET parameters 'dir' and 'path' |
||
| 6553 | * @param array $_course array |
||
| 6554 | * @return void |
||
| 6555 | */ |
||
| 6556 | public function edit_document($_course) |
||
| 6615 | |||
| 6616 | /** |
||
| 6617 | * Displays the selected item, with a panel for manipulating the item |
||
| 6618 | * @param int $item_id |
||
| 6619 | * @param string $msg |
||
| 6620 | * @return string |
||
| 6621 | */ |
||
| 6622 | public function display_item($item_id, $msg = null, $show_actions = true) |
||
| 6723 | |||
| 6724 | /** |
||
| 6725 | * Shows the needed forms for editing a specific item |
||
| 6726 | * @param int $item_id |
||
| 6727 | * @return string |
||
| 6728 | */ |
||
| 6729 | public function display_edit_item($item_id) |
||
| 6831 | |||
| 6832 | /** |
||
| 6833 | * Function that displays a list with al the resources that |
||
| 6834 | * could be added to the learning path |
||
| 6835 | * @return string |
||
| 6836 | */ |
||
| 6837 | public function display_resources() |
||
| 6887 | |||
| 6888 | /** |
||
| 6889 | * Returns the extension of a document |
||
| 6890 | * @param string $filename |
||
| 6891 | * @return string Extension (part after the last dot) |
||
| 6892 | */ |
||
| 6893 | public function get_extension($filename) |
||
| 6898 | |||
| 6899 | /** |
||
| 6900 | * Displays a document by id |
||
| 6901 | * |
||
| 6902 | * @param int $id |
||
| 6903 | * @return string |
||
| 6904 | */ |
||
| 6905 | public function display_document($id, $show_title = false, $iframe = true, $edit_link = false) |
||
| 6925 | |||
| 6926 | /** |
||
| 6927 | * Return HTML form to add/edit a quiz |
||
| 6928 | * @param string $action Action (add/edit) |
||
| 6929 | * @param integer $id Item ID if already exists |
||
| 6930 | * @param mixed $extra_info Extra information (quiz ID if integer) |
||
| 6931 | * @return string HTML form |
||
| 6932 | */ |
||
| 6933 | public function display_quiz_form($action = 'add', $id = 0, $extra_info = '') |
||
| 7131 | |||
| 7132 | /** |
||
| 7133 | * Addition of Hotpotatoes tests |
||
| 7134 | * @param string Action |
||
| 7135 | * @param integer Internal ID of the item |
||
| 7136 | * @param mixed Extra information - can be an array with title and description indexes |
||
| 7137 | * @return string HTML structure to display the hotpotatoes addition formular |
||
| 7138 | */ |
||
| 7139 | public function display_hotpotatoes_form($action = 'add', $id = 0, $extra_info = '') |
||
| 7316 | |||
| 7317 | /** |
||
| 7318 | * Return the form to display the forum edit/add option |
||
| 7319 | * @param string Action (add/edit) |
||
| 7320 | * @param integer ID of the lp_item if already exists |
||
| 7321 | * @param mixed Forum ID or title |
||
| 7322 | * @return string HTML form |
||
| 7323 | */ |
||
| 7324 | public function display_forum_form($action = 'add', $id = 0, $extra_info = '') |
||
| 7522 | |||
| 7523 | /** |
||
| 7524 | * Return HTML form to add/edit forum threads |
||
| 7525 | * @param string Action (add/edit) |
||
| 7526 | * @param integer Item ID if already exists in learning path |
||
| 7527 | * @param mixed Extra information (thread ID if integer) |
||
| 7528 | * @return string HTML form |
||
| 7529 | */ |
||
| 7530 | public function display_thread_form($action = 'add', $id = 0, $extra_info = '') |
||
| 7738 | |||
| 7739 | /** |
||
| 7740 | * Return the HTML form to display an item (generally a dir item) |
||
| 7741 | * @param string Item type (dir) |
||
| 7742 | * @param string Title (optional, only when creating) |
||
| 7743 | * @param string Action ('add'/'edit') |
||
| 7744 | * @param integer lp_item ID |
||
| 7745 | * @param mixed Extra info |
||
| 7746 | * @return string HTML form |
||
| 7747 | */ |
||
| 7748 | public function display_item_form($item_type, $title = '', $action = 'add_item', $id = 0, $extra_info = 'new') |
||
| 7956 | |||
| 7957 | /** |
||
| 7958 | * @return string |
||
| 7959 | */ |
||
| 7960 | public function getCurrentBuildingModeURL() |
||
| 7971 | |||
| 7972 | /** |
||
| 7973 | * Returns the form to update or create a document |
||
| 7974 | * @param string $action (add/edit) |
||
| 7975 | * @param integer $id ID of the lp_item (if already exists) |
||
| 7976 | * @param mixed $extra_info Integer if document ID, string if info ('new') |
||
| 7977 | * @return string HTML form |
||
| 7978 | */ |
||
| 7979 | public function display_document_form($action = 'add', $id = 0, $extra_info = 'new') |
||
| 8369 | |||
| 8370 | /** |
||
| 8371 | * Return HTML form to add/edit a link item |
||
| 8372 | * @param string $action (add/edit) |
||
| 8373 | * @param integer $id Item ID if exists |
||
| 8374 | * @param mixed $extra_info |
||
| 8375 | * @return string HTML form |
||
| 8376 | */ |
||
| 8377 | public function display_link_form($action = 'add', $id = 0, $extra_info = '') |
||
| 8582 | |||
| 8583 | /** |
||
| 8584 | * Return HTML form to add/edit a student publication (work) |
||
| 8585 | * @param string Action (add/edit) |
||
| 8586 | * @param integer Item ID if already exists |
||
| 8587 | * @param mixed Extra info (work ID if integer) |
||
| 8588 | * @return string HTML form |
||
| 8589 | */ |
||
| 8590 | public function display_student_publication_form($action = 'add', $id = 0, $extra_info = '') |
||
| 8782 | |||
| 8783 | /** |
||
| 8784 | * Displays the menu for manipulating a step |
||
| 8785 | * |
||
| 8786 | * @param $item_id |
||
| 8787 | * @param string $item_type |
||
| 8788 | * @return string |
||
| 8789 | */ |
||
| 8790 | public function display_manipulate($item_id, $item_type = TOOL_DOCUMENT) |
||
| 8897 | |||
| 8898 | /** |
||
| 8899 | * Creates the javascript needed for filling up the checkboxes without page reload |
||
| 8900 | * @return string |
||
| 8901 | */ |
||
| 8902 | public function get_js_dropdown_array() |
||
| 8951 | |||
| 8952 | /** |
||
| 8953 | * Display the form to allow moving an item |
||
| 8954 | * @param integer $item_id Item ID |
||
| 8955 | * @return string HTML form |
||
| 8956 | */ |
||
| 8957 | public function display_move_item($item_id) |
||
| 9015 | |||
| 9016 | /** |
||
| 9017 | * Displays a basic form on the overview page for changing the item title and the item description. |
||
| 9018 | * @param string $item_type |
||
| 9019 | * @param string $title |
||
| 9020 | * @param array $data |
||
| 9021 | * @return string |
||
| 9022 | */ |
||
| 9023 | public function display_item_small_form($item_type, $title = '', $data = array()) |
||
| 9037 | |||
| 9038 | /** |
||
| 9039 | * Return HTML form to allow prerequisites selection |
||
| 9040 | * @todo use FormValidator |
||
| 9041 | * @param integer Item ID |
||
| 9042 | * @return string HTML form |
||
| 9043 | */ |
||
| 9044 | public function display_item_prerequisites_form($item_id) |
||
| 9186 | |||
| 9187 | /** |
||
| 9188 | * Return HTML list to allow prerequisites selection for lp |
||
| 9189 | * @param integer Item ID |
||
| 9190 | * @return string HTML form |
||
| 9191 | */ |
||
| 9192 | public function display_lp_prerequisites_list() |
||
| 9224 | |||
| 9225 | /** |
||
| 9226 | * Creates a list with all the documents in it |
||
| 9227 | * @param bool $showInvisibleFiles |
||
| 9228 | * @return string |
||
| 9229 | */ |
||
| 9230 | public function get_documents($showInvisibleFiles = false) |
||
| 9321 | |||
| 9322 | /** |
||
| 9323 | * Creates a list with all the exercises (quiz) in it |
||
| 9324 | * @return string |
||
| 9325 | */ |
||
| 9326 | public function get_exercises() |
||
| 9410 | |||
| 9411 | /** |
||
| 9412 | * Creates a list with all the links in it |
||
| 9413 | * @return string |
||
| 9414 | */ |
||
| 9415 | public function get_links() |
||
| 9520 | |||
| 9521 | /** |
||
| 9522 | * Creates a list with all the student publications in it |
||
| 9523 | * @return string |
||
| 9524 | */ |
||
| 9525 | public function get_student_publications() |
||
| 9565 | |||
| 9566 | /** |
||
| 9567 | * Creates a list with all the forums in it |
||
| 9568 | * @return string |
||
| 9569 | */ |
||
| 9570 | public function get_forums() |
||
| 9681 | |||
| 9682 | /** |
||
| 9683 | * // TODO: The output encoding should be equal to the system encoding. |
||
| 9684 | * |
||
| 9685 | * Exports the learning path as a SCORM package. This is the main function that |
||
| 9686 | * gathers the content, transforms it, writes the imsmanifest.xml file, zips the |
||
| 9687 | * whole thing and returns the zip. |
||
| 9688 | * |
||
| 9689 | * This method needs to be called in PHP5, as it will fail with non-adequate |
||
| 9690 | * XML package (like the ones for PHP4), and it is *not* a static method, so |
||
| 9691 | * you need to call it on a learnpath object. |
||
| 9692 | * @TODO The method might be redefined later on in the scorm class itself to avoid |
||
| 9693 | * creating a SCORM structure if there is one already. However, if the initial SCORM |
||
| 9694 | * path has been modified, it should use the generic method here below. |
||
| 9695 | * @TODO link this function with the export_lp() function in the same class |
||
| 9696 | * @param string Optional name of zip file. If none, title of learnpath is |
||
| 9697 | * domesticated and trailed with ".zip" |
||
| 9698 | * @return string Returns the zip package string, or null if error |
||
| 9699 | */ |
||
| 9700 | public function scorm_export() |
||
| 10592 | |||
| 10593 | /** |
||
| 10594 | * @param int $lp_id |
||
| 10595 | * @return bool |
||
| 10596 | */ |
||
| 10597 | public function scorm_export_to_pdf($lp_id) |
||
| 10647 | |||
| 10648 | /** |
||
| 10649 | * Temp function to be moved in main_api or the best place around for this. |
||
| 10650 | * Creates a file path if it doesn't exist |
||
| 10651 | * @param string $path |
||
| 10652 | */ |
||
| 10653 | public function create_path($path) |
||
| 10672 | |||
| 10673 | /** |
||
| 10674 | * Delete the image relative to this learning path. No parameter. Only works on instanciated object. |
||
| 10675 | * @return boolean The results of the unlink function, or false if there was no image to start with |
||
| 10676 | */ |
||
| 10677 | public function delete_lp_image() |
||
| 10693 | |||
| 10694 | /** |
||
| 10695 | * Uploads an author image to the upload/learning_path/images directory |
||
| 10696 | * @param array The image array, coming from the $_FILES superglobal |
||
| 10697 | * @return boolean True on success, false on error |
||
| 10698 | */ |
||
| 10699 | public function upload_image($image_array) |
||
| 10741 | |||
| 10742 | /** |
||
| 10743 | * @param int $lp_id |
||
| 10744 | * @param string $status |
||
| 10745 | */ |
||
| 10746 | public function set_autolaunch($lp_id, $status) |
||
| 10764 | |||
| 10765 | /** |
||
| 10766 | * Gets previous_item_id for the next element of the lp_item table |
||
| 10767 | * @author Isaac flores paz |
||
| 10768 | * @return integer Previous item ID |
||
| 10769 | */ |
||
| 10770 | public function select_previous_item_id() |
||
| 10796 | |||
| 10797 | /** |
||
| 10798 | * Copies an LP |
||
| 10799 | */ |
||
| 10800 | public function copy() |
||
| 10828 | |||
| 10829 | /** |
||
| 10830 | * Verify document size |
||
| 10831 | * @param string $s |
||
| 10832 | * @return bool |
||
| 10833 | */ |
||
| 10834 | public static function verify_document_size($s) |
||
| 10857 | |||
| 10858 | /** |
||
| 10859 | * Clear LP prerequisites |
||
| 10860 | */ |
||
| 10861 | public function clear_prerequisites() |
||
| 10879 | |||
| 10880 | public function set_previous_step_as_prerequisite_for_all_items() |
||
| 10931 | |||
| 10932 | /** |
||
| 10933 | * @param array $params |
||
| 10934 | */ |
||
| 10935 | public static function createCategory($params) |
||
| 10944 | /** |
||
| 10945 | * @param array $params |
||
| 10946 | */ |
||
| 10947 | public static function updateCategory($params) |
||
| 10958 | |||
| 10959 | /** |
||
| 10960 | * @param int $id |
||
| 10961 | */ |
||
| 10962 | View Code Duplication | public static function moveUpCategory($id) |
|
| 10974 | |||
| 10975 | /** |
||
| 10976 | * @param int $id |
||
| 10977 | */ |
||
| 10978 | View Code Duplication | public static function moveDownCategory($id) |
|
| 10990 | |||
| 10991 | /** |
||
| 10992 | * @param int $courseId |
||
| 10993 | * @return int|mixed |
||
| 10994 | */ |
||
| 10995 | public static function getCountCategories($courseId) |
||
| 11006 | |||
| 11007 | /** |
||
| 11008 | * @param int $courseId |
||
| 11009 | * |
||
| 11010 | * @return mixed |
||
| 11011 | */ |
||
| 11012 | View Code Duplication | public static function getCategories($courseId) |
|
| 11030 | |||
| 11031 | /** |
||
| 11032 | * @param int $id |
||
| 11033 | * |
||
| 11034 | * @return CLpCategory |
||
| 11035 | */ |
||
| 11036 | public static function getCategory($id) |
||
| 11043 | |||
| 11044 | /** |
||
| 11045 | * @param int $courseId |
||
| 11046 | * @return array |
||
| 11047 | */ |
||
| 11048 | View Code Duplication | public static function getCategoryByCourse($courseId) |
|
| 11057 | |||
| 11058 | /** |
||
| 11059 | * @param int $id |
||
| 11060 | * |
||
| 11061 | * @return mixed |
||
| 11062 | */ |
||
| 11063 | public static function deleteCategory($id) |
||
| 11086 | |||
| 11087 | /** |
||
| 11088 | * @param int $courseId |
||
| 11089 | * @param bool $addSelectOption |
||
| 11090 | * |
||
| 11091 | * @return mixed |
||
| 11092 | */ |
||
| 11093 | public static function getCategoryFromCourseIntoSelect($courseId, $addSelectOption = false) |
||
| 11109 | |||
| 11110 | /** |
||
| 11111 | * Return the scorm item type object with spaces replaced with _ |
||
| 11112 | * The return result is use to build a css classname like scorm_type_$return |
||
| 11113 | * @param $in_type |
||
| 11114 | * @return mixed |
||
| 11115 | */ |
||
| 11116 | private static function format_scorm_type_item($in_type) |
||
| 11120 | |||
| 11121 | /** |
||
| 11122 | * @param string $courseCode |
||
| 11123 | * @param int $lp_id |
||
| 11124 | * @param int $user_id |
||
| 11125 | * |
||
| 11126 | * @return learnpath |
||
| 11127 | */ |
||
| 11128 | public static function getLpFromSession($courseCode, $lp_id, $user_id) |
||
| 11142 | |||
| 11143 | /** |
||
| 11144 | * @param int $itemId |
||
| 11145 | * @return learnpathItem|false |
||
| 11146 | */ |
||
| 11147 | public function getItem($itemId) |
||
| 11155 | |||
| 11156 | /** |
||
| 11157 | * @return int |
||
| 11158 | */ |
||
| 11159 | public function getCategoryId() |
||
| 11163 | |||
| 11164 | /** |
||
| 11165 | * @param int $categoryId |
||
| 11166 | * @return bool |
||
| 11167 | */ |
||
| 11168 | public function setCategoryId($categoryId) |
||
| 11180 | |||
| 11181 | /** |
||
| 11182 | * Get whether this is a learning path with the possibility to subscribe |
||
| 11183 | * users or not |
||
| 11184 | * @return int |
||
| 11185 | */ |
||
| 11186 | public function getSubscribeUsers() |
||
| 11190 | |||
| 11191 | /** |
||
| 11192 | * Set whether this is a learning path with the possibility to subscribe |
||
| 11193 | * users or not |
||
| 11194 | * @param int $value (0 = false, 1 = true) |
||
| 11195 | * @return bool |
||
| 11196 | */ |
||
| 11197 | View Code Duplication | public function setSubscribeUsers($value) |
|
| 11211 | |||
| 11212 | /** |
||
| 11213 | * Calculate the count of stars for a user in this LP |
||
| 11214 | * This calculation is based on the following rules: |
||
| 11215 | * - the student gets one star when he gets to 50% of the learning path |
||
| 11216 | * - the student gets a second star when the average score of all tests inside the learning path >= 50% |
||
| 11217 | * - the student gets a third star when the average score of all tests inside the learning path >= 80% |
||
| 11218 | * - the student gets the final star when the score for the *last* test is >= 80% |
||
| 11219 | * @param int $sessionId Optional. The session ID |
||
| 11220 | * @return int The count of stars |
||
| 11221 | */ |
||
| 11222 | public function getCalculateStars($sessionId = 0) |
||
| 11298 | |||
| 11299 | /** |
||
| 11300 | * Get the items of exercise type |
||
| 11301 | * @return array The items. Otherwise return false |
||
| 11302 | */ |
||
| 11303 | View Code Duplication | public function getExercisesItems() |
|
| 11317 | |||
| 11318 | /** |
||
| 11319 | * Get the item of exercise type (evaluation type) |
||
| 11320 | * @return array The final evaluation. Otherwise return false |
||
| 11321 | */ |
||
| 11322 | View Code Duplication | public function getFinalEvaluationItem() |
|
| 11335 | |||
| 11336 | /** |
||
| 11337 | * Calculate the total points achieved for the current user in this learning path |
||
| 11338 | * @param int $sessionId Optional. The session Id |
||
| 11339 | * @return int |
||
| 11340 | */ |
||
| 11341 | public function getCalculateScore($sessionId = 0) |
||
| 11389 | |||
| 11390 | /** |
||
| 11391 | * Check if URL is not allowed to be show in a iframe |
||
| 11392 | * @param string $src |
||
| 11393 | * |
||
| 11394 | * @return string |
||
| 11395 | */ |
||
| 11396 | public function fixBlockedLinks($src) |
||
| 11450 | |||
| 11451 | /** |
||
| 11452 | * Check if this LP has a created forum in the basis course |
||
| 11453 | * @return boolean |
||
| 11454 | */ |
||
| 11455 | public function lpHasForum() |
||
| 11482 | |||
| 11483 | /** |
||
| 11484 | * Get the forum for this learning path |
||
| 11485 | * @param int $sessionId |
||
| 11486 | * @return boolean |
||
| 11487 | */ |
||
| 11488 | public function getForum($sessionId = 0) |
||
| 11533 | |||
| 11534 | /** |
||
| 11535 | * Create a forum for this learning path |
||
| 11536 | * @param type $forumCategoryId |
||
| 11537 | * @return int The forum ID if was created. Otherwise return false |
||
| 11538 | */ |
||
| 11539 | public function createForum($forumCategoryId) |
||
| 11561 | |||
| 11562 | /** |
||
| 11563 | * Check and obtain the lp final item if exist |
||
| 11564 | * |
||
| 11565 | * @return learnpathItem |
||
| 11566 | */ |
||
| 11567 | private function getFinalItem() |
||
| 11581 | |||
| 11582 | /** |
||
| 11583 | * Get the LP Final Item Template |
||
| 11584 | * |
||
| 11585 | * @return string |
||
| 11586 | */ |
||
| 11587 | private function getFinalItemTemplate() |
||
| 11591 | |||
| 11592 | /** |
||
| 11593 | * Get the LP Final Item Url |
||
| 11594 | * |
||
| 11595 | * @return string |
||
| 11596 | */ |
||
| 11597 | private function getSavedFinalItem() |
||
| 11607 | |||
| 11608 | /** |
||
| 11609 | * Get the LP Final Item form |
||
| 11610 | * |
||
| 11611 | * @return string |
||
| 11612 | */ |
||
| 11613 | public function getFinalItemForm() |
||
| 11705 | |||
| 11706 | /** |
||
| 11707 | * Check if the current lp item is first, both, last or none from lp list |
||
| 11708 | * |
||
| 11709 | * @param int $currentItemId |
||
| 11710 | * @return string |
||
| 11711 | */ |
||
| 11712 | public function isFirstOrLastItem($currentItemId) |
||
| 11749 | |||
| 11750 | /** |
||
| 11751 | * Get whether this is a learning path with the accumulated SCORM time or not |
||
| 11752 | * @return int |
||
| 11753 | */ |
||
| 11754 | public function getAccumulateScormTime() |
||
| 11758 | |||
| 11759 | /** |
||
| 11760 | * Set whether this is a learning path with the accumulated SCORM time or not |
||
| 11761 | * @param int $value (0 = false, 1 = true) |
||
| 11762 | * @return bool Always returns true |
||
| 11763 | */ |
||
| 11764 | View Code Duplication | public function setAccumulateScormTime($value) |
|
| 11778 | |||
| 11779 | /** |
||
| 11780 | * Returns an HTML-formatted link to a resource, to incorporate directly into |
||
| 11781 | * the new learning path tool. |
||
| 11782 | * |
||
| 11783 | * The function is a big switch on tool type. |
||
| 11784 | * In each case, we query the corresponding table for information and build the link |
||
| 11785 | * with that information. |
||
| 11786 | * @author Yannick Warnier <[email protected]> - rebranding based on |
||
| 11787 | * previous work (display_addedresource_link_in_learnpath()) |
||
| 11788 | * @param int $course_id Course code |
||
| 11789 | * @param int $learningPathId The learning path ID (in lp table) |
||
| 11790 | * @param int $id_in_path the unique index in the items table |
||
| 11791 | * @param int $lpViewId |
||
| 11792 | * @param string $origin |
||
| 11793 | * @return string |
||
| 11794 | */ |
||
| 11795 | public static function rl_get_resource_link_for_learnpath( |
||
| 11941 | |||
| 11942 | /** |
||
| 11943 | * Gets the name of a resource (generally used in learnpath when no name is provided) |
||
| 11944 | * |
||
| 11945 | * @author Yannick Warnier <[email protected]> |
||
| 11946 | * @param string Course code |
||
| 11947 | * @param string The tool type (using constants declared in main_api.lib.php) |
||
| 11948 | * @param integer The resource ID |
||
| 11949 | * @return string |
||
| 11950 | */ |
||
| 11951 | public static function rl_get_resource_name($course_code, $learningPathId, $id_in_path) |
||
| 12050 | } |
||
| 12051 | |||
| 12057 |
Adding a
@returnannotation to a constructor is not recommended, since a constructor does not have a meaningful return value.Please refer to the PHP core documentation on constructors.