Minor - format code

pull/3683/head
Julio Montoya 5 years ago
parent bbf657b06a
commit abd9b3ee9f
  1. 7
      main/inc/ajax/lp.ajax.php
  2. 25
      main/lp/learnpath.class.php
  3. 120
      main/lp/learnpathItem.class.php
  4. 25
      main/lp/lp_ajax_save_item.php
  5. 9
      main/lp/lp_ajax_switch_item.php

@ -101,7 +101,7 @@ switch ($action) {
$orderList = [];
foreach ($sections as $items) {
list($id, $parentId) = explode('|', $items);
[$id, $parentId] = explode('|', $items);
$orderList[$id] = $parentId;
}
@ -298,6 +298,11 @@ switch ($action) {
if (empty($lp) || empty($itemId)) {
exit;
}
if ($lp->debug) {
error_log('--------------------------------------');
error_log('get_item_prerequisites');
}
$result = $lp->prerequisites_match($itemId);
if ($result) {
echo '1';

@ -1612,15 +1612,24 @@ class learnpath
$completedStatusList[] = 'failed';
}
if ($this->debug) {
error_log('START - get_complete_items_count');
error_log('Counting steps with status in: '.print_r($completedStatusList, 1));
}
foreach ($this->items as $id => $dummy) {
// Trying failed and browsed considered "progressed" as well.
if ($this->items[$id]->status_is($completedStatusList) &&
$this->items[$id]->get_type() != 'dir'
$this->items[$id]->get_type() !== 'dir'
) {
$i++;
}
}
if ($this->debug) {
error_log('END - Count: '.$i);
}
return $i;
}
@ -3174,7 +3183,7 @@ class learnpath
*
* @param int $lp_id
*
* @return mixed Type ID or name, depending on the parameter
* @return mixed Returns the lp_type: 1 = Chamilo lms / 2 = SCORM
*/
public static function get_type_static($lp_id = 0)
{
@ -4865,10 +4874,6 @@ class learnpath
if (isset($this->items[$item_id]) &&
is_object($this->items[$item_id])
) {
if ($debug) {
error_log('Object exists');
}
// Saving the item.
$res = $this->items[$item_id]->save(
$from_outside,
@ -5524,10 +5529,8 @@ class learnpath
}
}
if ($debug) {
error_log('lp_view_session_id');
error_log($this->lp_view_session_id);
error_log('api session id');
error_log(api_get_session_id());
error_log('lp_view_session_id: '.$this->lp_view_session_id);
error_log('api_get_session_id: '.api_get_session_id());
error_log('End of learnpath::start_current_item()');
}
@ -5543,7 +5546,7 @@ class learnpath
{
$debug = $this->debug;
if ($debug) {
error_log('In learnpath::stop_previous_item()', 0);
error_log('In learnpath::stop_previous_item()');
}
if ($this->last != 0 && $this->last != $this->current &&

@ -255,22 +255,42 @@ class learnpathItem
*/
public function close()
{
if (self::DEBUG) {
error_log('Start - learnpathItem:close');
}
$this->current_stop_time = time();
$type = $this->get_type();
if (self::DEBUG) {
error_log("Type: ".$type);
error_log("get_id: ".$this->get_id());
}
if ($type !== 'sco') {
if ($type == TOOL_QUIZ || $type == TOOL_HOTPOTATOES) {
$this->get_status(
true,
true
); // Update status (second option forces the update).
);
} else {
/*if ($this->prerequisites_match()) {
}*/
$this->status = $this->possible_status[2];
if (self::DEBUG) {
error_log("STATUS changed to: ".$this->status);
}
}
}
if ($this->save_on_close) {
if (self::DEBUG) {
error_log("save_on_close: ");
}
$this->save();
}
if (self::DEBUG) {
error_log('End - learnpathItem:close');
}
return true;
}
@ -830,10 +850,10 @@ class learnpathItem
WHERE iid = ".$this->lp_id;
$res = Database::query($sql);
if (Database::num_rows($res) < 1) {
$this->error = "Could not find parent learnpath in lp table";
$this->error = 'Could not find parent learnpath in lp table';
if (self::DEBUG > 2) {
error_log(
'New LP - End of learnpathItem::get_prevent_reinit() - Returning false',
'LearnpathItem::get_prevent_reinit() - Returning false',
0
);
}
@ -849,10 +869,7 @@ class learnpathItem
}
}
if (self::DEBUG > 2) {
error_log(
'New LP - End of learnpathItem::get_prevent_reinit() - Returned '.$this->prevent_reinit,
0
);
error_log('End of learnpathItem::get_prevent_reinit() - Returned '.$this->prevent_reinit);
}
return $this->prevent_reinit;
@ -1463,12 +1480,12 @@ class learnpathItem
{
$courseId = $this->courseId;
$debug = self::DEBUG;
if ($debug > 0) {
error_log('learnpathItem::get_status() on item '.$this->db_id, 0);
if ($debug) {
error_log('learnpathItem::get_status() on item '.$this->db_id);
}
if ($check_db) {
if ($debug > 2) {
error_log('learnpathItem::get_status(): checking db', 0);
if ($debug) {
error_log('learnpathItem::get_status(): checking db');
}
if (!empty($this->db_item_view_id) && !empty($courseId)) {
$table = Database::get_course_table(TABLE_LP_ITEM_VIEW);
@ -1481,18 +1498,32 @@ class learnpathItem
if (Database::num_rows($res) == 1) {
$row = Database::fetch_array($res);
if ($update_local) {
if ($debug) {
error_log('Status to be updated to: '.$row['status']);
}
$this->set_status($row['status']);
}
if ($debug) {
error_log('Return of $row[status]: '.$row['status']);
}
return $row['status'];
}
}
} else {
if ($debug) {
error_log('Status from this->status: '.$this->status);
}
if (!empty($this->status)) {
return $this->status;
}
}
if ($debug) {
error_log('Return default: '.$this->possible_status[0]);
}
return $this->possible_status[0];
}
@ -2671,7 +2702,7 @@ class learnpathItem
{
$debug = self::DEBUG;
if ($debug) {
error_log('learnpathItem::save()', 0);
error_log('learnpathItem::save()');
}
// First check if parameters passed via GET can be saved here
// in case it's a SCORM, we should get:
@ -2832,10 +2863,7 @@ class learnpathItem
}
if ($debug) {
error_log(
'New LP - End of learnpathItem::save() - Calling write_to_db()',
0
);
error_log('End of learnpathItem::save() - Calling write_to_db() now');
}
return $this->write_to_db();
@ -3126,8 +3154,8 @@ class learnpathItem
*/
public function set_status($status)
{
if (self::DEBUG > 0) {
error_log('learnpathItem::set_status('.$status.')', 0);
if (self::DEBUG) {
error_log('learnpathItem::set_status('.$status.')');
}
$found = false;
@ -3139,18 +3167,21 @@ class learnpathItem
if ($found) {
$this->status = $status;
if (self::DEBUG > 1) {
if (self::DEBUG) {
error_log(
'learnpathItem::set_status() - '.
'Updated object status of item '.$this->db_id.
' to '.$this->status,
0
' to '.$this->status
);
}
return true;
}
if (self::DEBUG) {
error_log('Setting status: '.$this->possible_status[0]);
}
$this->status = $this->possible_status[0];
return false;
@ -3559,7 +3590,8 @@ class learnpathItem
{
$debug = self::DEBUG;
if ($debug) {
error_log('learnpathItem::write_to_db()', 0);
error_log('------------------------');
error_log('learnpathItem::write_to_db()');
}
// Check the session visibility.
@ -3570,7 +3602,11 @@ class learnpathItem
return false;
}
if (api_is_invitee()) {
if ($debug) {
error_log('api_is_invitee');
}
// If the user is an invitee, we don't write anything to DB
return true;
}
@ -3670,10 +3706,7 @@ class learnpathItem
lp_view_id = ".$this->view_id." AND
view_count = ".$this->get_attempt_id();
if ($debug) {
error_log(
'learnpathItem::write_to_db() - Querying item_view: '.$sql,
0
);
error_log('learnpathItem::write_to_db() - Querying item_view: '.$sql);
}
$check_res = Database::query($sql);
@ -3709,6 +3742,9 @@ class learnpathItem
Database::query($sql);
}
} else {
if ($debug) {
error_log('item is: '.$this->type);
}
if ($this->type === 'hotpotatoes') {
$params = [
'total_time' => $this->get_total_time(),
@ -3731,9 +3767,6 @@ class learnpathItem
} else {
// For all other content types...
if ($this->type === 'quiz') {
if ($debug) {
error_log("item is quiz:");
}
$my_status = ' ';
$total_time = ' ';
if (!empty($_REQUEST['exeId'])) {
@ -3752,6 +3785,10 @@ class learnpathItem
}
} else {
$my_type_lp = learnpath::get_type_static($this->lp_id);
if ($debug) {
error_log('get_type_static: '.$my_type_lp);
}
// This is a array containing values finished
$case_completed = [
'completed',
@ -3774,12 +3811,17 @@ class learnpathItem
view_count="'.$this->get_attempt_id().'"
';
$rs_verified = Database::query($sql);
$row_verified = Database::fetch_array($rs_verified);
$row_verified = Database::fetch_array($rs_verified, 'ASSOC');
// Get type lp: 1=lp dokeos and 2=scorm.
if ($debug) {
error_log("Query: $sql");
error_log("With result: ".print_r($row_verified, 1));
}
// Get type lp: 1 = Chamilo and 2 = Scorm.
// If not is completed or passed or browsed and learning path is scorm.
if (!in_array($this->get_status(false), $case_completed) &&
$my_type_lp == 2
2 == $my_type_lp
) {
$total_time = " total_time = total_time +".$this->get_total_time().", ";
$my_status = " status = '".$this->get_status(false)."' ,";
@ -3788,16 +3830,17 @@ class learnpathItem
}
} else {
// Verified into database.
if (!in_array($row_verified['status'], $case_completed) &&
$my_type_lp == 2
if (2 == $my_type_lp &&
!in_array($row_verified['status'], $case_completed)
) {
$total_time = " total_time = total_time +".$this->get_total_time().", ";
$my_status = " status = '".$this->get_status(false)."' ,";
if ($debug) {
error_log("total_time time changed case 1: $total_time");
}
} elseif (in_array($row_verified['status'], $case_completed) &&
$my_type_lp == 2 && $this->type != 'sco'
} elseif (2 == $my_type_lp &&
$this->type != 'sco' &&
in_array($row_verified['status'], $case_completed)
) {
$total_time = " total_time = total_time +".$this->get_total_time().", ";
$my_status = " status = '".$this->get_status(false)."' ,";
@ -3849,6 +3892,11 @@ class learnpathItem
lp_view_id="'.$this->view_id.'" AND
view_count="'.$this->get_attempt_id().'" ';
$rs_status = Database::query($sql);
if ($debug) {
error_log("Query: $sql");
error_log("With result: ".print_r($rs_status, 1));
}
$current_status = Database::result($rs_status, 0, 'status');
if (in_array($current_status, $case_completed)) {
$my_status = '';

@ -62,22 +62,23 @@ function save_item(
) {
$debug = 0;
$return = null;
$courseCode = api_get_course_id();
if (!empty($courseId)) {
$courseInfo = api_get_course_info_by_id($courseId);
if ($courseInfo) {
$courseCode = $courseInfo['code'];
}
}
if ($debug > 0) {
error_log('--------------------------------------');
error_log('SAVE ITEM - lp_ajax_save_item.php : save_item() params: ');
error_log('SAVE ITEM - lp_ajax_save_item.php');
error_log('--------------------------------------');
error_log("item_id: $item_id - lp_id: $lp_id - user_id: - $user_id - view_id: $view_id - item_id: $item_id");
error_log("SCORE: $score - max:$max - min: $min - status:$status");
error_log("TIME: $time - suspend: $suspend - location: $location - core_exit: $core_exit");
error_log("finish: $lmsFinish - navigatesAway: $userNavigatesAway");
}
$courseCode = api_get_course_id();
if (!empty($courseId)) {
$courseInfo = api_get_course_info_by_id($courseId);
if ($courseInfo) {
$courseCode = $courseInfo['code'];
}
error_log("courseCode: $courseCode");
}
$myLP = learnpath::getLpFromSession($courseCode, $lp_id, $user_id);
@ -101,7 +102,7 @@ function save_item(
error_log("item #$item_id not found in the items array: ".print_r($myLP->items, 1));
}
return false;
return null;
}
// This functions sets the $this->db_item_view_id variable needed in get_status() see BT#5069
@ -111,10 +112,10 @@ function save_item(
if (true !== $prerequisitesCheck) {
// If prerequisites were not matched, don't update any item info
if ($debug) {
error_log("prereq_check: ".intval($prerequisitesCheck));
error_log("prereq_check failed: ".intval($prerequisitesCheck));
}
return $return;
return null;
} else {
if ($debug > 1) {
error_log('Prerequisites are OK');

@ -1,4 +1,5 @@
<?php
/* For licensing terms, see /license.txt */
use ChamiloSession as Session;
@ -29,10 +30,9 @@ function switch_item_details($lp_id, $user_id, $view_id, $current_item, $next_it
$debug = 0;
$return = '';
if ($debug > 0) {
error_log(
'In xajax_switch_item_details('.$lp_id.','.$user_id.','.$view_id.','.$current_item.','.$next_item.')',
0
);
error_log('--------------------------------------');
error_log('SWITCH');
error_log('Params('.$lp_id.','.$user_id.','.$view_id.','.$current_item.','.$next_item.')');
}
//$objResponse = new xajaxResponse();
/*$item_id may be one of:
@ -268,6 +268,7 @@ function switch_item_details($lp_id, $user_id, $view_id, $current_item, $next_it
$mylp->set_error_msg('');
$mylp->prerequisites_match(); // Check the prerequisites are all complete.
if ($debug > 1) {
error_log($return);
error_log('Prereq_match() returned '.htmlentities($mylp->error), 0);
}
// Save the new item ID for the exercise tool to use.

Loading…
Cancel
Save