Edit in functions

This commit is contained in:
Valentin Popov 2017-11-30 12:54:03 +04:00
parent 9b223669df
commit 12356f9fcc

82
lib.php
View File

@ -51,51 +51,51 @@ function tool_managertokens_activate_token($token = "") {
/** /**
* Creates an entry in the database. * Creates an entry in the database.
* *
* @param array $options * @param object $options
* @return number * @return number
*/ */
function tool_managertokens_create_record($options = array()) { function tool_managertokens_create_record($options) {
global $DB; global $DB;
if (!isset($options["targetid"])) { if (!isset($options->targetid)) {
print_error("missingparam", "error", "", "targetid"); print_error("missingparam", "error", "", "targetid");
} }
if (!isset($options["targettype"])) { if (!isset($options->targettype)) {
print_error("missingparam", "error", "", "targettype"); print_error("missingparam", "error", "", "targettype");
} }
if (!isset($options["token"])) { if (!isset($options->token)) {
print_error("missingparam", "error", "", "token"); print_error("missingparam", "error", "", "token");
} }
if ($DB->record_exists("tool_managertokens_tokens", array("token" => $options["token"]))) { if ($DB->record_exists("tool_managertokens_tokens", array("token" => $options->token))) {
print_error("duplicatefieldname", "error", "", "token"); print_error("duplicatefieldname", "error", "", "token");
} }
$token = array(); $token = new stdClass();
$token["enabled"] = false; $token->enabled = false;
$token["timecreated"] = time(); $token->timecreated = time();
$token["targetid"] = intval($options["targetid"]); $token->targetid = intval($options->targetid);
$token["targettype"] = intval($options["targettype"]); $token->targettype = intval($options->targettype);
$token["timemodified"] = $token["timecreated"]; $token->timemodified = $token->timecreated;
$token["token"] = strval($options["token"]); $token->token = strval($options->token);
if (isset($options["enabled"])) { if (isset($options->enabled)) {
$token["enabled"] = boolval($options["enabled"]); $token->enabled = boolval($options->enabled);
} }
if (isset($options["extendedaction"]) && isset($options["extendedoptions"])) { if (isset($options->extendedaction) && isset($options->extendedoptions)) {
$token["extendedaction"] = strval($options["extendedaction"]); $token->extendedaction = strval($options->extendedaction);
$token["extendedoptions"] = strval($options["extendedoptions"]); $token->extendedoptions = strval($options->extendedoptions);
} }
if (isset($options["limited"])) { if (isset($options->limited)) {
$token["limited"] = intval($options["limited"]); $token->limited = intval($options->limited);
} }
if (isset($options["timelimited"])) { if (isset($options->timelimited)) {
$token["timelimited"] = intval($options["timelimited"]); $token->timelimited = intval($options->timelimited);
} }
$recordid = $DB->insert_record("tool_managertokens_tokens", $token, true, false); $recordid = $DB->insert_record("tool_managertokens_tokens", $token, true, false);
@ -156,48 +156,48 @@ function tool_managertokens_get_list($limitfrom = 0, $limitnum = 0) {
/** /**
* Updates the entry in the database. * Updates the entry in the database.
* *
* @param array $options * @param object $options
* @return boolean * @return boolean
*/ */
function tool_managertokens_update_record($options = array()) { function tool_managertokens_update_record($options) {
global $DB; global $DB;
$result = false; $result = false;
if (!isset($options["id"])) { if (!isset($options->id)) {
print_error("missingparam", "error", "", "id"); print_error("missingparam", "error", "", "id");
} }
if ($token = $DB->get_record("tool_managertokens_tokens", array("id" => $options["id"]), "*", IGNORE_MISSING)) { if ($token = $DB->get_record("tool_managertokens_tokens", array("id" => $options->id), "*", IGNORE_MISSING)) {
$token->timemodified = time(); $token->timemodified = time();
if (isset($options["enabled"])) { if (isset($options->enabled)) {
$token->enabled = boolval($options["enabled"]); $token->enabled = boolval($options->enabled);
} }
if (isset($options["extendedaction"]) && isset($options["extendedoptions"])) { if (isset($options->extendedaction) && isset($options->extendedoptions)) {
$token->extendedaction = strval($options["extendedaction"]); $token->extendedaction = strval($options->extendedaction);
$token->extendedoptions = strval($options["extendedoptions"]); $token->extendedoptions = strval($options->extendedoptions);
} }
if (isset($options["limited"])) { if (isset($options->limited)) {
$token->limited = intval($options["limited"]); $token->limited = intval($options->limited);
} }
if (isset($options["targetid"])) { if (isset($options->targetid)) {
$token->targetid = intval($options["targetid"]); $token->targetid = intval($options->targetid);
} }
if (isset($options["targettype"])) { if (isset($options->targettype)) {
$token->targettype = strval($options["targettype"]); $token->targettype = strval($options->targettype);
} }
if (isset($options["token"])) { if (isset($options->token)) {
$token->token = strval($options["token"]); $token->token = strval($options->token);
} }
if (isset($options["timelimited"])) { if (isset($options->timelimited)) {
$token->timelimited = intval($options["timelimited"]); $token->timelimited = intval($options->timelimited);
} }
$result = $DB->update_record("tool_managertokens_tokens", $token, false); $result = $DB->update_record("tool_managertokens_tokens", $token, false);