Minor - format code.

pull/2487/head
jmontoyaa 8 years ago
parent 577210c635
commit 15841a797a
  1. 17
      main/lp/aicc.class.php
  2. 274
      main/webservices/cm_webservice.php

@ -70,7 +70,8 @@ class aicc extends learnpath
/** /**
* Parses a set of AICC config files and puts everything into the $config array * Parses a set of AICC config files and puts everything into the $config array
* @param string Path to the config files dir on the system. If not defined, uses the base path of the course's scorm dir * @param string Path to the config files dir on the system.
* If not defined, uses the base path of the course's scorm dir
* @return array Structured array representing the config files' contents * @return array Structured array representing the config files' contents
*/ */
function parse_config_files($dir = '') function parse_config_files($dir = '')
@ -231,7 +232,9 @@ class aicc extends learnpath
return false; return false;
} }
if ($this->debug > 0) { error_log('New LP - In aicc::import_aicc('.$course_code.')', 0); } if ($this->debug > 0) {
error_log('New LP - In aicc::import_aicc('.$course_code.')', 0);
}
$new_lp = Database::get_course_table(TABLE_LP_MAIN); $new_lp = Database::get_course_table(TABLE_LP_MAIN);
$new_lp_item = Database::get_course_table(TABLE_LP_ITEM); $new_lp_item = Database::get_course_table(TABLE_LP_ITEM);
@ -251,7 +254,9 @@ class aicc extends learnpath
"($course_id, 3, '".$this->course_title."', '".$this->course_id."','".$this->course_description."',". "($course_id, 3, '".$this->course_title."', '".$this->course_id."','".$this->course_description."',".
"'".$this->subdir."', 0, 'embedded', '".$this->config_encoding."',". "'".$this->subdir."', 0, 'embedded', '".$this->config_encoding."',".
"'aicc_api.php','".$this->course_creator."',$dsp)"; "'aicc_api.php','".$this->course_creator."',$dsp)";
if ($this->debug > 2) { error_log('New LP - In import_aicc(), inserting path: '.$sql, 0); } if ($this->debug > 2) {
error_log('New LP - In import_aicc(), inserting path: '.$sql, 0);
}
Database::query($sql); Database::query($sql);
$lp_id = Database::insert_id(); $lp_id = Database::insert_id();
@ -640,7 +645,8 @@ class aicc extends learnpath
$lp = $this->get_id(); $lp = $this->get_id();
if ($lp != 0) { if ($lp != 0) {
$tbl_lp = Database::get_course_table(TABLE_LP_MAIN); $tbl_lp = Database::get_course_table(TABLE_LP_MAIN);
$sql = "UPDATE $tbl_lp SET author = '$author' WHERE c_id = ".$course_id." id = ".$lp; $sql = "UPDATE $tbl_lp SET author = '$author'
WHERE c_id = ".$course_id." id = ".$lp;
Database::query($sql); Database::query($sql);
return true; return true;
} else { } else {
@ -660,7 +666,8 @@ class aicc extends learnpath
$lp = $this->get_id(); $lp = $this->get_id();
if ($lp != 0) { if ($lp != 0) {
$tbl_lp = Database::get_course_table(TABLE_LP_MAIN); $tbl_lp = Database::get_course_table(TABLE_LP_MAIN);
$sql = "UPDATE $tbl_lp SET content_maker = '$maker' WHERE c_id = ".$course_id." id = ".$lp; $sql = "UPDATE $tbl_lp SET content_maker = '$maker'
WHERE c_id = ".$course_id." id = ".$lp;
Database::query($sql); Database::query($sql);
return true; return true;
} else { } else {

@ -87,12 +87,12 @@ class WSCMError
*/ */
interface WSCMErrorHandler interface WSCMErrorHandler
{ {
/** /**
* Handle method * Handle method
* *
* @param WSError $error Error * @param WSError $error Error
*/ */
public function handle($error); public function handle($error);
} }
/** /**
@ -100,57 +100,57 @@ interface WSCMErrorHandler
*/ */
class WSCM class WSCM
{ {
/** /**
* Chamilo configuration * Chamilo configuration
* *
* @var array * @var array
*/ */
protected $_configuration; protected $_configuration;
/** /**
* Constructor * Constructor
*/ */
public function __construct() public function __construct()
{ {
$this->_configuration = $GLOBALS['_configuration']; $this->_configuration = $GLOBALS['_configuration'];
} }
/** /**
* Verifies the API key * Verifies the API key
* *
* @param string $secret_key Secret key * @param string $secret_key Secret key
* @return mixed WSError in case of failure, null in case of success * @return mixed WSError in case of failure, null in case of success
*/ */
protected function verifyKey($secret_key) protected function verifyKey($secret_key)
{ {
$ip = trim($_SERVER['REMOTE_ADDR']); $ip = trim($_SERVER['REMOTE_ADDR']);
// if we are behind a reverse proxy, assume it will send the // if we are behind a reverse proxy, assume it will send the
// HTTP_X_FORWARDED_FOR header and use this IP instead // HTTP_X_FORWARDED_FOR header and use this IP instead
if (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) { if (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
list($ip1, $ip2) = split(',', $_SERVER['HTTP_X_FORWARDED_FOR']); list($ip1, $ip2) = explode(',', $_SERVER['HTTP_X_FORWARDED_FOR']);
$ip = trim($ip1); $ip = trim($ip1);
} }
$security_key = $ip.$this->_configuration['security_key']; $security_key = $ip.$this->_configuration['security_key'];
if (!api_is_valid_secret_key($secret_key, $security_key)) { if (!api_is_valid_secret_key($secret_key, $security_key)) {
return new WSCMError(1, "API key is invalid"); return new WSCMError(1, "API key is invalid");
} else { } else {
return null; return null;
} }
} }
/** /**
* Verifies if the user is valid * Verifies if the user is valid
* *
* @param string $username of the user in chamilo * @param string $username of the user in chamilo
* @param string $pass of the same user (in MD5 of SHA) * @param string $pass of the same user (in MD5 of SHA)
* *
* @return mixed "valid" if username e password are correct! Else, return a message error * @return mixed "valid" if username e password are correct! Else, return a message error
*/ */
public function verifyUserPass($username, $pass) public function verifyUserPass($username, $pass)
{ {
$login = $username; $login = $username;
$password = $pass; $password = $pass;
$userRepo = UserManager::getRepository(); $userRepo = UserManager::getRepository();
/** @var User $uData */ /** @var User $uData */
@ -183,17 +183,17 @@ class WSCM
} }
} }
return get_lang('InvalidId'); return get_lang('InvalidId');
} }
/** /**
* Gets the real user id based on the user id field name and value. * Gets the real user id based on the user id field name and value.
* Note that if the user id field name is "chamilo_user_id", it will use the user id * Note that if the user id field name is "chamilo_user_id", it will use the user id
* in the system database * in the system database
* *
* @param string $user_id_field_name User id field name * @param string $user_id_field_name User id field name
* @param string $user_id_value User id value * @param string $user_id_value User id value
* @return mixed System user id if the user was found, WSError otherwise * @return mixed System user id if the user was found, WSError otherwise
*/ */
protected function getUserId($user_id_field_name, $user_id_value) protected function getUserId($user_id_field_name, $user_id_value)
{ {
if ($user_id_field_name == "chamilo_user_id") { if ($user_id_field_name == "chamilo_user_id") {
@ -215,16 +215,16 @@ class WSCM
} }
} }
/** /**
* Gets the real course id based on the course id field name and value. * Gets the real course id based on the course id field name and value.
* Note that if the course id field name is "chamilo_course_id", it will use the course id * Note that if the course id field name is "chamilo_course_id", it will use the course id
* in the system database * in the system database
* *
* @param string $course_id_field_name Course id field name * @param string $course_id_field_name Course id field name
* @param string $course_id_value Course id value * @param string $course_id_value Course id value
* @return mixed System course id if the course was found, WSError otherwise * @return mixed System course id if the course was found, WSError otherwise
*/ */
protected function getCourseId($course_id_field_name, $course_id_value) protected function getCourseId($course_id_field_name, $course_id_value)
{ {
if ($course_id_field_name == "chamilo_course_id") { if ($course_id_field_name == "chamilo_course_id") {
if (CourseManager::get_course_code_from_course_id($course_id_value) != null) { if (CourseManager::get_course_code_from_course_id($course_id_value) != null) {
@ -243,78 +243,78 @@ class WSCM
return $courseId; return $courseId;
} }
} }
} }
/** /**
* Gets the real session id based on the session id field name and value. * Gets the real session id based on the session id field name and value.
* Note that if the session id field name is "chamilo_session_id", it will use the session id * Note that if the session id field name is "chamilo_session_id", it will use the session id
* in the system database * in the system database
* *
* @param string $session_id_field_name Session id field name * @param string $session_id_field_name Session id field name
* @param string $session_id_value Session id value * @param string $session_id_value Session id value
* @return mixed System session id if the session was found, WSError otherwise * @return mixed System session id if the session was found, WSError otherwise
*/ */
protected function getSessionId($session_id_field_name, $session_id_value) protected function getSessionId($session_id_field_name, $session_id_value)
{ {
if ($session_id_field_name == "chamilo_session_id") { if ($session_id_field_name == "chamilo_session_id") {
$session = SessionManager::fetch((int) $session_id_value); $session = SessionManager::fetch((int) $session_id_value);
if (!empty($session)) { if (!empty($session)) {
return intval($session_id_value); return intval($session_id_value);
} else { } else {
return new WSCMError(300, "Session not found"); return new WSCMError(300, "Session not found");
} }
} else { } else {
$session_id = SessionManager::getSessionIdFromOriginalId( $session_id = SessionManager::getSessionIdFromOriginalId(
$session_id_value, $session_id_value,
$session_id_field_name $session_id_field_name
); );
if ($session_id == 0) { if ($session_id == 0) {
return new WSCMError(300, "Session not found"); return new WSCMError(300, "Session not found");
} else { } else {
return $session_id; return $session_id;
} }
} }
} }
/** /**
* Handles an error by calling the WSError error handler * Handles an error by calling the WSError error handler
* *
* @param WSError $error Error * @param WSError $error Error
*/ */
protected function handleError($error) protected function handleError($error)
{ {
$handler = WSCMError::getErrorHandler(); $handler = WSCMError::getErrorHandler();
$handler->handle($error); $handler->handle($error);
} }
/** /**
* Gets a successful result * Gets a successful result
* *
* @return array Array with a code of 0 and a message 'Operation was successful' * @return array Array with a code of 0 and a message 'Operation was successful'
*/ */
protected function getSuccessfulResult() protected function getSuccessfulResult()
{ {
return array('code' => 0, 'message' => 'Operation was successful'); return array('code' => 0, 'message' => 'Operation was successful');
} }
/** /**
* Test function. Returns the string success * Test function. Returns the string success
* *
* @return string Success * @return string Success
*/ */
public function test() public function test()
{ {
return "success"; return "success";
} }
/** /**
* *Strictly* reverts PHP's nl2br() effects (whether it was used in XHTML mode or not) * *Strictly* reverts PHP's nl2br() effects (whether it was used in XHTML mode or not)
* @param string $string * @param string $string
* @return string * @return string
*/ */
public function nl2br_revert($string) public function nl2br_revert($string)
{ {
return preg_replace('`<br(?: /)?>([\\n\\r])`', '$1', $string); return preg_replace('`<br(?: /)?>([\\n\\r])`', '$1', $string);
} }
} }

Loading…
Cancel
Save