Skip to content

Commit

Permalink
IO Issues resolved
Browse files Browse the repository at this point in the history
  • Loading branch information
disc5 committed Jun 2, 2015
1 parent 7f39020 commit 21862db
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@
require_once('./Services/Database/classes/class.ilAuthContainerMDB2.php');


class DescribrModel
{
class DescribrModel extends Libs\RESTModel {

/**
* Returns a description of an ILIAS object consisting of
Expand All @@ -29,9 +28,12 @@ class DescribrModel
*/
public function describeIliasObject($obj_id)
{
self::$app->log->debug('describe '.$obj_id);

$a_objdata = $this->getObjectData($obj_id);
$owner_id = $a_objdata['owner'];


$a_usrdata = $this->getUserData($owner_id);
foreach ($a_usrdata as $key => $value)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,16 @@
$request = $app->request();
$id_type = $request->params('id_type', 'ref_id');

$app->log->debug('in route '.$id_type);


$result = array('msg' => array());
$model = new DescribrModel();
if ($id_type == 'ref_id' || $id_type == 'obj_id') {
if ($id_type == 'ref_id') {
$app->log->debug('in route id: '.$id);
$obj_id = Libs\RESTLib::getObjIdFromRef($id);
$app->log->debug('in route id: '.$obj_id);
$id_type = 'obj_id';
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@
'execution_time' => $t_end - $t_start
));

} catch(LibExceptions\MissingParameter $e) {
} catch(Exceptions\MissingParameter $e) {
$app->halt(422, $e->getFormatedMessage(), $e::ID);
}
});
Expand Down Expand Up @@ -107,7 +107,7 @@
$app->success(array(
'execution_time' => $t_end - $t_start
));
} catch(LibExceptions\MissingParameter $e) {
} catch(Exceptions\MissingParameter $e) {
$app->halt(422, $e->getFormatedMessage(), $e::ID);
}
$response->send();
Expand Down Expand Up @@ -178,7 +178,7 @@
Libs\RESTLib::initAccessHandling();
$model = new Files\PersonalFileSpaceModel();
$model->deleteFromMyFileSpace($file_id, $user_id);
} catch(LibExceptions\MissingParameter $e) {
} catch(Exceptions\MissingParameter $e) {
$app->halt(422, $e->getFormatedMessage(), $e::ID);
}
$t_end = microtime();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@


$app->get('/v1/users', '\RESTController\libs\OAuth2Middleware::TokenAdminAuth', function () use ($app) {
try {

$limit = 10;
$offset = 0;

Expand Down Expand Up @@ -47,14 +45,10 @@

$app->success($result);

} catch (\Exception $e) {
$app->halt(400, $e->getMessage());
}
});


$app->get('/v1/users/:user_id', '\RESTController\libs\OAuth2Middleware::TokenAuth', function ($user_id) use ($app) {
try {
$id = $user_id;
if ($user_id == "mine") {
$auth = new Auth\Util();
Expand All @@ -68,14 +62,10 @@

$app->success($usr_basic_info);

} catch (\Exception $e) {
$app->halt(400, $e->getMessage());
}
});


$app->post('/v1/users', '\RESTController\libs\OAuth2Middleware::TokenRouteAuth', function () use ($app) { // create
try { // root only

$request = $app->request();
$attribs = array("login", "passwd", "firstname", "lastname", "email", "gender", "auth_mode");
Expand All @@ -94,9 +84,7 @@
$user_id = $usr_model->addUser($user_data);

$app->success($user_id);
} catch (\Exception $e) {
$app->halt(400, $e->getMessage());
}

});


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,6 @@ protected static function quoteParams($params) {
$value = sprintf('(%s)', implode(', ', $value));
$result[] = $value;
}
elseif (is_string($value))
$result[] = $ilDB->quote($value, 'text');
elseif (is_int($value))
$result[] = $ilDB->quote($value, 'integer');
elseif (is_integer($value))
Expand All @@ -96,8 +94,10 @@ protected static function quoteParams($params) {
$result[] = $ilDB->quote($value, 'float');
elseif (is_double($value))
$result[] = $ilDB->quote($value, 'float');
elseif (is_numeric($value))
elseif (is_numeric($value)) // TODO: could be improved
$result[] = $ilDB->quote($value, 'float');
elseif (is_string($value))
$result[] = $ilDB->quote($value, 'text');
// Fallback solution
else
$result[] = $value;
Expand Down Expand Up @@ -215,7 +215,7 @@ static public function authenticateViaIlias($username, $password) {
static public function getObjIdFromRef($ref_id) {
global $ilDB;

$sql = self::safeSQL('SELECT obj_id FROM object_reference WHERE object_reference.ref_id = %d', $ref_id);
$sql = self::safeSQL('SELECT obj_id FROM object_reference WHERE object_reference.ref_id = %d', intval($ref_id));
$query = $ilDB->query($sql);
$row = $ilDB->fetchAssoc($query);

Expand All @@ -233,7 +233,7 @@ static public function getObjIdFromRef($ref_id) {
static public function getRefIdFromObj($obj_id) {
global $ilDB;

$sql = self::safeSQL('SELECT ref_id FROM object_reference WHERE object_reference.obj_id = %d', $obj_id);
$sql = self::safeSQL('SELECT ref_id FROM object_reference WHERE object_reference.obj_id = %d', intval($obj_id));
$query = $ilDB->query($sql);
$row = $ilDB->fetchAssoc($query);

Expand Down

0 comments on commit 21862db

Please sign in to comment.