id
int32 0
241k
| repo
stringlengths 6
63
| path
stringlengths 5
140
| func_name
stringlengths 3
151
| original_string
stringlengths 84
13k
| language
stringclasses 1
value | code
stringlengths 84
13k
| code_tokens
list | docstring
stringlengths 3
47.2k
| docstring_tokens
list | sha
stringlengths 40
40
| url
stringlengths 91
247
|
|---|---|---|---|---|---|---|---|---|---|---|---|
215,500
|
moodle/moodle
|
message/classes/task/migrate_message_data.php
|
migrate_message_data.migrate_data
|
private function migrate_data($userid, $otheruserid) {
global $DB;
if ($userid == $otheruserid) {
// Since 3.7, pending self-conversations should be migrated during the upgrading process so shouldn't be any
// self-conversations on the legacy tables. However, this extra-check has been added just in case.
$conversation = \core_message\api::get_self_conversation($userid);
if (empty($conversation)) {
$conversation = \core_message\api::create_conversation(
\core_message\api::MESSAGE_CONVERSATION_TYPE_SELF,
[$userid]
);
}
$conversationid = $conversation->id;
} else if (!$conversationid = \core_message\api::get_conversation_between_users([$userid, $otheruserid])) {
$conversation = \core_message\api::create_conversation(
\core_message\api::MESSAGE_CONVERSATION_TYPE_INDIVIDUAL,
[
$userid,
$otheruserid
]
);
$conversationid = $conversation->id;
}
// First, get the rows from the 'message' table.
$select = "(useridfrom = ? AND useridto = ?) OR (useridfrom = ? AND useridto = ?)";
$params = [$userid, $otheruserid, $otheruserid, $userid];
$messages = $DB->get_recordset_select('message', $select, $params, 'id ASC');
foreach ($messages as $message) {
if ($message->notification) {
$this->migrate_notification($message, false);
} else {
$this->migrate_message($conversationid, $message);
}
}
$messages->close();
// Ok, all done, delete the records from the 'message' table.
$DB->delete_records_select('message', $select, $params);
// Now, get the rows from the 'message_read' table.
$messages = $DB->get_recordset_select('message_read', $select, $params, 'id ASC');
foreach ($messages as $message) {
if ($message->notification) {
$this->migrate_notification($message, true);
} else {
$this->migrate_message($conversationid, $message);
}
}
$messages->close();
// Ok, all done, delete the records from the 'message_read' table.
$DB->delete_records_select('message_read', $select, $params);
}
|
php
|
private function migrate_data($userid, $otheruserid) {
global $DB;
if ($userid == $otheruserid) {
// Since 3.7, pending self-conversations should be migrated during the upgrading process so shouldn't be any
// self-conversations on the legacy tables. However, this extra-check has been added just in case.
$conversation = \core_message\api::get_self_conversation($userid);
if (empty($conversation)) {
$conversation = \core_message\api::create_conversation(
\core_message\api::MESSAGE_CONVERSATION_TYPE_SELF,
[$userid]
);
}
$conversationid = $conversation->id;
} else if (!$conversationid = \core_message\api::get_conversation_between_users([$userid, $otheruserid])) {
$conversation = \core_message\api::create_conversation(
\core_message\api::MESSAGE_CONVERSATION_TYPE_INDIVIDUAL,
[
$userid,
$otheruserid
]
);
$conversationid = $conversation->id;
}
// First, get the rows from the 'message' table.
$select = "(useridfrom = ? AND useridto = ?) OR (useridfrom = ? AND useridto = ?)";
$params = [$userid, $otheruserid, $otheruserid, $userid];
$messages = $DB->get_recordset_select('message', $select, $params, 'id ASC');
foreach ($messages as $message) {
if ($message->notification) {
$this->migrate_notification($message, false);
} else {
$this->migrate_message($conversationid, $message);
}
}
$messages->close();
// Ok, all done, delete the records from the 'message' table.
$DB->delete_records_select('message', $select, $params);
// Now, get the rows from the 'message_read' table.
$messages = $DB->get_recordset_select('message_read', $select, $params, 'id ASC');
foreach ($messages as $message) {
if ($message->notification) {
$this->migrate_notification($message, true);
} else {
$this->migrate_message($conversationid, $message);
}
}
$messages->close();
// Ok, all done, delete the records from the 'message_read' table.
$DB->delete_records_select('message_read', $select, $params);
}
|
[
"private",
"function",
"migrate_data",
"(",
"$",
"userid",
",",
"$",
"otheruserid",
")",
"{",
"global",
"$",
"DB",
";",
"if",
"(",
"$",
"userid",
"==",
"$",
"otheruserid",
")",
"{",
"// Since 3.7, pending self-conversations should be migrated during the upgrading process so shouldn't be any",
"// self-conversations on the legacy tables. However, this extra-check has been added just in case.",
"$",
"conversation",
"=",
"\\",
"core_message",
"\\",
"api",
"::",
"get_self_conversation",
"(",
"$",
"userid",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"conversation",
")",
")",
"{",
"$",
"conversation",
"=",
"\\",
"core_message",
"\\",
"api",
"::",
"create_conversation",
"(",
"\\",
"core_message",
"\\",
"api",
"::",
"MESSAGE_CONVERSATION_TYPE_SELF",
",",
"[",
"$",
"userid",
"]",
")",
";",
"}",
"$",
"conversationid",
"=",
"$",
"conversation",
"->",
"id",
";",
"}",
"else",
"if",
"(",
"!",
"$",
"conversationid",
"=",
"\\",
"core_message",
"\\",
"api",
"::",
"get_conversation_between_users",
"(",
"[",
"$",
"userid",
",",
"$",
"otheruserid",
"]",
")",
")",
"{",
"$",
"conversation",
"=",
"\\",
"core_message",
"\\",
"api",
"::",
"create_conversation",
"(",
"\\",
"core_message",
"\\",
"api",
"::",
"MESSAGE_CONVERSATION_TYPE_INDIVIDUAL",
",",
"[",
"$",
"userid",
",",
"$",
"otheruserid",
"]",
")",
";",
"$",
"conversationid",
"=",
"$",
"conversation",
"->",
"id",
";",
"}",
"// First, get the rows from the 'message' table.",
"$",
"select",
"=",
"\"(useridfrom = ? AND useridto = ?) OR (useridfrom = ? AND useridto = ?)\"",
";",
"$",
"params",
"=",
"[",
"$",
"userid",
",",
"$",
"otheruserid",
",",
"$",
"otheruserid",
",",
"$",
"userid",
"]",
";",
"$",
"messages",
"=",
"$",
"DB",
"->",
"get_recordset_select",
"(",
"'message'",
",",
"$",
"select",
",",
"$",
"params",
",",
"'id ASC'",
")",
";",
"foreach",
"(",
"$",
"messages",
"as",
"$",
"message",
")",
"{",
"if",
"(",
"$",
"message",
"->",
"notification",
")",
"{",
"$",
"this",
"->",
"migrate_notification",
"(",
"$",
"message",
",",
"false",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"migrate_message",
"(",
"$",
"conversationid",
",",
"$",
"message",
")",
";",
"}",
"}",
"$",
"messages",
"->",
"close",
"(",
")",
";",
"// Ok, all done, delete the records from the 'message' table.",
"$",
"DB",
"->",
"delete_records_select",
"(",
"'message'",
",",
"$",
"select",
",",
"$",
"params",
")",
";",
"// Now, get the rows from the 'message_read' table.",
"$",
"messages",
"=",
"$",
"DB",
"->",
"get_recordset_select",
"(",
"'message_read'",
",",
"$",
"select",
",",
"$",
"params",
",",
"'id ASC'",
")",
";",
"foreach",
"(",
"$",
"messages",
"as",
"$",
"message",
")",
"{",
"if",
"(",
"$",
"message",
"->",
"notification",
")",
"{",
"$",
"this",
"->",
"migrate_notification",
"(",
"$",
"message",
",",
"true",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"migrate_message",
"(",
"$",
"conversationid",
",",
"$",
"message",
")",
";",
"}",
"}",
"$",
"messages",
"->",
"close",
"(",
")",
";",
"// Ok, all done, delete the records from the 'message_read' table.",
"$",
"DB",
"->",
"delete_records_select",
"(",
"'message_read'",
",",
"$",
"select",
",",
"$",
"params",
")",
";",
"}"
] |
Helper function to deal with migrating the data.
@param int $userid The current user id.
@param int $otheruserid The user id of the other user in the conversation.
@throws \dml_exception
|
[
"Helper",
"function",
"to",
"deal",
"with",
"migrating",
"the",
"data",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/message/classes/task/migrate_message_data.php#L122-L176
|
215,501
|
moodle/moodle
|
message/classes/task/migrate_message_data.php
|
migrate_message_data.migrate_notification
|
private function migrate_notification($notification, $isread) {
global $DB;
$tabledata = new \stdClass();
$tabledata->useridfrom = $notification->useridfrom;
$tabledata->useridto = $notification->useridto;
$tabledata->subject = $notification->subject;
$tabledata->fullmessage = $notification->fullmessage;
$tabledata->fullmessageformat = $notification->fullmessageformat ?? FORMAT_MOODLE;
$tabledata->fullmessagehtml = $notification->fullmessagehtml;
$tabledata->smallmessage = $notification->smallmessage;
$tabledata->component = $notification->component;
$tabledata->eventtype = $notification->eventtype;
$tabledata->contexturl = $notification->contexturl;
$tabledata->contexturlname = $notification->contexturlname;
$tabledata->timeread = $notification->timeread ?? null;
$tabledata->timecreated = $notification->timecreated;
$newid = $DB->insert_record('notifications', $tabledata);
// Check if there is a record to move to the new 'message_popup_notifications' table.
if ($mp = $DB->get_record('message_popup', ['messageid' => $notification->id, 'isread' => (int) $isread])) {
$mpn = new \stdClass();
$mpn->notificationid = $newid;
$DB->insert_record('message_popup_notifications', $mpn);
$DB->delete_records('message_popup', ['id' => $mp->id]);
}
}
|
php
|
private function migrate_notification($notification, $isread) {
global $DB;
$tabledata = new \stdClass();
$tabledata->useridfrom = $notification->useridfrom;
$tabledata->useridto = $notification->useridto;
$tabledata->subject = $notification->subject;
$tabledata->fullmessage = $notification->fullmessage;
$tabledata->fullmessageformat = $notification->fullmessageformat ?? FORMAT_MOODLE;
$tabledata->fullmessagehtml = $notification->fullmessagehtml;
$tabledata->smallmessage = $notification->smallmessage;
$tabledata->component = $notification->component;
$tabledata->eventtype = $notification->eventtype;
$tabledata->contexturl = $notification->contexturl;
$tabledata->contexturlname = $notification->contexturlname;
$tabledata->timeread = $notification->timeread ?? null;
$tabledata->timecreated = $notification->timecreated;
$newid = $DB->insert_record('notifications', $tabledata);
// Check if there is a record to move to the new 'message_popup_notifications' table.
if ($mp = $DB->get_record('message_popup', ['messageid' => $notification->id, 'isread' => (int) $isread])) {
$mpn = new \stdClass();
$mpn->notificationid = $newid;
$DB->insert_record('message_popup_notifications', $mpn);
$DB->delete_records('message_popup', ['id' => $mp->id]);
}
}
|
[
"private",
"function",
"migrate_notification",
"(",
"$",
"notification",
",",
"$",
"isread",
")",
"{",
"global",
"$",
"DB",
";",
"$",
"tabledata",
"=",
"new",
"\\",
"stdClass",
"(",
")",
";",
"$",
"tabledata",
"->",
"useridfrom",
"=",
"$",
"notification",
"->",
"useridfrom",
";",
"$",
"tabledata",
"->",
"useridto",
"=",
"$",
"notification",
"->",
"useridto",
";",
"$",
"tabledata",
"->",
"subject",
"=",
"$",
"notification",
"->",
"subject",
";",
"$",
"tabledata",
"->",
"fullmessage",
"=",
"$",
"notification",
"->",
"fullmessage",
";",
"$",
"tabledata",
"->",
"fullmessageformat",
"=",
"$",
"notification",
"->",
"fullmessageformat",
"??",
"FORMAT_MOODLE",
";",
"$",
"tabledata",
"->",
"fullmessagehtml",
"=",
"$",
"notification",
"->",
"fullmessagehtml",
";",
"$",
"tabledata",
"->",
"smallmessage",
"=",
"$",
"notification",
"->",
"smallmessage",
";",
"$",
"tabledata",
"->",
"component",
"=",
"$",
"notification",
"->",
"component",
";",
"$",
"tabledata",
"->",
"eventtype",
"=",
"$",
"notification",
"->",
"eventtype",
";",
"$",
"tabledata",
"->",
"contexturl",
"=",
"$",
"notification",
"->",
"contexturl",
";",
"$",
"tabledata",
"->",
"contexturlname",
"=",
"$",
"notification",
"->",
"contexturlname",
";",
"$",
"tabledata",
"->",
"timeread",
"=",
"$",
"notification",
"->",
"timeread",
"??",
"null",
";",
"$",
"tabledata",
"->",
"timecreated",
"=",
"$",
"notification",
"->",
"timecreated",
";",
"$",
"newid",
"=",
"$",
"DB",
"->",
"insert_record",
"(",
"'notifications'",
",",
"$",
"tabledata",
")",
";",
"// Check if there is a record to move to the new 'message_popup_notifications' table.",
"if",
"(",
"$",
"mp",
"=",
"$",
"DB",
"->",
"get_record",
"(",
"'message_popup'",
",",
"[",
"'messageid'",
"=>",
"$",
"notification",
"->",
"id",
",",
"'isread'",
"=>",
"(",
"int",
")",
"$",
"isread",
"]",
")",
")",
"{",
"$",
"mpn",
"=",
"new",
"\\",
"stdClass",
"(",
")",
";",
"$",
"mpn",
"->",
"notificationid",
"=",
"$",
"newid",
";",
"$",
"DB",
"->",
"insert_record",
"(",
"'message_popup_notifications'",
",",
"$",
"mpn",
")",
";",
"$",
"DB",
"->",
"delete_records",
"(",
"'message_popup'",
",",
"[",
"'id'",
"=>",
"$",
"mp",
"->",
"id",
"]",
")",
";",
"}",
"}"
] |
Helper function to deal with migrating an individual notification.
@param \stdClass $notification
@param bool $isread Was the notification read?
@throws \dml_exception
|
[
"Helper",
"function",
"to",
"deal",
"with",
"migrating",
"an",
"individual",
"notification",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/message/classes/task/migrate_message_data.php#L185-L213
|
215,502
|
moodle/moodle
|
message/classes/task/migrate_message_data.php
|
migrate_message_data.migrate_message
|
private function migrate_message($conversationid, $message) {
global $DB;
// Create the object we will be inserting into the database.
$tabledata = new \stdClass();
$tabledata->useridfrom = $message->useridfrom;
$tabledata->conversationid = $conversationid;
$tabledata->subject = $message->subject;
$tabledata->fullmessage = $message->fullmessage;
$tabledata->fullmessageformat = $message->fullmessageformat ?? FORMAT_MOODLE;
$tabledata->fullmessagehtml = $message->fullmessagehtml;
$tabledata->smallmessage = $message->smallmessage;
$tabledata->timecreated = $message->timecreated;
$messageid = $DB->insert_record('messages', $tabledata);
// Check if we need to mark this message as deleted for the user from.
if ($message->timeuserfromdeleted) {
$mua = new \stdClass();
$mua->userid = $message->useridfrom;
$mua->messageid = $messageid;
$mua->action = \core_message\api::MESSAGE_ACTION_DELETED;
$mua->timecreated = $message->timeuserfromdeleted;
$DB->insert_record('message_user_actions', $mua);
}
// Check if we need to mark this message as deleted for the user to.
if ($message->timeusertodeleted and ($message->useridfrom != $message->useridto)) {
$mua = new \stdClass();
$mua->userid = $message->useridto;
$mua->messageid = $messageid;
$mua->action = \core_message\api::MESSAGE_ACTION_DELETED;
$mua->timecreated = $message->timeusertodeleted;
$DB->insert_record('message_user_actions', $mua);
}
// Check if we need to mark this message as read for the user to (it is always read by the user from).
// Note - we do an isset() check here because this column only exists in the 'message_read' table.
if (isset($message->timeread)) {
$mua = new \stdClass();
$mua->userid = $message->useridto;
$mua->messageid = $messageid;
$mua->action = \core_message\api::MESSAGE_ACTION_READ;
$mua->timecreated = $message->timeread;
$DB->insert_record('message_user_actions', $mua);
}
}
|
php
|
private function migrate_message($conversationid, $message) {
global $DB;
// Create the object we will be inserting into the database.
$tabledata = new \stdClass();
$tabledata->useridfrom = $message->useridfrom;
$tabledata->conversationid = $conversationid;
$tabledata->subject = $message->subject;
$tabledata->fullmessage = $message->fullmessage;
$tabledata->fullmessageformat = $message->fullmessageformat ?? FORMAT_MOODLE;
$tabledata->fullmessagehtml = $message->fullmessagehtml;
$tabledata->smallmessage = $message->smallmessage;
$tabledata->timecreated = $message->timecreated;
$messageid = $DB->insert_record('messages', $tabledata);
// Check if we need to mark this message as deleted for the user from.
if ($message->timeuserfromdeleted) {
$mua = new \stdClass();
$mua->userid = $message->useridfrom;
$mua->messageid = $messageid;
$mua->action = \core_message\api::MESSAGE_ACTION_DELETED;
$mua->timecreated = $message->timeuserfromdeleted;
$DB->insert_record('message_user_actions', $mua);
}
// Check if we need to mark this message as deleted for the user to.
if ($message->timeusertodeleted and ($message->useridfrom != $message->useridto)) {
$mua = new \stdClass();
$mua->userid = $message->useridto;
$mua->messageid = $messageid;
$mua->action = \core_message\api::MESSAGE_ACTION_DELETED;
$mua->timecreated = $message->timeusertodeleted;
$DB->insert_record('message_user_actions', $mua);
}
// Check if we need to mark this message as read for the user to (it is always read by the user from).
// Note - we do an isset() check here because this column only exists in the 'message_read' table.
if (isset($message->timeread)) {
$mua = new \stdClass();
$mua->userid = $message->useridto;
$mua->messageid = $messageid;
$mua->action = \core_message\api::MESSAGE_ACTION_READ;
$mua->timecreated = $message->timeread;
$DB->insert_record('message_user_actions', $mua);
}
}
|
[
"private",
"function",
"migrate_message",
"(",
"$",
"conversationid",
",",
"$",
"message",
")",
"{",
"global",
"$",
"DB",
";",
"// Create the object we will be inserting into the database.",
"$",
"tabledata",
"=",
"new",
"\\",
"stdClass",
"(",
")",
";",
"$",
"tabledata",
"->",
"useridfrom",
"=",
"$",
"message",
"->",
"useridfrom",
";",
"$",
"tabledata",
"->",
"conversationid",
"=",
"$",
"conversationid",
";",
"$",
"tabledata",
"->",
"subject",
"=",
"$",
"message",
"->",
"subject",
";",
"$",
"tabledata",
"->",
"fullmessage",
"=",
"$",
"message",
"->",
"fullmessage",
";",
"$",
"tabledata",
"->",
"fullmessageformat",
"=",
"$",
"message",
"->",
"fullmessageformat",
"??",
"FORMAT_MOODLE",
";",
"$",
"tabledata",
"->",
"fullmessagehtml",
"=",
"$",
"message",
"->",
"fullmessagehtml",
";",
"$",
"tabledata",
"->",
"smallmessage",
"=",
"$",
"message",
"->",
"smallmessage",
";",
"$",
"tabledata",
"->",
"timecreated",
"=",
"$",
"message",
"->",
"timecreated",
";",
"$",
"messageid",
"=",
"$",
"DB",
"->",
"insert_record",
"(",
"'messages'",
",",
"$",
"tabledata",
")",
";",
"// Check if we need to mark this message as deleted for the user from.",
"if",
"(",
"$",
"message",
"->",
"timeuserfromdeleted",
")",
"{",
"$",
"mua",
"=",
"new",
"\\",
"stdClass",
"(",
")",
";",
"$",
"mua",
"->",
"userid",
"=",
"$",
"message",
"->",
"useridfrom",
";",
"$",
"mua",
"->",
"messageid",
"=",
"$",
"messageid",
";",
"$",
"mua",
"->",
"action",
"=",
"\\",
"core_message",
"\\",
"api",
"::",
"MESSAGE_ACTION_DELETED",
";",
"$",
"mua",
"->",
"timecreated",
"=",
"$",
"message",
"->",
"timeuserfromdeleted",
";",
"$",
"DB",
"->",
"insert_record",
"(",
"'message_user_actions'",
",",
"$",
"mua",
")",
";",
"}",
"// Check if we need to mark this message as deleted for the user to.",
"if",
"(",
"$",
"message",
"->",
"timeusertodeleted",
"and",
"(",
"$",
"message",
"->",
"useridfrom",
"!=",
"$",
"message",
"->",
"useridto",
")",
")",
"{",
"$",
"mua",
"=",
"new",
"\\",
"stdClass",
"(",
")",
";",
"$",
"mua",
"->",
"userid",
"=",
"$",
"message",
"->",
"useridto",
";",
"$",
"mua",
"->",
"messageid",
"=",
"$",
"messageid",
";",
"$",
"mua",
"->",
"action",
"=",
"\\",
"core_message",
"\\",
"api",
"::",
"MESSAGE_ACTION_DELETED",
";",
"$",
"mua",
"->",
"timecreated",
"=",
"$",
"message",
"->",
"timeusertodeleted",
";",
"$",
"DB",
"->",
"insert_record",
"(",
"'message_user_actions'",
",",
"$",
"mua",
")",
";",
"}",
"// Check if we need to mark this message as read for the user to (it is always read by the user from).",
"// Note - we do an isset() check here because this column only exists in the 'message_read' table.",
"if",
"(",
"isset",
"(",
"$",
"message",
"->",
"timeread",
")",
")",
"{",
"$",
"mua",
"=",
"new",
"\\",
"stdClass",
"(",
")",
";",
"$",
"mua",
"->",
"userid",
"=",
"$",
"message",
"->",
"useridto",
";",
"$",
"mua",
"->",
"messageid",
"=",
"$",
"messageid",
";",
"$",
"mua",
"->",
"action",
"=",
"\\",
"core_message",
"\\",
"api",
"::",
"MESSAGE_ACTION_READ",
";",
"$",
"mua",
"->",
"timecreated",
"=",
"$",
"message",
"->",
"timeread",
";",
"$",
"DB",
"->",
"insert_record",
"(",
"'message_user_actions'",
",",
"$",
"mua",
")",
";",
"}",
"}"
] |
Helper function to deal with migrating an individual message.
@param int $conversationid The conversation between the two users.
@param \stdClass $message The message from either the 'message' or 'message_read' table
@throws \dml_exception
|
[
"Helper",
"function",
"to",
"deal",
"with",
"migrating",
"an",
"individual",
"message",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/message/classes/task/migrate_message_data.php#L222-L271
|
215,503
|
moodle/moodle
|
message/classes/task/migrate_message_data.php
|
migrate_message_data.queue_task
|
public static function queue_task($userid) {
// Let's set up the adhoc task.
$task = new \core_message\task\migrate_message_data();
$task->set_custom_data(
[
'userid' => $userid
]
);
// Queue it.
\core\task\manager::queue_adhoc_task($task, true);
}
|
php
|
public static function queue_task($userid) {
// Let's set up the adhoc task.
$task = new \core_message\task\migrate_message_data();
$task->set_custom_data(
[
'userid' => $userid
]
);
// Queue it.
\core\task\manager::queue_adhoc_task($task, true);
}
|
[
"public",
"static",
"function",
"queue_task",
"(",
"$",
"userid",
")",
"{",
"// Let's set up the adhoc task.",
"$",
"task",
"=",
"new",
"\\",
"core_message",
"\\",
"task",
"\\",
"migrate_message_data",
"(",
")",
";",
"$",
"task",
"->",
"set_custom_data",
"(",
"[",
"'userid'",
"=>",
"$",
"userid",
"]",
")",
";",
"// Queue it.",
"\\",
"core",
"\\",
"task",
"\\",
"manager",
"::",
"queue_adhoc_task",
"(",
"$",
"task",
",",
"true",
")",
";",
"}"
] |
Queues the task.
@param int $userid
|
[
"Queues",
"the",
"task",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/message/classes/task/migrate_message_data.php#L278-L289
|
215,504
|
moodle/moodle
|
admin/tool/policy/classes/policy_exporter.php
|
policy_exporter.define_other_properties
|
protected static function define_other_properties() {
return [
'currentversion' => [
'type' => policy_version_exporter::read_properties_definition(),
'null' => NULL_ALLOWED,
],
'draftversions' => [
'type' => policy_version_exporter::read_properties_definition(),
'multiple' => true,
],
'archivedversions' => [
'type' => policy_version_exporter::read_properties_definition(),
'multiple' => true,
],
];
}
|
php
|
protected static function define_other_properties() {
return [
'currentversion' => [
'type' => policy_version_exporter::read_properties_definition(),
'null' => NULL_ALLOWED,
],
'draftversions' => [
'type' => policy_version_exporter::read_properties_definition(),
'multiple' => true,
],
'archivedversions' => [
'type' => policy_version_exporter::read_properties_definition(),
'multiple' => true,
],
];
}
|
[
"protected",
"static",
"function",
"define_other_properties",
"(",
")",
"{",
"return",
"[",
"'currentversion'",
"=>",
"[",
"'type'",
"=>",
"policy_version_exporter",
"::",
"read_properties_definition",
"(",
")",
",",
"'null'",
"=>",
"NULL_ALLOWED",
",",
"]",
",",
"'draftversions'",
"=>",
"[",
"'type'",
"=>",
"policy_version_exporter",
"::",
"read_properties_definition",
"(",
")",
",",
"'multiple'",
"=>",
"true",
",",
"]",
",",
"'archivedversions'",
"=>",
"[",
"'type'",
"=>",
"policy_version_exporter",
"::",
"read_properties_definition",
"(",
")",
",",
"'multiple'",
"=>",
"true",
",",
"]",
",",
"]",
";",
"}"
] |
Return the list of additional, generated dynamically from the given properties.
@return array
|
[
"Return",
"the",
"list",
"of",
"additional",
"generated",
"dynamically",
"from",
"the",
"given",
"properties",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/policy/classes/policy_exporter.php#L77-L92
|
215,505
|
moodle/moodle
|
backup/util/helper/restore_decode_rule.class.php
|
restore_decode_rule.get_mapping
|
protected function get_mapping($itemname, $itemid) {
// Check restoreid is set
if (!$this->restoreid) {
throw new restore_decode_rule_exception('decode_rule_restoreid_not_set');
}
if (!$found = restore_dbops::get_backup_ids_record($this->restoreid, $itemname, $itemid)) {
return false;
}
return $found->newitemid;
}
|
php
|
protected function get_mapping($itemname, $itemid) {
// Check restoreid is set
if (!$this->restoreid) {
throw new restore_decode_rule_exception('decode_rule_restoreid_not_set');
}
if (!$found = restore_dbops::get_backup_ids_record($this->restoreid, $itemname, $itemid)) {
return false;
}
return $found->newitemid;
}
|
[
"protected",
"function",
"get_mapping",
"(",
"$",
"itemname",
",",
"$",
"itemid",
")",
"{",
"// Check restoreid is set",
"if",
"(",
"!",
"$",
"this",
"->",
"restoreid",
")",
"{",
"throw",
"new",
"restore_decode_rule_exception",
"(",
"'decode_rule_restoreid_not_set'",
")",
";",
"}",
"if",
"(",
"!",
"$",
"found",
"=",
"restore_dbops",
"::",
"get_backup_ids_record",
"(",
"$",
"this",
"->",
"restoreid",
",",
"$",
"itemname",
",",
"$",
"itemid",
")",
")",
"{",
"return",
"false",
";",
"}",
"return",
"$",
"found",
"->",
"newitemid",
";",
"}"
] |
Looks for mapping values in backup_ids table, simple wrapper over get_backup_ids_record
|
[
"Looks",
"for",
"mapping",
"values",
"in",
"backup_ids",
"table",
"simple",
"wrapper",
"over",
"get_backup_ids_record"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/backup/util/helper/restore_decode_rule.class.php#L110-L119
|
215,506
|
moodle/moodle
|
backup/util/helper/restore_decode_rule.class.php
|
restore_decode_rule.validate_params
|
protected function validate_params($linkname, $urltemplate, $mappings) {
// Check linkname is A-Z0-9
if (empty($linkname) || preg_match('/[^A-Z0-9]/', $linkname)) {
throw new restore_decode_rule_exception('decode_rule_incorrect_name', $linkname);
}
// Look urltemplate starts by /
if (empty($urltemplate) || substr($urltemplate, 0, 1) != '/') {
throw new restore_decode_rule_exception('decode_rule_incorrect_urltemplate', $urltemplate);
}
if (!is_array($mappings)) {
$mappings = array($mappings);
}
// Look for placeholders in template
$countph = preg_match_all('/(\$\d+)/', $urltemplate, $matches);
$countma = count($mappings);
// Check mappings number matches placeholders
if ($countph != $countma) {
$a = new stdClass();
$a->placeholders = $countph;
$a->mappings = $countma;
throw new restore_decode_rule_exception('decode_rule_mappings_incorrect_count', $a);
}
// Verify they are consecutive (starting on 1)
$smatches = str_replace('$', '', $matches[1]);
sort($smatches, SORT_NUMERIC);
if (reset($smatches) != 1 || end($smatches) != $countma) {
throw new restore_decode_rule_exception('decode_rule_nonconsecutive_placeholders', implode(', ', $smatches));
}
// No dupes in placeholders
if (count($smatches) != count(array_unique($smatches))) {
throw new restore_decode_rule_exception('decode_rule_duplicate_placeholders', implode(', ', $smatches));
}
// Return one array of placeholders as keys and mappings as values
return array_combine($smatches, $mappings);
}
|
php
|
protected function validate_params($linkname, $urltemplate, $mappings) {
// Check linkname is A-Z0-9
if (empty($linkname) || preg_match('/[^A-Z0-9]/', $linkname)) {
throw new restore_decode_rule_exception('decode_rule_incorrect_name', $linkname);
}
// Look urltemplate starts by /
if (empty($urltemplate) || substr($urltemplate, 0, 1) != '/') {
throw new restore_decode_rule_exception('decode_rule_incorrect_urltemplate', $urltemplate);
}
if (!is_array($mappings)) {
$mappings = array($mappings);
}
// Look for placeholders in template
$countph = preg_match_all('/(\$\d+)/', $urltemplate, $matches);
$countma = count($mappings);
// Check mappings number matches placeholders
if ($countph != $countma) {
$a = new stdClass();
$a->placeholders = $countph;
$a->mappings = $countma;
throw new restore_decode_rule_exception('decode_rule_mappings_incorrect_count', $a);
}
// Verify they are consecutive (starting on 1)
$smatches = str_replace('$', '', $matches[1]);
sort($smatches, SORT_NUMERIC);
if (reset($smatches) != 1 || end($smatches) != $countma) {
throw new restore_decode_rule_exception('decode_rule_nonconsecutive_placeholders', implode(', ', $smatches));
}
// No dupes in placeholders
if (count($smatches) != count(array_unique($smatches))) {
throw new restore_decode_rule_exception('decode_rule_duplicate_placeholders', implode(', ', $smatches));
}
// Return one array of placeholders as keys and mappings as values
return array_combine($smatches, $mappings);
}
|
[
"protected",
"function",
"validate_params",
"(",
"$",
"linkname",
",",
"$",
"urltemplate",
",",
"$",
"mappings",
")",
"{",
"// Check linkname is A-Z0-9",
"if",
"(",
"empty",
"(",
"$",
"linkname",
")",
"||",
"preg_match",
"(",
"'/[^A-Z0-9]/'",
",",
"$",
"linkname",
")",
")",
"{",
"throw",
"new",
"restore_decode_rule_exception",
"(",
"'decode_rule_incorrect_name'",
",",
"$",
"linkname",
")",
";",
"}",
"// Look urltemplate starts by /",
"if",
"(",
"empty",
"(",
"$",
"urltemplate",
")",
"||",
"substr",
"(",
"$",
"urltemplate",
",",
"0",
",",
"1",
")",
"!=",
"'/'",
")",
"{",
"throw",
"new",
"restore_decode_rule_exception",
"(",
"'decode_rule_incorrect_urltemplate'",
",",
"$",
"urltemplate",
")",
";",
"}",
"if",
"(",
"!",
"is_array",
"(",
"$",
"mappings",
")",
")",
"{",
"$",
"mappings",
"=",
"array",
"(",
"$",
"mappings",
")",
";",
"}",
"// Look for placeholders in template",
"$",
"countph",
"=",
"preg_match_all",
"(",
"'/(\\$\\d+)/'",
",",
"$",
"urltemplate",
",",
"$",
"matches",
")",
";",
"$",
"countma",
"=",
"count",
"(",
"$",
"mappings",
")",
";",
"// Check mappings number matches placeholders",
"if",
"(",
"$",
"countph",
"!=",
"$",
"countma",
")",
"{",
"$",
"a",
"=",
"new",
"stdClass",
"(",
")",
";",
"$",
"a",
"->",
"placeholders",
"=",
"$",
"countph",
";",
"$",
"a",
"->",
"mappings",
"=",
"$",
"countma",
";",
"throw",
"new",
"restore_decode_rule_exception",
"(",
"'decode_rule_mappings_incorrect_count'",
",",
"$",
"a",
")",
";",
"}",
"// Verify they are consecutive (starting on 1)",
"$",
"smatches",
"=",
"str_replace",
"(",
"'$'",
",",
"''",
",",
"$",
"matches",
"[",
"1",
"]",
")",
";",
"sort",
"(",
"$",
"smatches",
",",
"SORT_NUMERIC",
")",
";",
"if",
"(",
"reset",
"(",
"$",
"smatches",
")",
"!=",
"1",
"||",
"end",
"(",
"$",
"smatches",
")",
"!=",
"$",
"countma",
")",
"{",
"throw",
"new",
"restore_decode_rule_exception",
"(",
"'decode_rule_nonconsecutive_placeholders'",
",",
"implode",
"(",
"', '",
",",
"$",
"smatches",
")",
")",
";",
"}",
"// No dupes in placeholders",
"if",
"(",
"count",
"(",
"$",
"smatches",
")",
"!=",
"count",
"(",
"array_unique",
"(",
"$",
"smatches",
")",
")",
")",
"{",
"throw",
"new",
"restore_decode_rule_exception",
"(",
"'decode_rule_duplicate_placeholders'",
",",
"implode",
"(",
"', '",
",",
"$",
"smatches",
")",
")",
";",
"}",
"// Return one array of placeholders as keys and mappings as values",
"return",
"array_combine",
"(",
"$",
"smatches",
",",
"$",
"mappings",
")",
";",
"}"
] |
Perform all the validations and checks on the rule attributes
|
[
"Perform",
"all",
"the",
"validations",
"and",
"checks",
"on",
"the",
"rule",
"attributes"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/backup/util/helper/restore_decode_rule.class.php#L137-L172
|
215,507
|
moodle/moodle
|
backup/util/helper/restore_decode_rule.class.php
|
restore_decode_rule.get_calculated_regexp
|
protected function get_calculated_regexp() {
$regexp = '/\$@' . $this->linkname;
foreach ($this->mappings as $key => $value) {
$regexp .= '\*(\d+)';
}
$regexp .= '@\$/';
return $regexp;
}
|
php
|
protected function get_calculated_regexp() {
$regexp = '/\$@' . $this->linkname;
foreach ($this->mappings as $key => $value) {
$regexp .= '\*(\d+)';
}
$regexp .= '@\$/';
return $regexp;
}
|
[
"protected",
"function",
"get_calculated_regexp",
"(",
")",
"{",
"$",
"regexp",
"=",
"'/\\$@'",
".",
"$",
"this",
"->",
"linkname",
";",
"foreach",
"(",
"$",
"this",
"->",
"mappings",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"$",
"regexp",
".=",
"'\\*(\\d+)'",
";",
"}",
"$",
"regexp",
".=",
"'@\\$/'",
";",
"return",
"$",
"regexp",
";",
"}"
] |
based on rule definition, build the regular expression to execute on decode
|
[
"based",
"on",
"rule",
"definition",
"build",
"the",
"regular",
"expression",
"to",
"execute",
"on",
"decode"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/backup/util/helper/restore_decode_rule.class.php#L177-L184
|
215,508
|
moodle/moodle
|
cache/stores/session/lib.php
|
session_data_store.flush_store
|
protected static function flush_store() {
$ids = array_keys(self::$sessionstore);
unset(self::$sessionstore);
self::$sessionstore = array();
foreach ($ids as $id) {
self::$sessionstore[$id] = array();
}
}
|
php
|
protected static function flush_store() {
$ids = array_keys(self::$sessionstore);
unset(self::$sessionstore);
self::$sessionstore = array();
foreach ($ids as $id) {
self::$sessionstore[$id] = array();
}
}
|
[
"protected",
"static",
"function",
"flush_store",
"(",
")",
"{",
"$",
"ids",
"=",
"array_keys",
"(",
"self",
"::",
"$",
"sessionstore",
")",
";",
"unset",
"(",
"self",
"::",
"$",
"sessionstore",
")",
";",
"self",
"::",
"$",
"sessionstore",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"ids",
"as",
"$",
"id",
")",
"{",
"self",
"::",
"$",
"sessionstore",
"[",
"$",
"id",
"]",
"=",
"array",
"(",
")",
";",
"}",
"}"
] |
Flushes the store of all data.
|
[
"Flushes",
"the",
"store",
"of",
"all",
"data",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/cache/stores/session/lib.php#L77-L84
|
215,509
|
moodle/moodle
|
cache/stores/session/lib.php
|
cachestore_session.has_any
|
public function has_any(array $keys) {
$maxtime = 0;
if ($this->ttl != 0) {
$maxtime = cache::now() - $this->ttl;
}
foreach ($keys as $key) {
if (isset($this->store[$key]) && ($this->ttl == 0 || $this->store[$key][1] >= $maxtime)) {
return true;
}
}
return false;
}
|
php
|
public function has_any(array $keys) {
$maxtime = 0;
if ($this->ttl != 0) {
$maxtime = cache::now() - $this->ttl;
}
foreach ($keys as $key) {
if (isset($this->store[$key]) && ($this->ttl == 0 || $this->store[$key][1] >= $maxtime)) {
return true;
}
}
return false;
}
|
[
"public",
"function",
"has_any",
"(",
"array",
"$",
"keys",
")",
"{",
"$",
"maxtime",
"=",
"0",
";",
"if",
"(",
"$",
"this",
"->",
"ttl",
"!=",
"0",
")",
"{",
"$",
"maxtime",
"=",
"cache",
"::",
"now",
"(",
")",
"-",
"$",
"this",
"->",
"ttl",
";",
"}",
"foreach",
"(",
"$",
"keys",
"as",
"$",
"key",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"store",
"[",
"$",
"key",
"]",
")",
"&&",
"(",
"$",
"this",
"->",
"ttl",
"==",
"0",
"||",
"$",
"this",
"->",
"store",
"[",
"$",
"key",
"]",
"[",
"1",
"]",
">=",
"$",
"maxtime",
")",
")",
"{",
"return",
"true",
";",
"}",
"}",
"return",
"false",
";",
"}"
] |
Returns true if the store contains records for any of the given keys.
@param array $keys
@return bool
|
[
"Returns",
"true",
"if",
"the",
"store",
"contains",
"records",
"for",
"any",
"of",
"the",
"given",
"keys",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/cache/stores/session/lib.php#L403-L415
|
215,510
|
moodle/moodle
|
cache/stores/session/lib.php
|
cachestore_session.check_ttl
|
protected function check_ttl() {
if ($this->ttl === 0) {
return 0;
}
$maxtime = cache::now() - $this->ttl;
$count = 0;
for ($value = reset($this->store); $value !== false; $value = next($this->store)) {
if ($value[1] >= $maxtime) {
// We know that elements are sorted by ttl so no need to continue.
break;
}
$count++;
}
if ($count) {
// Remove first $count elements as they are expired.
$this->store = array_slice($this->store, $count, null, true);
if ($this->maxsize !== false) {
$this->storecount -= $count;
}
}
return $count;
}
|
php
|
protected function check_ttl() {
if ($this->ttl === 0) {
return 0;
}
$maxtime = cache::now() - $this->ttl;
$count = 0;
for ($value = reset($this->store); $value !== false; $value = next($this->store)) {
if ($value[1] >= $maxtime) {
// We know that elements are sorted by ttl so no need to continue.
break;
}
$count++;
}
if ($count) {
// Remove first $count elements as they are expired.
$this->store = array_slice($this->store, $count, null, true);
if ($this->maxsize !== false) {
$this->storecount -= $count;
}
}
return $count;
}
|
[
"protected",
"function",
"check_ttl",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"ttl",
"===",
"0",
")",
"{",
"return",
"0",
";",
"}",
"$",
"maxtime",
"=",
"cache",
"::",
"now",
"(",
")",
"-",
"$",
"this",
"->",
"ttl",
";",
"$",
"count",
"=",
"0",
";",
"for",
"(",
"$",
"value",
"=",
"reset",
"(",
"$",
"this",
"->",
"store",
")",
";",
"$",
"value",
"!==",
"false",
";",
"$",
"value",
"=",
"next",
"(",
"$",
"this",
"->",
"store",
")",
")",
"{",
"if",
"(",
"$",
"value",
"[",
"1",
"]",
">=",
"$",
"maxtime",
")",
"{",
"// We know that elements are sorted by ttl so no need to continue.",
"break",
";",
"}",
"$",
"count",
"++",
";",
"}",
"if",
"(",
"$",
"count",
")",
"{",
"// Remove first $count elements as they are expired.",
"$",
"this",
"->",
"store",
"=",
"array_slice",
"(",
"$",
"this",
"->",
"store",
",",
"$",
"count",
",",
"null",
",",
"true",
")",
";",
"if",
"(",
"$",
"this",
"->",
"maxsize",
"!==",
"false",
")",
"{",
"$",
"this",
"->",
"storecount",
"-=",
"$",
"count",
";",
"}",
"}",
"return",
"$",
"count",
";",
"}"
] |
Removes expired elements.
@return int number of removed elements
|
[
"Removes",
"expired",
"elements",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/cache/stores/session/lib.php#L539-L560
|
215,511
|
moodle/moodle
|
privacy/classes/manager.php
|
manager.get_null_provider_reason
|
public function get_null_provider_reason(string $component) : string {
if ($this->component_implements($component, null_provider::class)) {
$reason = $this->handled_component_class_callback($component, null_provider::class, 'get_reason', []);
return empty($reason) ? 'privacy:reason' : $reason;
} else {
throw new \coding_exception('Call to undefined method', 'Please only call this method on a null provider.');
}
}
|
php
|
public function get_null_provider_reason(string $component) : string {
if ($this->component_implements($component, null_provider::class)) {
$reason = $this->handled_component_class_callback($component, null_provider::class, 'get_reason', []);
return empty($reason) ? 'privacy:reason' : $reason;
} else {
throw new \coding_exception('Call to undefined method', 'Please only call this method on a null provider.');
}
}
|
[
"public",
"function",
"get_null_provider_reason",
"(",
"string",
"$",
"component",
")",
":",
"string",
"{",
"if",
"(",
"$",
"this",
"->",
"component_implements",
"(",
"$",
"component",
",",
"null_provider",
"::",
"class",
")",
")",
"{",
"$",
"reason",
"=",
"$",
"this",
"->",
"handled_component_class_callback",
"(",
"$",
"component",
",",
"null_provider",
"::",
"class",
",",
"'get_reason'",
",",
"[",
"]",
")",
";",
"return",
"empty",
"(",
"$",
"reason",
")",
"?",
"'privacy:reason'",
":",
"$",
"reason",
";",
"}",
"else",
"{",
"throw",
"new",
"\\",
"coding_exception",
"(",
"'Call to undefined method'",
",",
"'Please only call this method on a null provider.'",
")",
";",
"}",
"}"
] |
Retrieve the reason for implementing the null provider interface.
@param string $component Frankenstyle component name.
@return string The key to retrieve the language string for the null provider reason.
|
[
"Retrieve",
"the",
"reason",
"for",
"implementing",
"the",
"null",
"provider",
"interface",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/privacy/classes/manager.php#L168-L175
|
215,512
|
moodle/moodle
|
privacy/classes/manager.php
|
manager.is_empty_subsystem
|
public static function is_empty_subsystem($component) {
if (strpos($component, 'core_') === 0) {
if (null === \core_component::get_subsystem_directory(substr($component, 5))) {
// This is a subsystem without a directory.
return true;
}
}
return false;
}
|
php
|
public static function is_empty_subsystem($component) {
if (strpos($component, 'core_') === 0) {
if (null === \core_component::get_subsystem_directory(substr($component, 5))) {
// This is a subsystem without a directory.
return true;
}
}
return false;
}
|
[
"public",
"static",
"function",
"is_empty_subsystem",
"(",
"$",
"component",
")",
"{",
"if",
"(",
"strpos",
"(",
"$",
"component",
",",
"'core_'",
")",
"===",
"0",
")",
"{",
"if",
"(",
"null",
"===",
"\\",
"core_component",
"::",
"get_subsystem_directory",
"(",
"substr",
"(",
"$",
"component",
",",
"5",
")",
")",
")",
"{",
"// This is a subsystem without a directory.",
"return",
"true",
";",
"}",
"}",
"return",
"false",
";",
"}"
] |
Return whether this is an 'empty' subsystem - that is, a subsystem without a directory.
@param string $component Frankenstyle component name.
@return string The key to retrieve the language string for the null provider reason.
|
[
"Return",
"whether",
"this",
"is",
"an",
"empty",
"subsystem",
"-",
"that",
"is",
"a",
"subsystem",
"without",
"a",
"directory",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/privacy/classes/manager.php#L183-L192
|
215,513
|
moodle/moodle
|
privacy/classes/manager.php
|
manager.get_metadata_for_components
|
public function get_metadata_for_components() : array {
// Get the metadata, and put into an assoc array indexed by component name.
$metadata = [];
foreach ($this->get_component_list() as $component) {
$componentmetadata = $this->handled_component_class_callback($component, metadata_provider::class,
'get_metadata', [new collection($component)]);
if ($componentmetadata !== null) {
$metadata[$component] = $componentmetadata;
}
}
return $metadata;
}
|
php
|
public function get_metadata_for_components() : array {
// Get the metadata, and put into an assoc array indexed by component name.
$metadata = [];
foreach ($this->get_component_list() as $component) {
$componentmetadata = $this->handled_component_class_callback($component, metadata_provider::class,
'get_metadata', [new collection($component)]);
if ($componentmetadata !== null) {
$metadata[$component] = $componentmetadata;
}
}
return $metadata;
}
|
[
"public",
"function",
"get_metadata_for_components",
"(",
")",
":",
"array",
"{",
"// Get the metadata, and put into an assoc array indexed by component name.",
"$",
"metadata",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"this",
"->",
"get_component_list",
"(",
")",
"as",
"$",
"component",
")",
"{",
"$",
"componentmetadata",
"=",
"$",
"this",
"->",
"handled_component_class_callback",
"(",
"$",
"component",
",",
"metadata_provider",
"::",
"class",
",",
"'get_metadata'",
",",
"[",
"new",
"collection",
"(",
"$",
"component",
")",
"]",
")",
";",
"if",
"(",
"$",
"componentmetadata",
"!==",
"null",
")",
"{",
"$",
"metadata",
"[",
"$",
"component",
"]",
"=",
"$",
"componentmetadata",
";",
"}",
"}",
"return",
"$",
"metadata",
";",
"}"
] |
Get the privacy metadata for all components.
@return collection[] The array of collection objects, indexed by frankenstyle component name.
|
[
"Get",
"the",
"privacy",
"metadata",
"for",
"all",
"components",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/privacy/classes/manager.php#L199-L210
|
215,514
|
moodle/moodle
|
privacy/classes/manager.php
|
manager.get_contexts_for_userid
|
public function get_contexts_for_userid(int $userid) : contextlist_collection {
$progress = static::get_log_tracer();
$components = $this->get_component_list();
$a = (object) [
'total' => count($components),
'progress' => 0,
'component' => '',
'datetime' => userdate(time()),
];
$clcollection = new contextlist_collection($userid);
$progress->output(get_string('trace:fetchcomponents', 'core_privacy', $a), 1);
foreach ($components as $component) {
$a->component = $component;
$a->progress++;
$a->datetime = userdate(time());
$progress->output(get_string('trace:processingcomponent', 'core_privacy', $a), 2);
$contextlist = $this->handled_component_class_callback($component, core_user_data_provider::class,
'get_contexts_for_userid', [$userid]);
if ($contextlist === null) {
$contextlist = new local\request\contextlist();
}
// Each contextlist is tied to its respective component.
$contextlist->set_component($component);
// Add contexts that the component may not know about.
// Example of these include activity completion which modules do not know about themselves.
$contextlist = local\request\helper::add_shared_contexts_to_contextlist_for($userid, $contextlist);
if (count($contextlist)) {
$clcollection->add_contextlist($contextlist);
}
}
$progress->output(get_string('trace:done', 'core_privacy'), 1);
return $clcollection;
}
|
php
|
public function get_contexts_for_userid(int $userid) : contextlist_collection {
$progress = static::get_log_tracer();
$components = $this->get_component_list();
$a = (object) [
'total' => count($components),
'progress' => 0,
'component' => '',
'datetime' => userdate(time()),
];
$clcollection = new contextlist_collection($userid);
$progress->output(get_string('trace:fetchcomponents', 'core_privacy', $a), 1);
foreach ($components as $component) {
$a->component = $component;
$a->progress++;
$a->datetime = userdate(time());
$progress->output(get_string('trace:processingcomponent', 'core_privacy', $a), 2);
$contextlist = $this->handled_component_class_callback($component, core_user_data_provider::class,
'get_contexts_for_userid', [$userid]);
if ($contextlist === null) {
$contextlist = new local\request\contextlist();
}
// Each contextlist is tied to its respective component.
$contextlist->set_component($component);
// Add contexts that the component may not know about.
// Example of these include activity completion which modules do not know about themselves.
$contextlist = local\request\helper::add_shared_contexts_to_contextlist_for($userid, $contextlist);
if (count($contextlist)) {
$clcollection->add_contextlist($contextlist);
}
}
$progress->output(get_string('trace:done', 'core_privacy'), 1);
return $clcollection;
}
|
[
"public",
"function",
"get_contexts_for_userid",
"(",
"int",
"$",
"userid",
")",
":",
"contextlist_collection",
"{",
"$",
"progress",
"=",
"static",
"::",
"get_log_tracer",
"(",
")",
";",
"$",
"components",
"=",
"$",
"this",
"->",
"get_component_list",
"(",
")",
";",
"$",
"a",
"=",
"(",
"object",
")",
"[",
"'total'",
"=>",
"count",
"(",
"$",
"components",
")",
",",
"'progress'",
"=>",
"0",
",",
"'component'",
"=>",
"''",
",",
"'datetime'",
"=>",
"userdate",
"(",
"time",
"(",
")",
")",
",",
"]",
";",
"$",
"clcollection",
"=",
"new",
"contextlist_collection",
"(",
"$",
"userid",
")",
";",
"$",
"progress",
"->",
"output",
"(",
"get_string",
"(",
"'trace:fetchcomponents'",
",",
"'core_privacy'",
",",
"$",
"a",
")",
",",
"1",
")",
";",
"foreach",
"(",
"$",
"components",
"as",
"$",
"component",
")",
"{",
"$",
"a",
"->",
"component",
"=",
"$",
"component",
";",
"$",
"a",
"->",
"progress",
"++",
";",
"$",
"a",
"->",
"datetime",
"=",
"userdate",
"(",
"time",
"(",
")",
")",
";",
"$",
"progress",
"->",
"output",
"(",
"get_string",
"(",
"'trace:processingcomponent'",
",",
"'core_privacy'",
",",
"$",
"a",
")",
",",
"2",
")",
";",
"$",
"contextlist",
"=",
"$",
"this",
"->",
"handled_component_class_callback",
"(",
"$",
"component",
",",
"core_user_data_provider",
"::",
"class",
",",
"'get_contexts_for_userid'",
",",
"[",
"$",
"userid",
"]",
")",
";",
"if",
"(",
"$",
"contextlist",
"===",
"null",
")",
"{",
"$",
"contextlist",
"=",
"new",
"local",
"\\",
"request",
"\\",
"contextlist",
"(",
")",
";",
"}",
"// Each contextlist is tied to its respective component.",
"$",
"contextlist",
"->",
"set_component",
"(",
"$",
"component",
")",
";",
"// Add contexts that the component may not know about.",
"// Example of these include activity completion which modules do not know about themselves.",
"$",
"contextlist",
"=",
"local",
"\\",
"request",
"\\",
"helper",
"::",
"add_shared_contexts_to_contextlist_for",
"(",
"$",
"userid",
",",
"$",
"contextlist",
")",
";",
"if",
"(",
"count",
"(",
"$",
"contextlist",
")",
")",
"{",
"$",
"clcollection",
"->",
"add_contextlist",
"(",
"$",
"contextlist",
")",
";",
"}",
"}",
"$",
"progress",
"->",
"output",
"(",
"get_string",
"(",
"'trace:done'",
",",
"'core_privacy'",
")",
",",
"1",
")",
";",
"return",
"$",
"clcollection",
";",
"}"
] |
Gets a collection of resultset objects for all components.
@param int $userid the id of the user we're fetching contexts for.
@return contextlist_collection the collection of contextlist items for the respective components.
|
[
"Gets",
"a",
"collection",
"of",
"resultset",
"objects",
"for",
"all",
"components",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/privacy/classes/manager.php#L219-L257
|
215,515
|
moodle/moodle
|
privacy/classes/manager.php
|
manager.get_users_in_context
|
public function get_users_in_context(\context $context) : \core_privacy\local\request\userlist_collection {
$progress = static::get_log_tracer();
$components = $this->get_component_list();
$a = (object) [
'total' => count($components),
'progress' => 0,
'component' => '',
'datetime' => userdate(time()),
];
$collection = new \core_privacy\local\request\userlist_collection($context);
$progress->output(get_string('trace:fetchcomponents', 'core_privacy', $a), 1);
foreach ($components as $component) {
$a->component = $component;
$a->progress++;
$a->datetime = userdate(time());
$progress->output(get_string('trace:preprocessingcomponent', 'core_privacy', $a), 2);
$userlist = new local\request\userlist($context, $component);
$this->handled_component_class_callback($component, core_userlist_provider::class, 'get_users_in_context', [$userlist]);
// Add contexts that the component may not know about.
\core_privacy\local\request\helper::add_shared_users_to_userlist($userlist);
if (count($userlist)) {
$collection->add_userlist($userlist);
}
}
$progress->output(get_string('trace:done', 'core_privacy'), 1);
return $collection;
}
|
php
|
public function get_users_in_context(\context $context) : \core_privacy\local\request\userlist_collection {
$progress = static::get_log_tracer();
$components = $this->get_component_list();
$a = (object) [
'total' => count($components),
'progress' => 0,
'component' => '',
'datetime' => userdate(time()),
];
$collection = new \core_privacy\local\request\userlist_collection($context);
$progress->output(get_string('trace:fetchcomponents', 'core_privacy', $a), 1);
foreach ($components as $component) {
$a->component = $component;
$a->progress++;
$a->datetime = userdate(time());
$progress->output(get_string('trace:preprocessingcomponent', 'core_privacy', $a), 2);
$userlist = new local\request\userlist($context, $component);
$this->handled_component_class_callback($component, core_userlist_provider::class, 'get_users_in_context', [$userlist]);
// Add contexts that the component may not know about.
\core_privacy\local\request\helper::add_shared_users_to_userlist($userlist);
if (count($userlist)) {
$collection->add_userlist($userlist);
}
}
$progress->output(get_string('trace:done', 'core_privacy'), 1);
return $collection;
}
|
[
"public",
"function",
"get_users_in_context",
"(",
"\\",
"context",
"$",
"context",
")",
":",
"\\",
"core_privacy",
"\\",
"local",
"\\",
"request",
"\\",
"userlist_collection",
"{",
"$",
"progress",
"=",
"static",
"::",
"get_log_tracer",
"(",
")",
";",
"$",
"components",
"=",
"$",
"this",
"->",
"get_component_list",
"(",
")",
";",
"$",
"a",
"=",
"(",
"object",
")",
"[",
"'total'",
"=>",
"count",
"(",
"$",
"components",
")",
",",
"'progress'",
"=>",
"0",
",",
"'component'",
"=>",
"''",
",",
"'datetime'",
"=>",
"userdate",
"(",
"time",
"(",
")",
")",
",",
"]",
";",
"$",
"collection",
"=",
"new",
"\\",
"core_privacy",
"\\",
"local",
"\\",
"request",
"\\",
"userlist_collection",
"(",
"$",
"context",
")",
";",
"$",
"progress",
"->",
"output",
"(",
"get_string",
"(",
"'trace:fetchcomponents'",
",",
"'core_privacy'",
",",
"$",
"a",
")",
",",
"1",
")",
";",
"foreach",
"(",
"$",
"components",
"as",
"$",
"component",
")",
"{",
"$",
"a",
"->",
"component",
"=",
"$",
"component",
";",
"$",
"a",
"->",
"progress",
"++",
";",
"$",
"a",
"->",
"datetime",
"=",
"userdate",
"(",
"time",
"(",
")",
")",
";",
"$",
"progress",
"->",
"output",
"(",
"get_string",
"(",
"'trace:preprocessingcomponent'",
",",
"'core_privacy'",
",",
"$",
"a",
")",
",",
"2",
")",
";",
"$",
"userlist",
"=",
"new",
"local",
"\\",
"request",
"\\",
"userlist",
"(",
"$",
"context",
",",
"$",
"component",
")",
";",
"$",
"this",
"->",
"handled_component_class_callback",
"(",
"$",
"component",
",",
"core_userlist_provider",
"::",
"class",
",",
"'get_users_in_context'",
",",
"[",
"$",
"userlist",
"]",
")",
";",
"// Add contexts that the component may not know about.",
"\\",
"core_privacy",
"\\",
"local",
"\\",
"request",
"\\",
"helper",
"::",
"add_shared_users_to_userlist",
"(",
"$",
"userlist",
")",
";",
"if",
"(",
"count",
"(",
"$",
"userlist",
")",
")",
"{",
"$",
"collection",
"->",
"add_userlist",
"(",
"$",
"userlist",
")",
";",
"}",
"}",
"$",
"progress",
"->",
"output",
"(",
"get_string",
"(",
"'trace:done'",
",",
"'core_privacy'",
")",
",",
"1",
")",
";",
"return",
"$",
"collection",
";",
"}"
] |
Gets a collection of users for all components in the specified context.
@param \context $context The context to search
@return userlist_collection the collection of userlist items for the respective components.
|
[
"Gets",
"a",
"collection",
"of",
"users",
"for",
"all",
"components",
"in",
"the",
"specified",
"context",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/privacy/classes/manager.php#L265-L297
|
215,516
|
moodle/moodle
|
privacy/classes/manager.php
|
manager.export_user_data
|
public function export_user_data(contextlist_collection $contextlistcollection) {
$progress = static::get_log_tracer();
$a = (object) [
'total' => count($contextlistcollection),
'progress' => 0,
'component' => '',
'datetime' => userdate(time()),
];
// Export for the various components/contexts.
$progress->output(get_string('trace:exportingapproved', 'core_privacy', $a), 1);
foreach ($contextlistcollection as $approvedcontextlist) {
if (!$approvedcontextlist instanceof \core_privacy\local\request\approved_contextlist) {
throw new \moodle_exception('Contextlist must be an approved_contextlist');
}
$component = $approvedcontextlist->get_component();
$a->component = $component;
$a->progress++;
$a->datetime = userdate(time());
$progress->output(get_string('trace:processingcomponent', 'core_privacy', $a), 2);
// Core user data providers.
if ($this->component_implements($component, core_user_data_provider::class)) {
if (count($approvedcontextlist)) {
// This plugin has data it knows about. It is responsible for storing basic data about anything it is
// told to export.
$this->handled_component_class_callback($component, core_user_data_provider::class,
'export_user_data', [$approvedcontextlist]);
}
} else if (!$this->component_implements($component, context_aware_provider::class)) {
// This plugin does not know that it has data - export the shared data it doesn't know about.
local\request\helper::export_data_for_null_provider($approvedcontextlist);
}
}
$progress->output(get_string('trace:done', 'core_privacy'), 1);
// Check each component for non contextlist items too.
$components = $this->get_component_list();
$a->total = count($components);
$a->progress = 0;
$a->datetime = userdate(time());
$progress->output(get_string('trace:exportingrelated', 'core_privacy', $a), 1);
foreach ($components as $component) {
$a->component = $component;
$a->progress++;
$a->datetime = userdate(time());
$progress->output(get_string('trace:processingcomponent', 'core_privacy', $a), 2);
// Core user preference providers.
$this->handled_component_class_callback($component, user_preference_provider::class,
'export_user_preferences', [$contextlistcollection->get_userid()]);
// Contextual information providers. Give each component a chance to include context information based on the
// existence of a child context in the contextlist_collection.
$this->handled_component_class_callback($component, context_aware_provider::class,
'export_context_data', [$contextlistcollection]);
}
$progress->output(get_string('trace:done', 'core_privacy'), 1);
$progress->output(get_string('trace:finalisingexport', 'core_privacy'), 1);
$location = local\request\writer::with_context(\context_system::instance())->finalise_content();
$progress->output(get_string('trace:exportcomplete', 'core_privacy'), 1);
return $location;
}
|
php
|
public function export_user_data(contextlist_collection $contextlistcollection) {
$progress = static::get_log_tracer();
$a = (object) [
'total' => count($contextlistcollection),
'progress' => 0,
'component' => '',
'datetime' => userdate(time()),
];
// Export for the various components/contexts.
$progress->output(get_string('trace:exportingapproved', 'core_privacy', $a), 1);
foreach ($contextlistcollection as $approvedcontextlist) {
if (!$approvedcontextlist instanceof \core_privacy\local\request\approved_contextlist) {
throw new \moodle_exception('Contextlist must be an approved_contextlist');
}
$component = $approvedcontextlist->get_component();
$a->component = $component;
$a->progress++;
$a->datetime = userdate(time());
$progress->output(get_string('trace:processingcomponent', 'core_privacy', $a), 2);
// Core user data providers.
if ($this->component_implements($component, core_user_data_provider::class)) {
if (count($approvedcontextlist)) {
// This plugin has data it knows about. It is responsible for storing basic data about anything it is
// told to export.
$this->handled_component_class_callback($component, core_user_data_provider::class,
'export_user_data', [$approvedcontextlist]);
}
} else if (!$this->component_implements($component, context_aware_provider::class)) {
// This plugin does not know that it has data - export the shared data it doesn't know about.
local\request\helper::export_data_for_null_provider($approvedcontextlist);
}
}
$progress->output(get_string('trace:done', 'core_privacy'), 1);
// Check each component for non contextlist items too.
$components = $this->get_component_list();
$a->total = count($components);
$a->progress = 0;
$a->datetime = userdate(time());
$progress->output(get_string('trace:exportingrelated', 'core_privacy', $a), 1);
foreach ($components as $component) {
$a->component = $component;
$a->progress++;
$a->datetime = userdate(time());
$progress->output(get_string('trace:processingcomponent', 'core_privacy', $a), 2);
// Core user preference providers.
$this->handled_component_class_callback($component, user_preference_provider::class,
'export_user_preferences', [$contextlistcollection->get_userid()]);
// Contextual information providers. Give each component a chance to include context information based on the
// existence of a child context in the contextlist_collection.
$this->handled_component_class_callback($component, context_aware_provider::class,
'export_context_data', [$contextlistcollection]);
}
$progress->output(get_string('trace:done', 'core_privacy'), 1);
$progress->output(get_string('trace:finalisingexport', 'core_privacy'), 1);
$location = local\request\writer::with_context(\context_system::instance())->finalise_content();
$progress->output(get_string('trace:exportcomplete', 'core_privacy'), 1);
return $location;
}
|
[
"public",
"function",
"export_user_data",
"(",
"contextlist_collection",
"$",
"contextlistcollection",
")",
"{",
"$",
"progress",
"=",
"static",
"::",
"get_log_tracer",
"(",
")",
";",
"$",
"a",
"=",
"(",
"object",
")",
"[",
"'total'",
"=>",
"count",
"(",
"$",
"contextlistcollection",
")",
",",
"'progress'",
"=>",
"0",
",",
"'component'",
"=>",
"''",
",",
"'datetime'",
"=>",
"userdate",
"(",
"time",
"(",
")",
")",
",",
"]",
";",
"// Export for the various components/contexts.",
"$",
"progress",
"->",
"output",
"(",
"get_string",
"(",
"'trace:exportingapproved'",
",",
"'core_privacy'",
",",
"$",
"a",
")",
",",
"1",
")",
";",
"foreach",
"(",
"$",
"contextlistcollection",
"as",
"$",
"approvedcontextlist",
")",
"{",
"if",
"(",
"!",
"$",
"approvedcontextlist",
"instanceof",
"\\",
"core_privacy",
"\\",
"local",
"\\",
"request",
"\\",
"approved_contextlist",
")",
"{",
"throw",
"new",
"\\",
"moodle_exception",
"(",
"'Contextlist must be an approved_contextlist'",
")",
";",
"}",
"$",
"component",
"=",
"$",
"approvedcontextlist",
"->",
"get_component",
"(",
")",
";",
"$",
"a",
"->",
"component",
"=",
"$",
"component",
";",
"$",
"a",
"->",
"progress",
"++",
";",
"$",
"a",
"->",
"datetime",
"=",
"userdate",
"(",
"time",
"(",
")",
")",
";",
"$",
"progress",
"->",
"output",
"(",
"get_string",
"(",
"'trace:processingcomponent'",
",",
"'core_privacy'",
",",
"$",
"a",
")",
",",
"2",
")",
";",
"// Core user data providers.",
"if",
"(",
"$",
"this",
"->",
"component_implements",
"(",
"$",
"component",
",",
"core_user_data_provider",
"::",
"class",
")",
")",
"{",
"if",
"(",
"count",
"(",
"$",
"approvedcontextlist",
")",
")",
"{",
"// This plugin has data it knows about. It is responsible for storing basic data about anything it is",
"// told to export.",
"$",
"this",
"->",
"handled_component_class_callback",
"(",
"$",
"component",
",",
"core_user_data_provider",
"::",
"class",
",",
"'export_user_data'",
",",
"[",
"$",
"approvedcontextlist",
"]",
")",
";",
"}",
"}",
"else",
"if",
"(",
"!",
"$",
"this",
"->",
"component_implements",
"(",
"$",
"component",
",",
"context_aware_provider",
"::",
"class",
")",
")",
"{",
"// This plugin does not know that it has data - export the shared data it doesn't know about.",
"local",
"\\",
"request",
"\\",
"helper",
"::",
"export_data_for_null_provider",
"(",
"$",
"approvedcontextlist",
")",
";",
"}",
"}",
"$",
"progress",
"->",
"output",
"(",
"get_string",
"(",
"'trace:done'",
",",
"'core_privacy'",
")",
",",
"1",
")",
";",
"// Check each component for non contextlist items too.",
"$",
"components",
"=",
"$",
"this",
"->",
"get_component_list",
"(",
")",
";",
"$",
"a",
"->",
"total",
"=",
"count",
"(",
"$",
"components",
")",
";",
"$",
"a",
"->",
"progress",
"=",
"0",
";",
"$",
"a",
"->",
"datetime",
"=",
"userdate",
"(",
"time",
"(",
")",
")",
";",
"$",
"progress",
"->",
"output",
"(",
"get_string",
"(",
"'trace:exportingrelated'",
",",
"'core_privacy'",
",",
"$",
"a",
")",
",",
"1",
")",
";",
"foreach",
"(",
"$",
"components",
"as",
"$",
"component",
")",
"{",
"$",
"a",
"->",
"component",
"=",
"$",
"component",
";",
"$",
"a",
"->",
"progress",
"++",
";",
"$",
"a",
"->",
"datetime",
"=",
"userdate",
"(",
"time",
"(",
")",
")",
";",
"$",
"progress",
"->",
"output",
"(",
"get_string",
"(",
"'trace:processingcomponent'",
",",
"'core_privacy'",
",",
"$",
"a",
")",
",",
"2",
")",
";",
"// Core user preference providers.",
"$",
"this",
"->",
"handled_component_class_callback",
"(",
"$",
"component",
",",
"user_preference_provider",
"::",
"class",
",",
"'export_user_preferences'",
",",
"[",
"$",
"contextlistcollection",
"->",
"get_userid",
"(",
")",
"]",
")",
";",
"// Contextual information providers. Give each component a chance to include context information based on the",
"// existence of a child context in the contextlist_collection.",
"$",
"this",
"->",
"handled_component_class_callback",
"(",
"$",
"component",
",",
"context_aware_provider",
"::",
"class",
",",
"'export_context_data'",
",",
"[",
"$",
"contextlistcollection",
"]",
")",
";",
"}",
"$",
"progress",
"->",
"output",
"(",
"get_string",
"(",
"'trace:done'",
",",
"'core_privacy'",
")",
",",
"1",
")",
";",
"$",
"progress",
"->",
"output",
"(",
"get_string",
"(",
"'trace:finalisingexport'",
",",
"'core_privacy'",
")",
",",
"1",
")",
";",
"$",
"location",
"=",
"local",
"\\",
"request",
"\\",
"writer",
"::",
"with_context",
"(",
"\\",
"context_system",
"::",
"instance",
"(",
")",
")",
"->",
"finalise_content",
"(",
")",
";",
"$",
"progress",
"->",
"output",
"(",
"get_string",
"(",
"'trace:exportcomplete'",
",",
"'core_privacy'",
")",
",",
"1",
")",
";",
"return",
"$",
"location",
";",
"}"
] |
Export all user data for the specified approved_contextlist items.
Note: userid and component are stored in each respective approved_contextlist.
@param contextlist_collection $contextlistcollection the collection of contextlists for all components.
@return string the location of the exported data.
@throws \moodle_exception if the contextlist_collection does not contain all approved_contextlist items or if one of the
approved_contextlists' components is not a core_data_provider.
|
[
"Export",
"all",
"user",
"data",
"for",
"the",
"specified",
"approved_contextlist",
"items",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/privacy/classes/manager.php#L309-L375
|
215,517
|
moodle/moodle
|
privacy/classes/manager.php
|
manager.delete_data_for_user
|
public function delete_data_for_user(contextlist_collection $contextlistcollection) {
$progress = static::get_log_tracer();
$a = (object) [
'total' => count($contextlistcollection),
'progress' => 0,
'component' => '',
'datetime' => userdate(time()),
];
// Delete the data.
$progress->output(get_string('trace:deletingapproved', 'core_privacy', $a), 1);
foreach ($contextlistcollection as $approvedcontextlist) {
if (!$approvedcontextlist instanceof \core_privacy\local\request\approved_contextlist) {
throw new \moodle_exception('Contextlist must be an approved_contextlist');
}
$component = $approvedcontextlist->get_component();
$a->component = $component;
$a->progress++;
$a->datetime = userdate(time());
$progress->output(get_string('trace:processingcomponent', 'core_privacy', $a), 2);
if (count($approvedcontextlist)) {
// The component knows about data that it has.
// Have it delete its own data.
$this->handled_component_class_callback($approvedcontextlist->get_component(), core_user_data_provider::class,
'delete_data_for_user', [$approvedcontextlist]);
}
// Delete any shared user data it doesn't know about.
local\request\helper::delete_data_for_user($approvedcontextlist);
}
$progress->output(get_string('trace:done', 'core_privacy'), 1);
}
|
php
|
public function delete_data_for_user(contextlist_collection $contextlistcollection) {
$progress = static::get_log_tracer();
$a = (object) [
'total' => count($contextlistcollection),
'progress' => 0,
'component' => '',
'datetime' => userdate(time()),
];
// Delete the data.
$progress->output(get_string('trace:deletingapproved', 'core_privacy', $a), 1);
foreach ($contextlistcollection as $approvedcontextlist) {
if (!$approvedcontextlist instanceof \core_privacy\local\request\approved_contextlist) {
throw new \moodle_exception('Contextlist must be an approved_contextlist');
}
$component = $approvedcontextlist->get_component();
$a->component = $component;
$a->progress++;
$a->datetime = userdate(time());
$progress->output(get_string('trace:processingcomponent', 'core_privacy', $a), 2);
if (count($approvedcontextlist)) {
// The component knows about data that it has.
// Have it delete its own data.
$this->handled_component_class_callback($approvedcontextlist->get_component(), core_user_data_provider::class,
'delete_data_for_user', [$approvedcontextlist]);
}
// Delete any shared user data it doesn't know about.
local\request\helper::delete_data_for_user($approvedcontextlist);
}
$progress->output(get_string('trace:done', 'core_privacy'), 1);
}
|
[
"public",
"function",
"delete_data_for_user",
"(",
"contextlist_collection",
"$",
"contextlistcollection",
")",
"{",
"$",
"progress",
"=",
"static",
"::",
"get_log_tracer",
"(",
")",
";",
"$",
"a",
"=",
"(",
"object",
")",
"[",
"'total'",
"=>",
"count",
"(",
"$",
"contextlistcollection",
")",
",",
"'progress'",
"=>",
"0",
",",
"'component'",
"=>",
"''",
",",
"'datetime'",
"=>",
"userdate",
"(",
"time",
"(",
")",
")",
",",
"]",
";",
"// Delete the data.",
"$",
"progress",
"->",
"output",
"(",
"get_string",
"(",
"'trace:deletingapproved'",
",",
"'core_privacy'",
",",
"$",
"a",
")",
",",
"1",
")",
";",
"foreach",
"(",
"$",
"contextlistcollection",
"as",
"$",
"approvedcontextlist",
")",
"{",
"if",
"(",
"!",
"$",
"approvedcontextlist",
"instanceof",
"\\",
"core_privacy",
"\\",
"local",
"\\",
"request",
"\\",
"approved_contextlist",
")",
"{",
"throw",
"new",
"\\",
"moodle_exception",
"(",
"'Contextlist must be an approved_contextlist'",
")",
";",
"}",
"$",
"component",
"=",
"$",
"approvedcontextlist",
"->",
"get_component",
"(",
")",
";",
"$",
"a",
"->",
"component",
"=",
"$",
"component",
";",
"$",
"a",
"->",
"progress",
"++",
";",
"$",
"a",
"->",
"datetime",
"=",
"userdate",
"(",
"time",
"(",
")",
")",
";",
"$",
"progress",
"->",
"output",
"(",
"get_string",
"(",
"'trace:processingcomponent'",
",",
"'core_privacy'",
",",
"$",
"a",
")",
",",
"2",
")",
";",
"if",
"(",
"count",
"(",
"$",
"approvedcontextlist",
")",
")",
"{",
"// The component knows about data that it has.",
"// Have it delete its own data.",
"$",
"this",
"->",
"handled_component_class_callback",
"(",
"$",
"approvedcontextlist",
"->",
"get_component",
"(",
")",
",",
"core_user_data_provider",
"::",
"class",
",",
"'delete_data_for_user'",
",",
"[",
"$",
"approvedcontextlist",
"]",
")",
";",
"}",
"// Delete any shared user data it doesn't know about.",
"local",
"\\",
"request",
"\\",
"helper",
"::",
"delete_data_for_user",
"(",
"$",
"approvedcontextlist",
")",
";",
"}",
"$",
"progress",
"->",
"output",
"(",
"get_string",
"(",
"'trace:done'",
",",
"'core_privacy'",
")",
",",
"1",
")",
";",
"}"
] |
Delete all user data for approved contexts lists provided in the collection.
This call relates to the forgetting of an entire user.
Note: userid and component are stored in each respective approved_contextlist.
@param contextlist_collection $contextlistcollection the collections of approved_contextlist items on which to call deletion.
@throws \moodle_exception if the contextlist_collection doesn't contain all approved_contextlist items, or if the component
for an approved_contextlist isn't a core provider.
|
[
"Delete",
"all",
"user",
"data",
"for",
"approved",
"contexts",
"lists",
"provided",
"in",
"the",
"collection",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/privacy/classes/manager.php#L388-L422
|
215,518
|
moodle/moodle
|
privacy/classes/manager.php
|
manager.delete_data_for_users_in_context
|
public function delete_data_for_users_in_context(\core_privacy\local\request\userlist_collection $collection) {
$progress = static::get_log_tracer();
$a = (object) [
'contextid' => $collection->get_context()->id,
'total' => count($collection),
'progress' => 0,
'component' => '',
'datetime' => userdate(time()),
];
// Delete the data.
$progress->output(get_string('trace:deletingapprovedusers', 'core_privacy', $a), 1);
foreach ($collection as $userlist) {
if (!$userlist instanceof \core_privacy\local\request\approved_userlist) {
throw new \moodle_exception('The supplied userlist must be an approved_userlist');
}
$component = $userlist->get_component();
$a->component = $component;
$a->progress++;
$a->datetime = userdate(time());
if (empty($userlist)) {
// This really shouldn't happen!
continue;
}
$progress->output(get_string('trace:processingcomponent', 'core_privacy', $a), 2);
$this->handled_component_class_callback($component, core_userlist_provider::class,
'delete_data_for_users', [$userlist]);
}
$progress->output(get_string('trace:done', 'core_privacy'), 1);
}
|
php
|
public function delete_data_for_users_in_context(\core_privacy\local\request\userlist_collection $collection) {
$progress = static::get_log_tracer();
$a = (object) [
'contextid' => $collection->get_context()->id,
'total' => count($collection),
'progress' => 0,
'component' => '',
'datetime' => userdate(time()),
];
// Delete the data.
$progress->output(get_string('trace:deletingapprovedusers', 'core_privacy', $a), 1);
foreach ($collection as $userlist) {
if (!$userlist instanceof \core_privacy\local\request\approved_userlist) {
throw new \moodle_exception('The supplied userlist must be an approved_userlist');
}
$component = $userlist->get_component();
$a->component = $component;
$a->progress++;
$a->datetime = userdate(time());
if (empty($userlist)) {
// This really shouldn't happen!
continue;
}
$progress->output(get_string('trace:processingcomponent', 'core_privacy', $a), 2);
$this->handled_component_class_callback($component, core_userlist_provider::class,
'delete_data_for_users', [$userlist]);
}
$progress->output(get_string('trace:done', 'core_privacy'), 1);
}
|
[
"public",
"function",
"delete_data_for_users_in_context",
"(",
"\\",
"core_privacy",
"\\",
"local",
"\\",
"request",
"\\",
"userlist_collection",
"$",
"collection",
")",
"{",
"$",
"progress",
"=",
"static",
"::",
"get_log_tracer",
"(",
")",
";",
"$",
"a",
"=",
"(",
"object",
")",
"[",
"'contextid'",
"=>",
"$",
"collection",
"->",
"get_context",
"(",
")",
"->",
"id",
",",
"'total'",
"=>",
"count",
"(",
"$",
"collection",
")",
",",
"'progress'",
"=>",
"0",
",",
"'component'",
"=>",
"''",
",",
"'datetime'",
"=>",
"userdate",
"(",
"time",
"(",
")",
")",
",",
"]",
";",
"// Delete the data.",
"$",
"progress",
"->",
"output",
"(",
"get_string",
"(",
"'trace:deletingapprovedusers'",
",",
"'core_privacy'",
",",
"$",
"a",
")",
",",
"1",
")",
";",
"foreach",
"(",
"$",
"collection",
"as",
"$",
"userlist",
")",
"{",
"if",
"(",
"!",
"$",
"userlist",
"instanceof",
"\\",
"core_privacy",
"\\",
"local",
"\\",
"request",
"\\",
"approved_userlist",
")",
"{",
"throw",
"new",
"\\",
"moodle_exception",
"(",
"'The supplied userlist must be an approved_userlist'",
")",
";",
"}",
"$",
"component",
"=",
"$",
"userlist",
"->",
"get_component",
"(",
")",
";",
"$",
"a",
"->",
"component",
"=",
"$",
"component",
";",
"$",
"a",
"->",
"progress",
"++",
";",
"$",
"a",
"->",
"datetime",
"=",
"userdate",
"(",
"time",
"(",
")",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"userlist",
")",
")",
"{",
"// This really shouldn't happen!",
"continue",
";",
"}",
"$",
"progress",
"->",
"output",
"(",
"get_string",
"(",
"'trace:processingcomponent'",
",",
"'core_privacy'",
",",
"$",
"a",
")",
",",
"2",
")",
";",
"$",
"this",
"->",
"handled_component_class_callback",
"(",
"$",
"component",
",",
"core_userlist_provider",
"::",
"class",
",",
"'delete_data_for_users'",
",",
"[",
"$",
"userlist",
"]",
")",
";",
"}",
"$",
"progress",
"->",
"output",
"(",
"get_string",
"(",
"'trace:done'",
",",
"'core_privacy'",
")",
",",
"1",
")",
";",
"}"
] |
Delete all user data for all specified users in a context.
@param \core_privacy\local\request\userlist_collection $collection
|
[
"Delete",
"all",
"user",
"data",
"for",
"all",
"specified",
"users",
"in",
"a",
"context",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/privacy/classes/manager.php#L429-L464
|
215,519
|
moodle/moodle
|
privacy/classes/manager.php
|
manager.delete_data_for_all_users_in_context
|
public function delete_data_for_all_users_in_context(\context $context) {
$progress = static::get_log_tracer();
$components = $this->get_component_list();
$a = (object) [
'total' => count($components),
'progress' => 0,
'component' => '',
'datetime' => userdate(time()),
];
$progress->output(get_string('trace:deletingcontext', 'core_privacy', $a), 1);
foreach ($this->get_component_list() as $component) {
$a->component = $component;
$a->progress++;
$a->datetime = userdate(time());
$progress->output(get_string('trace:processingcomponent', 'core_privacy', $a), 2);
// If this component knows about specific data that it owns,
// have it delete all of that user data for the context.
$this->handled_component_class_callback($component, core_user_data_provider::class,
'delete_data_for_all_users_in_context', [$context]);
// Delete any shared user data it doesn't know about.
local\request\helper::delete_data_for_all_users_in_context($component, $context);
}
$progress->output(get_string('trace:done', 'core_privacy'), 1);
}
|
php
|
public function delete_data_for_all_users_in_context(\context $context) {
$progress = static::get_log_tracer();
$components = $this->get_component_list();
$a = (object) [
'total' => count($components),
'progress' => 0,
'component' => '',
'datetime' => userdate(time()),
];
$progress->output(get_string('trace:deletingcontext', 'core_privacy', $a), 1);
foreach ($this->get_component_list() as $component) {
$a->component = $component;
$a->progress++;
$a->datetime = userdate(time());
$progress->output(get_string('trace:processingcomponent', 'core_privacy', $a), 2);
// If this component knows about specific data that it owns,
// have it delete all of that user data for the context.
$this->handled_component_class_callback($component, core_user_data_provider::class,
'delete_data_for_all_users_in_context', [$context]);
// Delete any shared user data it doesn't know about.
local\request\helper::delete_data_for_all_users_in_context($component, $context);
}
$progress->output(get_string('trace:done', 'core_privacy'), 1);
}
|
[
"public",
"function",
"delete_data_for_all_users_in_context",
"(",
"\\",
"context",
"$",
"context",
")",
"{",
"$",
"progress",
"=",
"static",
"::",
"get_log_tracer",
"(",
")",
";",
"$",
"components",
"=",
"$",
"this",
"->",
"get_component_list",
"(",
")",
";",
"$",
"a",
"=",
"(",
"object",
")",
"[",
"'total'",
"=>",
"count",
"(",
"$",
"components",
")",
",",
"'progress'",
"=>",
"0",
",",
"'component'",
"=>",
"''",
",",
"'datetime'",
"=>",
"userdate",
"(",
"time",
"(",
")",
")",
",",
"]",
";",
"$",
"progress",
"->",
"output",
"(",
"get_string",
"(",
"'trace:deletingcontext'",
",",
"'core_privacy'",
",",
"$",
"a",
")",
",",
"1",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"get_component_list",
"(",
")",
"as",
"$",
"component",
")",
"{",
"$",
"a",
"->",
"component",
"=",
"$",
"component",
";",
"$",
"a",
"->",
"progress",
"++",
";",
"$",
"a",
"->",
"datetime",
"=",
"userdate",
"(",
"time",
"(",
")",
")",
";",
"$",
"progress",
"->",
"output",
"(",
"get_string",
"(",
"'trace:processingcomponent'",
",",
"'core_privacy'",
",",
"$",
"a",
")",
",",
"2",
")",
";",
"// If this component knows about specific data that it owns,",
"// have it delete all of that user data for the context.",
"$",
"this",
"->",
"handled_component_class_callback",
"(",
"$",
"component",
",",
"core_user_data_provider",
"::",
"class",
",",
"'delete_data_for_all_users_in_context'",
",",
"[",
"$",
"context",
"]",
")",
";",
"// Delete any shared user data it doesn't know about.",
"local",
"\\",
"request",
"\\",
"helper",
"::",
"delete_data_for_all_users_in_context",
"(",
"$",
"component",
",",
"$",
"context",
")",
";",
"}",
"$",
"progress",
"->",
"output",
"(",
"get_string",
"(",
"'trace:done'",
",",
"'core_privacy'",
")",
",",
"1",
")",
";",
"}"
] |
Delete all use data which matches the specified deletion criteria.
@param \context $context The specific context to delete data for.
|
[
"Delete",
"all",
"use",
"data",
"which",
"matches",
"the",
"specified",
"deletion",
"criteria",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/privacy/classes/manager.php#L471-L498
|
215,520
|
moodle/moodle
|
privacy/classes/manager.php
|
manager.plugintype_class_callback
|
public static function plugintype_class_callback(string $plugintype, string $interface, string $methodname, array $params) {
$components = \core_component::get_plugin_list($plugintype);
foreach (array_keys($components) as $component) {
static::component_class_callback("{$plugintype}_{$component}", $interface, $methodname, $params);
}
}
|
php
|
public static function plugintype_class_callback(string $plugintype, string $interface, string $methodname, array $params) {
$components = \core_component::get_plugin_list($plugintype);
foreach (array_keys($components) as $component) {
static::component_class_callback("{$plugintype}_{$component}", $interface, $methodname, $params);
}
}
|
[
"public",
"static",
"function",
"plugintype_class_callback",
"(",
"string",
"$",
"plugintype",
",",
"string",
"$",
"interface",
",",
"string",
"$",
"methodname",
",",
"array",
"$",
"params",
")",
"{",
"$",
"components",
"=",
"\\",
"core_component",
"::",
"get_plugin_list",
"(",
"$",
"plugintype",
")",
";",
"foreach",
"(",
"array_keys",
"(",
"$",
"components",
")",
"as",
"$",
"component",
")",
"{",
"static",
"::",
"component_class_callback",
"(",
"\"{$plugintype}_{$component}\"",
",",
"$",
"interface",
",",
"$",
"methodname",
",",
"$",
"params",
")",
";",
"}",
"}"
] |
Call the named method with the specified params on any plugintype implementing the relevant interface.
@param string $plugintype The plugingtype to check
@param string $interface The interface to implement
@param string $methodname The method to call
@param array $params The params to call
|
[
"Call",
"the",
"named",
"method",
"with",
"the",
"specified",
"params",
"on",
"any",
"plugintype",
"implementing",
"the",
"relevant",
"interface",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/privacy/classes/manager.php#L559-L564
|
215,521
|
moodle/moodle
|
privacy/classes/manager.php
|
manager.component_class_callback_failed
|
protected function component_class_callback_failed(\Throwable $e, string $component, string $interface,
string $methodname, array $params) {
if ($this->observer) {
call_user_func_array([$this->observer, 'handle_component_failure'], func_get_args());
}
}
|
php
|
protected function component_class_callback_failed(\Throwable $e, string $component, string $interface,
string $methodname, array $params) {
if ($this->observer) {
call_user_func_array([$this->observer, 'handle_component_failure'], func_get_args());
}
}
|
[
"protected",
"function",
"component_class_callback_failed",
"(",
"\\",
"Throwable",
"$",
"e",
",",
"string",
"$",
"component",
",",
"string",
"$",
"interface",
",",
"string",
"$",
"methodname",
",",
"array",
"$",
"params",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"observer",
")",
"{",
"call_user_func_array",
"(",
"[",
"$",
"this",
"->",
"observer",
",",
"'handle_component_failure'",
"]",
",",
"func_get_args",
"(",
")",
")",
";",
"}",
"}"
] |
Notifies the observer of any failure.
@param \Throwable $e
@param string $component
@param string $interface
@param string $methodname
@param array $params
|
[
"Notifies",
"the",
"observer",
"of",
"any",
"failure",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/privacy/classes/manager.php#L629-L634
|
215,522
|
moodle/moodle
|
analytics/classes/local/target/base.php
|
base.prediction_actions
|
public function prediction_actions(\core_analytics\prediction $prediction, $includedetailsaction = false,
$isinsightuser = false) {
global $PAGE;
$predictionid = $prediction->get_prediction_data()->id;
$PAGE->requires->js_call_amd('report_insights/actions', 'init', array($predictionid));
$actions = array();
if ($includedetailsaction) {
$predictionurl = new \moodle_url('/report/insights/prediction.php', array('id' => $predictionid));
$detailstext = $this->get_view_details_text();
$actions[] = new \core_analytics\prediction_action(\core_analytics\prediction::ACTION_PREDICTION_DETAILS, $prediction,
$predictionurl, new \pix_icon('t/preview', $detailstext),
$detailstext);
}
// Flag as fixed / solved.
$fixedattrs = array(
'data-prediction-id' => $predictionid,
'data-prediction-methodname' => 'report_insights_set_fixed_prediction'
);
$actions[] = new \core_analytics\prediction_action(\core_analytics\prediction::ACTION_FIXED,
$prediction, new \moodle_url(''), new \pix_icon('t/check', get_string('fixedack', 'analytics')),
get_string('fixedack', 'analytics'), false, $fixedattrs);
// Flag as not useful.
$notusefulattrs = array(
'data-prediction-id' => $predictionid,
'data-prediction-methodname' => 'report_insights_set_notuseful_prediction'
);
$actions[] = new \core_analytics\prediction_action(\core_analytics\prediction::ACTION_NOT_USEFUL,
$prediction, new \moodle_url(''), new \pix_icon('t/delete', get_string('notuseful', 'analytics')),
get_string('notuseful', 'analytics'), false, $notusefulattrs);
return $actions;
}
|
php
|
public function prediction_actions(\core_analytics\prediction $prediction, $includedetailsaction = false,
$isinsightuser = false) {
global $PAGE;
$predictionid = $prediction->get_prediction_data()->id;
$PAGE->requires->js_call_amd('report_insights/actions', 'init', array($predictionid));
$actions = array();
if ($includedetailsaction) {
$predictionurl = new \moodle_url('/report/insights/prediction.php', array('id' => $predictionid));
$detailstext = $this->get_view_details_text();
$actions[] = new \core_analytics\prediction_action(\core_analytics\prediction::ACTION_PREDICTION_DETAILS, $prediction,
$predictionurl, new \pix_icon('t/preview', $detailstext),
$detailstext);
}
// Flag as fixed / solved.
$fixedattrs = array(
'data-prediction-id' => $predictionid,
'data-prediction-methodname' => 'report_insights_set_fixed_prediction'
);
$actions[] = new \core_analytics\prediction_action(\core_analytics\prediction::ACTION_FIXED,
$prediction, new \moodle_url(''), new \pix_icon('t/check', get_string('fixedack', 'analytics')),
get_string('fixedack', 'analytics'), false, $fixedattrs);
// Flag as not useful.
$notusefulattrs = array(
'data-prediction-id' => $predictionid,
'data-prediction-methodname' => 'report_insights_set_notuseful_prediction'
);
$actions[] = new \core_analytics\prediction_action(\core_analytics\prediction::ACTION_NOT_USEFUL,
$prediction, new \moodle_url(''), new \pix_icon('t/delete', get_string('notuseful', 'analytics')),
get_string('notuseful', 'analytics'), false, $notusefulattrs);
return $actions;
}
|
[
"public",
"function",
"prediction_actions",
"(",
"\\",
"core_analytics",
"\\",
"prediction",
"$",
"prediction",
",",
"$",
"includedetailsaction",
"=",
"false",
",",
"$",
"isinsightuser",
"=",
"false",
")",
"{",
"global",
"$",
"PAGE",
";",
"$",
"predictionid",
"=",
"$",
"prediction",
"->",
"get_prediction_data",
"(",
")",
"->",
"id",
";",
"$",
"PAGE",
"->",
"requires",
"->",
"js_call_amd",
"(",
"'report_insights/actions'",
",",
"'init'",
",",
"array",
"(",
"$",
"predictionid",
")",
")",
";",
"$",
"actions",
"=",
"array",
"(",
")",
";",
"if",
"(",
"$",
"includedetailsaction",
")",
"{",
"$",
"predictionurl",
"=",
"new",
"\\",
"moodle_url",
"(",
"'/report/insights/prediction.php'",
",",
"array",
"(",
"'id'",
"=>",
"$",
"predictionid",
")",
")",
";",
"$",
"detailstext",
"=",
"$",
"this",
"->",
"get_view_details_text",
"(",
")",
";",
"$",
"actions",
"[",
"]",
"=",
"new",
"\\",
"core_analytics",
"\\",
"prediction_action",
"(",
"\\",
"core_analytics",
"\\",
"prediction",
"::",
"ACTION_PREDICTION_DETAILS",
",",
"$",
"prediction",
",",
"$",
"predictionurl",
",",
"new",
"\\",
"pix_icon",
"(",
"'t/preview'",
",",
"$",
"detailstext",
")",
",",
"$",
"detailstext",
")",
";",
"}",
"// Flag as fixed / solved.",
"$",
"fixedattrs",
"=",
"array",
"(",
"'data-prediction-id'",
"=>",
"$",
"predictionid",
",",
"'data-prediction-methodname'",
"=>",
"'report_insights_set_fixed_prediction'",
")",
";",
"$",
"actions",
"[",
"]",
"=",
"new",
"\\",
"core_analytics",
"\\",
"prediction_action",
"(",
"\\",
"core_analytics",
"\\",
"prediction",
"::",
"ACTION_FIXED",
",",
"$",
"prediction",
",",
"new",
"\\",
"moodle_url",
"(",
"''",
")",
",",
"new",
"\\",
"pix_icon",
"(",
"'t/check'",
",",
"get_string",
"(",
"'fixedack'",
",",
"'analytics'",
")",
")",
",",
"get_string",
"(",
"'fixedack'",
",",
"'analytics'",
")",
",",
"false",
",",
"$",
"fixedattrs",
")",
";",
"// Flag as not useful.",
"$",
"notusefulattrs",
"=",
"array",
"(",
"'data-prediction-id'",
"=>",
"$",
"predictionid",
",",
"'data-prediction-methodname'",
"=>",
"'report_insights_set_notuseful_prediction'",
")",
";",
"$",
"actions",
"[",
"]",
"=",
"new",
"\\",
"core_analytics",
"\\",
"prediction_action",
"(",
"\\",
"core_analytics",
"\\",
"prediction",
"::",
"ACTION_NOT_USEFUL",
",",
"$",
"prediction",
",",
"new",
"\\",
"moodle_url",
"(",
"''",
")",
",",
"new",
"\\",
"pix_icon",
"(",
"'t/delete'",
",",
"get_string",
"(",
"'notuseful'",
",",
"'analytics'",
")",
")",
",",
"get_string",
"(",
"'notuseful'",
",",
"'analytics'",
")",
",",
"false",
",",
"$",
"notusefulattrs",
")",
";",
"return",
"$",
"actions",
";",
"}"
] |
Suggested actions for a user.
@param \core_analytics\prediction $prediction
@param bool $includedetailsaction
@param bool $isinsightuser
@return \core_analytics\prediction_action[]
|
[
"Suggested",
"actions",
"for",
"a",
"user",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/analytics/classes/local/target/base.php#L128-L167
|
215,523
|
moodle/moodle
|
analytics/classes/local/target/base.php
|
base.get_view_details_text
|
private function get_view_details_text() {
if ($this->based_on_assumptions()) {
$analyserclass = $this->get_analyser_class();
if ($analyserclass::one_sample_per_analysable()) {
$detailstext = get_string('viewinsightdetails', 'analytics');
} else {
$detailstext = get_string('viewdetails', 'analytics');
}
} else {
$detailstext = get_string('viewprediction', 'analytics');
}
return $detailstext;
}
|
php
|
private function get_view_details_text() {
if ($this->based_on_assumptions()) {
$analyserclass = $this->get_analyser_class();
if ($analyserclass::one_sample_per_analysable()) {
$detailstext = get_string('viewinsightdetails', 'analytics');
} else {
$detailstext = get_string('viewdetails', 'analytics');
}
} else {
$detailstext = get_string('viewprediction', 'analytics');
}
return $detailstext;
}
|
[
"private",
"function",
"get_view_details_text",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"based_on_assumptions",
"(",
")",
")",
"{",
"$",
"analyserclass",
"=",
"$",
"this",
"->",
"get_analyser_class",
"(",
")",
";",
"if",
"(",
"$",
"analyserclass",
"::",
"one_sample_per_analysable",
"(",
")",
")",
"{",
"$",
"detailstext",
"=",
"get_string",
"(",
"'viewinsightdetails'",
",",
"'analytics'",
")",
";",
"}",
"else",
"{",
"$",
"detailstext",
"=",
"get_string",
"(",
"'viewdetails'",
",",
"'analytics'",
")",
";",
"}",
"}",
"else",
"{",
"$",
"detailstext",
"=",
"get_string",
"(",
"'viewprediction'",
",",
"'analytics'",
")",
";",
"}",
"return",
"$",
"detailstext",
";",
"}"
] |
Returns the view details link text.
@return string
|
[
"Returns",
"the",
"view",
"details",
"link",
"text",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/analytics/classes/local/target/base.php#L173-L186
|
215,524
|
moodle/moodle
|
analytics/classes/local/target/base.php
|
base.generate_insight_notifications
|
public function generate_insight_notifications($modelid, $samplecontexts, array $predictions = []) {
// Delegate the processing of insights to the insights_generator.
$insightsgenerator = new \core_analytics\insights_generator($modelid, $this);
$insightsgenerator->generate($samplecontexts, $predictions);
}
|
php
|
public function generate_insight_notifications($modelid, $samplecontexts, array $predictions = []) {
// Delegate the processing of insights to the insights_generator.
$insightsgenerator = new \core_analytics\insights_generator($modelid, $this);
$insightsgenerator->generate($samplecontexts, $predictions);
}
|
[
"public",
"function",
"generate_insight_notifications",
"(",
"$",
"modelid",
",",
"$",
"samplecontexts",
",",
"array",
"$",
"predictions",
"=",
"[",
"]",
")",
"{",
"// Delegate the processing of insights to the insights_generator.",
"$",
"insightsgenerator",
"=",
"new",
"\\",
"core_analytics",
"\\",
"insights_generator",
"(",
"$",
"modelid",
",",
"$",
"this",
")",
";",
"$",
"insightsgenerator",
"->",
"generate",
"(",
"$",
"samplecontexts",
",",
"$",
"predictions",
")",
";",
"}"
] |
Generates insights notifications
@param int $modelid
@param \context[] $samplecontexts
@param \core_analytics\prediction[] $predictions
@return void
|
[
"Generates",
"insights",
"notifications"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/analytics/classes/local/target/base.php#L213-L217
|
215,525
|
moodle/moodle
|
analytics/classes/local/target/base.php
|
base.get_insights_users
|
public function get_insights_users(\context $context) {
if ($context->contextlevel === CONTEXT_USER) {
$users = [$context->instanceid => \core_user::get_user($context->instanceid)];
} else if ($context->contextlevel >= CONTEXT_COURSE) {
// At course level or below only enrolled users although this is not ideal for
// teachers assigned at category level.
$users = get_enrolled_users($context, 'moodle/analytics:listinsights');
} else {
$users = get_users_by_capability($context, 'moodle/analytics:listinsights');
}
return $users;
}
|
php
|
public function get_insights_users(\context $context) {
if ($context->contextlevel === CONTEXT_USER) {
$users = [$context->instanceid => \core_user::get_user($context->instanceid)];
} else if ($context->contextlevel >= CONTEXT_COURSE) {
// At course level or below only enrolled users although this is not ideal for
// teachers assigned at category level.
$users = get_enrolled_users($context, 'moodle/analytics:listinsights');
} else {
$users = get_users_by_capability($context, 'moodle/analytics:listinsights');
}
return $users;
}
|
[
"public",
"function",
"get_insights_users",
"(",
"\\",
"context",
"$",
"context",
")",
"{",
"if",
"(",
"$",
"context",
"->",
"contextlevel",
"===",
"CONTEXT_USER",
")",
"{",
"$",
"users",
"=",
"[",
"$",
"context",
"->",
"instanceid",
"=>",
"\\",
"core_user",
"::",
"get_user",
"(",
"$",
"context",
"->",
"instanceid",
")",
"]",
";",
"}",
"else",
"if",
"(",
"$",
"context",
"->",
"contextlevel",
">=",
"CONTEXT_COURSE",
")",
"{",
"// At course level or below only enrolled users although this is not ideal for",
"// teachers assigned at category level.",
"$",
"users",
"=",
"get_enrolled_users",
"(",
"$",
"context",
",",
"'moodle/analytics:listinsights'",
")",
";",
"}",
"else",
"{",
"$",
"users",
"=",
"get_users_by_capability",
"(",
"$",
"context",
",",
"'moodle/analytics:listinsights'",
")",
";",
"}",
"return",
"$",
"users",
";",
"}"
] |
Returns the list of users that will receive insights notifications.
Feel free to overwrite if you need to but keep in mind that moodle/analytics:listinsights
or moodle/analytics:listowninsights capability is required to access the list of insights.
@param \context $context
@return array
|
[
"Returns",
"the",
"list",
"of",
"users",
"that",
"will",
"receive",
"insights",
"notifications",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/analytics/classes/local/target/base.php#L228-L239
|
215,526
|
moodle/moodle
|
analytics/classes/local/target/base.php
|
base.calculate
|
public function calculate($sampleids, \core_analytics\analysable $analysable, $starttime = false, $endtime = false) {
if (!PHPUNIT_TEST && CLI_SCRIPT) {
echo '.';
}
$calculations = [];
foreach ($sampleids as $sampleid => $unusedsampleid) {
// No time limits when calculating the target to train models.
$calculatedvalue = $this->calculate_sample($sampleid, $analysable, $starttime, $endtime);
if (!is_null($calculatedvalue)) {
if ($this->is_linear() &&
($calculatedvalue > static::get_max_value() || $calculatedvalue < static::get_min_value())) {
throw new \coding_exception('Calculated values should be higher than ' . static::get_min_value() .
' and lower than ' . static::get_max_value() . '. ' . $calculatedvalue . ' received');
} else if (!$this->is_linear() && static::is_a_class($calculatedvalue) === false) {
throw new \coding_exception('Calculated values should be one of the target classes (' .
json_encode(static::get_classes()) . '). ' . $calculatedvalue . ' received');
}
}
$calculations[$sampleid] = $calculatedvalue;
}
return $calculations;
}
|
php
|
public function calculate($sampleids, \core_analytics\analysable $analysable, $starttime = false, $endtime = false) {
if (!PHPUNIT_TEST && CLI_SCRIPT) {
echo '.';
}
$calculations = [];
foreach ($sampleids as $sampleid => $unusedsampleid) {
// No time limits when calculating the target to train models.
$calculatedvalue = $this->calculate_sample($sampleid, $analysable, $starttime, $endtime);
if (!is_null($calculatedvalue)) {
if ($this->is_linear() &&
($calculatedvalue > static::get_max_value() || $calculatedvalue < static::get_min_value())) {
throw new \coding_exception('Calculated values should be higher than ' . static::get_min_value() .
' and lower than ' . static::get_max_value() . '. ' . $calculatedvalue . ' received');
} else if (!$this->is_linear() && static::is_a_class($calculatedvalue) === false) {
throw new \coding_exception('Calculated values should be one of the target classes (' .
json_encode(static::get_classes()) . '). ' . $calculatedvalue . ' received');
}
}
$calculations[$sampleid] = $calculatedvalue;
}
return $calculations;
}
|
[
"public",
"function",
"calculate",
"(",
"$",
"sampleids",
",",
"\\",
"core_analytics",
"\\",
"analysable",
"$",
"analysable",
",",
"$",
"starttime",
"=",
"false",
",",
"$",
"endtime",
"=",
"false",
")",
"{",
"if",
"(",
"!",
"PHPUNIT_TEST",
"&&",
"CLI_SCRIPT",
")",
"{",
"echo",
"'.'",
";",
"}",
"$",
"calculations",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"sampleids",
"as",
"$",
"sampleid",
"=>",
"$",
"unusedsampleid",
")",
"{",
"// No time limits when calculating the target to train models.",
"$",
"calculatedvalue",
"=",
"$",
"this",
"->",
"calculate_sample",
"(",
"$",
"sampleid",
",",
"$",
"analysable",
",",
"$",
"starttime",
",",
"$",
"endtime",
")",
";",
"if",
"(",
"!",
"is_null",
"(",
"$",
"calculatedvalue",
")",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"is_linear",
"(",
")",
"&&",
"(",
"$",
"calculatedvalue",
">",
"static",
"::",
"get_max_value",
"(",
")",
"||",
"$",
"calculatedvalue",
"<",
"static",
"::",
"get_min_value",
"(",
")",
")",
")",
"{",
"throw",
"new",
"\\",
"coding_exception",
"(",
"'Calculated values should be higher than '",
".",
"static",
"::",
"get_min_value",
"(",
")",
".",
"' and lower than '",
".",
"static",
"::",
"get_max_value",
"(",
")",
".",
"'. '",
".",
"$",
"calculatedvalue",
".",
"' received'",
")",
";",
"}",
"else",
"if",
"(",
"!",
"$",
"this",
"->",
"is_linear",
"(",
")",
"&&",
"static",
"::",
"is_a_class",
"(",
"$",
"calculatedvalue",
")",
"===",
"false",
")",
"{",
"throw",
"new",
"\\",
"coding_exception",
"(",
"'Calculated values should be one of the target classes ('",
".",
"json_encode",
"(",
"static",
"::",
"get_classes",
"(",
")",
")",
".",
"'). '",
".",
"$",
"calculatedvalue",
".",
"' received'",
")",
";",
"}",
"}",
"$",
"calculations",
"[",
"$",
"sampleid",
"]",
"=",
"$",
"calculatedvalue",
";",
"}",
"return",
"$",
"calculations",
";",
"}"
] |
Calculates the target.
Returns an array of values which size matches $sampleids size.
Rows with null values will be skipped as invalid by time splitting methods.
@param array $sampleids
@param \core_analytics\analysable $analysable
@param int $starttime
@param int $endtime
@return array The format to follow is [userid] = scalar|null
|
[
"Calculates",
"the",
"target",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/analytics/classes/local/target/base.php#L325-L350
|
215,527
|
moodle/moodle
|
analytics/classes/local/target/base.php
|
base.filter_out_invalid_samples
|
public function filter_out_invalid_samples(&$sampleids, \core_analytics\analysable $analysable, $fortraining = true) {
foreach ($sampleids as $sampleid => $unusedsampleid) {
if (!$this->is_valid_sample($sampleid, $analysable, $fortraining)) {
// Skip it and remove the sample from the list of calculated samples.
unset($sampleids[$sampleid]);
}
}
}
|
php
|
public function filter_out_invalid_samples(&$sampleids, \core_analytics\analysable $analysable, $fortraining = true) {
foreach ($sampleids as $sampleid => $unusedsampleid) {
if (!$this->is_valid_sample($sampleid, $analysable, $fortraining)) {
// Skip it and remove the sample from the list of calculated samples.
unset($sampleids[$sampleid]);
}
}
}
|
[
"public",
"function",
"filter_out_invalid_samples",
"(",
"&",
"$",
"sampleids",
",",
"\\",
"core_analytics",
"\\",
"analysable",
"$",
"analysable",
",",
"$",
"fortraining",
"=",
"true",
")",
"{",
"foreach",
"(",
"$",
"sampleids",
"as",
"$",
"sampleid",
"=>",
"$",
"unusedsampleid",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"is_valid_sample",
"(",
"$",
"sampleid",
",",
"$",
"analysable",
",",
"$",
"fortraining",
")",
")",
"{",
"// Skip it and remove the sample from the list of calculated samples.",
"unset",
"(",
"$",
"sampleids",
"[",
"$",
"sampleid",
"]",
")",
";",
"}",
"}",
"}"
] |
Filters out invalid samples for training.
@param int[] $sampleids
@param \core_analytics\analysable $analysable
@param bool $fortraining
@return void
|
[
"Filters",
"out",
"invalid",
"samples",
"for",
"training",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/analytics/classes/local/target/base.php#L360-L367
|
215,528
|
moodle/moodle
|
admin/tool/policy/classes/api.php
|
api.get_current_versions_ids
|
public static function get_current_versions_ids($audience = null) {
global $DB;
$sql = "SELECT v.policyid, v.id
FROM {tool_policy} d
LEFT JOIN {tool_policy_versions} v ON v.policyid = d.id
WHERE d.currentversionid = v.id";
$params = [];
if ($audience) {
$sql .= " AND v.audience IN (?, ?)";
$params = [$audience, policy_version::AUDIENCE_ALL];
}
return $DB->get_records_sql_menu($sql . " ORDER BY d.sortorder", $params);
}
|
php
|
public static function get_current_versions_ids($audience = null) {
global $DB;
$sql = "SELECT v.policyid, v.id
FROM {tool_policy} d
LEFT JOIN {tool_policy_versions} v ON v.policyid = d.id
WHERE d.currentversionid = v.id";
$params = [];
if ($audience) {
$sql .= " AND v.audience IN (?, ?)";
$params = [$audience, policy_version::AUDIENCE_ALL];
}
return $DB->get_records_sql_menu($sql . " ORDER BY d.sortorder", $params);
}
|
[
"public",
"static",
"function",
"get_current_versions_ids",
"(",
"$",
"audience",
"=",
"null",
")",
"{",
"global",
"$",
"DB",
";",
"$",
"sql",
"=",
"\"SELECT v.policyid, v.id\n FROM {tool_policy} d\n LEFT JOIN {tool_policy_versions} v ON v.policyid = d.id\n WHERE d.currentversionid = v.id\"",
";",
"$",
"params",
"=",
"[",
"]",
";",
"if",
"(",
"$",
"audience",
")",
"{",
"$",
"sql",
".=",
"\" AND v.audience IN (?, ?)\"",
";",
"$",
"params",
"=",
"[",
"$",
"audience",
",",
"policy_version",
"::",
"AUDIENCE_ALL",
"]",
";",
"}",
"return",
"$",
"DB",
"->",
"get_records_sql_menu",
"(",
"$",
"sql",
".",
"\" ORDER BY d.sortorder\"",
",",
"$",
"params",
")",
";",
"}"
] |
Checks if there are any current policies defined and returns their ids only
@param array $audience If defined, filter against the given audience (AUDIENCE_ALL always included)
@return array of version ids indexed by policies ids
|
[
"Checks",
"if",
"there",
"are",
"any",
"current",
"policies",
"defined",
"and",
"returns",
"their",
"ids",
"only"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/policy/classes/api.php#L77-L89
|
215,529
|
moodle/moodle
|
admin/tool/policy/classes/api.php
|
api.count_total_users
|
public static function count_total_users() {
global $DB, $CFG;
static $cached = null;
if ($cached === null) {
$cached = $DB->count_records_select('user', 'deleted = 0 AND id <> ?', [$CFG->siteguest]);
}
return $cached;
}
|
php
|
public static function count_total_users() {
global $DB, $CFG;
static $cached = null;
if ($cached === null) {
$cached = $DB->count_records_select('user', 'deleted = 0 AND id <> ?', [$CFG->siteguest]);
}
return $cached;
}
|
[
"public",
"static",
"function",
"count_total_users",
"(",
")",
"{",
"global",
"$",
"DB",
",",
"$",
"CFG",
";",
"static",
"$",
"cached",
"=",
"null",
";",
"if",
"(",
"$",
"cached",
"===",
"null",
")",
"{",
"$",
"cached",
"=",
"$",
"DB",
"->",
"count_records_select",
"(",
"'user'",
",",
"'deleted = 0 AND id <> ?'",
",",
"[",
"$",
"CFG",
"->",
"siteguest",
"]",
")",
";",
"}",
"return",
"$",
"cached",
";",
"}"
] |
Returns total number of users who are expected to accept site policy
@return int|null
|
[
"Returns",
"total",
"number",
"of",
"users",
"who",
"are",
"expected",
"to",
"accept",
"site",
"policy"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/policy/classes/api.php#L196-L203
|
215,530
|
moodle/moodle
|
admin/tool/policy/classes/api.php
|
api.get_policy_version
|
public static function get_policy_version($versionid, $policies = null) {
if ($policies === null) {
$policies = self::list_policies();
}
foreach ($policies as $policy) {
if ($policy->currentversionid == $versionid) {
return $policy->currentversion;
} else {
foreach ($policy->draftversions as $draft) {
if ($draft->id == $versionid) {
return $draft;
}
}
foreach ($policy->archivedversions as $archived) {
if ($archived->id == $versionid) {
return $archived;
}
}
}
}
throw new \moodle_exception('errorpolicyversionnotfound', 'tool_policy');
}
|
php
|
public static function get_policy_version($versionid, $policies = null) {
if ($policies === null) {
$policies = self::list_policies();
}
foreach ($policies as $policy) {
if ($policy->currentversionid == $versionid) {
return $policy->currentversion;
} else {
foreach ($policy->draftversions as $draft) {
if ($draft->id == $versionid) {
return $draft;
}
}
foreach ($policy->archivedversions as $archived) {
if ($archived->id == $versionid) {
return $archived;
}
}
}
}
throw new \moodle_exception('errorpolicyversionnotfound', 'tool_policy');
}
|
[
"public",
"static",
"function",
"get_policy_version",
"(",
"$",
"versionid",
",",
"$",
"policies",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"policies",
"===",
"null",
")",
"{",
"$",
"policies",
"=",
"self",
"::",
"list_policies",
"(",
")",
";",
"}",
"foreach",
"(",
"$",
"policies",
"as",
"$",
"policy",
")",
"{",
"if",
"(",
"$",
"policy",
"->",
"currentversionid",
"==",
"$",
"versionid",
")",
"{",
"return",
"$",
"policy",
"->",
"currentversion",
";",
"}",
"else",
"{",
"foreach",
"(",
"$",
"policy",
"->",
"draftversions",
"as",
"$",
"draft",
")",
"{",
"if",
"(",
"$",
"draft",
"->",
"id",
"==",
"$",
"versionid",
")",
"{",
"return",
"$",
"draft",
";",
"}",
"}",
"foreach",
"(",
"$",
"policy",
"->",
"archivedversions",
"as",
"$",
"archived",
")",
"{",
"if",
"(",
"$",
"archived",
"->",
"id",
"==",
"$",
"versionid",
")",
"{",
"return",
"$",
"archived",
";",
"}",
"}",
"}",
"}",
"throw",
"new",
"\\",
"moodle_exception",
"(",
"'errorpolicyversionnotfound'",
",",
"'tool_policy'",
")",
";",
"}"
] |
Load a particular policy document version.
@param int $versionid ID of the policy document version.
@param array $policies cached result of self::list_policies() in case this function needs to be called in a loop
@return stdClass - exported {@link tool_policy\policy_exporter} instance
|
[
"Load",
"a",
"particular",
"policy",
"document",
"version",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/policy/classes/api.php#L212-L236
|
215,531
|
moodle/moodle
|
admin/tool/policy/classes/api.php
|
api.fix_revision_values
|
public static function fix_revision_values(array $versions) {
$byrev = [];
foreach ($versions as $version) {
if ($version->revision === '') {
$version->revision = userdate($version->timecreated, get_string('strftimedate', 'core_langconfig'));
}
$byrev[$version->revision][$version->id] = true;
}
foreach ($byrev as $origrevision => $versionids) {
$cnt = count($byrev[$origrevision]);
if ($cnt > 1) {
foreach ($versionids as $versionid => $unused) {
foreach ($versions as $version) {
if ($version->id == $versionid) {
$version->revision = $version->revision.' - v'.$cnt;
$cnt--;
break;
}
}
}
}
}
}
|
php
|
public static function fix_revision_values(array $versions) {
$byrev = [];
foreach ($versions as $version) {
if ($version->revision === '') {
$version->revision = userdate($version->timecreated, get_string('strftimedate', 'core_langconfig'));
}
$byrev[$version->revision][$version->id] = true;
}
foreach ($byrev as $origrevision => $versionids) {
$cnt = count($byrev[$origrevision]);
if ($cnt > 1) {
foreach ($versionids as $versionid => $unused) {
foreach ($versions as $version) {
if ($version->id == $versionid) {
$version->revision = $version->revision.' - v'.$cnt;
$cnt--;
break;
}
}
}
}
}
}
|
[
"public",
"static",
"function",
"fix_revision_values",
"(",
"array",
"$",
"versions",
")",
"{",
"$",
"byrev",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"versions",
"as",
"$",
"version",
")",
"{",
"if",
"(",
"$",
"version",
"->",
"revision",
"===",
"''",
")",
"{",
"$",
"version",
"->",
"revision",
"=",
"userdate",
"(",
"$",
"version",
"->",
"timecreated",
",",
"get_string",
"(",
"'strftimedate'",
",",
"'core_langconfig'",
")",
")",
";",
"}",
"$",
"byrev",
"[",
"$",
"version",
"->",
"revision",
"]",
"[",
"$",
"version",
"->",
"id",
"]",
"=",
"true",
";",
"}",
"foreach",
"(",
"$",
"byrev",
"as",
"$",
"origrevision",
"=>",
"$",
"versionids",
")",
"{",
"$",
"cnt",
"=",
"count",
"(",
"$",
"byrev",
"[",
"$",
"origrevision",
"]",
")",
";",
"if",
"(",
"$",
"cnt",
">",
"1",
")",
"{",
"foreach",
"(",
"$",
"versionids",
"as",
"$",
"versionid",
"=>",
"$",
"unused",
")",
"{",
"foreach",
"(",
"$",
"versions",
"as",
"$",
"version",
")",
"{",
"if",
"(",
"$",
"version",
"->",
"id",
"==",
"$",
"versionid",
")",
"{",
"$",
"version",
"->",
"revision",
"=",
"$",
"version",
"->",
"revision",
".",
"' - v'",
".",
"$",
"cnt",
";",
"$",
"cnt",
"--",
";",
"break",
";",
"}",
"}",
"}",
"}",
"}",
"}"
] |
Make sure that each version has a unique revision value.
Empty value are replaced with a timecreated date. Duplicates are suffixed with v1, v2, v3, ... etc.
@param array $versions List of objects with id, timecreated and revision properties
|
[
"Make",
"sure",
"that",
"each",
"version",
"has",
"a",
"unique",
"revision",
"value",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/policy/classes/api.php#L245-L270
|
215,532
|
moodle/moodle
|
admin/tool/policy/classes/api.php
|
api.can_user_view_policy_version
|
public static function can_user_view_policy_version($policy, $behalfid = null, $userid = null) {
global $USER;
if ($policy->status == policy_version::STATUS_ACTIVE) {
return true;
}
if (empty($userid)) {
$userid = $USER->id;
}
// Check if the user is viewing the policy on someone else's behalf.
// Typical scenario is a parent viewing the policy on behalf of her child.
if ($behalfid > 0) {
$behalfcontext = context_user::instance($behalfid);
if ($behalfid != $userid && !has_capability('tool/policy:acceptbehalf', $behalfcontext, $userid)) {
return false;
}
// Check that the other user (e.g. the child) has access to the policy.
// Pass a negative third parameter to avoid eventual endless loop.
// We do not support grand-parent relations.
return static::can_user_view_policy_version($policy, -1, $behalfid);
}
// Users who can manage policies, can see all versions.
if (has_capability('tool/policy:managedocs', context_system::instance(), $userid)) {
return true;
}
// User who can see all acceptances, must be also allowed to see what was accepted.
if (has_capability('tool/policy:viewacceptances', context_system::instance(), $userid)) {
return true;
}
// Users have access to all the policies they have ever accepted/declined.
if (static::is_user_version_accepted($userid, $policy->id) !== null) {
return true;
}
// Check if the user could get access through some of her minors.
if ($behalfid === null) {
foreach (static::get_user_minors($userid) as $minor) {
if (static::can_user_view_policy_version($policy, $minor->id, $userid)) {
return true;
}
}
}
return false;
}
|
php
|
public static function can_user_view_policy_version($policy, $behalfid = null, $userid = null) {
global $USER;
if ($policy->status == policy_version::STATUS_ACTIVE) {
return true;
}
if (empty($userid)) {
$userid = $USER->id;
}
// Check if the user is viewing the policy on someone else's behalf.
// Typical scenario is a parent viewing the policy on behalf of her child.
if ($behalfid > 0) {
$behalfcontext = context_user::instance($behalfid);
if ($behalfid != $userid && !has_capability('tool/policy:acceptbehalf', $behalfcontext, $userid)) {
return false;
}
// Check that the other user (e.g. the child) has access to the policy.
// Pass a negative third parameter to avoid eventual endless loop.
// We do not support grand-parent relations.
return static::can_user_view_policy_version($policy, -1, $behalfid);
}
// Users who can manage policies, can see all versions.
if (has_capability('tool/policy:managedocs', context_system::instance(), $userid)) {
return true;
}
// User who can see all acceptances, must be also allowed to see what was accepted.
if (has_capability('tool/policy:viewacceptances', context_system::instance(), $userid)) {
return true;
}
// Users have access to all the policies they have ever accepted/declined.
if (static::is_user_version_accepted($userid, $policy->id) !== null) {
return true;
}
// Check if the user could get access through some of her minors.
if ($behalfid === null) {
foreach (static::get_user_minors($userid) as $minor) {
if (static::can_user_view_policy_version($policy, $minor->id, $userid)) {
return true;
}
}
}
return false;
}
|
[
"public",
"static",
"function",
"can_user_view_policy_version",
"(",
"$",
"policy",
",",
"$",
"behalfid",
"=",
"null",
",",
"$",
"userid",
"=",
"null",
")",
"{",
"global",
"$",
"USER",
";",
"if",
"(",
"$",
"policy",
"->",
"status",
"==",
"policy_version",
"::",
"STATUS_ACTIVE",
")",
"{",
"return",
"true",
";",
"}",
"if",
"(",
"empty",
"(",
"$",
"userid",
")",
")",
"{",
"$",
"userid",
"=",
"$",
"USER",
"->",
"id",
";",
"}",
"// Check if the user is viewing the policy on someone else's behalf.",
"// Typical scenario is a parent viewing the policy on behalf of her child.",
"if",
"(",
"$",
"behalfid",
">",
"0",
")",
"{",
"$",
"behalfcontext",
"=",
"context_user",
"::",
"instance",
"(",
"$",
"behalfid",
")",
";",
"if",
"(",
"$",
"behalfid",
"!=",
"$",
"userid",
"&&",
"!",
"has_capability",
"(",
"'tool/policy:acceptbehalf'",
",",
"$",
"behalfcontext",
",",
"$",
"userid",
")",
")",
"{",
"return",
"false",
";",
"}",
"// Check that the other user (e.g. the child) has access to the policy.",
"// Pass a negative third parameter to avoid eventual endless loop.",
"// We do not support grand-parent relations.",
"return",
"static",
"::",
"can_user_view_policy_version",
"(",
"$",
"policy",
",",
"-",
"1",
",",
"$",
"behalfid",
")",
";",
"}",
"// Users who can manage policies, can see all versions.",
"if",
"(",
"has_capability",
"(",
"'tool/policy:managedocs'",
",",
"context_system",
"::",
"instance",
"(",
")",
",",
"$",
"userid",
")",
")",
"{",
"return",
"true",
";",
"}",
"// User who can see all acceptances, must be also allowed to see what was accepted.",
"if",
"(",
"has_capability",
"(",
"'tool/policy:viewacceptances'",
",",
"context_system",
"::",
"instance",
"(",
")",
",",
"$",
"userid",
")",
")",
"{",
"return",
"true",
";",
"}",
"// Users have access to all the policies they have ever accepted/declined.",
"if",
"(",
"static",
"::",
"is_user_version_accepted",
"(",
"$",
"userid",
",",
"$",
"policy",
"->",
"id",
")",
"!==",
"null",
")",
"{",
"return",
"true",
";",
"}",
"// Check if the user could get access through some of her minors.",
"if",
"(",
"$",
"behalfid",
"===",
"null",
")",
"{",
"foreach",
"(",
"static",
"::",
"get_user_minors",
"(",
"$",
"userid",
")",
"as",
"$",
"minor",
")",
"{",
"if",
"(",
"static",
"::",
"can_user_view_policy_version",
"(",
"$",
"policy",
",",
"$",
"minor",
"->",
"id",
",",
"$",
"userid",
")",
")",
"{",
"return",
"true",
";",
"}",
"}",
"}",
"return",
"false",
";",
"}"
] |
Can the user view the given policy version document?
@param stdClass $policy - exported {@link tool_policy\policy_exporter} instance
@param int $behalfid The id of user on whose behalf the user is viewing the policy
@param int $userid The user whom access is evaluated, defaults to the current one
@return bool
|
[
"Can",
"the",
"user",
"view",
"the",
"given",
"policy",
"version",
"document?"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/policy/classes/api.php#L280-L331
|
215,533
|
moodle/moodle
|
admin/tool/policy/classes/api.php
|
api.get_user_minors
|
public static function get_user_minors($userid, array $extrafields = null) {
global $DB;
$ctxfields = context_helper::get_preload_record_columns_sql('c');
$namefields = get_all_user_name_fields(true, 'u');
$pixfields = user_picture::fields('u', $extrafields);
$sql = "SELECT $ctxfields, $namefields, $pixfields
FROM {role_assignments} ra
JOIN {context} c ON c.contextlevel = ".CONTEXT_USER." AND ra.contextid = c.id
JOIN {user} u ON c.instanceid = u.id
WHERE ra.userid = ?
ORDER BY u.lastname ASC, u.firstname ASC";
$rs = $DB->get_recordset_sql($sql, [$userid]);
$minors = [];
foreach ($rs as $record) {
context_helper::preload_from_record($record);
$childcontext = context_user::instance($record->id);
if (has_capability('tool/policy:acceptbehalf', $childcontext, $userid)) {
$minors[$record->id] = $record;
}
}
$rs->close();
return $minors;
}
|
php
|
public static function get_user_minors($userid, array $extrafields = null) {
global $DB;
$ctxfields = context_helper::get_preload_record_columns_sql('c');
$namefields = get_all_user_name_fields(true, 'u');
$pixfields = user_picture::fields('u', $extrafields);
$sql = "SELECT $ctxfields, $namefields, $pixfields
FROM {role_assignments} ra
JOIN {context} c ON c.contextlevel = ".CONTEXT_USER." AND ra.contextid = c.id
JOIN {user} u ON c.instanceid = u.id
WHERE ra.userid = ?
ORDER BY u.lastname ASC, u.firstname ASC";
$rs = $DB->get_recordset_sql($sql, [$userid]);
$minors = [];
foreach ($rs as $record) {
context_helper::preload_from_record($record);
$childcontext = context_user::instance($record->id);
if (has_capability('tool/policy:acceptbehalf', $childcontext, $userid)) {
$minors[$record->id] = $record;
}
}
$rs->close();
return $minors;
}
|
[
"public",
"static",
"function",
"get_user_minors",
"(",
"$",
"userid",
",",
"array",
"$",
"extrafields",
"=",
"null",
")",
"{",
"global",
"$",
"DB",
";",
"$",
"ctxfields",
"=",
"context_helper",
"::",
"get_preload_record_columns_sql",
"(",
"'c'",
")",
";",
"$",
"namefields",
"=",
"get_all_user_name_fields",
"(",
"true",
",",
"'u'",
")",
";",
"$",
"pixfields",
"=",
"user_picture",
"::",
"fields",
"(",
"'u'",
",",
"$",
"extrafields",
")",
";",
"$",
"sql",
"=",
"\"SELECT $ctxfields, $namefields, $pixfields\n FROM {role_assignments} ra\n JOIN {context} c ON c.contextlevel = \"",
".",
"CONTEXT_USER",
".",
"\" AND ra.contextid = c.id\n JOIN {user} u ON c.instanceid = u.id\n WHERE ra.userid = ?\n ORDER BY u.lastname ASC, u.firstname ASC\"",
";",
"$",
"rs",
"=",
"$",
"DB",
"->",
"get_recordset_sql",
"(",
"$",
"sql",
",",
"[",
"$",
"userid",
"]",
")",
";",
"$",
"minors",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"rs",
"as",
"$",
"record",
")",
"{",
"context_helper",
"::",
"preload_from_record",
"(",
"$",
"record",
")",
";",
"$",
"childcontext",
"=",
"context_user",
"::",
"instance",
"(",
"$",
"record",
"->",
"id",
")",
";",
"if",
"(",
"has_capability",
"(",
"'tool/policy:acceptbehalf'",
",",
"$",
"childcontext",
",",
"$",
"userid",
")",
")",
"{",
"$",
"minors",
"[",
"$",
"record",
"->",
"id",
"]",
"=",
"$",
"record",
";",
"}",
"}",
"$",
"rs",
"->",
"close",
"(",
")",
";",
"return",
"$",
"minors",
";",
"}"
] |
Return the user's minors - other users on which behalf we can accept policies.
Returned objects contain all the standard user name and picture fields as well as the context instanceid.
@param int $userid The id if the user with parental responsibility
@param array $extrafields Extra fields to be included in result
@return array of objects
|
[
"Return",
"the",
"user",
"s",
"minors",
"-",
"other",
"users",
"on",
"which",
"behalf",
"we",
"can",
"accept",
"policies",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/policy/classes/api.php#L342-L371
|
215,534
|
moodle/moodle
|
admin/tool/policy/classes/api.php
|
api.form_policydoc_add
|
public static function form_policydoc_add(stdClass $form) {
global $DB;
$form = clone($form);
$form->policyid = $DB->insert_record('tool_policy', (object) [
'sortorder' => 999,
]);
static::distribute_policy_document_sortorder();
return static::form_policydoc_update_new($form);
}
|
php
|
public static function form_policydoc_add(stdClass $form) {
global $DB;
$form = clone($form);
$form->policyid = $DB->insert_record('tool_policy', (object) [
'sortorder' => 999,
]);
static::distribute_policy_document_sortorder();
return static::form_policydoc_update_new($form);
}
|
[
"public",
"static",
"function",
"form_policydoc_add",
"(",
"stdClass",
"$",
"form",
")",
"{",
"global",
"$",
"DB",
";",
"$",
"form",
"=",
"clone",
"(",
"$",
"form",
")",
";",
"$",
"form",
"->",
"policyid",
"=",
"$",
"DB",
"->",
"insert_record",
"(",
"'tool_policy'",
",",
"(",
"object",
")",
"[",
"'sortorder'",
"=>",
"999",
",",
"]",
")",
";",
"static",
"::",
"distribute_policy_document_sortorder",
"(",
")",
";",
"return",
"static",
"::",
"form_policydoc_update_new",
"(",
"$",
"form",
")",
";",
"}"
] |
Save the data from the policydoc form as a new policy document.
@param stdClass $form data submitted from the {@link \tool_policy\form\policydoc} form.
@return \tool_policy\policy_version persistent
|
[
"Save",
"the",
"data",
"from",
"the",
"policydoc",
"form",
"as",
"a",
"new",
"policy",
"document",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/policy/classes/api.php#L407-L419
|
215,535
|
moodle/moodle
|
admin/tool/policy/classes/api.php
|
api.form_policydoc_update_new
|
public static function form_policydoc_update_new(stdClass $form) {
global $DB;
if (empty($form->policyid)) {
throw new coding_exception('Invalid policy document ID');
}
$form = clone($form);
$form->id = $DB->insert_record('tool_policy_versions', (new policy_version(0, (object) [
'timecreated' => time(),
'policyid' => $form->policyid,
]))->to_record());
return static::form_policydoc_update_overwrite($form);
}
|
php
|
public static function form_policydoc_update_new(stdClass $form) {
global $DB;
if (empty($form->policyid)) {
throw new coding_exception('Invalid policy document ID');
}
$form = clone($form);
$form->id = $DB->insert_record('tool_policy_versions', (new policy_version(0, (object) [
'timecreated' => time(),
'policyid' => $form->policyid,
]))->to_record());
return static::form_policydoc_update_overwrite($form);
}
|
[
"public",
"static",
"function",
"form_policydoc_update_new",
"(",
"stdClass",
"$",
"form",
")",
"{",
"global",
"$",
"DB",
";",
"if",
"(",
"empty",
"(",
"$",
"form",
"->",
"policyid",
")",
")",
"{",
"throw",
"new",
"coding_exception",
"(",
"'Invalid policy document ID'",
")",
";",
"}",
"$",
"form",
"=",
"clone",
"(",
"$",
"form",
")",
";",
"$",
"form",
"->",
"id",
"=",
"$",
"DB",
"->",
"insert_record",
"(",
"'tool_policy_versions'",
",",
"(",
"new",
"policy_version",
"(",
"0",
",",
"(",
"object",
")",
"[",
"'timecreated'",
"=>",
"time",
"(",
")",
",",
"'policyid'",
"=>",
"$",
"form",
"->",
"policyid",
",",
"]",
")",
")",
"->",
"to_record",
"(",
")",
")",
";",
"return",
"static",
"::",
"form_policydoc_update_overwrite",
"(",
"$",
"form",
")",
";",
"}"
] |
Save the data from the policydoc form as a new policy document version.
@param stdClass $form data submitted from the {@link \tool_policy\form\policydoc} form.
@return \tool_policy\policy_version persistent
|
[
"Save",
"the",
"data",
"from",
"the",
"policydoc",
"form",
"as",
"a",
"new",
"policy",
"document",
"version",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/policy/classes/api.php#L427-L442
|
215,536
|
moodle/moodle
|
admin/tool/policy/classes/api.php
|
api.form_policydoc_update_overwrite
|
public static function form_policydoc_update_overwrite(stdClass $form) {
$form = clone($form);
unset($form->timecreated);
$summaryfieldoptions = static::policy_summary_field_options();
$form = file_postupdate_standard_editor($form, 'summary', $summaryfieldoptions, $summaryfieldoptions['context'],
'tool_policy', 'policydocumentsummary', $form->id);
unset($form->summary_editor);
unset($form->summarytrust);
$contentfieldoptions = static::policy_content_field_options();
$form = file_postupdate_standard_editor($form, 'content', $contentfieldoptions, $contentfieldoptions['context'],
'tool_policy', 'policydocumentcontent', $form->id);
unset($form->content_editor);
unset($form->contenttrust);
unset($form->status);
unset($form->save);
unset($form->saveasdraft);
unset($form->minorchange);
$policyversion = new policy_version($form->id, $form);
$policyversion->update();
return $policyversion;
}
|
php
|
public static function form_policydoc_update_overwrite(stdClass $form) {
$form = clone($form);
unset($form->timecreated);
$summaryfieldoptions = static::policy_summary_field_options();
$form = file_postupdate_standard_editor($form, 'summary', $summaryfieldoptions, $summaryfieldoptions['context'],
'tool_policy', 'policydocumentsummary', $form->id);
unset($form->summary_editor);
unset($form->summarytrust);
$contentfieldoptions = static::policy_content_field_options();
$form = file_postupdate_standard_editor($form, 'content', $contentfieldoptions, $contentfieldoptions['context'],
'tool_policy', 'policydocumentcontent', $form->id);
unset($form->content_editor);
unset($form->contenttrust);
unset($form->status);
unset($form->save);
unset($form->saveasdraft);
unset($form->minorchange);
$policyversion = new policy_version($form->id, $form);
$policyversion->update();
return $policyversion;
}
|
[
"public",
"static",
"function",
"form_policydoc_update_overwrite",
"(",
"stdClass",
"$",
"form",
")",
"{",
"$",
"form",
"=",
"clone",
"(",
"$",
"form",
")",
";",
"unset",
"(",
"$",
"form",
"->",
"timecreated",
")",
";",
"$",
"summaryfieldoptions",
"=",
"static",
"::",
"policy_summary_field_options",
"(",
")",
";",
"$",
"form",
"=",
"file_postupdate_standard_editor",
"(",
"$",
"form",
",",
"'summary'",
",",
"$",
"summaryfieldoptions",
",",
"$",
"summaryfieldoptions",
"[",
"'context'",
"]",
",",
"'tool_policy'",
",",
"'policydocumentsummary'",
",",
"$",
"form",
"->",
"id",
")",
";",
"unset",
"(",
"$",
"form",
"->",
"summary_editor",
")",
";",
"unset",
"(",
"$",
"form",
"->",
"summarytrust",
")",
";",
"$",
"contentfieldoptions",
"=",
"static",
"::",
"policy_content_field_options",
"(",
")",
";",
"$",
"form",
"=",
"file_postupdate_standard_editor",
"(",
"$",
"form",
",",
"'content'",
",",
"$",
"contentfieldoptions",
",",
"$",
"contentfieldoptions",
"[",
"'context'",
"]",
",",
"'tool_policy'",
",",
"'policydocumentcontent'",
",",
"$",
"form",
"->",
"id",
")",
";",
"unset",
"(",
"$",
"form",
"->",
"content_editor",
")",
";",
"unset",
"(",
"$",
"form",
"->",
"contenttrust",
")",
";",
"unset",
"(",
"$",
"form",
"->",
"status",
")",
";",
"unset",
"(",
"$",
"form",
"->",
"save",
")",
";",
"unset",
"(",
"$",
"form",
"->",
"saveasdraft",
")",
";",
"unset",
"(",
"$",
"form",
"->",
"minorchange",
")",
";",
"$",
"policyversion",
"=",
"new",
"policy_version",
"(",
"$",
"form",
"->",
"id",
",",
"$",
"form",
")",
";",
"$",
"policyversion",
"->",
"update",
"(",
")",
";",
"return",
"$",
"policyversion",
";",
"}"
] |
Save the data from the policydoc form, overwriting the existing policy document version.
@param stdClass $form data submitted from the {@link \tool_policy\form\policydoc} form.
@return \tool_policy\policy_version persistent
|
[
"Save",
"the",
"data",
"from",
"the",
"policydoc",
"form",
"overwriting",
"the",
"existing",
"policy",
"document",
"version",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/policy/classes/api.php#L451-L477
|
215,537
|
moodle/moodle
|
admin/tool/policy/classes/api.php
|
api.make_current
|
public static function make_current($versionid) {
global $DB, $USER;
$policyversion = new policy_version($versionid);
if (! $policyversion->get('id') || $policyversion->get('archived')) {
throw new coding_exception('Version not found or is archived');
}
// Archive current version of this policy.
if ($currentversionid = $DB->get_field('tool_policy', 'currentversionid', ['id' => $policyversion->get('policyid')])) {
if ($currentversionid == $versionid) {
// Already current, do not change anything.
return;
}
$DB->set_field('tool_policy_versions', 'archived', 1, ['id' => $currentversionid]);
}
// Set given version as current.
$DB->set_field('tool_policy', 'currentversionid', $policyversion->get('id'), ['id' => $policyversion->get('policyid')]);
// Reset the policyagreed flag to force everybody re-accept the policies.
$DB->set_field('user', 'policyagreed', 0);
// Make sure that the current user is not immediately redirected to the policy acceptance page.
if (isloggedin() && !isguestuser()) {
$USER->policyagreed = 1;
}
}
|
php
|
public static function make_current($versionid) {
global $DB, $USER;
$policyversion = new policy_version($versionid);
if (! $policyversion->get('id') || $policyversion->get('archived')) {
throw new coding_exception('Version not found or is archived');
}
// Archive current version of this policy.
if ($currentversionid = $DB->get_field('tool_policy', 'currentversionid', ['id' => $policyversion->get('policyid')])) {
if ($currentversionid == $versionid) {
// Already current, do not change anything.
return;
}
$DB->set_field('tool_policy_versions', 'archived', 1, ['id' => $currentversionid]);
}
// Set given version as current.
$DB->set_field('tool_policy', 'currentversionid', $policyversion->get('id'), ['id' => $policyversion->get('policyid')]);
// Reset the policyagreed flag to force everybody re-accept the policies.
$DB->set_field('user', 'policyagreed', 0);
// Make sure that the current user is not immediately redirected to the policy acceptance page.
if (isloggedin() && !isguestuser()) {
$USER->policyagreed = 1;
}
}
|
[
"public",
"static",
"function",
"make_current",
"(",
"$",
"versionid",
")",
"{",
"global",
"$",
"DB",
",",
"$",
"USER",
";",
"$",
"policyversion",
"=",
"new",
"policy_version",
"(",
"$",
"versionid",
")",
";",
"if",
"(",
"!",
"$",
"policyversion",
"->",
"get",
"(",
"'id'",
")",
"||",
"$",
"policyversion",
"->",
"get",
"(",
"'archived'",
")",
")",
"{",
"throw",
"new",
"coding_exception",
"(",
"'Version not found or is archived'",
")",
";",
"}",
"// Archive current version of this policy.",
"if",
"(",
"$",
"currentversionid",
"=",
"$",
"DB",
"->",
"get_field",
"(",
"'tool_policy'",
",",
"'currentversionid'",
",",
"[",
"'id'",
"=>",
"$",
"policyversion",
"->",
"get",
"(",
"'policyid'",
")",
"]",
")",
")",
"{",
"if",
"(",
"$",
"currentversionid",
"==",
"$",
"versionid",
")",
"{",
"// Already current, do not change anything.",
"return",
";",
"}",
"$",
"DB",
"->",
"set_field",
"(",
"'tool_policy_versions'",
",",
"'archived'",
",",
"1",
",",
"[",
"'id'",
"=>",
"$",
"currentversionid",
"]",
")",
";",
"}",
"// Set given version as current.",
"$",
"DB",
"->",
"set_field",
"(",
"'tool_policy'",
",",
"'currentversionid'",
",",
"$",
"policyversion",
"->",
"get",
"(",
"'id'",
")",
",",
"[",
"'id'",
"=>",
"$",
"policyversion",
"->",
"get",
"(",
"'policyid'",
")",
"]",
")",
";",
"// Reset the policyagreed flag to force everybody re-accept the policies.",
"$",
"DB",
"->",
"set_field",
"(",
"'user'",
",",
"'policyagreed'",
",",
"0",
")",
";",
"// Make sure that the current user is not immediately redirected to the policy acceptance page.",
"if",
"(",
"isloggedin",
"(",
")",
"&&",
"!",
"isguestuser",
"(",
")",
")",
"{",
"$",
"USER",
"->",
"policyagreed",
"=",
"1",
";",
"}",
"}"
] |
Make the given version the current active one.
@param int $versionid
|
[
"Make",
"the",
"given",
"version",
"the",
"current",
"active",
"one",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/policy/classes/api.php#L484-L511
|
215,538
|
moodle/moodle
|
admin/tool/policy/classes/api.php
|
api.inactivate
|
public static function inactivate($policyid) {
global $DB;
if ($currentversionid = $DB->get_field('tool_policy', 'currentversionid', ['id' => $policyid])) {
// Archive the current version.
$DB->set_field('tool_policy_versions', 'archived', 1, ['id' => $currentversionid]);
// Unset current version for the policy.
$DB->set_field('tool_policy', 'currentversionid', null, ['id' => $policyid]);
}
}
|
php
|
public static function inactivate($policyid) {
global $DB;
if ($currentversionid = $DB->get_field('tool_policy', 'currentversionid', ['id' => $policyid])) {
// Archive the current version.
$DB->set_field('tool_policy_versions', 'archived', 1, ['id' => $currentversionid]);
// Unset current version for the policy.
$DB->set_field('tool_policy', 'currentversionid', null, ['id' => $policyid]);
}
}
|
[
"public",
"static",
"function",
"inactivate",
"(",
"$",
"policyid",
")",
"{",
"global",
"$",
"DB",
";",
"if",
"(",
"$",
"currentversionid",
"=",
"$",
"DB",
"->",
"get_field",
"(",
"'tool_policy'",
",",
"'currentversionid'",
",",
"[",
"'id'",
"=>",
"$",
"policyid",
"]",
")",
")",
"{",
"// Archive the current version.",
"$",
"DB",
"->",
"set_field",
"(",
"'tool_policy_versions'",
",",
"'archived'",
",",
"1",
",",
"[",
"'id'",
"=>",
"$",
"currentversionid",
"]",
")",
";",
"// Unset current version for the policy.",
"$",
"DB",
"->",
"set_field",
"(",
"'tool_policy'",
",",
"'currentversionid'",
",",
"null",
",",
"[",
"'id'",
"=>",
"$",
"policyid",
"]",
")",
";",
"}",
"}"
] |
Inactivate the policy document - no version marked as current and the document does not apply.
@param int $policyid
|
[
"Inactivate",
"the",
"policy",
"document",
"-",
"no",
"version",
"marked",
"as",
"current",
"and",
"the",
"document",
"does",
"not",
"apply",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/policy/classes/api.php#L518-L527
|
215,539
|
moodle/moodle
|
admin/tool/policy/classes/api.php
|
api.revert_to_draft
|
public static function revert_to_draft($versionid) {
$policyversion = new policy_version($versionid);
if (!$policyversion->get('id') || !$policyversion->get('archived')) {
throw new coding_exception('Version not found or is not archived');
}
$formdata = static::form_policydoc_data($policyversion);
// Unarchived the new version.
$formdata->archived = 0;
return static::form_policydoc_update_new($formdata);
}
|
php
|
public static function revert_to_draft($versionid) {
$policyversion = new policy_version($versionid);
if (!$policyversion->get('id') || !$policyversion->get('archived')) {
throw new coding_exception('Version not found or is not archived');
}
$formdata = static::form_policydoc_data($policyversion);
// Unarchived the new version.
$formdata->archived = 0;
return static::form_policydoc_update_new($formdata);
}
|
[
"public",
"static",
"function",
"revert_to_draft",
"(",
"$",
"versionid",
")",
"{",
"$",
"policyversion",
"=",
"new",
"policy_version",
"(",
"$",
"versionid",
")",
";",
"if",
"(",
"!",
"$",
"policyversion",
"->",
"get",
"(",
"'id'",
")",
"||",
"!",
"$",
"policyversion",
"->",
"get",
"(",
"'archived'",
")",
")",
"{",
"throw",
"new",
"coding_exception",
"(",
"'Version not found or is not archived'",
")",
";",
"}",
"$",
"formdata",
"=",
"static",
"::",
"form_policydoc_data",
"(",
"$",
"policyversion",
")",
";",
"// Unarchived the new version.",
"$",
"formdata",
"->",
"archived",
"=",
"0",
";",
"return",
"static",
"::",
"form_policydoc_update_new",
"(",
"$",
"formdata",
")",
";",
"}"
] |
Create a new draft policy document from an archived version.
@param int $versionid
@return \tool_policy\policy_version persistent
|
[
"Create",
"a",
"new",
"draft",
"policy",
"document",
"from",
"an",
"archived",
"version",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/policy/classes/api.php#L535-L545
|
215,540
|
moodle/moodle
|
admin/tool/policy/classes/api.php
|
api.distribute_policy_document_sortorder
|
protected static function distribute_policy_document_sortorder() {
global $DB;
$sql = "SELECT p.id, p.sortorder, MAX(v.timecreated) AS timerecentcreated
FROM {tool_policy} p
LEFT JOIN {tool_policy_versions} v ON v.policyid = p.id
GROUP BY p.id, p.sortorder
ORDER BY p.sortorder ASC, timerecentcreated ASC";
$rs = $DB->get_recordset_sql($sql);
$sortorder = 10;
foreach ($rs as $record) {
if ($record->sortorder != $sortorder) {
$DB->set_field('tool_policy', 'sortorder', $sortorder, ['id' => $record->id]);
}
$sortorder = $sortorder + 2;
}
$rs->close();
}
|
php
|
protected static function distribute_policy_document_sortorder() {
global $DB;
$sql = "SELECT p.id, p.sortorder, MAX(v.timecreated) AS timerecentcreated
FROM {tool_policy} p
LEFT JOIN {tool_policy_versions} v ON v.policyid = p.id
GROUP BY p.id, p.sortorder
ORDER BY p.sortorder ASC, timerecentcreated ASC";
$rs = $DB->get_recordset_sql($sql);
$sortorder = 10;
foreach ($rs as $record) {
if ($record->sortorder != $sortorder) {
$DB->set_field('tool_policy', 'sortorder', $sortorder, ['id' => $record->id]);
}
$sortorder = $sortorder + 2;
}
$rs->close();
}
|
[
"protected",
"static",
"function",
"distribute_policy_document_sortorder",
"(",
")",
"{",
"global",
"$",
"DB",
";",
"$",
"sql",
"=",
"\"SELECT p.id, p.sortorder, MAX(v.timecreated) AS timerecentcreated\n FROM {tool_policy} p\n LEFT JOIN {tool_policy_versions} v ON v.policyid = p.id\n GROUP BY p.id, p.sortorder\n ORDER BY p.sortorder ASC, timerecentcreated ASC\"",
";",
"$",
"rs",
"=",
"$",
"DB",
"->",
"get_recordset_sql",
"(",
"$",
"sql",
")",
";",
"$",
"sortorder",
"=",
"10",
";",
"foreach",
"(",
"$",
"rs",
"as",
"$",
"record",
")",
"{",
"if",
"(",
"$",
"record",
"->",
"sortorder",
"!=",
"$",
"sortorder",
")",
"{",
"$",
"DB",
"->",
"set_field",
"(",
"'tool_policy'",
",",
"'sortorder'",
",",
"$",
"sortorder",
",",
"[",
"'id'",
"=>",
"$",
"record",
"->",
"id",
"]",
")",
";",
"}",
"$",
"sortorder",
"=",
"$",
"sortorder",
"+",
"2",
";",
"}",
"$",
"rs",
"->",
"close",
"(",
")",
";",
"}"
] |
Re-sets the sortorder field of the policy documents to even values.
|
[
"Re",
"-",
"sets",
"the",
"sortorder",
"field",
"of",
"the",
"policy",
"documents",
"to",
"even",
"values",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/policy/classes/api.php#L615-L635
|
215,541
|
moodle/moodle
|
admin/tool/policy/classes/api.php
|
api.move_policy_document
|
protected static function move_policy_document($policyid, $step) {
global $DB;
$sortorder = $DB->get_field('tool_policy', 'sortorder', ['id' => $policyid], MUST_EXIST);
$DB->set_field('tool_policy', 'sortorder', $sortorder + $step, ['id' => $policyid]);
static::distribute_policy_document_sortorder();
}
|
php
|
protected static function move_policy_document($policyid, $step) {
global $DB;
$sortorder = $DB->get_field('tool_policy', 'sortorder', ['id' => $policyid], MUST_EXIST);
$DB->set_field('tool_policy', 'sortorder', $sortorder + $step, ['id' => $policyid]);
static::distribute_policy_document_sortorder();
}
|
[
"protected",
"static",
"function",
"move_policy_document",
"(",
"$",
"policyid",
",",
"$",
"step",
")",
"{",
"global",
"$",
"DB",
";",
"$",
"sortorder",
"=",
"$",
"DB",
"->",
"get_field",
"(",
"'tool_policy'",
",",
"'sortorder'",
",",
"[",
"'id'",
"=>",
"$",
"policyid",
"]",
",",
"MUST_EXIST",
")",
";",
"$",
"DB",
"->",
"set_field",
"(",
"'tool_policy'",
",",
"'sortorder'",
",",
"$",
"sortorder",
"+",
"$",
"step",
",",
"[",
"'id'",
"=>",
"$",
"policyid",
"]",
")",
";",
"static",
"::",
"distribute_policy_document_sortorder",
"(",
")",
";",
"}"
] |
Change the policy document's sortorder.
@param int $policyid
@param int $step
|
[
"Change",
"the",
"policy",
"document",
"s",
"sortorder",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/policy/classes/api.php#L643-L649
|
215,542
|
moodle/moodle
|
admin/tool/policy/classes/api.php
|
api.get_user_acceptances
|
public static function get_user_acceptances($userid, $versions = null) {
global $DB;
list($vsql, $vparams) = ['', []];
if (!empty($versions)) {
list($vsql, $vparams) = $DB->get_in_or_equal($versions, SQL_PARAMS_NAMED, 'ver');
$vsql = ' AND a.policyversionid ' . $vsql;
}
$userfieldsmod = get_all_user_name_fields(true, 'm', null, 'mod');
$sql = "SELECT u.id AS mainuserid, a.policyversionid, a.status, a.lang, a.timemodified, a.usermodified, a.note,
u.policyagreed, $userfieldsmod
FROM {user} u
INNER JOIN {tool_policy_acceptances} a ON a.userid = u.id AND a.userid = :userid $vsql
LEFT JOIN {user} m ON m.id = a.usermodified";
$params = ['userid' => $userid];
$result = $DB->get_recordset_sql($sql, $params + $vparams);
$acceptances = [];
foreach ($result as $row) {
if (!empty($row->policyversionid)) {
$acceptances[$row->policyversionid] = $row;
}
}
$result->close();
return $acceptances;
}
|
php
|
public static function get_user_acceptances($userid, $versions = null) {
global $DB;
list($vsql, $vparams) = ['', []];
if (!empty($versions)) {
list($vsql, $vparams) = $DB->get_in_or_equal($versions, SQL_PARAMS_NAMED, 'ver');
$vsql = ' AND a.policyversionid ' . $vsql;
}
$userfieldsmod = get_all_user_name_fields(true, 'm', null, 'mod');
$sql = "SELECT u.id AS mainuserid, a.policyversionid, a.status, a.lang, a.timemodified, a.usermodified, a.note,
u.policyagreed, $userfieldsmod
FROM {user} u
INNER JOIN {tool_policy_acceptances} a ON a.userid = u.id AND a.userid = :userid $vsql
LEFT JOIN {user} m ON m.id = a.usermodified";
$params = ['userid' => $userid];
$result = $DB->get_recordset_sql($sql, $params + $vparams);
$acceptances = [];
foreach ($result as $row) {
if (!empty($row->policyversionid)) {
$acceptances[$row->policyversionid] = $row;
}
}
$result->close();
return $acceptances;
}
|
[
"public",
"static",
"function",
"get_user_acceptances",
"(",
"$",
"userid",
",",
"$",
"versions",
"=",
"null",
")",
"{",
"global",
"$",
"DB",
";",
"list",
"(",
"$",
"vsql",
",",
"$",
"vparams",
")",
"=",
"[",
"''",
",",
"[",
"]",
"]",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"versions",
")",
")",
"{",
"list",
"(",
"$",
"vsql",
",",
"$",
"vparams",
")",
"=",
"$",
"DB",
"->",
"get_in_or_equal",
"(",
"$",
"versions",
",",
"SQL_PARAMS_NAMED",
",",
"'ver'",
")",
";",
"$",
"vsql",
"=",
"' AND a.policyversionid '",
".",
"$",
"vsql",
";",
"}",
"$",
"userfieldsmod",
"=",
"get_all_user_name_fields",
"(",
"true",
",",
"'m'",
",",
"null",
",",
"'mod'",
")",
";",
"$",
"sql",
"=",
"\"SELECT u.id AS mainuserid, a.policyversionid, a.status, a.lang, a.timemodified, a.usermodified, a.note,\n u.policyagreed, $userfieldsmod\n FROM {user} u\n INNER JOIN {tool_policy_acceptances} a ON a.userid = u.id AND a.userid = :userid $vsql\n LEFT JOIN {user} m ON m.id = a.usermodified\"",
";",
"$",
"params",
"=",
"[",
"'userid'",
"=>",
"$",
"userid",
"]",
";",
"$",
"result",
"=",
"$",
"DB",
"->",
"get_recordset_sql",
"(",
"$",
"sql",
",",
"$",
"params",
"+",
"$",
"vparams",
")",
";",
"$",
"acceptances",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"result",
"as",
"$",
"row",
")",
"{",
"if",
"(",
"!",
"empty",
"(",
"$",
"row",
"->",
"policyversionid",
")",
")",
"{",
"$",
"acceptances",
"[",
"$",
"row",
"->",
"policyversionid",
"]",
"=",
"$",
"row",
";",
"}",
"}",
"$",
"result",
"->",
"close",
"(",
")",
";",
"return",
"$",
"acceptances",
";",
"}"
] |
Returns list of acceptances for this user.
@param int $userid id of a user.
@param int|array $versions list of policy versions.
@return array list of acceptances indexed by versionid.
|
[
"Returns",
"list",
"of",
"acceptances",
"for",
"this",
"user",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/policy/classes/api.php#L676-L703
|
215,543
|
moodle/moodle
|
admin/tool/policy/classes/api.php
|
api.get_user_version_acceptance
|
public static function get_user_version_acceptance($userid, $versionid, $acceptances = null) {
if (empty($acceptances)) {
$acceptances = static::get_user_acceptances($userid, $versionid);
}
if (array_key_exists($versionid, $acceptances)) {
// The policy version has ever been accepted.
return $acceptances[$versionid];
}
return null;
}
|
php
|
public static function get_user_version_acceptance($userid, $versionid, $acceptances = null) {
if (empty($acceptances)) {
$acceptances = static::get_user_acceptances($userid, $versionid);
}
if (array_key_exists($versionid, $acceptances)) {
// The policy version has ever been accepted.
return $acceptances[$versionid];
}
return null;
}
|
[
"public",
"static",
"function",
"get_user_version_acceptance",
"(",
"$",
"userid",
",",
"$",
"versionid",
",",
"$",
"acceptances",
"=",
"null",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"acceptances",
")",
")",
"{",
"$",
"acceptances",
"=",
"static",
"::",
"get_user_acceptances",
"(",
"$",
"userid",
",",
"$",
"versionid",
")",
";",
"}",
"if",
"(",
"array_key_exists",
"(",
"$",
"versionid",
",",
"$",
"acceptances",
")",
")",
"{",
"// The policy version has ever been accepted.",
"return",
"$",
"acceptances",
"[",
"$",
"versionid",
"]",
";",
"}",
"return",
"null",
";",
"}"
] |
Returns version acceptance for this user.
@param int $userid User identifier.
@param int $versionid Policy version identifier.
@param array|null $acceptances List of policy version acceptances indexed by versionid.
@return stdClass|null Acceptance object if the user has ever accepted this version or null if not.
|
[
"Returns",
"version",
"acceptance",
"for",
"this",
"user",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/policy/classes/api.php#L713-L723
|
215,544
|
moodle/moodle
|
admin/tool/policy/classes/api.php
|
api.is_user_version_accepted
|
public static function is_user_version_accepted($userid, $versionid, $acceptances = null) {
$acceptance = static::get_user_version_acceptance($userid, $versionid, $acceptances);
if (!empty($acceptance)) {
return (bool) $acceptance->status;
}
return null;
}
|
php
|
public static function is_user_version_accepted($userid, $versionid, $acceptances = null) {
$acceptance = static::get_user_version_acceptance($userid, $versionid, $acceptances);
if (!empty($acceptance)) {
return (bool) $acceptance->status;
}
return null;
}
|
[
"public",
"static",
"function",
"is_user_version_accepted",
"(",
"$",
"userid",
",",
"$",
"versionid",
",",
"$",
"acceptances",
"=",
"null",
")",
"{",
"$",
"acceptance",
"=",
"static",
"::",
"get_user_version_acceptance",
"(",
"$",
"userid",
",",
"$",
"versionid",
",",
"$",
"acceptances",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"acceptance",
")",
")",
"{",
"return",
"(",
"bool",
")",
"$",
"acceptance",
"->",
"status",
";",
"}",
"return",
"null",
";",
"}"
] |
Did the user accept the given policy version?
@param int $userid User identifier.
@param int $versionid Policy version identifier.
@param array|null $acceptances Pre-loaded list of policy version acceptances indexed by versionid.
@return bool|null True/false if this user accepted/declined the policy; null otherwise.
|
[
"Did",
"the",
"user",
"accept",
"the",
"given",
"policy",
"version?"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/policy/classes/api.php#L733-L742
|
215,545
|
moodle/moodle
|
admin/tool/policy/classes/api.php
|
api.get_policies_with_acceptances
|
public static function get_policies_with_acceptances($userid) {
// Get the list of policies and versions that current user is able to see
// and the respective acceptance records for the selected user.
$policies = static::list_policies();
$acceptances = static::get_user_acceptances($userid);
$ret = [];
foreach ($policies as $policy) {
$versions = [];
if ($policy->currentversion && $policy->currentversion->audience != policy_version::AUDIENCE_GUESTS) {
if (isset($acceptances[$policy->currentversion->id])) {
$policy->currentversion->acceptance = $acceptances[$policy->currentversion->id];
} else {
$policy->currentversion->acceptance = null;
}
$versions[] = $policy->currentversion;
}
foreach ($policy->archivedversions as $version) {
if ($version->audience != policy_version::AUDIENCE_GUESTS
&& static::can_user_view_policy_version($version, $userid)) {
$version->acceptance = isset($acceptances[$version->id]) ? $acceptances[$version->id] : null;
$versions[] = $version;
}
}
if ($versions) {
$ret[] = (object)['id' => $policy->id, 'versions' => $versions];
}
}
return $ret;
}
|
php
|
public static function get_policies_with_acceptances($userid) {
// Get the list of policies and versions that current user is able to see
// and the respective acceptance records for the selected user.
$policies = static::list_policies();
$acceptances = static::get_user_acceptances($userid);
$ret = [];
foreach ($policies as $policy) {
$versions = [];
if ($policy->currentversion && $policy->currentversion->audience != policy_version::AUDIENCE_GUESTS) {
if (isset($acceptances[$policy->currentversion->id])) {
$policy->currentversion->acceptance = $acceptances[$policy->currentversion->id];
} else {
$policy->currentversion->acceptance = null;
}
$versions[] = $policy->currentversion;
}
foreach ($policy->archivedversions as $version) {
if ($version->audience != policy_version::AUDIENCE_GUESTS
&& static::can_user_view_policy_version($version, $userid)) {
$version->acceptance = isset($acceptances[$version->id]) ? $acceptances[$version->id] : null;
$versions[] = $version;
}
}
if ($versions) {
$ret[] = (object)['id' => $policy->id, 'versions' => $versions];
}
}
return $ret;
}
|
[
"public",
"static",
"function",
"get_policies_with_acceptances",
"(",
"$",
"userid",
")",
"{",
"// Get the list of policies and versions that current user is able to see",
"// and the respective acceptance records for the selected user.",
"$",
"policies",
"=",
"static",
"::",
"list_policies",
"(",
")",
";",
"$",
"acceptances",
"=",
"static",
"::",
"get_user_acceptances",
"(",
"$",
"userid",
")",
";",
"$",
"ret",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"policies",
"as",
"$",
"policy",
")",
"{",
"$",
"versions",
"=",
"[",
"]",
";",
"if",
"(",
"$",
"policy",
"->",
"currentversion",
"&&",
"$",
"policy",
"->",
"currentversion",
"->",
"audience",
"!=",
"policy_version",
"::",
"AUDIENCE_GUESTS",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"acceptances",
"[",
"$",
"policy",
"->",
"currentversion",
"->",
"id",
"]",
")",
")",
"{",
"$",
"policy",
"->",
"currentversion",
"->",
"acceptance",
"=",
"$",
"acceptances",
"[",
"$",
"policy",
"->",
"currentversion",
"->",
"id",
"]",
";",
"}",
"else",
"{",
"$",
"policy",
"->",
"currentversion",
"->",
"acceptance",
"=",
"null",
";",
"}",
"$",
"versions",
"[",
"]",
"=",
"$",
"policy",
"->",
"currentversion",
";",
"}",
"foreach",
"(",
"$",
"policy",
"->",
"archivedversions",
"as",
"$",
"version",
")",
"{",
"if",
"(",
"$",
"version",
"->",
"audience",
"!=",
"policy_version",
"::",
"AUDIENCE_GUESTS",
"&&",
"static",
"::",
"can_user_view_policy_version",
"(",
"$",
"version",
",",
"$",
"userid",
")",
")",
"{",
"$",
"version",
"->",
"acceptance",
"=",
"isset",
"(",
"$",
"acceptances",
"[",
"$",
"version",
"->",
"id",
"]",
")",
"?",
"$",
"acceptances",
"[",
"$",
"version",
"->",
"id",
"]",
":",
"null",
";",
"$",
"versions",
"[",
"]",
"=",
"$",
"version",
";",
"}",
"}",
"if",
"(",
"$",
"versions",
")",
"{",
"$",
"ret",
"[",
"]",
"=",
"(",
"object",
")",
"[",
"'id'",
"=>",
"$",
"policy",
"->",
"id",
",",
"'versions'",
"=>",
"$",
"versions",
"]",
";",
"}",
"}",
"return",
"$",
"ret",
";",
"}"
] |
Get the list of policies and versions that current user is able to see and the respective acceptance records for
the selected user.
@param int $userid
@return array array with the same structure that list_policies() returns with additional attribute acceptance for versions
|
[
"Get",
"the",
"list",
"of",
"policies",
"and",
"versions",
"that",
"current",
"user",
"is",
"able",
"to",
"see",
"and",
"the",
"respective",
"acceptance",
"records",
"for",
"the",
"selected",
"user",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/policy/classes/api.php#L751-L780
|
215,546
|
moodle/moodle
|
admin/tool/policy/classes/api.php
|
api.accept_policies
|
public static function accept_policies($policyversionid, $userid = null, $note = null, $lang = null) {
static::set_acceptances_status($policyversionid, $userid, $note, $lang, 1);
}
|
php
|
public static function accept_policies($policyversionid, $userid = null, $note = null, $lang = null) {
static::set_acceptances_status($policyversionid, $userid, $note, $lang, 1);
}
|
[
"public",
"static",
"function",
"accept_policies",
"(",
"$",
"policyversionid",
",",
"$",
"userid",
"=",
"null",
",",
"$",
"note",
"=",
"null",
",",
"$",
"lang",
"=",
"null",
")",
"{",
"static",
"::",
"set_acceptances_status",
"(",
"$",
"policyversionid",
",",
"$",
"userid",
",",
"$",
"note",
",",
"$",
"lang",
",",
"1",
")",
";",
"}"
] |
Mark the given policy versions as accepted by the user.
@param array|int $policyversionid Policy version id(s) to set acceptance status for.
@param int|null $userid Id of the user accepting the policy version, defaults to the current one.
@param string|null $note Note to be recorded.
@param string|null $lang Language in which the policy was shown, defaults to the current one.
|
[
"Mark",
"the",
"given",
"policy",
"versions",
"as",
"accepted",
"by",
"the",
"user",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/policy/classes/api.php#L928-L930
|
215,547
|
moodle/moodle
|
admin/tool/policy/classes/api.php
|
api.decline_policies
|
public static function decline_policies($policyversionid, $userid = null, $note = null, $lang = null) {
static::set_acceptances_status($policyversionid, $userid, $note, $lang, 0);
}
|
php
|
public static function decline_policies($policyversionid, $userid = null, $note = null, $lang = null) {
static::set_acceptances_status($policyversionid, $userid, $note, $lang, 0);
}
|
[
"public",
"static",
"function",
"decline_policies",
"(",
"$",
"policyversionid",
",",
"$",
"userid",
"=",
"null",
",",
"$",
"note",
"=",
"null",
",",
"$",
"lang",
"=",
"null",
")",
"{",
"static",
"::",
"set_acceptances_status",
"(",
"$",
"policyversionid",
",",
"$",
"userid",
",",
"$",
"note",
",",
"$",
"lang",
",",
"0",
")",
";",
"}"
] |
Mark the given policy versions as declined by the user.
@param array|int $policyversionid Policy version id(s) to set acceptance status for.
@param int|null $userid Id of the user accepting the policy version, defaults to the current one.
@param string|null $note Note to be recorded.
@param string|null $lang Language in which the policy was shown, defaults to the current one.
|
[
"Mark",
"the",
"given",
"policy",
"versions",
"as",
"declined",
"by",
"the",
"user",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/policy/classes/api.php#L940-L942
|
215,548
|
moodle/moodle
|
admin/tool/policy/classes/api.php
|
api.set_acceptances_status
|
protected static function set_acceptances_status($policyversionid, $userid = null, $note = null, $lang = null, $status = 1) {
global $DB, $USER;
// Validate arguments and capabilities.
if (empty($policyversionid)) {
return;
} else if (!is_array($policyversionid)) {
$policyversionid = [$policyversionid];
}
if (!$userid) {
$userid = $USER->id;
}
self::can_accept_policies([$policyversionid], $userid, true);
// Retrieve the list of policy versions that need agreement (do not update existing agreements).
list($sql, $params) = $DB->get_in_or_equal($policyversionid, SQL_PARAMS_NAMED);
$sql = "SELECT v.id AS versionid, a.*
FROM {tool_policy_versions} v
LEFT JOIN {tool_policy_acceptances} a ON a.userid = :userid AND a.policyversionid = v.id
WHERE v.id $sql AND (a.id IS NULL OR a.status <> :status)";
$needacceptance = $DB->get_records_sql($sql, $params + [
'userid' => $userid,
'status' => $status,
]);
$realuser = manager::get_realuser();
$updatedata = ['status' => $status, 'lang' => $lang ?: current_language(),
'timemodified' => time(), 'usermodified' => $realuser->id, 'note' => $note];
foreach ($needacceptance as $versionid => $currentacceptance) {
unset($currentacceptance->versionid);
if ($currentacceptance->id) {
$updatedata['id'] = $currentacceptance->id;
$DB->update_record('tool_policy_acceptances', $updatedata);
acceptance_updated::create_from_record((object)($updatedata + (array)$currentacceptance))->trigger();
} else {
$updatedata['timecreated'] = $updatedata['timemodified'];
$updatedata['policyversionid'] = $versionid;
$updatedata['userid'] = $userid;
$updatedata['id'] = $DB->insert_record('tool_policy_acceptances', $updatedata);
acceptance_created::create_from_record((object)($updatedata + (array)$currentacceptance))->trigger();
}
}
static::update_policyagreed($userid);
}
|
php
|
protected static function set_acceptances_status($policyversionid, $userid = null, $note = null, $lang = null, $status = 1) {
global $DB, $USER;
// Validate arguments and capabilities.
if (empty($policyversionid)) {
return;
} else if (!is_array($policyversionid)) {
$policyversionid = [$policyversionid];
}
if (!$userid) {
$userid = $USER->id;
}
self::can_accept_policies([$policyversionid], $userid, true);
// Retrieve the list of policy versions that need agreement (do not update existing agreements).
list($sql, $params) = $DB->get_in_or_equal($policyversionid, SQL_PARAMS_NAMED);
$sql = "SELECT v.id AS versionid, a.*
FROM {tool_policy_versions} v
LEFT JOIN {tool_policy_acceptances} a ON a.userid = :userid AND a.policyversionid = v.id
WHERE v.id $sql AND (a.id IS NULL OR a.status <> :status)";
$needacceptance = $DB->get_records_sql($sql, $params + [
'userid' => $userid,
'status' => $status,
]);
$realuser = manager::get_realuser();
$updatedata = ['status' => $status, 'lang' => $lang ?: current_language(),
'timemodified' => time(), 'usermodified' => $realuser->id, 'note' => $note];
foreach ($needacceptance as $versionid => $currentacceptance) {
unset($currentacceptance->versionid);
if ($currentacceptance->id) {
$updatedata['id'] = $currentacceptance->id;
$DB->update_record('tool_policy_acceptances', $updatedata);
acceptance_updated::create_from_record((object)($updatedata + (array)$currentacceptance))->trigger();
} else {
$updatedata['timecreated'] = $updatedata['timemodified'];
$updatedata['policyversionid'] = $versionid;
$updatedata['userid'] = $userid;
$updatedata['id'] = $DB->insert_record('tool_policy_acceptances', $updatedata);
acceptance_created::create_from_record((object)($updatedata + (array)$currentacceptance))->trigger();
}
}
static::update_policyagreed($userid);
}
|
[
"protected",
"static",
"function",
"set_acceptances_status",
"(",
"$",
"policyversionid",
",",
"$",
"userid",
"=",
"null",
",",
"$",
"note",
"=",
"null",
",",
"$",
"lang",
"=",
"null",
",",
"$",
"status",
"=",
"1",
")",
"{",
"global",
"$",
"DB",
",",
"$",
"USER",
";",
"// Validate arguments and capabilities.",
"if",
"(",
"empty",
"(",
"$",
"policyversionid",
")",
")",
"{",
"return",
";",
"}",
"else",
"if",
"(",
"!",
"is_array",
"(",
"$",
"policyversionid",
")",
")",
"{",
"$",
"policyversionid",
"=",
"[",
"$",
"policyversionid",
"]",
";",
"}",
"if",
"(",
"!",
"$",
"userid",
")",
"{",
"$",
"userid",
"=",
"$",
"USER",
"->",
"id",
";",
"}",
"self",
"::",
"can_accept_policies",
"(",
"[",
"$",
"policyversionid",
"]",
",",
"$",
"userid",
",",
"true",
")",
";",
"// Retrieve the list of policy versions that need agreement (do not update existing agreements).",
"list",
"(",
"$",
"sql",
",",
"$",
"params",
")",
"=",
"$",
"DB",
"->",
"get_in_or_equal",
"(",
"$",
"policyversionid",
",",
"SQL_PARAMS_NAMED",
")",
";",
"$",
"sql",
"=",
"\"SELECT v.id AS versionid, a.*\n FROM {tool_policy_versions} v\n LEFT JOIN {tool_policy_acceptances} a ON a.userid = :userid AND a.policyversionid = v.id\n WHERE v.id $sql AND (a.id IS NULL OR a.status <> :status)\"",
";",
"$",
"needacceptance",
"=",
"$",
"DB",
"->",
"get_records_sql",
"(",
"$",
"sql",
",",
"$",
"params",
"+",
"[",
"'userid'",
"=>",
"$",
"userid",
",",
"'status'",
"=>",
"$",
"status",
",",
"]",
")",
";",
"$",
"realuser",
"=",
"manager",
"::",
"get_realuser",
"(",
")",
";",
"$",
"updatedata",
"=",
"[",
"'status'",
"=>",
"$",
"status",
",",
"'lang'",
"=>",
"$",
"lang",
"?",
":",
"current_language",
"(",
")",
",",
"'timemodified'",
"=>",
"time",
"(",
")",
",",
"'usermodified'",
"=>",
"$",
"realuser",
"->",
"id",
",",
"'note'",
"=>",
"$",
"note",
"]",
";",
"foreach",
"(",
"$",
"needacceptance",
"as",
"$",
"versionid",
"=>",
"$",
"currentacceptance",
")",
"{",
"unset",
"(",
"$",
"currentacceptance",
"->",
"versionid",
")",
";",
"if",
"(",
"$",
"currentacceptance",
"->",
"id",
")",
"{",
"$",
"updatedata",
"[",
"'id'",
"]",
"=",
"$",
"currentacceptance",
"->",
"id",
";",
"$",
"DB",
"->",
"update_record",
"(",
"'tool_policy_acceptances'",
",",
"$",
"updatedata",
")",
";",
"acceptance_updated",
"::",
"create_from_record",
"(",
"(",
"object",
")",
"(",
"$",
"updatedata",
"+",
"(",
"array",
")",
"$",
"currentacceptance",
")",
")",
"->",
"trigger",
"(",
")",
";",
"}",
"else",
"{",
"$",
"updatedata",
"[",
"'timecreated'",
"]",
"=",
"$",
"updatedata",
"[",
"'timemodified'",
"]",
";",
"$",
"updatedata",
"[",
"'policyversionid'",
"]",
"=",
"$",
"versionid",
";",
"$",
"updatedata",
"[",
"'userid'",
"]",
"=",
"$",
"userid",
";",
"$",
"updatedata",
"[",
"'id'",
"]",
"=",
"$",
"DB",
"->",
"insert_record",
"(",
"'tool_policy_acceptances'",
",",
"$",
"updatedata",
")",
";",
"acceptance_created",
"::",
"create_from_record",
"(",
"(",
"object",
")",
"(",
"$",
"updatedata",
"+",
"(",
"array",
")",
"$",
"currentacceptance",
")",
")",
"->",
"trigger",
"(",
")",
";",
"}",
"}",
"static",
"::",
"update_policyagreed",
"(",
"$",
"userid",
")",
";",
"}"
] |
Mark the given policy versions as accepted or declined by the user.
@param array|int $policyversionid Policy version id(s) to set acceptance status for.
@param int|null $userid Id of the user accepting the policy version, defaults to the current one.
@param string|null $note Note to be recorded.
@param string|null $lang Language in which the policy was shown, defaults to the current one.
@param int $status The acceptance status, defaults to 1 = accepted
|
[
"Mark",
"the",
"given",
"policy",
"versions",
"as",
"accepted",
"or",
"declined",
"by",
"the",
"user",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/policy/classes/api.php#L953-L998
|
215,549
|
moodle/moodle
|
admin/tool/policy/classes/api.php
|
api.revoke_acceptance
|
public static function revoke_acceptance($policyversionid, $userid, $note = null) {
global $DB, $USER;
if (!$userid) {
$userid = $USER->id;
}
self::can_accept_policies([$policyversionid], $userid, true);
if ($currentacceptance = $DB->get_record('tool_policy_acceptances',
['policyversionid' => $policyversionid, 'userid' => $userid])) {
$realuser = manager::get_realuser();
$updatedata = ['id' => $currentacceptance->id, 'status' => 0, 'timemodified' => time(),
'usermodified' => $realuser->id, 'note' => $note];
$DB->update_record('tool_policy_acceptances', $updatedata);
acceptance_updated::create_from_record((object)($updatedata + (array)$currentacceptance))->trigger();
}
static::update_policyagreed($userid);
}
|
php
|
public static function revoke_acceptance($policyversionid, $userid, $note = null) {
global $DB, $USER;
if (!$userid) {
$userid = $USER->id;
}
self::can_accept_policies([$policyversionid], $userid, true);
if ($currentacceptance = $DB->get_record('tool_policy_acceptances',
['policyversionid' => $policyversionid, 'userid' => $userid])) {
$realuser = manager::get_realuser();
$updatedata = ['id' => $currentacceptance->id, 'status' => 0, 'timemodified' => time(),
'usermodified' => $realuser->id, 'note' => $note];
$DB->update_record('tool_policy_acceptances', $updatedata);
acceptance_updated::create_from_record((object)($updatedata + (array)$currentacceptance))->trigger();
}
static::update_policyagreed($userid);
}
|
[
"public",
"static",
"function",
"revoke_acceptance",
"(",
"$",
"policyversionid",
",",
"$",
"userid",
",",
"$",
"note",
"=",
"null",
")",
"{",
"global",
"$",
"DB",
",",
"$",
"USER",
";",
"if",
"(",
"!",
"$",
"userid",
")",
"{",
"$",
"userid",
"=",
"$",
"USER",
"->",
"id",
";",
"}",
"self",
"::",
"can_accept_policies",
"(",
"[",
"$",
"policyversionid",
"]",
",",
"$",
"userid",
",",
"true",
")",
";",
"if",
"(",
"$",
"currentacceptance",
"=",
"$",
"DB",
"->",
"get_record",
"(",
"'tool_policy_acceptances'",
",",
"[",
"'policyversionid'",
"=>",
"$",
"policyversionid",
",",
"'userid'",
"=>",
"$",
"userid",
"]",
")",
")",
"{",
"$",
"realuser",
"=",
"manager",
"::",
"get_realuser",
"(",
")",
";",
"$",
"updatedata",
"=",
"[",
"'id'",
"=>",
"$",
"currentacceptance",
"->",
"id",
",",
"'status'",
"=>",
"0",
",",
"'timemodified'",
"=>",
"time",
"(",
")",
",",
"'usermodified'",
"=>",
"$",
"realuser",
"->",
"id",
",",
"'note'",
"=>",
"$",
"note",
"]",
";",
"$",
"DB",
"->",
"update_record",
"(",
"'tool_policy_acceptances'",
",",
"$",
"updatedata",
")",
";",
"acceptance_updated",
"::",
"create_from_record",
"(",
"(",
"object",
")",
"(",
"$",
"updatedata",
"+",
"(",
"array",
")",
"$",
"currentacceptance",
")",
")",
"->",
"trigger",
"(",
")",
";",
"}",
"static",
"::",
"update_policyagreed",
"(",
"$",
"userid",
")",
";",
"}"
] |
May be used to revert accidentally granted acceptance for another user
@param int $policyversionid
@param int $userid
@param null $note
|
[
"May",
"be",
"used",
"to",
"revert",
"accidentally",
"granted",
"acceptance",
"for",
"another",
"user"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/policy/classes/api.php#L1049-L1066
|
215,550
|
moodle/moodle
|
admin/tool/policy/classes/api.php
|
api.create_acceptances_user_created
|
public static function create_acceptances_user_created(\core\event\user_created $event) {
global $USER, $CFG, $DB;
// Do nothing if not set as the site policies handler.
if (empty($CFG->sitepolicyhandler) || $CFG->sitepolicyhandler !== 'tool_policy') {
return;
}
$userid = $event->objectid;
$lang = current_language();
$user = $event->get_record_snapshot('user', $userid);
// Do nothing if the user has not accepted the current policies.
if (!$user->policyagreed) {
return;
}
// Cleanup our bits in the presignup cache (we can not rely on them at this stage any more anyway).
$cache = \cache::make('core', 'presignup');
$cache->delete('tool_policy_userpolicyagreed');
$cache->delete('tool_policy_viewedpolicies');
$cache->delete('tool_policy_policyversionidsagreed');
// Mark all compulsory policies as implicitly accepted during the signup.
if ($policyversions = static::list_current_versions(policy_version::AUDIENCE_LOGGEDIN)) {
$acceptances = array();
$now = time();
foreach ($policyversions as $policyversion) {
if ($policyversion->optional == policy_version::AGREEMENT_OPTIONAL) {
continue;
}
$acceptances[] = array(
'policyversionid' => $policyversion->id,
'userid' => $userid,
'status' => 1,
'lang' => $lang,
'usermodified' => isset($USER->id) ? $USER->id : 0,
'timecreated' => $now,
'timemodified' => $now,
);
}
$DB->insert_records('tool_policy_acceptances', $acceptances);
}
static::update_policyagreed($userid);
}
|
php
|
public static function create_acceptances_user_created(\core\event\user_created $event) {
global $USER, $CFG, $DB;
// Do nothing if not set as the site policies handler.
if (empty($CFG->sitepolicyhandler) || $CFG->sitepolicyhandler !== 'tool_policy') {
return;
}
$userid = $event->objectid;
$lang = current_language();
$user = $event->get_record_snapshot('user', $userid);
// Do nothing if the user has not accepted the current policies.
if (!$user->policyagreed) {
return;
}
// Cleanup our bits in the presignup cache (we can not rely on them at this stage any more anyway).
$cache = \cache::make('core', 'presignup');
$cache->delete('tool_policy_userpolicyagreed');
$cache->delete('tool_policy_viewedpolicies');
$cache->delete('tool_policy_policyversionidsagreed');
// Mark all compulsory policies as implicitly accepted during the signup.
if ($policyversions = static::list_current_versions(policy_version::AUDIENCE_LOGGEDIN)) {
$acceptances = array();
$now = time();
foreach ($policyversions as $policyversion) {
if ($policyversion->optional == policy_version::AGREEMENT_OPTIONAL) {
continue;
}
$acceptances[] = array(
'policyversionid' => $policyversion->id,
'userid' => $userid,
'status' => 1,
'lang' => $lang,
'usermodified' => isset($USER->id) ? $USER->id : 0,
'timecreated' => $now,
'timemodified' => $now,
);
}
$DB->insert_records('tool_policy_acceptances', $acceptances);
}
static::update_policyagreed($userid);
}
|
[
"public",
"static",
"function",
"create_acceptances_user_created",
"(",
"\\",
"core",
"\\",
"event",
"\\",
"user_created",
"$",
"event",
")",
"{",
"global",
"$",
"USER",
",",
"$",
"CFG",
",",
"$",
"DB",
";",
"// Do nothing if not set as the site policies handler.",
"if",
"(",
"empty",
"(",
"$",
"CFG",
"->",
"sitepolicyhandler",
")",
"||",
"$",
"CFG",
"->",
"sitepolicyhandler",
"!==",
"'tool_policy'",
")",
"{",
"return",
";",
"}",
"$",
"userid",
"=",
"$",
"event",
"->",
"objectid",
";",
"$",
"lang",
"=",
"current_language",
"(",
")",
";",
"$",
"user",
"=",
"$",
"event",
"->",
"get_record_snapshot",
"(",
"'user'",
",",
"$",
"userid",
")",
";",
"// Do nothing if the user has not accepted the current policies.",
"if",
"(",
"!",
"$",
"user",
"->",
"policyagreed",
")",
"{",
"return",
";",
"}",
"// Cleanup our bits in the presignup cache (we can not rely on them at this stage any more anyway).",
"$",
"cache",
"=",
"\\",
"cache",
"::",
"make",
"(",
"'core'",
",",
"'presignup'",
")",
";",
"$",
"cache",
"->",
"delete",
"(",
"'tool_policy_userpolicyagreed'",
")",
";",
"$",
"cache",
"->",
"delete",
"(",
"'tool_policy_viewedpolicies'",
")",
";",
"$",
"cache",
"->",
"delete",
"(",
"'tool_policy_policyversionidsagreed'",
")",
";",
"// Mark all compulsory policies as implicitly accepted during the signup.",
"if",
"(",
"$",
"policyversions",
"=",
"static",
"::",
"list_current_versions",
"(",
"policy_version",
"::",
"AUDIENCE_LOGGEDIN",
")",
")",
"{",
"$",
"acceptances",
"=",
"array",
"(",
")",
";",
"$",
"now",
"=",
"time",
"(",
")",
";",
"foreach",
"(",
"$",
"policyversions",
"as",
"$",
"policyversion",
")",
"{",
"if",
"(",
"$",
"policyversion",
"->",
"optional",
"==",
"policy_version",
"::",
"AGREEMENT_OPTIONAL",
")",
"{",
"continue",
";",
"}",
"$",
"acceptances",
"[",
"]",
"=",
"array",
"(",
"'policyversionid'",
"=>",
"$",
"policyversion",
"->",
"id",
",",
"'userid'",
"=>",
"$",
"userid",
",",
"'status'",
"=>",
"1",
",",
"'lang'",
"=>",
"$",
"lang",
",",
"'usermodified'",
"=>",
"isset",
"(",
"$",
"USER",
"->",
"id",
")",
"?",
"$",
"USER",
"->",
"id",
":",
"0",
",",
"'timecreated'",
"=>",
"$",
"now",
",",
"'timemodified'",
"=>",
"$",
"now",
",",
")",
";",
"}",
"$",
"DB",
"->",
"insert_records",
"(",
"'tool_policy_acceptances'",
",",
"$",
"acceptances",
")",
";",
"}",
"static",
"::",
"update_policyagreed",
"(",
"$",
"userid",
")",
";",
"}"
] |
Create user policy acceptances when the user is created.
@param \core\event\user_created $event
|
[
"Create",
"user",
"policy",
"acceptances",
"when",
"the",
"user",
"is",
"created",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/policy/classes/api.php#L1073-L1117
|
215,551
|
moodle/moodle
|
admin/tool/policy/classes/api.php
|
api.get_agreement_optional
|
public static function get_agreement_optional($versionid) {
global $DB;
$optcache = \cache::make('tool_policy', 'policy_optional');
$hit = $optcache->get($versionid);
if ($hit === false) {
$flags = $DB->get_records_menu('tool_policy_versions', null, '', 'id, optional');
$optcache->set_many($flags);
$hit = $flags[$versionid];
}
return $hit;
}
|
php
|
public static function get_agreement_optional($versionid) {
global $DB;
$optcache = \cache::make('tool_policy', 'policy_optional');
$hit = $optcache->get($versionid);
if ($hit === false) {
$flags = $DB->get_records_menu('tool_policy_versions', null, '', 'id, optional');
$optcache->set_many($flags);
$hit = $flags[$versionid];
}
return $hit;
}
|
[
"public",
"static",
"function",
"get_agreement_optional",
"(",
"$",
"versionid",
")",
"{",
"global",
"$",
"DB",
";",
"$",
"optcache",
"=",
"\\",
"cache",
"::",
"make",
"(",
"'tool_policy'",
",",
"'policy_optional'",
")",
";",
"$",
"hit",
"=",
"$",
"optcache",
"->",
"get",
"(",
"$",
"versionid",
")",
";",
"if",
"(",
"$",
"hit",
"===",
"false",
")",
"{",
"$",
"flags",
"=",
"$",
"DB",
"->",
"get_records_menu",
"(",
"'tool_policy_versions'",
",",
"null",
",",
"''",
",",
"'id, optional'",
")",
";",
"$",
"optcache",
"->",
"set_many",
"(",
"$",
"flags",
")",
";",
"$",
"hit",
"=",
"$",
"flags",
"[",
"$",
"versionid",
"]",
";",
"}",
"return",
"$",
"hit",
";",
"}"
] |
Returns the value of the optional flag for the given policy version.
Optimised for being called multiple times by making use of a request cache. The cache is normally populated as a
side effect of calling {@link self::list_policies()} and in most cases should be warm enough for hits.
@param int $versionid
@return int policy_version::AGREEMENT_COMPULSORY | policy_version::AGREEMENT_OPTIONAL
|
[
"Returns",
"the",
"value",
"of",
"the",
"optional",
"flag",
"for",
"the",
"given",
"policy",
"version",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/policy/classes/api.php#L1128-L1142
|
215,552
|
moodle/moodle
|
blocks/recentlyaccesseditems/classes/observer.php
|
observer.store
|
public static function store(\core\event\base $event) {
global $DB;
if (!isloggedin() or \core\session\manager::is_loggedinas() or isguestuser()) {
// No access tracking.
return;
}
$conditions = [
'userid' => $event->userid
];
$records = $DB->get_records(self::$table, $conditions, "timeaccess DESC");
foreach ($records as $record) {
if (($record->userid == $event->userid) && ($record->cmid == $event->contextinstanceid)) {
$conditions = [
'userid' => $event->userid,
'cmid' => $event->contextinstanceid
];
$DB->set_field(self::$table, 'timeaccess', $event->timecreated, $conditions);
return;
}
}
if (count($records) >= 9) {
$conditions = [
'id' => end($records)->id,
];
$DB->delete_records(self::$table, $conditions);
}
$eventdata = new \stdClass();
$eventdata->cmid = $event->contextinstanceid;
$eventdata->timeaccess = $event->timecreated;
$eventdata->courseid = $event->courseid;
$eventdata->userid = $event->userid;
$DB->insert_record(self::$table, $eventdata);
}
|
php
|
public static function store(\core\event\base $event) {
global $DB;
if (!isloggedin() or \core\session\manager::is_loggedinas() or isguestuser()) {
// No access tracking.
return;
}
$conditions = [
'userid' => $event->userid
];
$records = $DB->get_records(self::$table, $conditions, "timeaccess DESC");
foreach ($records as $record) {
if (($record->userid == $event->userid) && ($record->cmid == $event->contextinstanceid)) {
$conditions = [
'userid' => $event->userid,
'cmid' => $event->contextinstanceid
];
$DB->set_field(self::$table, 'timeaccess', $event->timecreated, $conditions);
return;
}
}
if (count($records) >= 9) {
$conditions = [
'id' => end($records)->id,
];
$DB->delete_records(self::$table, $conditions);
}
$eventdata = new \stdClass();
$eventdata->cmid = $event->contextinstanceid;
$eventdata->timeaccess = $event->timecreated;
$eventdata->courseid = $event->courseid;
$eventdata->userid = $event->userid;
$DB->insert_record(self::$table, $eventdata);
}
|
[
"public",
"static",
"function",
"store",
"(",
"\\",
"core",
"\\",
"event",
"\\",
"base",
"$",
"event",
")",
"{",
"global",
"$",
"DB",
";",
"if",
"(",
"!",
"isloggedin",
"(",
")",
"or",
"\\",
"core",
"\\",
"session",
"\\",
"manager",
"::",
"is_loggedinas",
"(",
")",
"or",
"isguestuser",
"(",
")",
")",
"{",
"// No access tracking.",
"return",
";",
"}",
"$",
"conditions",
"=",
"[",
"'userid'",
"=>",
"$",
"event",
"->",
"userid",
"]",
";",
"$",
"records",
"=",
"$",
"DB",
"->",
"get_records",
"(",
"self",
"::",
"$",
"table",
",",
"$",
"conditions",
",",
"\"timeaccess DESC\"",
")",
";",
"foreach",
"(",
"$",
"records",
"as",
"$",
"record",
")",
"{",
"if",
"(",
"(",
"$",
"record",
"->",
"userid",
"==",
"$",
"event",
"->",
"userid",
")",
"&&",
"(",
"$",
"record",
"->",
"cmid",
"==",
"$",
"event",
"->",
"contextinstanceid",
")",
")",
"{",
"$",
"conditions",
"=",
"[",
"'userid'",
"=>",
"$",
"event",
"->",
"userid",
",",
"'cmid'",
"=>",
"$",
"event",
"->",
"contextinstanceid",
"]",
";",
"$",
"DB",
"->",
"set_field",
"(",
"self",
"::",
"$",
"table",
",",
"'timeaccess'",
",",
"$",
"event",
"->",
"timecreated",
",",
"$",
"conditions",
")",
";",
"return",
";",
"}",
"}",
"if",
"(",
"count",
"(",
"$",
"records",
")",
">=",
"9",
")",
"{",
"$",
"conditions",
"=",
"[",
"'id'",
"=>",
"end",
"(",
"$",
"records",
")",
"->",
"id",
",",
"]",
";",
"$",
"DB",
"->",
"delete_records",
"(",
"self",
"::",
"$",
"table",
",",
"$",
"conditions",
")",
";",
"}",
"$",
"eventdata",
"=",
"new",
"\\",
"stdClass",
"(",
")",
";",
"$",
"eventdata",
"->",
"cmid",
"=",
"$",
"event",
"->",
"contextinstanceid",
";",
"$",
"eventdata",
"->",
"timeaccess",
"=",
"$",
"event",
"->",
"timecreated",
";",
"$",
"eventdata",
"->",
"courseid",
"=",
"$",
"event",
"->",
"courseid",
";",
"$",
"eventdata",
"->",
"userid",
"=",
"$",
"event",
"->",
"userid",
";",
"$",
"DB",
"->",
"insert_record",
"(",
"self",
"::",
"$",
"table",
",",
"$",
"eventdata",
")",
";",
"}"
] |
Register items views in block_recentlyaccesseditems table.
When the item is view for the first time, a new record is created. If the item was viewed before, the time is
updated.
@param \core\event\base $event
|
[
"Register",
"items",
"views",
"in",
"block_recentlyaccesseditems",
"table",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/blocks/recentlyaccesseditems/classes/observer.php#L53-L93
|
215,553
|
moodle/moodle
|
blocks/recentlyaccesseditems/classes/observer.php
|
observer.remove
|
public static function remove(\core\event\base $event) {
global $DB;
$DB->delete_records(self::$table, array('cmid' => $event->contextinstanceid));
}
|
php
|
public static function remove(\core\event\base $event) {
global $DB;
$DB->delete_records(self::$table, array('cmid' => $event->contextinstanceid));
}
|
[
"public",
"static",
"function",
"remove",
"(",
"\\",
"core",
"\\",
"event",
"\\",
"base",
"$",
"event",
")",
"{",
"global",
"$",
"DB",
";",
"$",
"DB",
"->",
"delete_records",
"(",
"self",
"::",
"$",
"table",
",",
"array",
"(",
"'cmid'",
"=>",
"$",
"event",
"->",
"contextinstanceid",
")",
")",
";",
"}"
] |
Remove record when course module is deleted.
@param \core\event\base $event
|
[
"Remove",
"record",
"when",
"course",
"module",
"is",
"deleted",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/blocks/recentlyaccesseditems/classes/observer.php#L100-L104
|
215,554
|
moodle/moodle
|
admin/tool/policy/classes/output/user_agreement.php
|
user_agreement.export_for_download
|
public function export_for_download() {
if (count($this->versions) == 1) {
if ($this->accepted) {
if ($this->onbehalf) {
return get_string('acceptancestatusacceptedbehalf', 'tool_policy');
} else {
return get_string('acceptancestatusaccepted', 'tool_policy');
}
} else if ($this->declined) {
if ($this->onbehalf) {
return get_string('acceptancestatusdeclinedbehalf', 'tool_policy');
} else {
return get_string('acceptancestatusdeclined', 'tool_policy');
}
} else {
return get_string('acceptancestatuspending', 'tool_policy');
}
} else if (count($this->versions) > 1) {
if (count($this->accepted) == count($this->versions)) {
return get_string('acceptancestatusaccepted', 'tool_policy');
} else if (count($this->declined) == count($this->versions)) {
return get_string('acceptancestatusdeclined', 'tool_policy');
} else if (count($this->accepted) > 0 || count($this->declined) > 0) {
return get_string('acceptancestatuspartial', 'tool_policy');
} else {
return get_string('acceptancestatuspending', 'tool_policy');
}
}
}
|
php
|
public function export_for_download() {
if (count($this->versions) == 1) {
if ($this->accepted) {
if ($this->onbehalf) {
return get_string('acceptancestatusacceptedbehalf', 'tool_policy');
} else {
return get_string('acceptancestatusaccepted', 'tool_policy');
}
} else if ($this->declined) {
if ($this->onbehalf) {
return get_string('acceptancestatusdeclinedbehalf', 'tool_policy');
} else {
return get_string('acceptancestatusdeclined', 'tool_policy');
}
} else {
return get_string('acceptancestatuspending', 'tool_policy');
}
} else if (count($this->versions) > 1) {
if (count($this->accepted) == count($this->versions)) {
return get_string('acceptancestatusaccepted', 'tool_policy');
} else if (count($this->declined) == count($this->versions)) {
return get_string('acceptancestatusdeclined', 'tool_policy');
} else if (count($this->accepted) > 0 || count($this->declined) > 0) {
return get_string('acceptancestatuspartial', 'tool_policy');
} else {
return get_string('acceptancestatuspending', 'tool_policy');
}
}
}
|
[
"public",
"function",
"export_for_download",
"(",
")",
"{",
"if",
"(",
"count",
"(",
"$",
"this",
"->",
"versions",
")",
"==",
"1",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"accepted",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"onbehalf",
")",
"{",
"return",
"get_string",
"(",
"'acceptancestatusacceptedbehalf'",
",",
"'tool_policy'",
")",
";",
"}",
"else",
"{",
"return",
"get_string",
"(",
"'acceptancestatusaccepted'",
",",
"'tool_policy'",
")",
";",
"}",
"}",
"else",
"if",
"(",
"$",
"this",
"->",
"declined",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"onbehalf",
")",
"{",
"return",
"get_string",
"(",
"'acceptancestatusdeclinedbehalf'",
",",
"'tool_policy'",
")",
";",
"}",
"else",
"{",
"return",
"get_string",
"(",
"'acceptancestatusdeclined'",
",",
"'tool_policy'",
")",
";",
"}",
"}",
"else",
"{",
"return",
"get_string",
"(",
"'acceptancestatuspending'",
",",
"'tool_policy'",
")",
";",
"}",
"}",
"else",
"if",
"(",
"count",
"(",
"$",
"this",
"->",
"versions",
")",
">",
"1",
")",
"{",
"if",
"(",
"count",
"(",
"$",
"this",
"->",
"accepted",
")",
"==",
"count",
"(",
"$",
"this",
"->",
"versions",
")",
")",
"{",
"return",
"get_string",
"(",
"'acceptancestatusaccepted'",
",",
"'tool_policy'",
")",
";",
"}",
"else",
"if",
"(",
"count",
"(",
"$",
"this",
"->",
"declined",
")",
"==",
"count",
"(",
"$",
"this",
"->",
"versions",
")",
")",
"{",
"return",
"get_string",
"(",
"'acceptancestatusdeclined'",
",",
"'tool_policy'",
")",
";",
"}",
"else",
"if",
"(",
"count",
"(",
"$",
"this",
"->",
"accepted",
")",
">",
"0",
"||",
"count",
"(",
"$",
"this",
"->",
"declined",
")",
">",
"0",
")",
"{",
"return",
"get_string",
"(",
"'acceptancestatuspartial'",
",",
"'tool_policy'",
")",
";",
"}",
"else",
"{",
"return",
"get_string",
"(",
"'acceptancestatuspending'",
",",
"'tool_policy'",
")",
";",
"}",
"}",
"}"
] |
Describe the status with a plain text for downloading purposes.
@return string
|
[
"Describe",
"the",
"status",
"with",
"a",
"plain",
"text",
"for",
"downloading",
"purposes",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/policy/classes/output/user_agreement.php#L309-L344
|
215,555
|
moodle/moodle
|
lib/filebrowser/virtual_root_file.php
|
virtual_root_file.get_pathnamehash
|
public function get_pathnamehash() {
return sha1('/'.$this->get_contextid().'/'.$this->get_component().'/'.$this->get_filearea().'/'.$this->get_itemid().$this->get_filepath().$this->get_filename());
}
|
php
|
public function get_pathnamehash() {
return sha1('/'.$this->get_contextid().'/'.$this->get_component().'/'.$this->get_filearea().'/'.$this->get_itemid().$this->get_filepath().$this->get_filename());
}
|
[
"public",
"function",
"get_pathnamehash",
"(",
")",
"{",
"return",
"sha1",
"(",
"'/'",
".",
"$",
"this",
"->",
"get_contextid",
"(",
")",
".",
"'/'",
".",
"$",
"this",
"->",
"get_component",
"(",
")",
".",
"'/'",
".",
"$",
"this",
"->",
"get_filearea",
"(",
")",
".",
"'/'",
".",
"$",
"this",
"->",
"get_itemid",
"(",
")",
".",
"$",
"this",
"->",
"get_filepath",
"(",
")",
".",
"$",
"this",
"->",
"get_filename",
"(",
")",
")",
";",
"}"
] |
Returns path name hash
@return string
|
[
"Returns",
"path",
"name",
"hash"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/filebrowser/virtual_root_file.php#L313-L315
|
215,556
|
moodle/moodle
|
mod/workshop/eval/lib.php
|
workshop_evaluation_settings_form.definition
|
public function definition() {
$mform = $this->_form;
$workshop = $this->_customdata['workshop'];
$mform->addElement('header', 'general', get_string('evaluationsettings', 'mod_workshop'));
$this->definition_sub();
$mform->addElement('submit', 'submit', get_string('aggregategrades', 'workshop'));
}
|
php
|
public function definition() {
$mform = $this->_form;
$workshop = $this->_customdata['workshop'];
$mform->addElement('header', 'general', get_string('evaluationsettings', 'mod_workshop'));
$this->definition_sub();
$mform->addElement('submit', 'submit', get_string('aggregategrades', 'workshop'));
}
|
[
"public",
"function",
"definition",
"(",
")",
"{",
"$",
"mform",
"=",
"$",
"this",
"->",
"_form",
";",
"$",
"workshop",
"=",
"$",
"this",
"->",
"_customdata",
"[",
"'workshop'",
"]",
";",
"$",
"mform",
"->",
"addElement",
"(",
"'header'",
",",
"'general'",
",",
"get_string",
"(",
"'evaluationsettings'",
",",
"'mod_workshop'",
")",
")",
";",
"$",
"this",
"->",
"definition_sub",
"(",
")",
";",
"$",
"mform",
"->",
"addElement",
"(",
"'submit'",
",",
"'submit'",
",",
"get_string",
"(",
"'aggregategrades'",
",",
"'workshop'",
")",
")",
";",
"}"
] |
Defines the common form fields.
|
[
"Defines",
"the",
"common",
"form",
"fields",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/workshop/eval/lib.php#L81-L91
|
215,557
|
moodle/moodle
|
lib/spout/src/Spout/Reader/AbstractReader.php
|
AbstractReader.open
|
public function open($filePath)
{
if ($this->isStreamWrapper($filePath) && (!$this->doesSupportStreamWrapper() || !$this->isSupportedStreamWrapper($filePath))) {
throw new IOException("Could not open $filePath for reading! Stream wrapper used is not supported for this type of file.");
}
if (!$this->isPhpStream($filePath)) {
// we skip the checks if the provided file path points to a PHP stream
if (!$this->globalFunctionsHelper->file_exists($filePath)) {
throw new IOException("Could not open $filePath for reading! File does not exist.");
} else if (!$this->globalFunctionsHelper->is_readable($filePath)) {
throw new IOException("Could not open $filePath for reading! File is not readable.");
}
}
try {
$fileRealPath = $this->getFileRealPath($filePath);
$this->openReader($fileRealPath);
$this->isStreamOpened = true;
} catch (\Exception $exception) {
throw new IOException("Could not open $filePath for reading! ({$exception->getMessage()})");
}
}
|
php
|
public function open($filePath)
{
if ($this->isStreamWrapper($filePath) && (!$this->doesSupportStreamWrapper() || !$this->isSupportedStreamWrapper($filePath))) {
throw new IOException("Could not open $filePath for reading! Stream wrapper used is not supported for this type of file.");
}
if (!$this->isPhpStream($filePath)) {
// we skip the checks if the provided file path points to a PHP stream
if (!$this->globalFunctionsHelper->file_exists($filePath)) {
throw new IOException("Could not open $filePath for reading! File does not exist.");
} else if (!$this->globalFunctionsHelper->is_readable($filePath)) {
throw new IOException("Could not open $filePath for reading! File is not readable.");
}
}
try {
$fileRealPath = $this->getFileRealPath($filePath);
$this->openReader($fileRealPath);
$this->isStreamOpened = true;
} catch (\Exception $exception) {
throw new IOException("Could not open $filePath for reading! ({$exception->getMessage()})");
}
}
|
[
"public",
"function",
"open",
"(",
"$",
"filePath",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"isStreamWrapper",
"(",
"$",
"filePath",
")",
"&&",
"(",
"!",
"$",
"this",
"->",
"doesSupportStreamWrapper",
"(",
")",
"||",
"!",
"$",
"this",
"->",
"isSupportedStreamWrapper",
"(",
"$",
"filePath",
")",
")",
")",
"{",
"throw",
"new",
"IOException",
"(",
"\"Could not open $filePath for reading! Stream wrapper used is not supported for this type of file.\"",
")",
";",
"}",
"if",
"(",
"!",
"$",
"this",
"->",
"isPhpStream",
"(",
"$",
"filePath",
")",
")",
"{",
"// we skip the checks if the provided file path points to a PHP stream",
"if",
"(",
"!",
"$",
"this",
"->",
"globalFunctionsHelper",
"->",
"file_exists",
"(",
"$",
"filePath",
")",
")",
"{",
"throw",
"new",
"IOException",
"(",
"\"Could not open $filePath for reading! File does not exist.\"",
")",
";",
"}",
"else",
"if",
"(",
"!",
"$",
"this",
"->",
"globalFunctionsHelper",
"->",
"is_readable",
"(",
"$",
"filePath",
")",
")",
"{",
"throw",
"new",
"IOException",
"(",
"\"Could not open $filePath for reading! File is not readable.\"",
")",
";",
"}",
"}",
"try",
"{",
"$",
"fileRealPath",
"=",
"$",
"this",
"->",
"getFileRealPath",
"(",
"$",
"filePath",
")",
";",
"$",
"this",
"->",
"openReader",
"(",
"$",
"fileRealPath",
")",
";",
"$",
"this",
"->",
"isStreamOpened",
"=",
"true",
";",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"exception",
")",
"{",
"throw",
"new",
"IOException",
"(",
"\"Could not open $filePath for reading! ({$exception->getMessage()})\"",
")",
";",
"}",
"}"
] |
Prepares the reader to read the given file. It also makes sure
that the file exists and is readable.
@api
@param string $filePath Path of the file to be read
@return void
@throws \Box\Spout\Common\Exception\IOException If the file at the given path does not exist, is not readable or is corrupted
|
[
"Prepares",
"the",
"reader",
"to",
"read",
"the",
"given",
"file",
".",
"It",
"also",
"makes",
"sure",
"that",
"the",
"file",
"exists",
"and",
"is",
"readable",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/spout/src/Spout/Reader/AbstractReader.php#L106-L128
|
215,558
|
moodle/moodle
|
lib/spout/src/Spout/Reader/AbstractReader.php
|
AbstractReader.close
|
public function close()
{
if ($this->isStreamOpened) {
$this->closeReader();
$sheetIterator = $this->getConcreteSheetIterator();
if ($sheetIterator) {
$sheetIterator->end();
}
$this->isStreamOpened = false;
}
}
|
php
|
public function close()
{
if ($this->isStreamOpened) {
$this->closeReader();
$sheetIterator = $this->getConcreteSheetIterator();
if ($sheetIterator) {
$sheetIterator->end();
}
$this->isStreamOpened = false;
}
}
|
[
"public",
"function",
"close",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"isStreamOpened",
")",
"{",
"$",
"this",
"->",
"closeReader",
"(",
")",
";",
"$",
"sheetIterator",
"=",
"$",
"this",
"->",
"getConcreteSheetIterator",
"(",
")",
";",
"if",
"(",
"$",
"sheetIterator",
")",
"{",
"$",
"sheetIterator",
"->",
"end",
"(",
")",
";",
"}",
"$",
"this",
"->",
"isStreamOpened",
"=",
"false",
";",
"}",
"}"
] |
Closes the reader, preventing any additional reading
@api
@return void
|
[
"Closes",
"the",
"reader",
"preventing",
"any",
"additional",
"reading"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/spout/src/Spout/Reader/AbstractReader.php#L225-L237
|
215,559
|
moodle/moodle
|
mod/data/field/latlong/field.class.php
|
data_field_latlong.field_validation
|
public function field_validation($values) {
$valuecount = 0;
// The lat long class has two values that need to be checked.
foreach ($values as $value) {
if (isset($value->value) && !($value->value == '')) {
$valuecount++;
}
}
// If we have nothing filled in or both filled in then everything is okay.
if ($valuecount == 0 || $valuecount == 2) {
return false;
}
// If we get here then only one field has been filled in.
return get_string('latlongboth', 'data');
}
|
php
|
public function field_validation($values) {
$valuecount = 0;
// The lat long class has two values that need to be checked.
foreach ($values as $value) {
if (isset($value->value) && !($value->value == '')) {
$valuecount++;
}
}
// If we have nothing filled in or both filled in then everything is okay.
if ($valuecount == 0 || $valuecount == 2) {
return false;
}
// If we get here then only one field has been filled in.
return get_string('latlongboth', 'data');
}
|
[
"public",
"function",
"field_validation",
"(",
"$",
"values",
")",
"{",
"$",
"valuecount",
"=",
"0",
";",
"// The lat long class has two values that need to be checked.",
"foreach",
"(",
"$",
"values",
"as",
"$",
"value",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"value",
"->",
"value",
")",
"&&",
"!",
"(",
"$",
"value",
"->",
"value",
"==",
"''",
")",
")",
"{",
"$",
"valuecount",
"++",
";",
"}",
"}",
"// If we have nothing filled in or both filled in then everything is okay.",
"if",
"(",
"$",
"valuecount",
"==",
"0",
"||",
"$",
"valuecount",
"==",
"2",
")",
"{",
"return",
"false",
";",
"}",
"// If we get here then only one field has been filled in.",
"return",
"get_string",
"(",
"'latlongboth'",
",",
"'data'",
")",
";",
"}"
] |
Validate values for this field.
Both the Latitude and the Longitude fields need to be filled in.
@param array $values The entered values for the lat. and long.
@return string|bool Error message or false.
|
[
"Validate",
"values",
"for",
"this",
"field",
".",
"Both",
"the",
"Latitude",
"and",
"the",
"Longitude",
"fields",
"need",
"to",
"be",
"filled",
"in",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/data/field/latlong/field.class.php#L286-L300
|
215,560
|
moodle/moodle
|
competency/classes/template.php
|
template.validate_duedate
|
protected function validate_duedate($value) {
// During update.
if ($this->get('id')) {
$before = $this->beforeupdate->get('duedate');
// The value has not changed, then it's always OK.
if ($before == $value) {
return true;
}
}
// During create and update, the date must be set in the future, or not set.
if (!empty($value) && $value <= time() - 600) {
// We cannot set the date in the past. But we allow for 10 minutes of margin so that
// a user can set the due date to "now" without risking to hit a validation error.
return new lang_string('errorcannotsetduedateinthepast', 'core_competency');
}
return true;
}
|
php
|
protected function validate_duedate($value) {
// During update.
if ($this->get('id')) {
$before = $this->beforeupdate->get('duedate');
// The value has not changed, then it's always OK.
if ($before == $value) {
return true;
}
}
// During create and update, the date must be set in the future, or not set.
if (!empty($value) && $value <= time() - 600) {
// We cannot set the date in the past. But we allow for 10 minutes of margin so that
// a user can set the due date to "now" without risking to hit a validation error.
return new lang_string('errorcannotsetduedateinthepast', 'core_competency');
}
return true;
}
|
[
"protected",
"function",
"validate_duedate",
"(",
"$",
"value",
")",
"{",
"// During update.",
"if",
"(",
"$",
"this",
"->",
"get",
"(",
"'id'",
")",
")",
"{",
"$",
"before",
"=",
"$",
"this",
"->",
"beforeupdate",
"->",
"get",
"(",
"'duedate'",
")",
";",
"// The value has not changed, then it's always OK.",
"if",
"(",
"$",
"before",
"==",
"$",
"value",
")",
"{",
"return",
"true",
";",
"}",
"}",
"// During create and update, the date must be set in the future, or not set.",
"if",
"(",
"!",
"empty",
"(",
"$",
"value",
")",
"&&",
"$",
"value",
"<=",
"time",
"(",
")",
"-",
"600",
")",
"{",
"// We cannot set the date in the past. But we allow for 10 minutes of margin so that",
"// a user can set the due date to \"now\" without risking to hit a validation error.",
"return",
"new",
"lang_string",
"(",
"'errorcannotsetduedateinthepast'",
",",
"'core_competency'",
")",
";",
"}",
"return",
"true",
";",
"}"
] |
Validate the due date.
The due date can always be changed, but when it is it must be:
- unset
- set in the future.
@param int $value The due date.
@return bool|lang_string
|
[
"Validate",
"the",
"due",
"date",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/competency/classes/template.php#L174-L194
|
215,561
|
moodle/moodle
|
lib/external/externallib.php
|
core_external.get_strings_parameters
|
public static function get_strings_parameters() {
return new external_function_parameters(
array('strings' => new external_multiple_structure (
new external_single_structure (array(
'stringid' => new external_value(PARAM_STRINGID, 'string identifier'),
'component' => new external_value(PARAM_COMPONENT, 'component', VALUE_DEFAULT, 'moodle'),
'lang' => new external_value(PARAM_LANG, 'lang', VALUE_DEFAULT, null),
'stringparams' => new external_multiple_structure (
new external_single_structure(array(
'name' => new external_value(PARAM_ALPHANUMEXT, 'param name
- if the string expect only one $a parameter then don\'t send this field, just send the value.', VALUE_OPTIONAL),
'value' => new external_value(PARAM_RAW, 'param value'))),
'the definition of a string param (i.e. {$a->name})', VALUE_DEFAULT, array()
))
)
)
)
);
}
|
php
|
public static function get_strings_parameters() {
return new external_function_parameters(
array('strings' => new external_multiple_structure (
new external_single_structure (array(
'stringid' => new external_value(PARAM_STRINGID, 'string identifier'),
'component' => new external_value(PARAM_COMPONENT, 'component', VALUE_DEFAULT, 'moodle'),
'lang' => new external_value(PARAM_LANG, 'lang', VALUE_DEFAULT, null),
'stringparams' => new external_multiple_structure (
new external_single_structure(array(
'name' => new external_value(PARAM_ALPHANUMEXT, 'param name
- if the string expect only one $a parameter then don\'t send this field, just send the value.', VALUE_OPTIONAL),
'value' => new external_value(PARAM_RAW, 'param value'))),
'the definition of a string param (i.e. {$a->name})', VALUE_DEFAULT, array()
))
)
)
)
);
}
|
[
"public",
"static",
"function",
"get_strings_parameters",
"(",
")",
"{",
"return",
"new",
"external_function_parameters",
"(",
"array",
"(",
"'strings'",
"=>",
"new",
"external_multiple_structure",
"(",
"new",
"external_single_structure",
"(",
"array",
"(",
"'stringid'",
"=>",
"new",
"external_value",
"(",
"PARAM_STRINGID",
",",
"'string identifier'",
")",
",",
"'component'",
"=>",
"new",
"external_value",
"(",
"PARAM_COMPONENT",
",",
"'component'",
",",
"VALUE_DEFAULT",
",",
"'moodle'",
")",
",",
"'lang'",
"=>",
"new",
"external_value",
"(",
"PARAM_LANG",
",",
"'lang'",
",",
"VALUE_DEFAULT",
",",
"null",
")",
",",
"'stringparams'",
"=>",
"new",
"external_multiple_structure",
"(",
"new",
"external_single_structure",
"(",
"array",
"(",
"'name'",
"=>",
"new",
"external_value",
"(",
"PARAM_ALPHANUMEXT",
",",
"'param name\n - if the string expect only one $a parameter then don\\'t send this field, just send the value.'",
",",
"VALUE_OPTIONAL",
")",
",",
"'value'",
"=>",
"new",
"external_value",
"(",
"PARAM_RAW",
",",
"'param value'",
")",
")",
")",
",",
"'the definition of a string param (i.e. {$a->name})'",
",",
"VALUE_DEFAULT",
",",
"array",
"(",
")",
")",
")",
")",
")",
")",
")",
";",
"}"
] |
Returns description of get_string parameters
@return external_function_parameters
@since Moodle 2.4
|
[
"Returns",
"description",
"of",
"get_string",
"parameters"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/external/externallib.php#L136-L154
|
215,562
|
moodle/moodle
|
lib/external/externallib.php
|
core_external.get_user_dates_parameters
|
public static function get_user_dates_parameters() {
return new external_function_parameters(
[
'contextid' => new external_value(
PARAM_INT,
'Context ID. Either use this value, or level and instanceid.',
VALUE_DEFAULT,
0
),
'contextlevel' => new external_value(
PARAM_ALPHA,
'Context level. To be used with instanceid.',
VALUE_DEFAULT,
''
),
'instanceid' => new external_value(
PARAM_INT,
'Context instance ID. To be used with level',
VALUE_DEFAULT,
0
),
'timestamps' => new external_multiple_structure (
new external_single_structure (
[
'timestamp' => new external_value(PARAM_INT, 'unix timestamp'),
'format' => new external_value(PARAM_TEXT, 'format string'),
]
)
)
]
);
}
|
php
|
public static function get_user_dates_parameters() {
return new external_function_parameters(
[
'contextid' => new external_value(
PARAM_INT,
'Context ID. Either use this value, or level and instanceid.',
VALUE_DEFAULT,
0
),
'contextlevel' => new external_value(
PARAM_ALPHA,
'Context level. To be used with instanceid.',
VALUE_DEFAULT,
''
),
'instanceid' => new external_value(
PARAM_INT,
'Context instance ID. To be used with level',
VALUE_DEFAULT,
0
),
'timestamps' => new external_multiple_structure (
new external_single_structure (
[
'timestamp' => new external_value(PARAM_INT, 'unix timestamp'),
'format' => new external_value(PARAM_TEXT, 'format string'),
]
)
)
]
);
}
|
[
"public",
"static",
"function",
"get_user_dates_parameters",
"(",
")",
"{",
"return",
"new",
"external_function_parameters",
"(",
"[",
"'contextid'",
"=>",
"new",
"external_value",
"(",
"PARAM_INT",
",",
"'Context ID. Either use this value, or level and instanceid.'",
",",
"VALUE_DEFAULT",
",",
"0",
")",
",",
"'contextlevel'",
"=>",
"new",
"external_value",
"(",
"PARAM_ALPHA",
",",
"'Context level. To be used with instanceid.'",
",",
"VALUE_DEFAULT",
",",
"''",
")",
",",
"'instanceid'",
"=>",
"new",
"external_value",
"(",
"PARAM_INT",
",",
"'Context instance ID. To be used with level'",
",",
"VALUE_DEFAULT",
",",
"0",
")",
",",
"'timestamps'",
"=>",
"new",
"external_multiple_structure",
"(",
"new",
"external_single_structure",
"(",
"[",
"'timestamp'",
"=>",
"new",
"external_value",
"(",
"PARAM_INT",
",",
"'unix timestamp'",
")",
",",
"'format'",
"=>",
"new",
"external_value",
"(",
"PARAM_TEXT",
",",
"'format string'",
")",
",",
"]",
")",
")",
"]",
")",
";",
"}"
] |
Returns description of get_user_dates parameters
@return external_function_parameters
|
[
"Returns",
"description",
"of",
"get_user_dates",
"parameters"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/external/externallib.php#L210-L241
|
215,563
|
moodle/moodle
|
lib/external/externallib.php
|
core_external.get_user_dates
|
public static function get_user_dates($contextid, $contextlevel, $instanceid, $timestamps) {
$params = self::validate_parameters(
self::get_user_dates_parameters(),
[
'contextid' => $contextid,
'contextlevel' => $contextlevel,
'instanceid' => $instanceid,
'timestamps' => $timestamps,
]
);
$context = self::get_context_from_params($params);
self::validate_context($context);
$formatteddates = array_map(function($timestamp) {
return userdate($timestamp['timestamp'], $timestamp['format']);
}, $params['timestamps']);
return ['dates' => $formatteddates];
}
|
php
|
public static function get_user_dates($contextid, $contextlevel, $instanceid, $timestamps) {
$params = self::validate_parameters(
self::get_user_dates_parameters(),
[
'contextid' => $contextid,
'contextlevel' => $contextlevel,
'instanceid' => $instanceid,
'timestamps' => $timestamps,
]
);
$context = self::get_context_from_params($params);
self::validate_context($context);
$formatteddates = array_map(function($timestamp) {
return userdate($timestamp['timestamp'], $timestamp['format']);
}, $params['timestamps']);
return ['dates' => $formatteddates];
}
|
[
"public",
"static",
"function",
"get_user_dates",
"(",
"$",
"contextid",
",",
"$",
"contextlevel",
",",
"$",
"instanceid",
",",
"$",
"timestamps",
")",
"{",
"$",
"params",
"=",
"self",
"::",
"validate_parameters",
"(",
"self",
"::",
"get_user_dates_parameters",
"(",
")",
",",
"[",
"'contextid'",
"=>",
"$",
"contextid",
",",
"'contextlevel'",
"=>",
"$",
"contextlevel",
",",
"'instanceid'",
"=>",
"$",
"instanceid",
",",
"'timestamps'",
"=>",
"$",
"timestamps",
",",
"]",
")",
";",
"$",
"context",
"=",
"self",
"::",
"get_context_from_params",
"(",
"$",
"params",
")",
";",
"self",
"::",
"validate_context",
"(",
"$",
"context",
")",
";",
"$",
"formatteddates",
"=",
"array_map",
"(",
"function",
"(",
"$",
"timestamp",
")",
"{",
"return",
"userdate",
"(",
"$",
"timestamp",
"[",
"'timestamp'",
"]",
",",
"$",
"timestamp",
"[",
"'format'",
"]",
")",
";",
"}",
",",
"$",
"params",
"[",
"'timestamps'",
"]",
")",
";",
"return",
"[",
"'dates'",
"=>",
"$",
"formatteddates",
"]",
";",
"}"
] |
Format an array of timestamps.
@param int|null $contextid The contenxt id
@param string|null $contextlevel The context level
@param int|null $instanceid The instnace id for the context level
@param array $timestamps Timestamps to format
@return array
|
[
"Format",
"an",
"array",
"of",
"timestamps",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/external/externallib.php#L252-L271
|
215,564
|
moodle/moodle
|
lib/external/externallib.php
|
core_external.get_fragment_parameters
|
public static function get_fragment_parameters() {
return new external_function_parameters(
array(
'component' => new external_value(PARAM_COMPONENT, 'Component for the callback e.g. mod_assign'),
'callback' => new external_value(PARAM_ALPHANUMEXT, 'Name of the callback to execute'),
'contextid' => new external_value(PARAM_INT, 'Context ID that the fragment is from'),
'args' => new external_multiple_structure(
new external_single_structure(
array(
'name' => new external_value(PARAM_ALPHANUMEXT, 'param name'),
'value' => new external_value(PARAM_RAW, 'param value')
)
), 'args for the callback are optional', VALUE_OPTIONAL
)
)
);
}
|
php
|
public static function get_fragment_parameters() {
return new external_function_parameters(
array(
'component' => new external_value(PARAM_COMPONENT, 'Component for the callback e.g. mod_assign'),
'callback' => new external_value(PARAM_ALPHANUMEXT, 'Name of the callback to execute'),
'contextid' => new external_value(PARAM_INT, 'Context ID that the fragment is from'),
'args' => new external_multiple_structure(
new external_single_structure(
array(
'name' => new external_value(PARAM_ALPHANUMEXT, 'param name'),
'value' => new external_value(PARAM_RAW, 'param value')
)
), 'args for the callback are optional', VALUE_OPTIONAL
)
)
);
}
|
[
"public",
"static",
"function",
"get_fragment_parameters",
"(",
")",
"{",
"return",
"new",
"external_function_parameters",
"(",
"array",
"(",
"'component'",
"=>",
"new",
"external_value",
"(",
"PARAM_COMPONENT",
",",
"'Component for the callback e.g. mod_assign'",
")",
",",
"'callback'",
"=>",
"new",
"external_value",
"(",
"PARAM_ALPHANUMEXT",
",",
"'Name of the callback to execute'",
")",
",",
"'contextid'",
"=>",
"new",
"external_value",
"(",
"PARAM_INT",
",",
"'Context ID that the fragment is from'",
")",
",",
"'args'",
"=>",
"new",
"external_multiple_structure",
"(",
"new",
"external_single_structure",
"(",
"array",
"(",
"'name'",
"=>",
"new",
"external_value",
"(",
"PARAM_ALPHANUMEXT",
",",
"'param name'",
")",
",",
"'value'",
"=>",
"new",
"external_value",
"(",
"PARAM_RAW",
",",
"'param value'",
")",
")",
")",
",",
"'args for the callback are optional'",
",",
"VALUE_OPTIONAL",
")",
")",
")",
";",
"}"
] |
Returns description of get_fragment parameters
@return external_function_parameters
@since Moodle 3.1
|
[
"Returns",
"description",
"of",
"get_fragment",
"parameters"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/external/externallib.php#L353-L369
|
215,565
|
moodle/moodle
|
lib/external/externallib.php
|
core_external.get_fragment
|
public static function get_fragment($component, $callback, $contextid, $args = null) {
global $OUTPUT, $PAGE;
$params = self::validate_parameters(self::get_fragment_parameters(),
array(
'component' => $component,
'callback' => $callback,
'contextid' => $contextid,
'args' => $args
)
);
// Reformat arguments into something less unwieldy.
$arguments = array();
foreach ($params['args'] as $paramargument) {
$arguments[$paramargument['name']] = $paramargument['value'];
}
$context = context::instance_by_id($contextid);
self::validate_context($context);
$arguments['context'] = $context;
// Hack alert: Set a default URL to stop the annoying debug.
$PAGE->set_url('/');
// Hack alert: Forcing bootstrap_renderer to initiate moodle page.
$OUTPUT->header();
// Overwriting page_requirements_manager with the fragment one so only JS included from
// this point is returned to the user.
$PAGE->start_collecting_javascript_requirements();
$data = component_callback($params['component'], 'output_fragment_' . $params['callback'], array($arguments));
$jsfooter = $PAGE->requires->get_end_code();
$output = array('html' => $data, 'javascript' => $jsfooter);
return $output;
}
|
php
|
public static function get_fragment($component, $callback, $contextid, $args = null) {
global $OUTPUT, $PAGE;
$params = self::validate_parameters(self::get_fragment_parameters(),
array(
'component' => $component,
'callback' => $callback,
'contextid' => $contextid,
'args' => $args
)
);
// Reformat arguments into something less unwieldy.
$arguments = array();
foreach ($params['args'] as $paramargument) {
$arguments[$paramargument['name']] = $paramargument['value'];
}
$context = context::instance_by_id($contextid);
self::validate_context($context);
$arguments['context'] = $context;
// Hack alert: Set a default URL to stop the annoying debug.
$PAGE->set_url('/');
// Hack alert: Forcing bootstrap_renderer to initiate moodle page.
$OUTPUT->header();
// Overwriting page_requirements_manager with the fragment one so only JS included from
// this point is returned to the user.
$PAGE->start_collecting_javascript_requirements();
$data = component_callback($params['component'], 'output_fragment_' . $params['callback'], array($arguments));
$jsfooter = $PAGE->requires->get_end_code();
$output = array('html' => $data, 'javascript' => $jsfooter);
return $output;
}
|
[
"public",
"static",
"function",
"get_fragment",
"(",
"$",
"component",
",",
"$",
"callback",
",",
"$",
"contextid",
",",
"$",
"args",
"=",
"null",
")",
"{",
"global",
"$",
"OUTPUT",
",",
"$",
"PAGE",
";",
"$",
"params",
"=",
"self",
"::",
"validate_parameters",
"(",
"self",
"::",
"get_fragment_parameters",
"(",
")",
",",
"array",
"(",
"'component'",
"=>",
"$",
"component",
",",
"'callback'",
"=>",
"$",
"callback",
",",
"'contextid'",
"=>",
"$",
"contextid",
",",
"'args'",
"=>",
"$",
"args",
")",
")",
";",
"// Reformat arguments into something less unwieldy.",
"$",
"arguments",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"params",
"[",
"'args'",
"]",
"as",
"$",
"paramargument",
")",
"{",
"$",
"arguments",
"[",
"$",
"paramargument",
"[",
"'name'",
"]",
"]",
"=",
"$",
"paramargument",
"[",
"'value'",
"]",
";",
"}",
"$",
"context",
"=",
"context",
"::",
"instance_by_id",
"(",
"$",
"contextid",
")",
";",
"self",
"::",
"validate_context",
"(",
"$",
"context",
")",
";",
"$",
"arguments",
"[",
"'context'",
"]",
"=",
"$",
"context",
";",
"// Hack alert: Set a default URL to stop the annoying debug.",
"$",
"PAGE",
"->",
"set_url",
"(",
"'/'",
")",
";",
"// Hack alert: Forcing bootstrap_renderer to initiate moodle page.",
"$",
"OUTPUT",
"->",
"header",
"(",
")",
";",
"// Overwriting page_requirements_manager with the fragment one so only JS included from",
"// this point is returned to the user.",
"$",
"PAGE",
"->",
"start_collecting_javascript_requirements",
"(",
")",
";",
"$",
"data",
"=",
"component_callback",
"(",
"$",
"params",
"[",
"'component'",
"]",
",",
"'output_fragment_'",
".",
"$",
"params",
"[",
"'callback'",
"]",
",",
"array",
"(",
"$",
"arguments",
")",
")",
";",
"$",
"jsfooter",
"=",
"$",
"PAGE",
"->",
"requires",
"->",
"get_end_code",
"(",
")",
";",
"$",
"output",
"=",
"array",
"(",
"'html'",
"=>",
"$",
"data",
",",
"'javascript'",
"=>",
"$",
"jsfooter",
")",
";",
"return",
"$",
"output",
";",
"}"
] |
Get a HTML fragment for inserting into something. Initial use is for inserting mforms into
a page using AJAX.
This web service is designed to be called only via AJAX and not directly.
Callbacks that are called by this web service are responsible for doing the appropriate security checks
to access the information returned. This only does minimal validation on the context.
@param string $component Name of the component.
@param string $callback Function callback name.
@param int $contextid Context ID this fragment is in.
@param array $args optional arguments for the callback.
@return array HTML and JavaScript fragments for insertion into stuff.
@since Moodle 3.1
|
[
"Get",
"a",
"HTML",
"fragment",
"for",
"inserting",
"into",
"something",
".",
"Initial",
"use",
"is",
"for",
"inserting",
"mforms",
"into",
"a",
"page",
"using",
"AJAX",
".",
"This",
"web",
"service",
"is",
"designed",
"to",
"be",
"called",
"only",
"via",
"AJAX",
"and",
"not",
"directly",
".",
"Callbacks",
"that",
"are",
"called",
"by",
"this",
"web",
"service",
"are",
"responsible",
"for",
"doing",
"the",
"appropriate",
"security",
"checks",
"to",
"access",
"the",
"information",
"returned",
".",
"This",
"only",
"does",
"minimal",
"validation",
"on",
"the",
"context",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/external/externallib.php#L385-L419
|
215,566
|
moodle/moodle
|
lib/external/externallib.php
|
core_external.update_inplace_editable
|
public static function update_inplace_editable($component, $itemtype, $itemid, $value) {
global $PAGE;
// Validate and normalize parameters.
$params = self::validate_parameters(self::update_inplace_editable_parameters(),
array('component' => $component, 'itemtype' => $itemtype, 'itemid' => $itemid, 'value' => $value));
if (!$functionname = component_callback_exists($component, 'inplace_editable')) {
throw new \moodle_exception('inplaceeditableerror');
}
$tmpl = component_callback($params['component'], 'inplace_editable',
array($params['itemtype'], $params['itemid'], $params['value']));
if (!$tmpl || !($tmpl instanceof \core\output\inplace_editable)) {
throw new \moodle_exception('inplaceeditableerror');
}
return $tmpl->export_for_template($PAGE->get_renderer('core'));
}
|
php
|
public static function update_inplace_editable($component, $itemtype, $itemid, $value) {
global $PAGE;
// Validate and normalize parameters.
$params = self::validate_parameters(self::update_inplace_editable_parameters(),
array('component' => $component, 'itemtype' => $itemtype, 'itemid' => $itemid, 'value' => $value));
if (!$functionname = component_callback_exists($component, 'inplace_editable')) {
throw new \moodle_exception('inplaceeditableerror');
}
$tmpl = component_callback($params['component'], 'inplace_editable',
array($params['itemtype'], $params['itemid'], $params['value']));
if (!$tmpl || !($tmpl instanceof \core\output\inplace_editable)) {
throw new \moodle_exception('inplaceeditableerror');
}
return $tmpl->export_for_template($PAGE->get_renderer('core'));
}
|
[
"public",
"static",
"function",
"update_inplace_editable",
"(",
"$",
"component",
",",
"$",
"itemtype",
",",
"$",
"itemid",
",",
"$",
"value",
")",
"{",
"global",
"$",
"PAGE",
";",
"// Validate and normalize parameters.",
"$",
"params",
"=",
"self",
"::",
"validate_parameters",
"(",
"self",
"::",
"update_inplace_editable_parameters",
"(",
")",
",",
"array",
"(",
"'component'",
"=>",
"$",
"component",
",",
"'itemtype'",
"=>",
"$",
"itemtype",
",",
"'itemid'",
"=>",
"$",
"itemid",
",",
"'value'",
"=>",
"$",
"value",
")",
")",
";",
"if",
"(",
"!",
"$",
"functionname",
"=",
"component_callback_exists",
"(",
"$",
"component",
",",
"'inplace_editable'",
")",
")",
"{",
"throw",
"new",
"\\",
"moodle_exception",
"(",
"'inplaceeditableerror'",
")",
";",
"}",
"$",
"tmpl",
"=",
"component_callback",
"(",
"$",
"params",
"[",
"'component'",
"]",
",",
"'inplace_editable'",
",",
"array",
"(",
"$",
"params",
"[",
"'itemtype'",
"]",
",",
"$",
"params",
"[",
"'itemid'",
"]",
",",
"$",
"params",
"[",
"'value'",
"]",
")",
")",
";",
"if",
"(",
"!",
"$",
"tmpl",
"||",
"!",
"(",
"$",
"tmpl",
"instanceof",
"\\",
"core",
"\\",
"output",
"\\",
"inplace_editable",
")",
")",
"{",
"throw",
"new",
"\\",
"moodle_exception",
"(",
"'inplaceeditableerror'",
")",
";",
"}",
"return",
"$",
"tmpl",
"->",
"export_for_template",
"(",
"$",
"PAGE",
"->",
"get_renderer",
"(",
"'core'",
")",
")",
";",
"}"
] |
Update any component's editable value assuming that component implements necessary callback
@since Moodle 3.1
@param string $component
@param string $itemtype
@param string $itemid
@param string $value
|
[
"Update",
"any",
"component",
"s",
"editable",
"value",
"assuming",
"that",
"component",
"implements",
"necessary",
"callback"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/external/externallib.php#L461-L475
|
215,567
|
moodle/moodle
|
lib/external/externallib.php
|
core_external.fetch_notifications
|
public static function fetch_notifications($contextid) {
global $PAGE;
self::validate_parameters(self::fetch_notifications_parameters(), [
'contextid' => $contextid,
]);
$context = \context::instance_by_id($contextid);
self::validate_context($context);
return \core\notification::fetch_as_array($PAGE->get_renderer('core'));
}
|
php
|
public static function fetch_notifications($contextid) {
global $PAGE;
self::validate_parameters(self::fetch_notifications_parameters(), [
'contextid' => $contextid,
]);
$context = \context::instance_by_id($contextid);
self::validate_context($context);
return \core\notification::fetch_as_array($PAGE->get_renderer('core'));
}
|
[
"public",
"static",
"function",
"fetch_notifications",
"(",
"$",
"contextid",
")",
"{",
"global",
"$",
"PAGE",
";",
"self",
"::",
"validate_parameters",
"(",
"self",
"::",
"fetch_notifications_parameters",
"(",
")",
",",
"[",
"'contextid'",
"=>",
"$",
"contextid",
",",
"]",
")",
";",
"$",
"context",
"=",
"\\",
"context",
"::",
"instance_by_id",
"(",
"$",
"contextid",
")",
";",
"self",
"::",
"validate_context",
"(",
"$",
"context",
")",
";",
"return",
"\\",
"core",
"\\",
"notification",
"::",
"fetch_as_array",
"(",
"$",
"PAGE",
"->",
"get_renderer",
"(",
"'core'",
")",
")",
";",
"}"
] |
Returns the list of notifications against the current session.
@return array
@since Moodle 3.1
|
[
"Returns",
"the",
"list",
"of",
"notifications",
"against",
"the",
"current",
"session",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/external/externallib.php#L541-L552
|
215,568
|
moodle/moodle
|
mod/workshop/form/accumulative/backup/moodle2/backup_workshopform_accumulative_subplugin.class.php
|
backup_workshopform_accumulative_subplugin.dimension_grades_structure
|
private function dimension_grades_structure($elementname) {
// create XML elements
$subplugin = $this->get_subplugin_element(); // virtual optigroup element
$subpluginwrapper = new backup_nested_element($this->get_recommended_name());
$subplugingrade = new backup_nested_element($elementname, array('id'), array(
'dimensionid', 'grade', 'peercomment', 'peercommentformat'));
// connect XML elements into the tree
$subplugin->add_child($subpluginwrapper);
$subpluginwrapper->add_child($subplugingrade);
// set source to populate the data
$subplugingrade->set_source_sql(
"SELECT id, dimensionid, grade, peercomment, peercommentformat
FROM {workshop_grades}
WHERE strategy = 'accumulative' AND assessmentid = ?",
array(backup::VAR_PARENTID));
return $subplugin;
}
|
php
|
private function dimension_grades_structure($elementname) {
// create XML elements
$subplugin = $this->get_subplugin_element(); // virtual optigroup element
$subpluginwrapper = new backup_nested_element($this->get_recommended_name());
$subplugingrade = new backup_nested_element($elementname, array('id'), array(
'dimensionid', 'grade', 'peercomment', 'peercommentformat'));
// connect XML elements into the tree
$subplugin->add_child($subpluginwrapper);
$subpluginwrapper->add_child($subplugingrade);
// set source to populate the data
$subplugingrade->set_source_sql(
"SELECT id, dimensionid, grade, peercomment, peercommentformat
FROM {workshop_grades}
WHERE strategy = 'accumulative' AND assessmentid = ?",
array(backup::VAR_PARENTID));
return $subplugin;
}
|
[
"private",
"function",
"dimension_grades_structure",
"(",
"$",
"elementname",
")",
"{",
"// create XML elements",
"$",
"subplugin",
"=",
"$",
"this",
"->",
"get_subplugin_element",
"(",
")",
";",
"// virtual optigroup element",
"$",
"subpluginwrapper",
"=",
"new",
"backup_nested_element",
"(",
"$",
"this",
"->",
"get_recommended_name",
"(",
")",
")",
";",
"$",
"subplugingrade",
"=",
"new",
"backup_nested_element",
"(",
"$",
"elementname",
",",
"array",
"(",
"'id'",
")",
",",
"array",
"(",
"'dimensionid'",
",",
"'grade'",
",",
"'peercomment'",
",",
"'peercommentformat'",
")",
")",
";",
"// connect XML elements into the tree",
"$",
"subplugin",
"->",
"add_child",
"(",
"$",
"subpluginwrapper",
")",
";",
"$",
"subpluginwrapper",
"->",
"add_child",
"(",
"$",
"subplugingrade",
")",
";",
"// set source to populate the data",
"$",
"subplugingrade",
"->",
"set_source_sql",
"(",
"\"SELECT id, dimensionid, grade, peercomment, peercommentformat\n FROM {workshop_grades}\n WHERE strategy = 'accumulative' AND assessmentid = ?\"",
",",
"array",
"(",
"backup",
"::",
"VAR_PARENTID",
")",
")",
";",
"return",
"$",
"subplugin",
";",
"}"
] |
Returns the structure of dimension grades
@param string first parameter of {@link backup_nested_element} constructor
|
[
"Returns",
"the",
"structure",
"of",
"dimension",
"grades"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/workshop/form/accumulative/backup/moodle2/backup_workshopform_accumulative_subplugin.class.php#L87-L107
|
215,569
|
moodle/moodle
|
lib/behat/classes/behat_config_manager.php
|
behat_config_manager.update_config_file
|
public static function update_config_file($component = '', $testsrunner = true, $tags = '',
$themesuitewithallfeatures = false, $parallelruns = 0, $run = 0) {
global $CFG;
// Behat must have a separate behat.yml to have access to the whole set of features and steps definitions.
if ($testsrunner === true) {
$configfilepath = behat_command::get_behat_dir($run) . '/behat.yml';
} else {
// Alternative for steps definitions filtering, one for each user.
$configfilepath = self::get_steps_list_config_filepath();
}
$behatconfigutil = self::get_behat_config_util();
$behatconfigutil->set_theme_suite_to_include_core_features($themesuitewithallfeatures);
$behatconfigutil->set_tag_for_feature_filter($tags);
// Gets all the components with features, if running the tests otherwise not required.
$features = array();
if ($testsrunner) {
$features = $behatconfigutil->get_components_features();
}
// Gets all the components with steps definitions.
$stepsdefinitions = $behatconfigutil->get_components_contexts($component);
// We don't want the deprecated steps definitions here.
if (!$testsrunner) {
unset($stepsdefinitions['behat_deprecated']);
}
// Get current run.
if (empty($run) && ($run !== false) && !empty($CFG->behatrunprocess)) {
$run = $CFG->behatrunprocess;
}
// Get number of parallel runs if not passed.
if (empty($parallelruns) && ($parallelruns !== false)) {
$parallelruns = self::get_behat_run_config_value('parallel');
}
// Behat config file specifing the main context class,
// the required Behat extensions and Moodle test wwwroot.
$contents = $behatconfigutil->get_config_file_contents($features, $stepsdefinitions, $tags, $parallelruns, $run);
// Stores the file.
if (!file_put_contents($configfilepath, $contents)) {
behat_error(BEHAT_EXITCODE_PERMISSIONS, 'File ' . $configfilepath . ' can not be created');
}
}
|
php
|
public static function update_config_file($component = '', $testsrunner = true, $tags = '',
$themesuitewithallfeatures = false, $parallelruns = 0, $run = 0) {
global $CFG;
// Behat must have a separate behat.yml to have access to the whole set of features and steps definitions.
if ($testsrunner === true) {
$configfilepath = behat_command::get_behat_dir($run) . '/behat.yml';
} else {
// Alternative for steps definitions filtering, one for each user.
$configfilepath = self::get_steps_list_config_filepath();
}
$behatconfigutil = self::get_behat_config_util();
$behatconfigutil->set_theme_suite_to_include_core_features($themesuitewithallfeatures);
$behatconfigutil->set_tag_for_feature_filter($tags);
// Gets all the components with features, if running the tests otherwise not required.
$features = array();
if ($testsrunner) {
$features = $behatconfigutil->get_components_features();
}
// Gets all the components with steps definitions.
$stepsdefinitions = $behatconfigutil->get_components_contexts($component);
// We don't want the deprecated steps definitions here.
if (!$testsrunner) {
unset($stepsdefinitions['behat_deprecated']);
}
// Get current run.
if (empty($run) && ($run !== false) && !empty($CFG->behatrunprocess)) {
$run = $CFG->behatrunprocess;
}
// Get number of parallel runs if not passed.
if (empty($parallelruns) && ($parallelruns !== false)) {
$parallelruns = self::get_behat_run_config_value('parallel');
}
// Behat config file specifing the main context class,
// the required Behat extensions and Moodle test wwwroot.
$contents = $behatconfigutil->get_config_file_contents($features, $stepsdefinitions, $tags, $parallelruns, $run);
// Stores the file.
if (!file_put_contents($configfilepath, $contents)) {
behat_error(BEHAT_EXITCODE_PERMISSIONS, 'File ' . $configfilepath . ' can not be created');
}
}
|
[
"public",
"static",
"function",
"update_config_file",
"(",
"$",
"component",
"=",
"''",
",",
"$",
"testsrunner",
"=",
"true",
",",
"$",
"tags",
"=",
"''",
",",
"$",
"themesuitewithallfeatures",
"=",
"false",
",",
"$",
"parallelruns",
"=",
"0",
",",
"$",
"run",
"=",
"0",
")",
"{",
"global",
"$",
"CFG",
";",
"// Behat must have a separate behat.yml to have access to the whole set of features and steps definitions.",
"if",
"(",
"$",
"testsrunner",
"===",
"true",
")",
"{",
"$",
"configfilepath",
"=",
"behat_command",
"::",
"get_behat_dir",
"(",
"$",
"run",
")",
".",
"'/behat.yml'",
";",
"}",
"else",
"{",
"// Alternative for steps definitions filtering, one for each user.",
"$",
"configfilepath",
"=",
"self",
"::",
"get_steps_list_config_filepath",
"(",
")",
";",
"}",
"$",
"behatconfigutil",
"=",
"self",
"::",
"get_behat_config_util",
"(",
")",
";",
"$",
"behatconfigutil",
"->",
"set_theme_suite_to_include_core_features",
"(",
"$",
"themesuitewithallfeatures",
")",
";",
"$",
"behatconfigutil",
"->",
"set_tag_for_feature_filter",
"(",
"$",
"tags",
")",
";",
"// Gets all the components with features, if running the tests otherwise not required.",
"$",
"features",
"=",
"array",
"(",
")",
";",
"if",
"(",
"$",
"testsrunner",
")",
"{",
"$",
"features",
"=",
"$",
"behatconfigutil",
"->",
"get_components_features",
"(",
")",
";",
"}",
"// Gets all the components with steps definitions.",
"$",
"stepsdefinitions",
"=",
"$",
"behatconfigutil",
"->",
"get_components_contexts",
"(",
"$",
"component",
")",
";",
"// We don't want the deprecated steps definitions here.",
"if",
"(",
"!",
"$",
"testsrunner",
")",
"{",
"unset",
"(",
"$",
"stepsdefinitions",
"[",
"'behat_deprecated'",
"]",
")",
";",
"}",
"// Get current run.",
"if",
"(",
"empty",
"(",
"$",
"run",
")",
"&&",
"(",
"$",
"run",
"!==",
"false",
")",
"&&",
"!",
"empty",
"(",
"$",
"CFG",
"->",
"behatrunprocess",
")",
")",
"{",
"$",
"run",
"=",
"$",
"CFG",
"->",
"behatrunprocess",
";",
"}",
"// Get number of parallel runs if not passed.",
"if",
"(",
"empty",
"(",
"$",
"parallelruns",
")",
"&&",
"(",
"$",
"parallelruns",
"!==",
"false",
")",
")",
"{",
"$",
"parallelruns",
"=",
"self",
"::",
"get_behat_run_config_value",
"(",
"'parallel'",
")",
";",
"}",
"// Behat config file specifing the main context class,",
"// the required Behat extensions and Moodle test wwwroot.",
"$",
"contents",
"=",
"$",
"behatconfigutil",
"->",
"get_config_file_contents",
"(",
"$",
"features",
",",
"$",
"stepsdefinitions",
",",
"$",
"tags",
",",
"$",
"parallelruns",
",",
"$",
"run",
")",
";",
"// Stores the file.",
"if",
"(",
"!",
"file_put_contents",
"(",
"$",
"configfilepath",
",",
"$",
"contents",
")",
")",
"{",
"behat_error",
"(",
"BEHAT_EXITCODE_PERMISSIONS",
",",
"'File '",
".",
"$",
"configfilepath",
".",
"' can not be created'",
")",
";",
"}",
"}"
] |
Updates a config file
The tests runner and the steps definitions list uses different
config files to avoid problems with concurrent executions.
The steps definitions list can be filtered by component so it's
behat.yml is different from the $CFG->dirroot one.
@param string $component Restricts the obtained steps definitions to the specified component
@param string $testsrunner If the config file will be used to run tests
@param string $tags features files including tags.
@param bool $themesuitewithallfeatures if only theme specific features need to be included in the suite.
@param int $parallelruns number of parallel runs.
@param int $run current run for which config needs to be updated.
@return void
|
[
"Updates",
"a",
"config",
"file"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/behat/classes/behat_config_manager.php#L83-L132
|
215,570
|
moodle/moodle
|
lib/behat/classes/behat_config_manager.php
|
behat_config_manager.get_steps_list_config_filepath
|
public static function get_steps_list_config_filepath() {
global $USER;
// We don't cygwin-it as it is called using exec() which uses cmd.exe.
$userdir = behat_command::get_behat_dir() . '/users/' . $USER->id;
make_writable_directory($userdir);
return $userdir . '/behat.yml';
}
|
php
|
public static function get_steps_list_config_filepath() {
global $USER;
// We don't cygwin-it as it is called using exec() which uses cmd.exe.
$userdir = behat_command::get_behat_dir() . '/users/' . $USER->id;
make_writable_directory($userdir);
return $userdir . '/behat.yml';
}
|
[
"public",
"static",
"function",
"get_steps_list_config_filepath",
"(",
")",
"{",
"global",
"$",
"USER",
";",
"// We don't cygwin-it as it is called using exec() which uses cmd.exe.",
"$",
"userdir",
"=",
"behat_command",
"::",
"get_behat_dir",
"(",
")",
".",
"'/users/'",
".",
"$",
"USER",
"->",
"id",
";",
"make_writable_directory",
"(",
"$",
"userdir",
")",
";",
"return",
"$",
"userdir",
".",
"'/behat.yml'",
";",
"}"
] |
Returns the behat config file path used by the steps definition list
@return string
|
[
"Returns",
"the",
"behat",
"config",
"file",
"path",
"used",
"by",
"the",
"steps",
"definition",
"list"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/behat/classes/behat_config_manager.php#L155-L163
|
215,571
|
moodle/moodle
|
lib/behat/classes/behat_config_manager.php
|
behat_config_manager.get_behat_cli_config_filepath
|
public static function get_behat_cli_config_filepath($runprocess = 0) {
global $CFG;
if ($runprocess) {
if (isset($CFG->behat_parallel_run[$runprocess - 1 ]['behat_dataroot'])) {
$command = $CFG->behat_parallel_run[$runprocess - 1]['behat_dataroot'];
} else {
$command = $CFG->behat_dataroot . $runprocess;
}
} else {
$command = $CFG->behat_dataroot;
}
$command .= DIRECTORY_SEPARATOR . 'behat' . DIRECTORY_SEPARATOR . 'behat.yml';
// Cygwin uses linux-style directory separators.
if (testing_is_cygwin()) {
$command = str_replace('\\', '/', $command);
}
return $command;
}
|
php
|
public static function get_behat_cli_config_filepath($runprocess = 0) {
global $CFG;
if ($runprocess) {
if (isset($CFG->behat_parallel_run[$runprocess - 1 ]['behat_dataroot'])) {
$command = $CFG->behat_parallel_run[$runprocess - 1]['behat_dataroot'];
} else {
$command = $CFG->behat_dataroot . $runprocess;
}
} else {
$command = $CFG->behat_dataroot;
}
$command .= DIRECTORY_SEPARATOR . 'behat' . DIRECTORY_SEPARATOR . 'behat.yml';
// Cygwin uses linux-style directory separators.
if (testing_is_cygwin()) {
$command = str_replace('\\', '/', $command);
}
return $command;
}
|
[
"public",
"static",
"function",
"get_behat_cli_config_filepath",
"(",
"$",
"runprocess",
"=",
"0",
")",
"{",
"global",
"$",
"CFG",
";",
"if",
"(",
"$",
"runprocess",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"CFG",
"->",
"behat_parallel_run",
"[",
"$",
"runprocess",
"-",
"1",
"]",
"[",
"'behat_dataroot'",
"]",
")",
")",
"{",
"$",
"command",
"=",
"$",
"CFG",
"->",
"behat_parallel_run",
"[",
"$",
"runprocess",
"-",
"1",
"]",
"[",
"'behat_dataroot'",
"]",
";",
"}",
"else",
"{",
"$",
"command",
"=",
"$",
"CFG",
"->",
"behat_dataroot",
".",
"$",
"runprocess",
";",
"}",
"}",
"else",
"{",
"$",
"command",
"=",
"$",
"CFG",
"->",
"behat_dataroot",
";",
"}",
"$",
"command",
".=",
"DIRECTORY_SEPARATOR",
".",
"'behat'",
".",
"DIRECTORY_SEPARATOR",
".",
"'behat.yml'",
";",
"// Cygwin uses linux-style directory separators.",
"if",
"(",
"testing_is_cygwin",
"(",
")",
")",
"{",
"$",
"command",
"=",
"str_replace",
"(",
"'\\\\'",
",",
"'/'",
",",
"$",
"command",
")",
";",
"}",
"return",
"$",
"command",
";",
"}"
] |
Returns the behat config file path used by the behat cli command.
@param int $runprocess Runprocess.
@return string
|
[
"Returns",
"the",
"behat",
"config",
"file",
"path",
"used",
"by",
"the",
"behat",
"cli",
"command",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/behat/classes/behat_config_manager.php#L171-L191
|
215,572
|
moodle/moodle
|
lib/behat/classes/behat_config_manager.php
|
behat_config_manager.get_behat_run_config_value
|
public final static function get_behat_run_config_value($key) {
$parallelrunconfigfile = self::get_behat_run_config_file_path();
if (file_exists($parallelrunconfigfile)) {
if ($parallelrunconfigs = @json_decode(file_get_contents($parallelrunconfigfile), true)) {
if (isset($parallelrunconfigs[$key])) {
return $parallelrunconfigs[$key];
}
}
}
return false;
}
|
php
|
public final static function get_behat_run_config_value($key) {
$parallelrunconfigfile = self::get_behat_run_config_file_path();
if (file_exists($parallelrunconfigfile)) {
if ($parallelrunconfigs = @json_decode(file_get_contents($parallelrunconfigfile), true)) {
if (isset($parallelrunconfigs[$key])) {
return $parallelrunconfigs[$key];
}
}
}
return false;
}
|
[
"public",
"final",
"static",
"function",
"get_behat_run_config_value",
"(",
"$",
"key",
")",
"{",
"$",
"parallelrunconfigfile",
"=",
"self",
"::",
"get_behat_run_config_file_path",
"(",
")",
";",
"if",
"(",
"file_exists",
"(",
"$",
"parallelrunconfigfile",
")",
")",
"{",
"if",
"(",
"$",
"parallelrunconfigs",
"=",
"@",
"json_decode",
"(",
"file_get_contents",
"(",
"$",
"parallelrunconfigfile",
")",
",",
"true",
")",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"parallelrunconfigs",
"[",
"$",
"key",
"]",
")",
")",
"{",
"return",
"$",
"parallelrunconfigs",
"[",
"$",
"key",
"]",
";",
"}",
"}",
"}",
"return",
"false",
";",
"}"
] |
Get config for parallel run.
@param string $key Key to store
@return string|int|array value which is stored.
|
[
"Get",
"config",
"for",
"parallel",
"run",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/behat/classes/behat_config_manager.php#L209-L221
|
215,573
|
moodle/moodle
|
lib/behat/classes/behat_config_manager.php
|
behat_config_manager.drop_parallel_site_links
|
public final static function drop_parallel_site_links() {
global $CFG;
// Get parallel test runs.
$parallelrun = self::get_behat_run_config_value('parallel');
if (empty($parallelrun)) {
return false;
}
// If parallel run then remove links and original file.
clearstatcache();
for ($i = 1; $i <= $parallelrun; $i++) {
// Don't delete links for specified sites, as they should be accessible.
if (!empty($CFG->behat_parallel_run['behat_wwwroot'][$i - 1]['behat_wwwroot'])) {
continue;
}
$link = $CFG->dirroot . '/' . BEHAT_PARALLEL_SITE_NAME . $i;
if (file_exists($link) && is_link($link)) {
@unlink($link);
}
}
return true;
}
|
php
|
public final static function drop_parallel_site_links() {
global $CFG;
// Get parallel test runs.
$parallelrun = self::get_behat_run_config_value('parallel');
if (empty($parallelrun)) {
return false;
}
// If parallel run then remove links and original file.
clearstatcache();
for ($i = 1; $i <= $parallelrun; $i++) {
// Don't delete links for specified sites, as they should be accessible.
if (!empty($CFG->behat_parallel_run['behat_wwwroot'][$i - 1]['behat_wwwroot'])) {
continue;
}
$link = $CFG->dirroot . '/' . BEHAT_PARALLEL_SITE_NAME . $i;
if (file_exists($link) && is_link($link)) {
@unlink($link);
}
}
return true;
}
|
[
"public",
"final",
"static",
"function",
"drop_parallel_site_links",
"(",
")",
"{",
"global",
"$",
"CFG",
";",
"// Get parallel test runs.",
"$",
"parallelrun",
"=",
"self",
"::",
"get_behat_run_config_value",
"(",
"'parallel'",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"parallelrun",
")",
")",
"{",
"return",
"false",
";",
"}",
"// If parallel run then remove links and original file.",
"clearstatcache",
"(",
")",
";",
"for",
"(",
"$",
"i",
"=",
"1",
";",
"$",
"i",
"<=",
"$",
"parallelrun",
";",
"$",
"i",
"++",
")",
"{",
"// Don't delete links for specified sites, as they should be accessible.",
"if",
"(",
"!",
"empty",
"(",
"$",
"CFG",
"->",
"behat_parallel_run",
"[",
"'behat_wwwroot'",
"]",
"[",
"$",
"i",
"-",
"1",
"]",
"[",
"'behat_wwwroot'",
"]",
")",
")",
"{",
"continue",
";",
"}",
"$",
"link",
"=",
"$",
"CFG",
"->",
"dirroot",
".",
"'/'",
".",
"BEHAT_PARALLEL_SITE_NAME",
".",
"$",
"i",
";",
"if",
"(",
"file_exists",
"(",
"$",
"link",
")",
"&&",
"is_link",
"(",
"$",
"link",
")",
")",
"{",
"@",
"unlink",
"(",
"$",
"link",
")",
";",
"}",
"}",
"return",
"true",
";",
"}"
] |
Drops parallel site links.
@return bool true on success else false.
|
[
"Drops",
"parallel",
"site",
"links",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/behat/classes/behat_config_manager.php#L247-L270
|
215,574
|
moodle/moodle
|
lib/behat/classes/behat_config_manager.php
|
behat_config_manager.create_parallel_site_links
|
public final static function create_parallel_site_links($fromrun, $torun) {
global $CFG;
// Create site symlink if necessary.
clearstatcache();
for ($i = $fromrun; $i <= $torun; $i++) {
// Don't create links for specified sites, as they should be accessible.
if (!empty($CFG->behat_parallel_run['behat_wwwroot'][$i - 1]['behat_wwwroot'])) {
continue;
}
$link = $CFG->dirroot.'/'.BEHAT_PARALLEL_SITE_NAME.$i;
clearstatcache();
if (file_exists($link)) {
if (!is_link($link) || !is_dir($link)) {
echo "File exists at link location ($link) but is not a link or directory!" . PHP_EOL;
return false;
}
} else if (!symlink($CFG->dirroot, $link)) {
// Try create link in case it's not already present.
echo "Unable to create behat site symlink ($link)" . PHP_EOL;
return false;
}
}
return true;
}
|
php
|
public final static function create_parallel_site_links($fromrun, $torun) {
global $CFG;
// Create site symlink if necessary.
clearstatcache();
for ($i = $fromrun; $i <= $torun; $i++) {
// Don't create links for specified sites, as they should be accessible.
if (!empty($CFG->behat_parallel_run['behat_wwwroot'][$i - 1]['behat_wwwroot'])) {
continue;
}
$link = $CFG->dirroot.'/'.BEHAT_PARALLEL_SITE_NAME.$i;
clearstatcache();
if (file_exists($link)) {
if (!is_link($link) || !is_dir($link)) {
echo "File exists at link location ($link) but is not a link or directory!" . PHP_EOL;
return false;
}
} else if (!symlink($CFG->dirroot, $link)) {
// Try create link in case it's not already present.
echo "Unable to create behat site symlink ($link)" . PHP_EOL;
return false;
}
}
return true;
}
|
[
"public",
"final",
"static",
"function",
"create_parallel_site_links",
"(",
"$",
"fromrun",
",",
"$",
"torun",
")",
"{",
"global",
"$",
"CFG",
";",
"// Create site symlink if necessary.",
"clearstatcache",
"(",
")",
";",
"for",
"(",
"$",
"i",
"=",
"$",
"fromrun",
";",
"$",
"i",
"<=",
"$",
"torun",
";",
"$",
"i",
"++",
")",
"{",
"// Don't create links for specified sites, as they should be accessible.",
"if",
"(",
"!",
"empty",
"(",
"$",
"CFG",
"->",
"behat_parallel_run",
"[",
"'behat_wwwroot'",
"]",
"[",
"$",
"i",
"-",
"1",
"]",
"[",
"'behat_wwwroot'",
"]",
")",
")",
"{",
"continue",
";",
"}",
"$",
"link",
"=",
"$",
"CFG",
"->",
"dirroot",
".",
"'/'",
".",
"BEHAT_PARALLEL_SITE_NAME",
".",
"$",
"i",
";",
"clearstatcache",
"(",
")",
";",
"if",
"(",
"file_exists",
"(",
"$",
"link",
")",
")",
"{",
"if",
"(",
"!",
"is_link",
"(",
"$",
"link",
")",
"||",
"!",
"is_dir",
"(",
"$",
"link",
")",
")",
"{",
"echo",
"\"File exists at link location ($link) but is not a link or directory!\"",
".",
"PHP_EOL",
";",
"return",
"false",
";",
"}",
"}",
"else",
"if",
"(",
"!",
"symlink",
"(",
"$",
"CFG",
"->",
"dirroot",
",",
"$",
"link",
")",
")",
"{",
"// Try create link in case it's not already present.",
"echo",
"\"Unable to create behat site symlink ($link)\"",
".",
"PHP_EOL",
";",
"return",
"false",
";",
"}",
"}",
"return",
"true",
";",
"}"
] |
Create parallel site links.
@param int $fromrun first run
@param int $torun last run.
@return bool true for sucess, else false.
|
[
"Create",
"parallel",
"site",
"links",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/behat/classes/behat_config_manager.php#L279-L303
|
215,575
|
moodle/moodle
|
lib/horde/framework/Horde/Imap/Client/Cache.php
|
Horde_Imap_Client_Cache.get
|
public function get($mailbox, array $uids = array(), $fields = array(),
$uidvalid = null)
{
$mailbox = strval($mailbox);
if (empty($uids)) {
$ret = $this->_backend->getCachedUids($mailbox, $uidvalid);
} else {
$ret = $this->_backend->get($mailbox, $uids, $fields, $uidvalid);
if ($this->_debug && !empty($ret)) {
$this->_debug->info(sprintf(
'CACHE: Retrieved messages (%s [%s; %s])',
empty($fields) ? 'ALL' : implode(',', $fields),
$mailbox,
$this->_baseob->getIdsOb(array_keys($ret))->tostring_sort
));
}
}
return $ret;
}
|
php
|
public function get($mailbox, array $uids = array(), $fields = array(),
$uidvalid = null)
{
$mailbox = strval($mailbox);
if (empty($uids)) {
$ret = $this->_backend->getCachedUids($mailbox, $uidvalid);
} else {
$ret = $this->_backend->get($mailbox, $uids, $fields, $uidvalid);
if ($this->_debug && !empty($ret)) {
$this->_debug->info(sprintf(
'CACHE: Retrieved messages (%s [%s; %s])',
empty($fields) ? 'ALL' : implode(',', $fields),
$mailbox,
$this->_baseob->getIdsOb(array_keys($ret))->tostring_sort
));
}
}
return $ret;
}
|
[
"public",
"function",
"get",
"(",
"$",
"mailbox",
",",
"array",
"$",
"uids",
"=",
"array",
"(",
")",
",",
"$",
"fields",
"=",
"array",
"(",
")",
",",
"$",
"uidvalid",
"=",
"null",
")",
"{",
"$",
"mailbox",
"=",
"strval",
"(",
"$",
"mailbox",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"uids",
")",
")",
"{",
"$",
"ret",
"=",
"$",
"this",
"->",
"_backend",
"->",
"getCachedUids",
"(",
"$",
"mailbox",
",",
"$",
"uidvalid",
")",
";",
"}",
"else",
"{",
"$",
"ret",
"=",
"$",
"this",
"->",
"_backend",
"->",
"get",
"(",
"$",
"mailbox",
",",
"$",
"uids",
",",
"$",
"fields",
",",
"$",
"uidvalid",
")",
";",
"if",
"(",
"$",
"this",
"->",
"_debug",
"&&",
"!",
"empty",
"(",
"$",
"ret",
")",
")",
"{",
"$",
"this",
"->",
"_debug",
"->",
"info",
"(",
"sprintf",
"(",
"'CACHE: Retrieved messages (%s [%s; %s])'",
",",
"empty",
"(",
"$",
"fields",
")",
"?",
"'ALL'",
":",
"implode",
"(",
"','",
",",
"$",
"fields",
")",
",",
"$",
"mailbox",
",",
"$",
"this",
"->",
"_baseob",
"->",
"getIdsOb",
"(",
"array_keys",
"(",
"$",
"ret",
")",
")",
"->",
"tostring_sort",
")",
")",
";",
"}",
"}",
"return",
"$",
"ret",
";",
"}"
] |
Get information from the cache.
@param string $mailbox An IMAP mailbox string.
@param array $uids The list of message UIDs to retrieve
information for. If empty, returns the list
of cached UIDs.
@param array $fields An array of fields to retrieve. If empty,
returns all cached fields.
@param integer $uidvalid The IMAP uidvalidity value of the mailbox.
@return array An array of arrays with the UID of the message as the
key (if found) and the fields as values (will be
undefined if not found). If $uids is empty, returns the
full (unsorted) list of cached UIDs.
|
[
"Get",
"information",
"from",
"the",
"cache",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/horde/framework/Horde/Imap/Client/Cache.php#L104-L125
|
215,576
|
moodle/moodle
|
lib/horde/framework/Horde/Imap/Client/Cache.php
|
Horde_Imap_Client_Cache.set
|
public function set($mailbox, $data, $uidvalid)
{
$mailbox = strval($mailbox);
if (empty($data)) {
$this->_backend->getMetaData($mailbox, $uidvalid, array('uidvalid'));
} else {
$this->_backend->set($mailbox, $data, $uidvalid);
if ($this->_debug) {
$this->_debug->info(sprintf(
'CACHE: Stored messages [%s; %s]',
$mailbox,
$this->_baseob->getIdsOb(array_keys($data))->tostring_sort
));
}
}
}
|
php
|
public function set($mailbox, $data, $uidvalid)
{
$mailbox = strval($mailbox);
if (empty($data)) {
$this->_backend->getMetaData($mailbox, $uidvalid, array('uidvalid'));
} else {
$this->_backend->set($mailbox, $data, $uidvalid);
if ($this->_debug) {
$this->_debug->info(sprintf(
'CACHE: Stored messages [%s; %s]',
$mailbox,
$this->_baseob->getIdsOb(array_keys($data))->tostring_sort
));
}
}
}
|
[
"public",
"function",
"set",
"(",
"$",
"mailbox",
",",
"$",
"data",
",",
"$",
"uidvalid",
")",
"{",
"$",
"mailbox",
"=",
"strval",
"(",
"$",
"mailbox",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"data",
")",
")",
"{",
"$",
"this",
"->",
"_backend",
"->",
"getMetaData",
"(",
"$",
"mailbox",
",",
"$",
"uidvalid",
",",
"array",
"(",
"'uidvalid'",
")",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"_backend",
"->",
"set",
"(",
"$",
"mailbox",
",",
"$",
"data",
",",
"$",
"uidvalid",
")",
";",
"if",
"(",
"$",
"this",
"->",
"_debug",
")",
"{",
"$",
"this",
"->",
"_debug",
"->",
"info",
"(",
"sprintf",
"(",
"'CACHE: Stored messages [%s; %s]'",
",",
"$",
"mailbox",
",",
"$",
"this",
"->",
"_baseob",
"->",
"getIdsOb",
"(",
"array_keys",
"(",
"$",
"data",
")",
")",
"->",
"tostring_sort",
")",
")",
";",
"}",
"}",
"}"
] |
Store information in cache.
@param string $mailbox An IMAP mailbox string.
@param array $data The list of data to save. The keys are the
UIDs, the values are an array of information
to save. If empty, do a check to make sure
the uidvalidity is still valid.
@param integer $uidvalid The IMAP uidvalidity value of the mailbox.
|
[
"Store",
"information",
"in",
"cache",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/horde/framework/Horde/Imap/Client/Cache.php#L137-L154
|
215,577
|
moodle/moodle
|
lib/horde/framework/Horde/Imap/Client/Cache.php
|
Horde_Imap_Client_Cache.getMetaData
|
public function getMetaData($mailbox, $uidvalid = null,
array $entries = array())
{
return $this->_backend->getMetaData(strval($mailbox), $uidvalid, $entries);
}
|
php
|
public function getMetaData($mailbox, $uidvalid = null,
array $entries = array())
{
return $this->_backend->getMetaData(strval($mailbox), $uidvalid, $entries);
}
|
[
"public",
"function",
"getMetaData",
"(",
"$",
"mailbox",
",",
"$",
"uidvalid",
"=",
"null",
",",
"array",
"$",
"entries",
"=",
"array",
"(",
")",
")",
"{",
"return",
"$",
"this",
"->",
"_backend",
"->",
"getMetaData",
"(",
"strval",
"(",
"$",
"mailbox",
")",
",",
"$",
"uidvalid",
",",
"$",
"entries",
")",
";",
"}"
] |
Get metadata information for a mailbox.
@param string $mailbox An IMAP mailbox string.
@param integer $uidvalid The IMAP uidvalidity value of the mailbox.
@param array $entries An array of entries to return. If empty,
returns all metadata.
@return array The requested metadata. Requested entries that do not
exist will be undefined. The following entries are
defaults and always present:
- uidvalid: (integer) The UIDVALIDITY of the mailbox.
|
[
"Get",
"metadata",
"information",
"for",
"a",
"mailbox",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/horde/framework/Horde/Imap/Client/Cache.php#L169-L173
|
215,578
|
moodle/moodle
|
lib/horde/framework/Horde/Imap/Client/Cache.php
|
Horde_Imap_Client_Cache.setMetaData
|
public function setMetaData($mailbox, $uidvalid, array $data = array())
{
unset($data['uidvalid']);
if (!empty($data)) {
if (!empty($uidvalid)) {
$data['uidvalid'] = $uidvalid;
}
$mailbox = strval($mailbox);
$this->_backend->setMetaData($mailbox, $data);
if ($this->_debug) {
$this->_debug->info(sprintf(
'CACHE: Stored metadata (%s [%s])',
implode(',', array_keys($data)),
$mailbox
));
}
}
}
|
php
|
public function setMetaData($mailbox, $uidvalid, array $data = array())
{
unset($data['uidvalid']);
if (!empty($data)) {
if (!empty($uidvalid)) {
$data['uidvalid'] = $uidvalid;
}
$mailbox = strval($mailbox);
$this->_backend->setMetaData($mailbox, $data);
if ($this->_debug) {
$this->_debug->info(sprintf(
'CACHE: Stored metadata (%s [%s])',
implode(',', array_keys($data)),
$mailbox
));
}
}
}
|
[
"public",
"function",
"setMetaData",
"(",
"$",
"mailbox",
",",
"$",
"uidvalid",
",",
"array",
"$",
"data",
"=",
"array",
"(",
")",
")",
"{",
"unset",
"(",
"$",
"data",
"[",
"'uidvalid'",
"]",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"data",
")",
")",
"{",
"if",
"(",
"!",
"empty",
"(",
"$",
"uidvalid",
")",
")",
"{",
"$",
"data",
"[",
"'uidvalid'",
"]",
"=",
"$",
"uidvalid",
";",
"}",
"$",
"mailbox",
"=",
"strval",
"(",
"$",
"mailbox",
")",
";",
"$",
"this",
"->",
"_backend",
"->",
"setMetaData",
"(",
"$",
"mailbox",
",",
"$",
"data",
")",
";",
"if",
"(",
"$",
"this",
"->",
"_debug",
")",
"{",
"$",
"this",
"->",
"_debug",
"->",
"info",
"(",
"sprintf",
"(",
"'CACHE: Stored metadata (%s [%s])'",
",",
"implode",
"(",
"','",
",",
"array_keys",
"(",
"$",
"data",
")",
")",
",",
"$",
"mailbox",
")",
")",
";",
"}",
"}",
"}"
] |
Set metadata information for a mailbox.
@param string $mailbox An IMAP mailbox string.
@param integer $uidvalid The IMAP uidvalidity value of the mailbox.
@param array $data The list of data to save. The keys are the
metadata IDs, the values are the associated
data. The following labels are reserved:
'uidvalid'.
|
[
"Set",
"metadata",
"information",
"for",
"a",
"mailbox",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/horde/framework/Horde/Imap/Client/Cache.php#L185-L205
|
215,579
|
moodle/moodle
|
course/classes/analytics/target/course_enrolments.php
|
course_enrolments.is_valid_sample
|
public function is_valid_sample($sampleid, \core_analytics\analysable $course, $fortraining = true) {
$userenrol = $this->retrieve('user_enrolments', $sampleid);
if ($userenrol->timeend && $course->get_start() > $userenrol->timeend) {
// Discard enrolments which time end is prior to the course start. This should get rid of
// old user enrolments that remain on the course.
return false;
}
$limit = $course->get_start() - (YEARSECS + (WEEKSECS * 4));
if (($userenrol->timestart && $userenrol->timestart < $limit) ||
(!$userenrol->timestart && $userenrol->timecreated < $limit)) {
// Following what we do in is_valid_sample, we will discard enrolments that last more than 1 academic year
// because they have incorrect start and end dates or because they are reused along multiple years
// without removing previous academic years students. This may not be very accurate because some courses
// can last just some months, but it is better than nothing.
return false;
}
if (($userenrol->timestart && $userenrol->timestart > $course->get_end()) ||
(!$userenrol->timestart && $userenrol->timecreated > $course->get_end())) {
// Discard user enrolments that starts after the analysable official end.
return false;
}
return true;
}
|
php
|
public function is_valid_sample($sampleid, \core_analytics\analysable $course, $fortraining = true) {
$userenrol = $this->retrieve('user_enrolments', $sampleid);
if ($userenrol->timeend && $course->get_start() > $userenrol->timeend) {
// Discard enrolments which time end is prior to the course start. This should get rid of
// old user enrolments that remain on the course.
return false;
}
$limit = $course->get_start() - (YEARSECS + (WEEKSECS * 4));
if (($userenrol->timestart && $userenrol->timestart < $limit) ||
(!$userenrol->timestart && $userenrol->timecreated < $limit)) {
// Following what we do in is_valid_sample, we will discard enrolments that last more than 1 academic year
// because they have incorrect start and end dates or because they are reused along multiple years
// without removing previous academic years students. This may not be very accurate because some courses
// can last just some months, but it is better than nothing.
return false;
}
if (($userenrol->timestart && $userenrol->timestart > $course->get_end()) ||
(!$userenrol->timestart && $userenrol->timecreated > $course->get_end())) {
// Discard user enrolments that starts after the analysable official end.
return false;
}
return true;
}
|
[
"public",
"function",
"is_valid_sample",
"(",
"$",
"sampleid",
",",
"\\",
"core_analytics",
"\\",
"analysable",
"$",
"course",
",",
"$",
"fortraining",
"=",
"true",
")",
"{",
"$",
"userenrol",
"=",
"$",
"this",
"->",
"retrieve",
"(",
"'user_enrolments'",
",",
"$",
"sampleid",
")",
";",
"if",
"(",
"$",
"userenrol",
"->",
"timeend",
"&&",
"$",
"course",
"->",
"get_start",
"(",
")",
">",
"$",
"userenrol",
"->",
"timeend",
")",
"{",
"// Discard enrolments which time end is prior to the course start. This should get rid of",
"// old user enrolments that remain on the course.",
"return",
"false",
";",
"}",
"$",
"limit",
"=",
"$",
"course",
"->",
"get_start",
"(",
")",
"-",
"(",
"YEARSECS",
"+",
"(",
"WEEKSECS",
"*",
"4",
")",
")",
";",
"if",
"(",
"(",
"$",
"userenrol",
"->",
"timestart",
"&&",
"$",
"userenrol",
"->",
"timestart",
"<",
"$",
"limit",
")",
"||",
"(",
"!",
"$",
"userenrol",
"->",
"timestart",
"&&",
"$",
"userenrol",
"->",
"timecreated",
"<",
"$",
"limit",
")",
")",
"{",
"// Following what we do in is_valid_sample, we will discard enrolments that last more than 1 academic year",
"// because they have incorrect start and end dates or because they are reused along multiple years",
"// without removing previous academic years students. This may not be very accurate because some courses",
"// can last just some months, but it is better than nothing.",
"return",
"false",
";",
"}",
"if",
"(",
"(",
"$",
"userenrol",
"->",
"timestart",
"&&",
"$",
"userenrol",
"->",
"timestart",
">",
"$",
"course",
"->",
"get_end",
"(",
")",
")",
"||",
"(",
"!",
"$",
"userenrol",
"->",
"timestart",
"&&",
"$",
"userenrol",
"->",
"timecreated",
">",
"$",
"course",
"->",
"get_end",
"(",
")",
")",
")",
"{",
"// Discard user enrolments that starts after the analysable official end.",
"return",
"false",
";",
"}",
"return",
"true",
";",
"}"
] |
Discard student enrolments that are invalid.
@param int $sampleid
@param \core_analytics\analysable $course
@param bool $fortraining
@return bool
|
[
"Discard",
"student",
"enrolments",
"that",
"are",
"invalid",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/course/classes/analytics/target/course_enrolments.php#L123-L149
|
215,580
|
moodle/moodle
|
report/eventlist/classes/filter_form.php
|
report_eventlist_filter_form.definition
|
public function definition() {
$mform = $this->_form;
$mform->disable_form_change_checker();
$componentarray = $this->_customdata['components'];
$edulevelarray = $this->_customdata['edulevel'];
$crudarray = $this->_customdata['crud'];
$mform->addElement('header', 'displayinfo', get_string('filter', 'report_eventlist'));
$mform->addElement('text', 'eventname', get_string('name', 'report_eventlist'));
$mform->setType('eventname', PARAM_RAW);
$mform->addElement('select', 'eventcomponent', get_string('component', 'report_eventlist'), $componentarray);
$mform->addElement('select', 'eventedulevel', get_string('edulevel', 'report_eventlist'), $edulevelarray);
$mform->addElement('select', 'eventcrud', get_string('crud', 'report_eventlist'), $crudarray);
$buttonarray = array();
$buttonarray[] = $mform->createElement('button', 'filterbutton', get_string('filter', 'report_eventlist'));
$buttonarray[] = $mform->createElement('button', 'clearbutton', get_string('clear', 'report_eventlist'));
$mform->addGroup($buttonarray, 'filterbuttons', '', array(' '), false);
}
|
php
|
public function definition() {
$mform = $this->_form;
$mform->disable_form_change_checker();
$componentarray = $this->_customdata['components'];
$edulevelarray = $this->_customdata['edulevel'];
$crudarray = $this->_customdata['crud'];
$mform->addElement('header', 'displayinfo', get_string('filter', 'report_eventlist'));
$mform->addElement('text', 'eventname', get_string('name', 'report_eventlist'));
$mform->setType('eventname', PARAM_RAW);
$mform->addElement('select', 'eventcomponent', get_string('component', 'report_eventlist'), $componentarray);
$mform->addElement('select', 'eventedulevel', get_string('edulevel', 'report_eventlist'), $edulevelarray);
$mform->addElement('select', 'eventcrud', get_string('crud', 'report_eventlist'), $crudarray);
$buttonarray = array();
$buttonarray[] = $mform->createElement('button', 'filterbutton', get_string('filter', 'report_eventlist'));
$buttonarray[] = $mform->createElement('button', 'clearbutton', get_string('clear', 'report_eventlist'));
$mform->addGroup($buttonarray, 'filterbuttons', '', array(' '), false);
}
|
[
"public",
"function",
"definition",
"(",
")",
"{",
"$",
"mform",
"=",
"$",
"this",
"->",
"_form",
";",
"$",
"mform",
"->",
"disable_form_change_checker",
"(",
")",
";",
"$",
"componentarray",
"=",
"$",
"this",
"->",
"_customdata",
"[",
"'components'",
"]",
";",
"$",
"edulevelarray",
"=",
"$",
"this",
"->",
"_customdata",
"[",
"'edulevel'",
"]",
";",
"$",
"crudarray",
"=",
"$",
"this",
"->",
"_customdata",
"[",
"'crud'",
"]",
";",
"$",
"mform",
"->",
"addElement",
"(",
"'header'",
",",
"'displayinfo'",
",",
"get_string",
"(",
"'filter'",
",",
"'report_eventlist'",
")",
")",
";",
"$",
"mform",
"->",
"addElement",
"(",
"'text'",
",",
"'eventname'",
",",
"get_string",
"(",
"'name'",
",",
"'report_eventlist'",
")",
")",
";",
"$",
"mform",
"->",
"setType",
"(",
"'eventname'",
",",
"PARAM_RAW",
")",
";",
"$",
"mform",
"->",
"addElement",
"(",
"'select'",
",",
"'eventcomponent'",
",",
"get_string",
"(",
"'component'",
",",
"'report_eventlist'",
")",
",",
"$",
"componentarray",
")",
";",
"$",
"mform",
"->",
"addElement",
"(",
"'select'",
",",
"'eventedulevel'",
",",
"get_string",
"(",
"'edulevel'",
",",
"'report_eventlist'",
")",
",",
"$",
"edulevelarray",
")",
";",
"$",
"mform",
"->",
"addElement",
"(",
"'select'",
",",
"'eventcrud'",
",",
"get_string",
"(",
"'crud'",
",",
"'report_eventlist'",
")",
",",
"$",
"crudarray",
")",
";",
"$",
"buttonarray",
"=",
"array",
"(",
")",
";",
"$",
"buttonarray",
"[",
"]",
"=",
"$",
"mform",
"->",
"createElement",
"(",
"'button'",
",",
"'filterbutton'",
",",
"get_string",
"(",
"'filter'",
",",
"'report_eventlist'",
")",
")",
";",
"$",
"buttonarray",
"[",
"]",
"=",
"$",
"mform",
"->",
"createElement",
"(",
"'button'",
",",
"'clearbutton'",
",",
"get_string",
"(",
"'clear'",
",",
"'report_eventlist'",
")",
")",
";",
"$",
"mform",
"->",
"addGroup",
"(",
"$",
"buttonarray",
",",
"'filterbuttons'",
",",
"''",
",",
"array",
"(",
"' '",
")",
",",
"false",
")",
";",
"}"
] |
Form definition method.
|
[
"Form",
"definition",
"method",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/report/eventlist/classes/filter_form.php#L33-L54
|
215,581
|
moodle/moodle
|
lib/spout/src/Spout/Writer/CSV/Writer.php
|
Writer.openWriter
|
protected function openWriter()
{
if ($this->shouldAddBOM) {
// Adds UTF-8 BOM for Unicode compatibility
$this->globalFunctionsHelper->fputs($this->filePointer, EncodingHelper::BOM_UTF8);
}
}
|
php
|
protected function openWriter()
{
if ($this->shouldAddBOM) {
// Adds UTF-8 BOM for Unicode compatibility
$this->globalFunctionsHelper->fputs($this->filePointer, EncodingHelper::BOM_UTF8);
}
}
|
[
"protected",
"function",
"openWriter",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"shouldAddBOM",
")",
"{",
"// Adds UTF-8 BOM for Unicode compatibility",
"$",
"this",
"->",
"globalFunctionsHelper",
"->",
"fputs",
"(",
"$",
"this",
"->",
"filePointer",
",",
"EncodingHelper",
"::",
"BOM_UTF8",
")",
";",
"}",
"}"
] |
Opens the CSV streamer and makes it ready to accept data.
@return void
|
[
"Opens",
"the",
"CSV",
"streamer",
"and",
"makes",
"it",
"ready",
"to",
"accept",
"data",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/spout/src/Spout/Writer/CSV/Writer.php#L78-L84
|
215,582
|
moodle/moodle
|
lib/spout/src/Spout/Writer/CSV/Writer.php
|
Writer.addRowToWriter
|
protected function addRowToWriter(array $dataRow, $style)
{
$wasWriteSuccessful = $this->globalFunctionsHelper->fputcsv($this->filePointer, $dataRow, $this->fieldDelimiter, $this->fieldEnclosure);
if ($wasWriteSuccessful === false) {
throw new IOException('Unable to write data');
}
$this->lastWrittenRowIndex++;
if ($this->lastWrittenRowIndex % self::FLUSH_THRESHOLD === 0) {
$this->globalFunctionsHelper->fflush($this->filePointer);
}
}
|
php
|
protected function addRowToWriter(array $dataRow, $style)
{
$wasWriteSuccessful = $this->globalFunctionsHelper->fputcsv($this->filePointer, $dataRow, $this->fieldDelimiter, $this->fieldEnclosure);
if ($wasWriteSuccessful === false) {
throw new IOException('Unable to write data');
}
$this->lastWrittenRowIndex++;
if ($this->lastWrittenRowIndex % self::FLUSH_THRESHOLD === 0) {
$this->globalFunctionsHelper->fflush($this->filePointer);
}
}
|
[
"protected",
"function",
"addRowToWriter",
"(",
"array",
"$",
"dataRow",
",",
"$",
"style",
")",
"{",
"$",
"wasWriteSuccessful",
"=",
"$",
"this",
"->",
"globalFunctionsHelper",
"->",
"fputcsv",
"(",
"$",
"this",
"->",
"filePointer",
",",
"$",
"dataRow",
",",
"$",
"this",
"->",
"fieldDelimiter",
",",
"$",
"this",
"->",
"fieldEnclosure",
")",
";",
"if",
"(",
"$",
"wasWriteSuccessful",
"===",
"false",
")",
"{",
"throw",
"new",
"IOException",
"(",
"'Unable to write data'",
")",
";",
"}",
"$",
"this",
"->",
"lastWrittenRowIndex",
"++",
";",
"if",
"(",
"$",
"this",
"->",
"lastWrittenRowIndex",
"%",
"self",
"::",
"FLUSH_THRESHOLD",
"===",
"0",
")",
"{",
"$",
"this",
"->",
"globalFunctionsHelper",
"->",
"fflush",
"(",
"$",
"this",
"->",
"filePointer",
")",
";",
"}",
"}"
] |
Adds data to the currently opened writer.
@param array $dataRow Array containing data to be written.
Example $dataRow = ['data1', 1234, null, '', 'data5'];
@param \Box\Spout\Writer\Style\Style $style Ignored here since CSV does not support styling.
@return void
@throws \Box\Spout\Common\Exception\IOException If unable to write data
|
[
"Adds",
"data",
"to",
"the",
"currently",
"opened",
"writer",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/spout/src/Spout/Writer/CSV/Writer.php#L95-L106
|
215,583
|
moodle/moodle
|
lib/dtl/database_importer.php
|
database_importer.begin_table_import
|
public function begin_table_import($tablename, $schemaHash) {
if ($this->transactionmode == 'pertable') {
$this->transaction = $this->mdb->start_delegated_transaction();
}
if (!$table = $this->schema->getTable($tablename)) {
throw new dbtransfer_exception('unknowntableexception', $tablename);
}
if ($schemaHash != $table->getHash()) {
throw new dbtransfer_exception('differenttableexception', $tablename);
}
// this should not happen, unless someone drops tables after import started
if (!$this->manager->table_exists($table)) {
throw new ddl_table_missing_exception($tablename);
}
$this->mdb->delete_records($tablename);
}
|
php
|
public function begin_table_import($tablename, $schemaHash) {
if ($this->transactionmode == 'pertable') {
$this->transaction = $this->mdb->start_delegated_transaction();
}
if (!$table = $this->schema->getTable($tablename)) {
throw new dbtransfer_exception('unknowntableexception', $tablename);
}
if ($schemaHash != $table->getHash()) {
throw new dbtransfer_exception('differenttableexception', $tablename);
}
// this should not happen, unless someone drops tables after import started
if (!$this->manager->table_exists($table)) {
throw new ddl_table_missing_exception($tablename);
}
$this->mdb->delete_records($tablename);
}
|
[
"public",
"function",
"begin_table_import",
"(",
"$",
"tablename",
",",
"$",
"schemaHash",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"transactionmode",
"==",
"'pertable'",
")",
"{",
"$",
"this",
"->",
"transaction",
"=",
"$",
"this",
"->",
"mdb",
"->",
"start_delegated_transaction",
"(",
")",
";",
"}",
"if",
"(",
"!",
"$",
"table",
"=",
"$",
"this",
"->",
"schema",
"->",
"getTable",
"(",
"$",
"tablename",
")",
")",
"{",
"throw",
"new",
"dbtransfer_exception",
"(",
"'unknowntableexception'",
",",
"$",
"tablename",
")",
";",
"}",
"if",
"(",
"$",
"schemaHash",
"!=",
"$",
"table",
"->",
"getHash",
"(",
")",
")",
"{",
"throw",
"new",
"dbtransfer_exception",
"(",
"'differenttableexception'",
",",
"$",
"tablename",
")",
";",
"}",
"// this should not happen, unless someone drops tables after import started",
"if",
"(",
"!",
"$",
"this",
"->",
"manager",
"->",
"table_exists",
"(",
"$",
"table",
")",
")",
"{",
"throw",
"new",
"ddl_table_missing_exception",
"(",
"$",
"tablename",
")",
";",
"}",
"$",
"this",
"->",
"mdb",
"->",
"delete_records",
"(",
"$",
"tablename",
")",
";",
"}"
] |
Callback function. Should be called only once per table import operation,
before any table changes are made. It will delete all table data.
@throws dbtransfer_exception an unknown table import is attempted
@throws ddl_table_missing_exception if the table is missing
@param string $tablename - the name of the table that will be imported
@param string $schemaHash - the hash of the xmldb_table schema of the table
@return void
|
[
"Callback",
"function",
".",
"Should",
"be",
"called",
"only",
"once",
"per",
"table",
"import",
"operation",
"before",
"any",
"table",
"changes",
"are",
"made",
".",
"It",
"will",
"delete",
"all",
"table",
"data",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/dtl/database_importer.php#L142-L157
|
215,584
|
moodle/moodle
|
lib/dtl/database_importer.php
|
database_importer.finish_table_import
|
public function finish_table_import($tablename) {
$table = $this->schema->getTable($tablename);
$fields = $table->getFields();
foreach ($fields as $field) {
if ($field->getSequence()) {
$this->manager->reset_sequence($tablename);
return;
}
}
if ($this->transactionmode == 'pertable') {
$this->transaction->allow_commit();
}
}
|
php
|
public function finish_table_import($tablename) {
$table = $this->schema->getTable($tablename);
$fields = $table->getFields();
foreach ($fields as $field) {
if ($field->getSequence()) {
$this->manager->reset_sequence($tablename);
return;
}
}
if ($this->transactionmode == 'pertable') {
$this->transaction->allow_commit();
}
}
|
[
"public",
"function",
"finish_table_import",
"(",
"$",
"tablename",
")",
"{",
"$",
"table",
"=",
"$",
"this",
"->",
"schema",
"->",
"getTable",
"(",
"$",
"tablename",
")",
";",
"$",
"fields",
"=",
"$",
"table",
"->",
"getFields",
"(",
")",
";",
"foreach",
"(",
"$",
"fields",
"as",
"$",
"field",
")",
"{",
"if",
"(",
"$",
"field",
"->",
"getSequence",
"(",
")",
")",
"{",
"$",
"this",
"->",
"manager",
"->",
"reset_sequence",
"(",
"$",
"tablename",
")",
";",
"return",
";",
"}",
"}",
"if",
"(",
"$",
"this",
"->",
"transactionmode",
"==",
"'pertable'",
")",
"{",
"$",
"this",
"->",
"transaction",
"->",
"allow_commit",
"(",
")",
";",
"}",
"}"
] |
Callback function. Should be called only once per table import operation,
after all table changes are made. It will reset table sequences if any.
@param string $tablename
@return void
|
[
"Callback",
"function",
".",
"Should",
"be",
"called",
"only",
"once",
"per",
"table",
"import",
"operation",
"after",
"all",
"table",
"changes",
"are",
"made",
".",
"It",
"will",
"reset",
"table",
"sequences",
"if",
"any",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/dtl/database_importer.php#L165-L177
|
215,585
|
moodle/moodle
|
question/renderer.php
|
core_question_bank_renderer.extra_horizontal_navigation
|
public function extra_horizontal_navigation() {
// Horizontal navigation for question bank.
if ($questionnode = $this->page->settingsnav->find("questionbank", \navigation_node::TYPE_CONTAINER)) {
if ($children = $questionnode->children) {
$tabs = [];
foreach ($children as $key => $node) {
$tabs[] = new \tabobject($node->key, $node->action, $node->text);
}
$active = $questionnode->find_active_node()->key;
return \html_writer::div(print_tabs([$tabs], $active, null, null, true), 'questionbank-navigation');
}
}
return '';
}
|
php
|
public function extra_horizontal_navigation() {
// Horizontal navigation for question bank.
if ($questionnode = $this->page->settingsnav->find("questionbank", \navigation_node::TYPE_CONTAINER)) {
if ($children = $questionnode->children) {
$tabs = [];
foreach ($children as $key => $node) {
$tabs[] = new \tabobject($node->key, $node->action, $node->text);
}
$active = $questionnode->find_active_node()->key;
return \html_writer::div(print_tabs([$tabs], $active, null, null, true), 'questionbank-navigation');
}
}
return '';
}
|
[
"public",
"function",
"extra_horizontal_navigation",
"(",
")",
"{",
"// Horizontal navigation for question bank.",
"if",
"(",
"$",
"questionnode",
"=",
"$",
"this",
"->",
"page",
"->",
"settingsnav",
"->",
"find",
"(",
"\"questionbank\"",
",",
"\\",
"navigation_node",
"::",
"TYPE_CONTAINER",
")",
")",
"{",
"if",
"(",
"$",
"children",
"=",
"$",
"questionnode",
"->",
"children",
")",
"{",
"$",
"tabs",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"children",
"as",
"$",
"key",
"=>",
"$",
"node",
")",
"{",
"$",
"tabs",
"[",
"]",
"=",
"new",
"\\",
"tabobject",
"(",
"$",
"node",
"->",
"key",
",",
"$",
"node",
"->",
"action",
",",
"$",
"node",
"->",
"text",
")",
";",
"}",
"$",
"active",
"=",
"$",
"questionnode",
"->",
"find_active_node",
"(",
")",
"->",
"key",
";",
"return",
"\\",
"html_writer",
"::",
"div",
"(",
"print_tabs",
"(",
"[",
"$",
"tabs",
"]",
",",
"$",
"active",
",",
"null",
",",
"null",
",",
"true",
")",
",",
"'questionbank-navigation'",
")",
";",
"}",
"}",
"return",
"''",
";",
"}"
] |
Display additional navigation if needed.
@return string
|
[
"Display",
"additional",
"navigation",
"if",
"needed",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/question/renderer.php#L43-L56
|
215,586
|
moodle/moodle
|
question/renderer.php
|
core_question_bank_renderer.qtype_icon
|
public function qtype_icon($qtype) {
$qtype = question_bank::get_qtype($qtype, false);
$namestr = $qtype->local_name();
return $this->image_icon('icon', $namestr, $qtype->plugin_name(), array('title' => $namestr));
}
|
php
|
public function qtype_icon($qtype) {
$qtype = question_bank::get_qtype($qtype, false);
$namestr = $qtype->local_name();
return $this->image_icon('icon', $namestr, $qtype->plugin_name(), array('title' => $namestr));
}
|
[
"public",
"function",
"qtype_icon",
"(",
"$",
"qtype",
")",
"{",
"$",
"qtype",
"=",
"question_bank",
"::",
"get_qtype",
"(",
"$",
"qtype",
",",
"false",
")",
";",
"$",
"namestr",
"=",
"$",
"qtype",
"->",
"local_name",
"(",
")",
";",
"return",
"$",
"this",
"->",
"image_icon",
"(",
"'icon'",
",",
"$",
"namestr",
",",
"$",
"qtype",
"->",
"plugin_name",
"(",
")",
",",
"array",
"(",
"'title'",
"=>",
"$",
"namestr",
")",
")",
";",
"}"
] |
Output the icon for a question type.
@param string $qtype the question type.
@return string HTML fragment.
|
[
"Output",
"the",
"icon",
"for",
"a",
"question",
"type",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/question/renderer.php#L64-L69
|
215,587
|
moodle/moodle
|
enrol/lti/classes/task/sync_members.php
|
sync_members.execute
|
public function execute() {
if (!is_enabled_auth('lti')) {
mtrace('Skipping task - ' . get_string('pluginnotenabled', 'auth', get_string('pluginname', 'auth_lti')));
return;
}
// Check if the enrolment plugin is disabled - isn't really necessary as the task should not run if
// the plugin is disabled, but there is no harm in making sure core hasn't done something wrong.
if (!enrol_is_enabled('lti')) {
mtrace('Skipping task - ' . get_string('enrolisdisabled', 'enrol_lti'));
return;
}
$this->dataconnector = new data_connector();
// Get all the enabled tools.
$tools = helper::get_lti_tools(array('status' => ENROL_INSTANCE_ENABLED, 'membersync' => 1));
foreach ($tools as $tool) {
mtrace("Starting - Member sync for published tool '$tool->id' for course '$tool->courseid'.");
// Variables to keep track of information to display later.
$usercount = 0;
$enrolcount = 0;
$unenrolcount = 0;
// Fetch consumer records mapped to this tool.
$consumers = $this->dataconnector->get_consumers_mapped_to_tool($tool->id);
// Perform processing for each consumer.
foreach ($consumers as $consumer) {
mtrace("Requesting membership service for the tool consumer '{$consumer->getRecordId()}'");
// Get members through this tool consumer.
$members = $this->fetch_members_from_consumer($consumer);
// Check if we were able to fetch the members.
if ($members === false) {
mtrace("Skipping - Membership service request failed.\n");
continue;
}
// Fetched members count.
$membercount = count($members);
mtrace("$membercount members received.\n");
// Process member information.
list($usercount, $enrolcount) = $this->sync_member_information($tool, $consumer, $members);
}
// Now we check if we have to unenrol users who were not listed.
if ($this->should_sync_unenrol($tool->membersyncmode)) {
$unenrolcount = $this->sync_unenrol($tool);
}
mtrace("Completed - Synced members for tool '$tool->id' in the course '$tool->courseid'. " .
"Processed $usercount users; enrolled $enrolcount members; unenrolled $unenrolcount members.\n");
}
// Sync the user profile photos.
mtrace("Started - Syncing user profile images.");
$countsyncedimages = $this->sync_profile_images();
mtrace("Completed - Synced $countsyncedimages profile images.");
}
|
php
|
public function execute() {
if (!is_enabled_auth('lti')) {
mtrace('Skipping task - ' . get_string('pluginnotenabled', 'auth', get_string('pluginname', 'auth_lti')));
return;
}
// Check if the enrolment plugin is disabled - isn't really necessary as the task should not run if
// the plugin is disabled, but there is no harm in making sure core hasn't done something wrong.
if (!enrol_is_enabled('lti')) {
mtrace('Skipping task - ' . get_string('enrolisdisabled', 'enrol_lti'));
return;
}
$this->dataconnector = new data_connector();
// Get all the enabled tools.
$tools = helper::get_lti_tools(array('status' => ENROL_INSTANCE_ENABLED, 'membersync' => 1));
foreach ($tools as $tool) {
mtrace("Starting - Member sync for published tool '$tool->id' for course '$tool->courseid'.");
// Variables to keep track of information to display later.
$usercount = 0;
$enrolcount = 0;
$unenrolcount = 0;
// Fetch consumer records mapped to this tool.
$consumers = $this->dataconnector->get_consumers_mapped_to_tool($tool->id);
// Perform processing for each consumer.
foreach ($consumers as $consumer) {
mtrace("Requesting membership service for the tool consumer '{$consumer->getRecordId()}'");
// Get members through this tool consumer.
$members = $this->fetch_members_from_consumer($consumer);
// Check if we were able to fetch the members.
if ($members === false) {
mtrace("Skipping - Membership service request failed.\n");
continue;
}
// Fetched members count.
$membercount = count($members);
mtrace("$membercount members received.\n");
// Process member information.
list($usercount, $enrolcount) = $this->sync_member_information($tool, $consumer, $members);
}
// Now we check if we have to unenrol users who were not listed.
if ($this->should_sync_unenrol($tool->membersyncmode)) {
$unenrolcount = $this->sync_unenrol($tool);
}
mtrace("Completed - Synced members for tool '$tool->id' in the course '$tool->courseid'. " .
"Processed $usercount users; enrolled $enrolcount members; unenrolled $unenrolcount members.\n");
}
// Sync the user profile photos.
mtrace("Started - Syncing user profile images.");
$countsyncedimages = $this->sync_profile_images();
mtrace("Completed - Synced $countsyncedimages profile images.");
}
|
[
"public",
"function",
"execute",
"(",
")",
"{",
"if",
"(",
"!",
"is_enabled_auth",
"(",
"'lti'",
")",
")",
"{",
"mtrace",
"(",
"'Skipping task - '",
".",
"get_string",
"(",
"'pluginnotenabled'",
",",
"'auth'",
",",
"get_string",
"(",
"'pluginname'",
",",
"'auth_lti'",
")",
")",
")",
";",
"return",
";",
"}",
"// Check if the enrolment plugin is disabled - isn't really necessary as the task should not run if",
"// the plugin is disabled, but there is no harm in making sure core hasn't done something wrong.",
"if",
"(",
"!",
"enrol_is_enabled",
"(",
"'lti'",
")",
")",
"{",
"mtrace",
"(",
"'Skipping task - '",
".",
"get_string",
"(",
"'enrolisdisabled'",
",",
"'enrol_lti'",
")",
")",
";",
"return",
";",
"}",
"$",
"this",
"->",
"dataconnector",
"=",
"new",
"data_connector",
"(",
")",
";",
"// Get all the enabled tools.",
"$",
"tools",
"=",
"helper",
"::",
"get_lti_tools",
"(",
"array",
"(",
"'status'",
"=>",
"ENROL_INSTANCE_ENABLED",
",",
"'membersync'",
"=>",
"1",
")",
")",
";",
"foreach",
"(",
"$",
"tools",
"as",
"$",
"tool",
")",
"{",
"mtrace",
"(",
"\"Starting - Member sync for published tool '$tool->id' for course '$tool->courseid'.\"",
")",
";",
"// Variables to keep track of information to display later.",
"$",
"usercount",
"=",
"0",
";",
"$",
"enrolcount",
"=",
"0",
";",
"$",
"unenrolcount",
"=",
"0",
";",
"// Fetch consumer records mapped to this tool.",
"$",
"consumers",
"=",
"$",
"this",
"->",
"dataconnector",
"->",
"get_consumers_mapped_to_tool",
"(",
"$",
"tool",
"->",
"id",
")",
";",
"// Perform processing for each consumer.",
"foreach",
"(",
"$",
"consumers",
"as",
"$",
"consumer",
")",
"{",
"mtrace",
"(",
"\"Requesting membership service for the tool consumer '{$consumer->getRecordId()}'\"",
")",
";",
"// Get members through this tool consumer.",
"$",
"members",
"=",
"$",
"this",
"->",
"fetch_members_from_consumer",
"(",
"$",
"consumer",
")",
";",
"// Check if we were able to fetch the members.",
"if",
"(",
"$",
"members",
"===",
"false",
")",
"{",
"mtrace",
"(",
"\"Skipping - Membership service request failed.\\n\"",
")",
";",
"continue",
";",
"}",
"// Fetched members count.",
"$",
"membercount",
"=",
"count",
"(",
"$",
"members",
")",
";",
"mtrace",
"(",
"\"$membercount members received.\\n\"",
")",
";",
"// Process member information.",
"list",
"(",
"$",
"usercount",
",",
"$",
"enrolcount",
")",
"=",
"$",
"this",
"->",
"sync_member_information",
"(",
"$",
"tool",
",",
"$",
"consumer",
",",
"$",
"members",
")",
";",
"}",
"// Now we check if we have to unenrol users who were not listed.",
"if",
"(",
"$",
"this",
"->",
"should_sync_unenrol",
"(",
"$",
"tool",
"->",
"membersyncmode",
")",
")",
"{",
"$",
"unenrolcount",
"=",
"$",
"this",
"->",
"sync_unenrol",
"(",
"$",
"tool",
")",
";",
"}",
"mtrace",
"(",
"\"Completed - Synced members for tool '$tool->id' in the course '$tool->courseid'. \"",
".",
"\"Processed $usercount users; enrolled $enrolcount members; unenrolled $unenrolcount members.\\n\"",
")",
";",
"}",
"// Sync the user profile photos.",
"mtrace",
"(",
"\"Started - Syncing user profile images.\"",
")",
";",
"$",
"countsyncedimages",
"=",
"$",
"this",
"->",
"sync_profile_images",
"(",
")",
";",
"mtrace",
"(",
"\"Completed - Synced $countsyncedimages profile images.\"",
")",
";",
"}"
] |
Performs the synchronisation of members.
|
[
"Performs",
"the",
"synchronisation",
"of",
"members",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/enrol/lti/classes/task/sync_members.php#L71-L133
|
215,588
|
moodle/moodle
|
enrol/lti/classes/task/sync_members.php
|
sync_members.fetch_members_from_consumer
|
protected function fetch_members_from_consumer(ToolConsumer $consumer) {
$dataconnector = $this->dataconnector;
// Get membership URL template from consumer profile data.
$defaultmembershipsurl = null;
if (isset($consumer->profile->service_offered)) {
$servicesoffered = $consumer->profile->service_offered;
foreach ($servicesoffered as $service) {
if (isset($service->{'@id'}) && strpos($service->{'@id'}, 'tcp:ToolProxyBindingMemberships') !== false &&
isset($service->endpoint)) {
$defaultmembershipsurl = $service->endpoint;
if (isset($consumer->profile->product_instance->product_info->product_family->vendor->code)) {
$vendorcode = $consumer->profile->product_instance->product_info->product_family->vendor->code;
$defaultmembershipsurl = str_replace('{vendor_code}', $vendorcode, $defaultmembershipsurl);
}
$defaultmembershipsurl = str_replace('{product_code}', $consumer->getKey(), $defaultmembershipsurl);
break;
}
}
}
$members = false;
// Fetch the resource link linked to the consumer.
$resourcelink = $dataconnector->get_resourcelink_from_consumer($consumer);
if ($resourcelink !== null) {
// Try to perform a membership service request using this resource link.
$members = $this->do_resourcelink_membership_request($resourcelink);
}
// If membership service can't be performed through resource link, fallback through context memberships.
if ($members === false) {
// Fetch context records that are mapped to this ToolConsumer.
$contexts = $dataconnector->get_contexts_from_consumer($consumer);
// Perform membership service request for each of these contexts.
foreach ($contexts as $context) {
$contextmembership = $this->do_context_membership_request($context, $resourcelink, $defaultmembershipsurl);
if ($contextmembership) {
// Add $contextmembership contents to $members array.
if (is_array($members)) {
$members = array_merge($members, $contextmembership);
} else {
$members = $contextmembership;
}
}
}
}
return $members;
}
|
php
|
protected function fetch_members_from_consumer(ToolConsumer $consumer) {
$dataconnector = $this->dataconnector;
// Get membership URL template from consumer profile data.
$defaultmembershipsurl = null;
if (isset($consumer->profile->service_offered)) {
$servicesoffered = $consumer->profile->service_offered;
foreach ($servicesoffered as $service) {
if (isset($service->{'@id'}) && strpos($service->{'@id'}, 'tcp:ToolProxyBindingMemberships') !== false &&
isset($service->endpoint)) {
$defaultmembershipsurl = $service->endpoint;
if (isset($consumer->profile->product_instance->product_info->product_family->vendor->code)) {
$vendorcode = $consumer->profile->product_instance->product_info->product_family->vendor->code;
$defaultmembershipsurl = str_replace('{vendor_code}', $vendorcode, $defaultmembershipsurl);
}
$defaultmembershipsurl = str_replace('{product_code}', $consumer->getKey(), $defaultmembershipsurl);
break;
}
}
}
$members = false;
// Fetch the resource link linked to the consumer.
$resourcelink = $dataconnector->get_resourcelink_from_consumer($consumer);
if ($resourcelink !== null) {
// Try to perform a membership service request using this resource link.
$members = $this->do_resourcelink_membership_request($resourcelink);
}
// If membership service can't be performed through resource link, fallback through context memberships.
if ($members === false) {
// Fetch context records that are mapped to this ToolConsumer.
$contexts = $dataconnector->get_contexts_from_consumer($consumer);
// Perform membership service request for each of these contexts.
foreach ($contexts as $context) {
$contextmembership = $this->do_context_membership_request($context, $resourcelink, $defaultmembershipsurl);
if ($contextmembership) {
// Add $contextmembership contents to $members array.
if (is_array($members)) {
$members = array_merge($members, $contextmembership);
} else {
$members = $contextmembership;
}
}
}
}
return $members;
}
|
[
"protected",
"function",
"fetch_members_from_consumer",
"(",
"ToolConsumer",
"$",
"consumer",
")",
"{",
"$",
"dataconnector",
"=",
"$",
"this",
"->",
"dataconnector",
";",
"// Get membership URL template from consumer profile data.",
"$",
"defaultmembershipsurl",
"=",
"null",
";",
"if",
"(",
"isset",
"(",
"$",
"consumer",
"->",
"profile",
"->",
"service_offered",
")",
")",
"{",
"$",
"servicesoffered",
"=",
"$",
"consumer",
"->",
"profile",
"->",
"service_offered",
";",
"foreach",
"(",
"$",
"servicesoffered",
"as",
"$",
"service",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"service",
"->",
"{",
"'@id'",
"}",
")",
"&&",
"strpos",
"(",
"$",
"service",
"->",
"{",
"'@id'",
"}",
",",
"'tcp:ToolProxyBindingMemberships'",
")",
"!==",
"false",
"&&",
"isset",
"(",
"$",
"service",
"->",
"endpoint",
")",
")",
"{",
"$",
"defaultmembershipsurl",
"=",
"$",
"service",
"->",
"endpoint",
";",
"if",
"(",
"isset",
"(",
"$",
"consumer",
"->",
"profile",
"->",
"product_instance",
"->",
"product_info",
"->",
"product_family",
"->",
"vendor",
"->",
"code",
")",
")",
"{",
"$",
"vendorcode",
"=",
"$",
"consumer",
"->",
"profile",
"->",
"product_instance",
"->",
"product_info",
"->",
"product_family",
"->",
"vendor",
"->",
"code",
";",
"$",
"defaultmembershipsurl",
"=",
"str_replace",
"(",
"'{vendor_code}'",
",",
"$",
"vendorcode",
",",
"$",
"defaultmembershipsurl",
")",
";",
"}",
"$",
"defaultmembershipsurl",
"=",
"str_replace",
"(",
"'{product_code}'",
",",
"$",
"consumer",
"->",
"getKey",
"(",
")",
",",
"$",
"defaultmembershipsurl",
")",
";",
"break",
";",
"}",
"}",
"}",
"$",
"members",
"=",
"false",
";",
"// Fetch the resource link linked to the consumer.",
"$",
"resourcelink",
"=",
"$",
"dataconnector",
"->",
"get_resourcelink_from_consumer",
"(",
"$",
"consumer",
")",
";",
"if",
"(",
"$",
"resourcelink",
"!==",
"null",
")",
"{",
"// Try to perform a membership service request using this resource link.",
"$",
"members",
"=",
"$",
"this",
"->",
"do_resourcelink_membership_request",
"(",
"$",
"resourcelink",
")",
";",
"}",
"// If membership service can't be performed through resource link, fallback through context memberships.",
"if",
"(",
"$",
"members",
"===",
"false",
")",
"{",
"// Fetch context records that are mapped to this ToolConsumer.",
"$",
"contexts",
"=",
"$",
"dataconnector",
"->",
"get_contexts_from_consumer",
"(",
"$",
"consumer",
")",
";",
"// Perform membership service request for each of these contexts.",
"foreach",
"(",
"$",
"contexts",
"as",
"$",
"context",
")",
"{",
"$",
"contextmembership",
"=",
"$",
"this",
"->",
"do_context_membership_request",
"(",
"$",
"context",
",",
"$",
"resourcelink",
",",
"$",
"defaultmembershipsurl",
")",
";",
"if",
"(",
"$",
"contextmembership",
")",
"{",
"// Add $contextmembership contents to $members array.",
"if",
"(",
"is_array",
"(",
"$",
"members",
")",
")",
"{",
"$",
"members",
"=",
"array_merge",
"(",
"$",
"members",
",",
"$",
"contextmembership",
")",
";",
"}",
"else",
"{",
"$",
"members",
"=",
"$",
"contextmembership",
";",
"}",
"}",
"}",
"}",
"return",
"$",
"members",
";",
"}"
] |
Fetches the members that belong to a ToolConsumer.
@param ToolConsumer $consumer
@return bool|User[]
|
[
"Fetches",
"the",
"members",
"that",
"belong",
"to",
"a",
"ToolConsumer",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/enrol/lti/classes/task/sync_members.php#L141-L191
|
215,589
|
moodle/moodle
|
enrol/lti/classes/task/sync_members.php
|
sync_members.sync_member_information
|
protected function sync_member_information(stdClass $tool, ToolConsumer $consumer, $members) {
global $DB;
$usercount = 0;
$enrolcount = 0;
// Process member information.
foreach ($members as $member) {
$usercount++;
// Set the user data.
$user = new stdClass();
$user->username = helper::create_username($consumer->getKey(), $member->ltiUserId);
$user->firstname = core_user::clean_field($member->firstname, 'firstname');
$user->lastname = core_user::clean_field($member->lastname, 'lastname');
$user->email = core_user::clean_field($member->email, 'email');
// Get the user data from the LTI consumer.
$user = helper::assign_user_tool_data($tool, $user);
$dbuser = core_user::get_user_by_username($user->username, 'id');
if ($dbuser) {
// If email is empty remove it, so we don't update the user with an empty email.
if (empty($user->email)) {
unset($user->email);
}
$user->id = $dbuser->id;
user_update_user($user);
// Add the information to the necessary arrays.
if (!in_array($user->id, $this->currentusers)) {
$this->currentusers[] = $user->id;
}
$this->userphotos[$user->id] = $member->image;
} else {
if ($this->should_sync_enrol($tool->membersyncmode)) {
// If the email was stripped/not set then fill it with a default one. This
// stops the user from being redirected to edit their profile page.
if (empty($user->email)) {
$user->email = $user->username . "@example.com";
}
$user->auth = 'lti';
$user->id = user_create_user($user);
// Add the information to the necessary arrays.
$this->currentusers[] = $user->id;
$this->userphotos[$user->id] = $member->image;
}
}
// Sync enrolments.
if ($this->should_sync_enrol($tool->membersyncmode)) {
// Enrol the user in the course.
if (helper::enrol_user($tool, $user->id) === helper::ENROLMENT_SUCCESSFUL) {
// Increment enrol count.
$enrolcount++;
}
// Check if this user has already been registered in the enrol_lti_users table.
if (!$DB->record_exists('enrol_lti_users', ['toolid' => $tool->id, 'userid' => $user->id])) {
// Create an initial enrol_lti_user record that we can use later when syncing grades and members.
$userlog = new stdClass();
$userlog->userid = $user->id;
$userlog->toolid = $tool->id;
$userlog->consumerkey = $consumer->getKey();
$DB->insert_record('enrol_lti_users', $userlog);
}
}
}
return [$usercount, $enrolcount];
}
|
php
|
protected function sync_member_information(stdClass $tool, ToolConsumer $consumer, $members) {
global $DB;
$usercount = 0;
$enrolcount = 0;
// Process member information.
foreach ($members as $member) {
$usercount++;
// Set the user data.
$user = new stdClass();
$user->username = helper::create_username($consumer->getKey(), $member->ltiUserId);
$user->firstname = core_user::clean_field($member->firstname, 'firstname');
$user->lastname = core_user::clean_field($member->lastname, 'lastname');
$user->email = core_user::clean_field($member->email, 'email');
// Get the user data from the LTI consumer.
$user = helper::assign_user_tool_data($tool, $user);
$dbuser = core_user::get_user_by_username($user->username, 'id');
if ($dbuser) {
// If email is empty remove it, so we don't update the user with an empty email.
if (empty($user->email)) {
unset($user->email);
}
$user->id = $dbuser->id;
user_update_user($user);
// Add the information to the necessary arrays.
if (!in_array($user->id, $this->currentusers)) {
$this->currentusers[] = $user->id;
}
$this->userphotos[$user->id] = $member->image;
} else {
if ($this->should_sync_enrol($tool->membersyncmode)) {
// If the email was stripped/not set then fill it with a default one. This
// stops the user from being redirected to edit their profile page.
if (empty($user->email)) {
$user->email = $user->username . "@example.com";
}
$user->auth = 'lti';
$user->id = user_create_user($user);
// Add the information to the necessary arrays.
$this->currentusers[] = $user->id;
$this->userphotos[$user->id] = $member->image;
}
}
// Sync enrolments.
if ($this->should_sync_enrol($tool->membersyncmode)) {
// Enrol the user in the course.
if (helper::enrol_user($tool, $user->id) === helper::ENROLMENT_SUCCESSFUL) {
// Increment enrol count.
$enrolcount++;
}
// Check if this user has already been registered in the enrol_lti_users table.
if (!$DB->record_exists('enrol_lti_users', ['toolid' => $tool->id, 'userid' => $user->id])) {
// Create an initial enrol_lti_user record that we can use later when syncing grades and members.
$userlog = new stdClass();
$userlog->userid = $user->id;
$userlog->toolid = $tool->id;
$userlog->consumerkey = $consumer->getKey();
$DB->insert_record('enrol_lti_users', $userlog);
}
}
}
return [$usercount, $enrolcount];
}
|
[
"protected",
"function",
"sync_member_information",
"(",
"stdClass",
"$",
"tool",
",",
"ToolConsumer",
"$",
"consumer",
",",
"$",
"members",
")",
"{",
"global",
"$",
"DB",
";",
"$",
"usercount",
"=",
"0",
";",
"$",
"enrolcount",
"=",
"0",
";",
"// Process member information.",
"foreach",
"(",
"$",
"members",
"as",
"$",
"member",
")",
"{",
"$",
"usercount",
"++",
";",
"// Set the user data.",
"$",
"user",
"=",
"new",
"stdClass",
"(",
")",
";",
"$",
"user",
"->",
"username",
"=",
"helper",
"::",
"create_username",
"(",
"$",
"consumer",
"->",
"getKey",
"(",
")",
",",
"$",
"member",
"->",
"ltiUserId",
")",
";",
"$",
"user",
"->",
"firstname",
"=",
"core_user",
"::",
"clean_field",
"(",
"$",
"member",
"->",
"firstname",
",",
"'firstname'",
")",
";",
"$",
"user",
"->",
"lastname",
"=",
"core_user",
"::",
"clean_field",
"(",
"$",
"member",
"->",
"lastname",
",",
"'lastname'",
")",
";",
"$",
"user",
"->",
"email",
"=",
"core_user",
"::",
"clean_field",
"(",
"$",
"member",
"->",
"email",
",",
"'email'",
")",
";",
"// Get the user data from the LTI consumer.",
"$",
"user",
"=",
"helper",
"::",
"assign_user_tool_data",
"(",
"$",
"tool",
",",
"$",
"user",
")",
";",
"$",
"dbuser",
"=",
"core_user",
"::",
"get_user_by_username",
"(",
"$",
"user",
"->",
"username",
",",
"'id'",
")",
";",
"if",
"(",
"$",
"dbuser",
")",
"{",
"// If email is empty remove it, so we don't update the user with an empty email.",
"if",
"(",
"empty",
"(",
"$",
"user",
"->",
"email",
")",
")",
"{",
"unset",
"(",
"$",
"user",
"->",
"email",
")",
";",
"}",
"$",
"user",
"->",
"id",
"=",
"$",
"dbuser",
"->",
"id",
";",
"user_update_user",
"(",
"$",
"user",
")",
";",
"// Add the information to the necessary arrays.",
"if",
"(",
"!",
"in_array",
"(",
"$",
"user",
"->",
"id",
",",
"$",
"this",
"->",
"currentusers",
")",
")",
"{",
"$",
"this",
"->",
"currentusers",
"[",
"]",
"=",
"$",
"user",
"->",
"id",
";",
"}",
"$",
"this",
"->",
"userphotos",
"[",
"$",
"user",
"->",
"id",
"]",
"=",
"$",
"member",
"->",
"image",
";",
"}",
"else",
"{",
"if",
"(",
"$",
"this",
"->",
"should_sync_enrol",
"(",
"$",
"tool",
"->",
"membersyncmode",
")",
")",
"{",
"// If the email was stripped/not set then fill it with a default one. This",
"// stops the user from being redirected to edit their profile page.",
"if",
"(",
"empty",
"(",
"$",
"user",
"->",
"email",
")",
")",
"{",
"$",
"user",
"->",
"email",
"=",
"$",
"user",
"->",
"username",
".",
"\"@example.com\"",
";",
"}",
"$",
"user",
"->",
"auth",
"=",
"'lti'",
";",
"$",
"user",
"->",
"id",
"=",
"user_create_user",
"(",
"$",
"user",
")",
";",
"// Add the information to the necessary arrays.",
"$",
"this",
"->",
"currentusers",
"[",
"]",
"=",
"$",
"user",
"->",
"id",
";",
"$",
"this",
"->",
"userphotos",
"[",
"$",
"user",
"->",
"id",
"]",
"=",
"$",
"member",
"->",
"image",
";",
"}",
"}",
"// Sync enrolments.",
"if",
"(",
"$",
"this",
"->",
"should_sync_enrol",
"(",
"$",
"tool",
"->",
"membersyncmode",
")",
")",
"{",
"// Enrol the user in the course.",
"if",
"(",
"helper",
"::",
"enrol_user",
"(",
"$",
"tool",
",",
"$",
"user",
"->",
"id",
")",
"===",
"helper",
"::",
"ENROLMENT_SUCCESSFUL",
")",
"{",
"// Increment enrol count.",
"$",
"enrolcount",
"++",
";",
"}",
"// Check if this user has already been registered in the enrol_lti_users table.",
"if",
"(",
"!",
"$",
"DB",
"->",
"record_exists",
"(",
"'enrol_lti_users'",
",",
"[",
"'toolid'",
"=>",
"$",
"tool",
"->",
"id",
",",
"'userid'",
"=>",
"$",
"user",
"->",
"id",
"]",
")",
")",
"{",
"// Create an initial enrol_lti_user record that we can use later when syncing grades and members.",
"$",
"userlog",
"=",
"new",
"stdClass",
"(",
")",
";",
"$",
"userlog",
"->",
"userid",
"=",
"$",
"user",
"->",
"id",
";",
"$",
"userlog",
"->",
"toolid",
"=",
"$",
"tool",
"->",
"id",
";",
"$",
"userlog",
"->",
"consumerkey",
"=",
"$",
"consumer",
"->",
"getKey",
"(",
")",
";",
"$",
"DB",
"->",
"insert_record",
"(",
"'enrol_lti_users'",
",",
"$",
"userlog",
")",
";",
"}",
"}",
"}",
"return",
"[",
"$",
"usercount",
",",
"$",
"enrolcount",
"]",
";",
"}"
] |
Performs synchronisation of member information and enrolments.
@param stdClass $tool
@param ToolConsumer $consumer
@param User[] $members
@return array An array containing the number of members that were processed and the number of members that were enrolled.
|
[
"Performs",
"synchronisation",
"of",
"member",
"information",
"and",
"enrolments",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/enrol/lti/classes/task/sync_members.php#L221-L294
|
215,590
|
moodle/moodle
|
enrol/lti/classes/task/sync_members.php
|
sync_members.sync_unenrol
|
protected function sync_unenrol(stdClass $tool) {
global $DB;
$ltiplugin = enrol_get_plugin('lti');
if (!$this->should_sync_unenrol($tool->membersyncmode)) {
return 0;
}
if (empty($this->currentusers)) {
return 0;
}
$unenrolcount = 0;
$ltiusersrs = $DB->get_recordset('enrol_lti_users', array('toolid' => $tool->id), 'lastaccess DESC', 'userid');
// Go through the users and check if any were never listed, if so, remove them.
foreach ($ltiusersrs as $ltiuser) {
if (!in_array($ltiuser->userid, $this->currentusers)) {
$instance = new stdClass();
$instance->id = $tool->enrolid;
$instance->courseid = $tool->courseid;
$instance->enrol = 'lti';
$ltiplugin->unenrol_user($instance, $ltiuser->userid);
// Increment unenrol count.
$unenrolcount++;
}
}
$ltiusersrs->close();
return $unenrolcount;
}
|
php
|
protected function sync_unenrol(stdClass $tool) {
global $DB;
$ltiplugin = enrol_get_plugin('lti');
if (!$this->should_sync_unenrol($tool->membersyncmode)) {
return 0;
}
if (empty($this->currentusers)) {
return 0;
}
$unenrolcount = 0;
$ltiusersrs = $DB->get_recordset('enrol_lti_users', array('toolid' => $tool->id), 'lastaccess DESC', 'userid');
// Go through the users and check if any were never listed, if so, remove them.
foreach ($ltiusersrs as $ltiuser) {
if (!in_array($ltiuser->userid, $this->currentusers)) {
$instance = new stdClass();
$instance->id = $tool->enrolid;
$instance->courseid = $tool->courseid;
$instance->enrol = 'lti';
$ltiplugin->unenrol_user($instance, $ltiuser->userid);
// Increment unenrol count.
$unenrolcount++;
}
}
$ltiusersrs->close();
return $unenrolcount;
}
|
[
"protected",
"function",
"sync_unenrol",
"(",
"stdClass",
"$",
"tool",
")",
"{",
"global",
"$",
"DB",
";",
"$",
"ltiplugin",
"=",
"enrol_get_plugin",
"(",
"'lti'",
")",
";",
"if",
"(",
"!",
"$",
"this",
"->",
"should_sync_unenrol",
"(",
"$",
"tool",
"->",
"membersyncmode",
")",
")",
"{",
"return",
"0",
";",
"}",
"if",
"(",
"empty",
"(",
"$",
"this",
"->",
"currentusers",
")",
")",
"{",
"return",
"0",
";",
"}",
"$",
"unenrolcount",
"=",
"0",
";",
"$",
"ltiusersrs",
"=",
"$",
"DB",
"->",
"get_recordset",
"(",
"'enrol_lti_users'",
",",
"array",
"(",
"'toolid'",
"=>",
"$",
"tool",
"->",
"id",
")",
",",
"'lastaccess DESC'",
",",
"'userid'",
")",
";",
"// Go through the users and check if any were never listed, if so, remove them.",
"foreach",
"(",
"$",
"ltiusersrs",
"as",
"$",
"ltiuser",
")",
"{",
"if",
"(",
"!",
"in_array",
"(",
"$",
"ltiuser",
"->",
"userid",
",",
"$",
"this",
"->",
"currentusers",
")",
")",
"{",
"$",
"instance",
"=",
"new",
"stdClass",
"(",
")",
";",
"$",
"instance",
"->",
"id",
"=",
"$",
"tool",
"->",
"enrolid",
";",
"$",
"instance",
"->",
"courseid",
"=",
"$",
"tool",
"->",
"courseid",
";",
"$",
"instance",
"->",
"enrol",
"=",
"'lti'",
";",
"$",
"ltiplugin",
"->",
"unenrol_user",
"(",
"$",
"instance",
",",
"$",
"ltiuser",
"->",
"userid",
")",
";",
"// Increment unenrol count.",
"$",
"unenrolcount",
"++",
";",
"}",
"}",
"$",
"ltiusersrs",
"->",
"close",
"(",
")",
";",
"return",
"$",
"unenrolcount",
";",
"}"
] |
Performs unenrolment of users that are no longer enrolled in the consumer side.
@param stdClass $tool The tool record object.
@return int The number of users that have been unenrolled.
|
[
"Performs",
"unenrolment",
"of",
"users",
"that",
"are",
"no",
"longer",
"enrolled",
"in",
"the",
"consumer",
"side",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/enrol/lti/classes/task/sync_members.php#L302-L333
|
215,591
|
moodle/moodle
|
enrol/lti/classes/task/sync_members.php
|
sync_members.sync_profile_images
|
protected function sync_profile_images() {
$counter = 0;
foreach ($this->userphotos as $userid => $url) {
if ($url) {
$result = helper::update_user_profile_image($userid, $url);
if ($result === helper::PROFILE_IMAGE_UPDATE_SUCCESSFUL) {
$counter++;
mtrace("Profile image succesfully downloaded and created for user '$userid' from $url.");
} else {
mtrace($result);
}
}
}
return $counter;
}
|
php
|
protected function sync_profile_images() {
$counter = 0;
foreach ($this->userphotos as $userid => $url) {
if ($url) {
$result = helper::update_user_profile_image($userid, $url);
if ($result === helper::PROFILE_IMAGE_UPDATE_SUCCESSFUL) {
$counter++;
mtrace("Profile image succesfully downloaded and created for user '$userid' from $url.");
} else {
mtrace($result);
}
}
}
return $counter;
}
|
[
"protected",
"function",
"sync_profile_images",
"(",
")",
"{",
"$",
"counter",
"=",
"0",
";",
"foreach",
"(",
"$",
"this",
"->",
"userphotos",
"as",
"$",
"userid",
"=>",
"$",
"url",
")",
"{",
"if",
"(",
"$",
"url",
")",
"{",
"$",
"result",
"=",
"helper",
"::",
"update_user_profile_image",
"(",
"$",
"userid",
",",
"$",
"url",
")",
";",
"if",
"(",
"$",
"result",
"===",
"helper",
"::",
"PROFILE_IMAGE_UPDATE_SUCCESSFUL",
")",
"{",
"$",
"counter",
"++",
";",
"mtrace",
"(",
"\"Profile image succesfully downloaded and created for user '$userid' from $url.\"",
")",
";",
"}",
"else",
"{",
"mtrace",
"(",
"$",
"result",
")",
";",
"}",
"}",
"}",
"return",
"$",
"counter",
";",
"}"
] |
Performs synchronisation of user profile images.
|
[
"Performs",
"synchronisation",
"of",
"user",
"profile",
"images",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/enrol/lti/classes/task/sync_members.php#L338-L352
|
215,592
|
moodle/moodle
|
enrol/lti/classes/task/sync_members.php
|
sync_members.do_context_membership_request
|
protected function do_context_membership_request(Context $context, ResourceLink $resourcelink = null,
$membershipsurltemplate = '') {
$dataconnector = $this->dataconnector;
// Flag to indicate whether to save the context later.
$contextupdated = false;
// If membership URL is not set, try to generate using the default membership URL from the consumer profile.
if (!$context->hasMembershipService()) {
if (empty($membershipsurltemplate)) {
mtrace("Skipping - No membership service available.\n");
return false;
}
if ($resourcelink === null) {
$resourcelink = $dataconnector->get_resourcelink_from_context($context);
}
if ($resourcelink !== null) {
// Try to perform a membership service request using this resource link.
$resourcelinkmembers = $this->do_resourcelink_membership_request($resourcelink);
if ($resourcelinkmembers) {
// If we're able to fetch members using this resource link, return these.
return $resourcelinkmembers;
}
}
// If fetching memberships through resource link failed and we don't have a memberships URL, build one from template.
mtrace("'custom_context_memberships_url' not set. Fetching default template: $membershipsurltemplate");
$membershipsurl = $membershipsurltemplate;
// Check if we need to fetch tool code.
$needstoolcode = strpos($membershipsurl, '{tool_code}') !== false;
if ($needstoolcode) {
$toolcode = false;
// Fetch tool code from the resource link data.
$lisresultsourcedidjson = $resourcelink->getSetting('lis_result_sourcedid');
if ($lisresultsourcedidjson) {
$lisresultsourcedid = json_decode($lisresultsourcedidjson);
if (isset($lisresultsourcedid->data->typeid)) {
$toolcode = $lisresultsourcedid->data->typeid;
}
}
if ($toolcode) {
// Substitute fetched tool code value.
$membershipsurl = str_replace('{tool_code}', $toolcode, $membershipsurl);
} else {
// We're unable to determine the tool code. End this processing.
return false;
}
}
// Get context_id parameter and substitute, if applicable.
$membershipsurl = str_replace('{context_id}', $context->getId(), $membershipsurl);
// Get context_type and substitute, if applicable.
if (strpos($membershipsurl, '{context_type}') !== false) {
$contexttype = $context->type !== null ? $context->type : 'CourseSection';
$membershipsurl = str_replace('{context_type}', $contexttype, $membershipsurl);
}
// Save this URL for the context's custom_context_memberships_url setting.
$context->setSetting('custom_context_memberships_url', $membershipsurl);
$contextupdated = true;
}
// Perform membership service request.
$url = $context->getSetting('custom_context_memberships_url');
mtrace("Performing membership service request from context with URL {$url}.");
$members = $context->getMembership();
// Save the context if membership request succeeded and if it has been updated.
if ($members && $contextupdated) {
$context->save();
}
return $members;
}
|
php
|
protected function do_context_membership_request(Context $context, ResourceLink $resourcelink = null,
$membershipsurltemplate = '') {
$dataconnector = $this->dataconnector;
// Flag to indicate whether to save the context later.
$contextupdated = false;
// If membership URL is not set, try to generate using the default membership URL from the consumer profile.
if (!$context->hasMembershipService()) {
if (empty($membershipsurltemplate)) {
mtrace("Skipping - No membership service available.\n");
return false;
}
if ($resourcelink === null) {
$resourcelink = $dataconnector->get_resourcelink_from_context($context);
}
if ($resourcelink !== null) {
// Try to perform a membership service request using this resource link.
$resourcelinkmembers = $this->do_resourcelink_membership_request($resourcelink);
if ($resourcelinkmembers) {
// If we're able to fetch members using this resource link, return these.
return $resourcelinkmembers;
}
}
// If fetching memberships through resource link failed and we don't have a memberships URL, build one from template.
mtrace("'custom_context_memberships_url' not set. Fetching default template: $membershipsurltemplate");
$membershipsurl = $membershipsurltemplate;
// Check if we need to fetch tool code.
$needstoolcode = strpos($membershipsurl, '{tool_code}') !== false;
if ($needstoolcode) {
$toolcode = false;
// Fetch tool code from the resource link data.
$lisresultsourcedidjson = $resourcelink->getSetting('lis_result_sourcedid');
if ($lisresultsourcedidjson) {
$lisresultsourcedid = json_decode($lisresultsourcedidjson);
if (isset($lisresultsourcedid->data->typeid)) {
$toolcode = $lisresultsourcedid->data->typeid;
}
}
if ($toolcode) {
// Substitute fetched tool code value.
$membershipsurl = str_replace('{tool_code}', $toolcode, $membershipsurl);
} else {
// We're unable to determine the tool code. End this processing.
return false;
}
}
// Get context_id parameter and substitute, if applicable.
$membershipsurl = str_replace('{context_id}', $context->getId(), $membershipsurl);
// Get context_type and substitute, if applicable.
if (strpos($membershipsurl, '{context_type}') !== false) {
$contexttype = $context->type !== null ? $context->type : 'CourseSection';
$membershipsurl = str_replace('{context_type}', $contexttype, $membershipsurl);
}
// Save this URL for the context's custom_context_memberships_url setting.
$context->setSetting('custom_context_memberships_url', $membershipsurl);
$contextupdated = true;
}
// Perform membership service request.
$url = $context->getSetting('custom_context_memberships_url');
mtrace("Performing membership service request from context with URL {$url}.");
$members = $context->getMembership();
// Save the context if membership request succeeded and if it has been updated.
if ($members && $contextupdated) {
$context->save();
}
return $members;
}
|
[
"protected",
"function",
"do_context_membership_request",
"(",
"Context",
"$",
"context",
",",
"ResourceLink",
"$",
"resourcelink",
"=",
"null",
",",
"$",
"membershipsurltemplate",
"=",
"''",
")",
"{",
"$",
"dataconnector",
"=",
"$",
"this",
"->",
"dataconnector",
";",
"// Flag to indicate whether to save the context later.",
"$",
"contextupdated",
"=",
"false",
";",
"// If membership URL is not set, try to generate using the default membership URL from the consumer profile.",
"if",
"(",
"!",
"$",
"context",
"->",
"hasMembershipService",
"(",
")",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"membershipsurltemplate",
")",
")",
"{",
"mtrace",
"(",
"\"Skipping - No membership service available.\\n\"",
")",
";",
"return",
"false",
";",
"}",
"if",
"(",
"$",
"resourcelink",
"===",
"null",
")",
"{",
"$",
"resourcelink",
"=",
"$",
"dataconnector",
"->",
"get_resourcelink_from_context",
"(",
"$",
"context",
")",
";",
"}",
"if",
"(",
"$",
"resourcelink",
"!==",
"null",
")",
"{",
"// Try to perform a membership service request using this resource link.",
"$",
"resourcelinkmembers",
"=",
"$",
"this",
"->",
"do_resourcelink_membership_request",
"(",
"$",
"resourcelink",
")",
";",
"if",
"(",
"$",
"resourcelinkmembers",
")",
"{",
"// If we're able to fetch members using this resource link, return these.",
"return",
"$",
"resourcelinkmembers",
";",
"}",
"}",
"// If fetching memberships through resource link failed and we don't have a memberships URL, build one from template.",
"mtrace",
"(",
"\"'custom_context_memberships_url' not set. Fetching default template: $membershipsurltemplate\"",
")",
";",
"$",
"membershipsurl",
"=",
"$",
"membershipsurltemplate",
";",
"// Check if we need to fetch tool code.",
"$",
"needstoolcode",
"=",
"strpos",
"(",
"$",
"membershipsurl",
",",
"'{tool_code}'",
")",
"!==",
"false",
";",
"if",
"(",
"$",
"needstoolcode",
")",
"{",
"$",
"toolcode",
"=",
"false",
";",
"// Fetch tool code from the resource link data.",
"$",
"lisresultsourcedidjson",
"=",
"$",
"resourcelink",
"->",
"getSetting",
"(",
"'lis_result_sourcedid'",
")",
";",
"if",
"(",
"$",
"lisresultsourcedidjson",
")",
"{",
"$",
"lisresultsourcedid",
"=",
"json_decode",
"(",
"$",
"lisresultsourcedidjson",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"lisresultsourcedid",
"->",
"data",
"->",
"typeid",
")",
")",
"{",
"$",
"toolcode",
"=",
"$",
"lisresultsourcedid",
"->",
"data",
"->",
"typeid",
";",
"}",
"}",
"if",
"(",
"$",
"toolcode",
")",
"{",
"// Substitute fetched tool code value.",
"$",
"membershipsurl",
"=",
"str_replace",
"(",
"'{tool_code}'",
",",
"$",
"toolcode",
",",
"$",
"membershipsurl",
")",
";",
"}",
"else",
"{",
"// We're unable to determine the tool code. End this processing.",
"return",
"false",
";",
"}",
"}",
"// Get context_id parameter and substitute, if applicable.",
"$",
"membershipsurl",
"=",
"str_replace",
"(",
"'{context_id}'",
",",
"$",
"context",
"->",
"getId",
"(",
")",
",",
"$",
"membershipsurl",
")",
";",
"// Get context_type and substitute, if applicable.",
"if",
"(",
"strpos",
"(",
"$",
"membershipsurl",
",",
"'{context_type}'",
")",
"!==",
"false",
")",
"{",
"$",
"contexttype",
"=",
"$",
"context",
"->",
"type",
"!==",
"null",
"?",
"$",
"context",
"->",
"type",
":",
"'CourseSection'",
";",
"$",
"membershipsurl",
"=",
"str_replace",
"(",
"'{context_type}'",
",",
"$",
"contexttype",
",",
"$",
"membershipsurl",
")",
";",
"}",
"// Save this URL for the context's custom_context_memberships_url setting.",
"$",
"context",
"->",
"setSetting",
"(",
"'custom_context_memberships_url'",
",",
"$",
"membershipsurl",
")",
";",
"$",
"contextupdated",
"=",
"true",
";",
"}",
"// Perform membership service request.",
"$",
"url",
"=",
"$",
"context",
"->",
"getSetting",
"(",
"'custom_context_memberships_url'",
")",
";",
"mtrace",
"(",
"\"Performing membership service request from context with URL {$url}.\"",
")",
";",
"$",
"members",
"=",
"$",
"context",
"->",
"getMembership",
"(",
")",
";",
"// Save the context if membership request succeeded and if it has been updated.",
"if",
"(",
"$",
"members",
"&&",
"$",
"contextupdated",
")",
"{",
"$",
"context",
"->",
"save",
"(",
")",
";",
"}",
"return",
"$",
"members",
";",
"}"
] |
Performs membership service request using an LTI Context object.
If the context has a 'custom_context_memberships_url' setting, we use this to perform the membership service request.
Otherwise, if a context is associated with resource link, we try first to get the members using the
ResourceLink::doMembershipsService() method.
If we're still unable to fetch members from the resource link, we try to build a memberships URL from the memberships URL
endpoint template that is defined in the ToolConsumer profile and substitute the parameters accordingly.
@param Context $context The context object.
@param ResourceLink $resourcelink The resource link object.
@param string $membershipsurltemplate The memberships endpoint URL template.
@return bool|User[] Array of User objects upon successful membership service request. False, otherwise.
|
[
"Performs",
"membership",
"service",
"request",
"using",
"an",
"LTI",
"Context",
"object",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/enrol/lti/classes/task/sync_members.php#L368-L447
|
215,593
|
moodle/moodle
|
filter/mediaplugin/filter.php
|
filter_mediaplugin.setup
|
public function setup($page, $context) {
// This only requires execution once per request.
static $jsinitialised = false;
if ($jsinitialised) {
return;
}
$jsinitialised = true;
// Set up the media manager so that media plugins requiring JS are initialised.
$mediamanager = core_media_manager::instance($page);
}
|
php
|
public function setup($page, $context) {
// This only requires execution once per request.
static $jsinitialised = false;
if ($jsinitialised) {
return;
}
$jsinitialised = true;
// Set up the media manager so that media plugins requiring JS are initialised.
$mediamanager = core_media_manager::instance($page);
}
|
[
"public",
"function",
"setup",
"(",
"$",
"page",
",",
"$",
"context",
")",
"{",
"// This only requires execution once per request.",
"static",
"$",
"jsinitialised",
"=",
"false",
";",
"if",
"(",
"$",
"jsinitialised",
")",
"{",
"return",
";",
"}",
"$",
"jsinitialised",
"=",
"true",
";",
"// Set up the media manager so that media plugins requiring JS are initialised.",
"$",
"mediamanager",
"=",
"core_media_manager",
"::",
"instance",
"(",
"$",
"page",
")",
";",
"}"
] |
Setup page with filter requirements and other prepare stuff.
@param moodle_page $page The page we are going to add requirements to.
@param context $context The context which contents are going to be filtered.
|
[
"Setup",
"page",
"with",
"filter",
"requirements",
"and",
"other",
"prepare",
"stuff",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/filter/mediaplugin/filter.php#L52-L62
|
215,594
|
moodle/moodle
|
filter/mediaplugin/filter.php
|
filter_mediaplugin.callback
|
private function callback(array $matches) {
$mediamanager = core_media_manager::instance();
global $CFG, $PAGE;
// Check if we ignore it.
if (preg_match('/class="[^"]*nomediaplugin/i', $matches[0])) {
return $matches[0];
}
// Get name.
$name = trim($matches[2]);
if (empty($name) or strpos($name, 'http') === 0) {
$name = ''; // Use default name.
}
// Split provided URL into alternatives.
$urls = $mediamanager->split_alternatives($matches[1], $width, $height);
$options = [core_media_manager::OPTION_ORIGINAL_TEXT => $matches[0]];
return $this->embed_alternatives($urls, $name, $width, $height, $options);
}
|
php
|
private function callback(array $matches) {
$mediamanager = core_media_manager::instance();
global $CFG, $PAGE;
// Check if we ignore it.
if (preg_match('/class="[^"]*nomediaplugin/i', $matches[0])) {
return $matches[0];
}
// Get name.
$name = trim($matches[2]);
if (empty($name) or strpos($name, 'http') === 0) {
$name = ''; // Use default name.
}
// Split provided URL into alternatives.
$urls = $mediamanager->split_alternatives($matches[1], $width, $height);
$options = [core_media_manager::OPTION_ORIGINAL_TEXT => $matches[0]];
return $this->embed_alternatives($urls, $name, $width, $height, $options);
}
|
[
"private",
"function",
"callback",
"(",
"array",
"$",
"matches",
")",
"{",
"$",
"mediamanager",
"=",
"core_media_manager",
"::",
"instance",
"(",
")",
";",
"global",
"$",
"CFG",
",",
"$",
"PAGE",
";",
"// Check if we ignore it.",
"if",
"(",
"preg_match",
"(",
"'/class=\"[^\"]*nomediaplugin/i'",
",",
"$",
"matches",
"[",
"0",
"]",
")",
")",
"{",
"return",
"$",
"matches",
"[",
"0",
"]",
";",
"}",
"// Get name.",
"$",
"name",
"=",
"trim",
"(",
"$",
"matches",
"[",
"2",
"]",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"name",
")",
"or",
"strpos",
"(",
"$",
"name",
",",
"'http'",
")",
"===",
"0",
")",
"{",
"$",
"name",
"=",
"''",
";",
"// Use default name.",
"}",
"// Split provided URL into alternatives.",
"$",
"urls",
"=",
"$",
"mediamanager",
"->",
"split_alternatives",
"(",
"$",
"matches",
"[",
"1",
"]",
",",
"$",
"width",
",",
"$",
"height",
")",
";",
"$",
"options",
"=",
"[",
"core_media_manager",
"::",
"OPTION_ORIGINAL_TEXT",
"=>",
"$",
"matches",
"[",
"0",
"]",
"]",
";",
"return",
"$",
"this",
"->",
"embed_alternatives",
"(",
"$",
"urls",
",",
"$",
"name",
",",
"$",
"width",
",",
"$",
"height",
",",
"$",
"options",
")",
";",
"}"
] |
Replace link with embedded content, if supported.
@param array $matches
@return string
|
[
"Replace",
"link",
"with",
"embedded",
"content",
"if",
"supported",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/filter/mediaplugin/filter.php#L144-L164
|
215,595
|
moodle/moodle
|
lib/pdflib.php
|
pdf.get_font_families
|
public function get_font_families() {
$families = array();
foreach ($this->fontlist as $font) {
if (strpos($font, 'uni2cid') === 0) {
// This is not an font file.
continue;
}
if (strpos($font, 'cid0') === 0) {
// These do not seem to work with utf-8, better ignore them for now.
continue;
}
if (substr($font, -2) === 'bi') {
$family = substr($font, 0, -2);
if (in_array($family, $this->fontlist)) {
$families[$family]['BI'] = 'BI';
continue;
}
}
if (substr($font, -1) === 'i') {
$family = substr($font, 0, -1);
if (in_array($family, $this->fontlist)) {
$families[$family]['I'] = 'I';
continue;
}
}
if (substr($font, -1) === 'b') {
$family = substr($font, 0, -1);
if (in_array($family, $this->fontlist)) {
$families[$family]['B'] = 'B';
continue;
}
}
// This must be a Family or incomplete set of fonts present.
$families[$font]['R'] = 'R';
}
// Sort everything consistently.
ksort($families);
foreach ($families as $k => $v) {
krsort($families[$k]);
}
return $families;
}
|
php
|
public function get_font_families() {
$families = array();
foreach ($this->fontlist as $font) {
if (strpos($font, 'uni2cid') === 0) {
// This is not an font file.
continue;
}
if (strpos($font, 'cid0') === 0) {
// These do not seem to work with utf-8, better ignore them for now.
continue;
}
if (substr($font, -2) === 'bi') {
$family = substr($font, 0, -2);
if (in_array($family, $this->fontlist)) {
$families[$family]['BI'] = 'BI';
continue;
}
}
if (substr($font, -1) === 'i') {
$family = substr($font, 0, -1);
if (in_array($family, $this->fontlist)) {
$families[$family]['I'] = 'I';
continue;
}
}
if (substr($font, -1) === 'b') {
$family = substr($font, 0, -1);
if (in_array($family, $this->fontlist)) {
$families[$family]['B'] = 'B';
continue;
}
}
// This must be a Family or incomplete set of fonts present.
$families[$font]['R'] = 'R';
}
// Sort everything consistently.
ksort($families);
foreach ($families as $k => $v) {
krsort($families[$k]);
}
return $families;
}
|
[
"public",
"function",
"get_font_families",
"(",
")",
"{",
"$",
"families",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"fontlist",
"as",
"$",
"font",
")",
"{",
"if",
"(",
"strpos",
"(",
"$",
"font",
",",
"'uni2cid'",
")",
"===",
"0",
")",
"{",
"// This is not an font file.",
"continue",
";",
"}",
"if",
"(",
"strpos",
"(",
"$",
"font",
",",
"'cid0'",
")",
"===",
"0",
")",
"{",
"// These do not seem to work with utf-8, better ignore them for now.",
"continue",
";",
"}",
"if",
"(",
"substr",
"(",
"$",
"font",
",",
"-",
"2",
")",
"===",
"'bi'",
")",
"{",
"$",
"family",
"=",
"substr",
"(",
"$",
"font",
",",
"0",
",",
"-",
"2",
")",
";",
"if",
"(",
"in_array",
"(",
"$",
"family",
",",
"$",
"this",
"->",
"fontlist",
")",
")",
"{",
"$",
"families",
"[",
"$",
"family",
"]",
"[",
"'BI'",
"]",
"=",
"'BI'",
";",
"continue",
";",
"}",
"}",
"if",
"(",
"substr",
"(",
"$",
"font",
",",
"-",
"1",
")",
"===",
"'i'",
")",
"{",
"$",
"family",
"=",
"substr",
"(",
"$",
"font",
",",
"0",
",",
"-",
"1",
")",
";",
"if",
"(",
"in_array",
"(",
"$",
"family",
",",
"$",
"this",
"->",
"fontlist",
")",
")",
"{",
"$",
"families",
"[",
"$",
"family",
"]",
"[",
"'I'",
"]",
"=",
"'I'",
";",
"continue",
";",
"}",
"}",
"if",
"(",
"substr",
"(",
"$",
"font",
",",
"-",
"1",
")",
"===",
"'b'",
")",
"{",
"$",
"family",
"=",
"substr",
"(",
"$",
"font",
",",
"0",
",",
"-",
"1",
")",
";",
"if",
"(",
"in_array",
"(",
"$",
"family",
",",
"$",
"this",
"->",
"fontlist",
")",
")",
"{",
"$",
"families",
"[",
"$",
"family",
"]",
"[",
"'B'",
"]",
"=",
"'B'",
";",
"continue",
";",
"}",
"}",
"// This must be a Family or incomplete set of fonts present.",
"$",
"families",
"[",
"$",
"font",
"]",
"[",
"'R'",
"]",
"=",
"'R'",
";",
"}",
"// Sort everything consistently.",
"ksort",
"(",
"$",
"families",
")",
";",
"foreach",
"(",
"$",
"families",
"as",
"$",
"k",
"=>",
"$",
"v",
")",
"{",
"krsort",
"(",
"$",
"families",
"[",
"$",
"k",
"]",
")",
";",
"}",
"return",
"$",
"families",
";",
"}"
] |
Returns list of font families and types of fonts.
@return array multidimensional array with font families as keys and B, I, BI and N as values.
|
[
"Returns",
"list",
"of",
"font",
"families",
"and",
"types",
"of",
"fonts",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/pdflib.php#L209-L252
|
215,596
|
moodle/moodle
|
cache/locks/file/lib.php
|
cachelock_file.lock
|
public function lock($key, $ownerid, $block = false) {
// Get the name of the lock file we want to use.
$lockfile = $this->get_lock_file($key);
// Attempt to create a handle to the lock file.
// Mode xb is the secret to this whole function.
// x = Creates the file and opens it for writing. If the file already exists fopen returns false and a warning is thrown.
// b = Forces binary mode.
$result = @fopen($lockfile, 'xb');
// Check if we could create the file or not.
if ($result === false) {
// Lock exists already.
if ($this->maxlife !== null && !array_key_exists($key, $this->locks)) {
$mtime = filemtime($lockfile);
if ($mtime < time() - $this->maxlife) {
$this->unlock($key, true);
$result = $this->lock($key, false);
if ($result) {
return true;
}
}
}
if ($block) {
// OK we are blocking. We had better sleep and then retry to lock.
$iterations = 0;
$maxiterations = $this->blockattempts;
while (($result = $this->lock($key, false)) === false) {
// Usleep causes the application to cleep to x microseconds.
// Before anyone asks there are 1'000'000 microseconds to a second.
usleep(rand(1000, 50000)); // Sleep between 1 and 50 milliseconds.
$iterations++;
if ($iterations > $maxiterations) {
// BOOM! We've exceeded the maximum number of iterations we want to block for.
throw new cache_exception('ex_unabletolock');
}
}
}
return false;
} else {
// We have the lock.
fclose($result);
$this->locks[$key] = $lockfile;
return true;
}
}
|
php
|
public function lock($key, $ownerid, $block = false) {
// Get the name of the lock file we want to use.
$lockfile = $this->get_lock_file($key);
// Attempt to create a handle to the lock file.
// Mode xb is the secret to this whole function.
// x = Creates the file and opens it for writing. If the file already exists fopen returns false and a warning is thrown.
// b = Forces binary mode.
$result = @fopen($lockfile, 'xb');
// Check if we could create the file or not.
if ($result === false) {
// Lock exists already.
if ($this->maxlife !== null && !array_key_exists($key, $this->locks)) {
$mtime = filemtime($lockfile);
if ($mtime < time() - $this->maxlife) {
$this->unlock($key, true);
$result = $this->lock($key, false);
if ($result) {
return true;
}
}
}
if ($block) {
// OK we are blocking. We had better sleep and then retry to lock.
$iterations = 0;
$maxiterations = $this->blockattempts;
while (($result = $this->lock($key, false)) === false) {
// Usleep causes the application to cleep to x microseconds.
// Before anyone asks there are 1'000'000 microseconds to a second.
usleep(rand(1000, 50000)); // Sleep between 1 and 50 milliseconds.
$iterations++;
if ($iterations > $maxiterations) {
// BOOM! We've exceeded the maximum number of iterations we want to block for.
throw new cache_exception('ex_unabletolock');
}
}
}
return false;
} else {
// We have the lock.
fclose($result);
$this->locks[$key] = $lockfile;
return true;
}
}
|
[
"public",
"function",
"lock",
"(",
"$",
"key",
",",
"$",
"ownerid",
",",
"$",
"block",
"=",
"false",
")",
"{",
"// Get the name of the lock file we want to use.",
"$",
"lockfile",
"=",
"$",
"this",
"->",
"get_lock_file",
"(",
"$",
"key",
")",
";",
"// Attempt to create a handle to the lock file.",
"// Mode xb is the secret to this whole function.",
"// x = Creates the file and opens it for writing. If the file already exists fopen returns false and a warning is thrown.",
"// b = Forces binary mode.",
"$",
"result",
"=",
"@",
"fopen",
"(",
"$",
"lockfile",
",",
"'xb'",
")",
";",
"// Check if we could create the file or not.",
"if",
"(",
"$",
"result",
"===",
"false",
")",
"{",
"// Lock exists already.",
"if",
"(",
"$",
"this",
"->",
"maxlife",
"!==",
"null",
"&&",
"!",
"array_key_exists",
"(",
"$",
"key",
",",
"$",
"this",
"->",
"locks",
")",
")",
"{",
"$",
"mtime",
"=",
"filemtime",
"(",
"$",
"lockfile",
")",
";",
"if",
"(",
"$",
"mtime",
"<",
"time",
"(",
")",
"-",
"$",
"this",
"->",
"maxlife",
")",
"{",
"$",
"this",
"->",
"unlock",
"(",
"$",
"key",
",",
"true",
")",
";",
"$",
"result",
"=",
"$",
"this",
"->",
"lock",
"(",
"$",
"key",
",",
"false",
")",
";",
"if",
"(",
"$",
"result",
")",
"{",
"return",
"true",
";",
"}",
"}",
"}",
"if",
"(",
"$",
"block",
")",
"{",
"// OK we are blocking. We had better sleep and then retry to lock.",
"$",
"iterations",
"=",
"0",
";",
"$",
"maxiterations",
"=",
"$",
"this",
"->",
"blockattempts",
";",
"while",
"(",
"(",
"$",
"result",
"=",
"$",
"this",
"->",
"lock",
"(",
"$",
"key",
",",
"false",
")",
")",
"===",
"false",
")",
"{",
"// Usleep causes the application to cleep to x microseconds.",
"// Before anyone asks there are 1'000'000 microseconds to a second.",
"usleep",
"(",
"rand",
"(",
"1000",
",",
"50000",
")",
")",
";",
"// Sleep between 1 and 50 milliseconds.",
"$",
"iterations",
"++",
";",
"if",
"(",
"$",
"iterations",
">",
"$",
"maxiterations",
")",
"{",
"// BOOM! We've exceeded the maximum number of iterations we want to block for.",
"throw",
"new",
"cache_exception",
"(",
"'ex_unabletolock'",
")",
";",
"}",
"}",
"}",
"return",
"false",
";",
"}",
"else",
"{",
"// We have the lock.",
"fclose",
"(",
"$",
"result",
")",
";",
"$",
"this",
"->",
"locks",
"[",
"$",
"key",
"]",
"=",
"$",
"lockfile",
";",
"return",
"true",
";",
"}",
"}"
] |
Acquire a lock.
If the lock can be acquired:
This function will return true.
If the lock cannot be acquired the result of this method is determined by the block param:
$block = true (default)
The function will block any further execution unti the lock can be acquired.
This involves the function attempting to acquire the lock and the sleeping for a period of time. This process
will be repeated until the lock is required or until a limit is hit (100 by default) in which case a cache
exception will be thrown.
$block = false
The function will return false immediately.
If a max life has been specified and the lock can not be acquired then the lock file will be checked against this time.
In the case that the file exceeds that max time it will be forcefully deleted.
Because this can obviously be a dangerous thing it is not used by default. If it is used it should be set high enough that
we can be as sure as possible that the executing code has completed.
@param string $key The key that we want to lock
@param string $ownerid A unique identifier for the owner of this lock. Not used by default.
@param bool $block True if we want the program block further execution until the lock has been acquired.
@return bool
@throws cache_exception If block is set to true and more than 100 attempts have been made to acquire a lock.
|
[
"Acquire",
"a",
"lock",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/cache/locks/file/lib.php#L125-L171
|
215,597
|
moodle/moodle
|
cache/locks/file/lib.php
|
cachelock_file.unlock
|
public function unlock($key, $ownerid, $forceunlock = false) {
if (array_key_exists($key, $this->locks)) {
@unlink($this->locks[$key]);
unset($this->locks[$key]);
return true;
} else if ($forceunlock) {
$lockfile = $this->get_lock_file($key);
if (file_exists($lockfile)) {
@unlink($lockfile);
}
return true;
}
// You cannot unlock a file you didn't lock.
return false;
}
|
php
|
public function unlock($key, $ownerid, $forceunlock = false) {
if (array_key_exists($key, $this->locks)) {
@unlink($this->locks[$key]);
unset($this->locks[$key]);
return true;
} else if ($forceunlock) {
$lockfile = $this->get_lock_file($key);
if (file_exists($lockfile)) {
@unlink($lockfile);
}
return true;
}
// You cannot unlock a file you didn't lock.
return false;
}
|
[
"public",
"function",
"unlock",
"(",
"$",
"key",
",",
"$",
"ownerid",
",",
"$",
"forceunlock",
"=",
"false",
")",
"{",
"if",
"(",
"array_key_exists",
"(",
"$",
"key",
",",
"$",
"this",
"->",
"locks",
")",
")",
"{",
"@",
"unlink",
"(",
"$",
"this",
"->",
"locks",
"[",
"$",
"key",
"]",
")",
";",
"unset",
"(",
"$",
"this",
"->",
"locks",
"[",
"$",
"key",
"]",
")",
";",
"return",
"true",
";",
"}",
"else",
"if",
"(",
"$",
"forceunlock",
")",
"{",
"$",
"lockfile",
"=",
"$",
"this",
"->",
"get_lock_file",
"(",
"$",
"key",
")",
";",
"if",
"(",
"file_exists",
"(",
"$",
"lockfile",
")",
")",
"{",
"@",
"unlink",
"(",
"$",
"lockfile",
")",
";",
"}",
"return",
"true",
";",
"}",
"// You cannot unlock a file you didn't lock.",
"return",
"false",
";",
"}"
] |
Releases an acquired lock.
For more details see {@link cache_lock::unlock()}
@param string $key
@param string $ownerid A unique identifier for the owner of this lock. Not used by default.
@param bool $forceunlock If set to true the lock will be removed if it exists regardless of whether or not we own it.
@return bool
|
[
"Releases",
"an",
"acquired",
"lock",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/cache/locks/file/lib.php#L183-L197
|
215,598
|
moodle/moodle
|
cache/locks/file/lib.php
|
cachelock_file.check_state
|
public function check_state($key, $ownerid) {
if (array_key_exists($key, $this->locks)) {
// The key is locked and we own it.
return true;
}
$lockfile = $this->get_lock_file($key);
if (file_exists($lockfile)) {
// The key is locked and we don't own it.
return false;
}
return null;
}
|
php
|
public function check_state($key, $ownerid) {
if (array_key_exists($key, $this->locks)) {
// The key is locked and we own it.
return true;
}
$lockfile = $this->get_lock_file($key);
if (file_exists($lockfile)) {
// The key is locked and we don't own it.
return false;
}
return null;
}
|
[
"public",
"function",
"check_state",
"(",
"$",
"key",
",",
"$",
"ownerid",
")",
"{",
"if",
"(",
"array_key_exists",
"(",
"$",
"key",
",",
"$",
"this",
"->",
"locks",
")",
")",
"{",
"// The key is locked and we own it.",
"return",
"true",
";",
"}",
"$",
"lockfile",
"=",
"$",
"this",
"->",
"get_lock_file",
"(",
"$",
"key",
")",
";",
"if",
"(",
"file_exists",
"(",
"$",
"lockfile",
")",
")",
"{",
"// The key is locked and we don't own it.",
"return",
"false",
";",
"}",
"return",
"null",
";",
"}"
] |
Checks if the given key is locked.
@param string $key
@param string $ownerid
|
[
"Checks",
"if",
"the",
"given",
"key",
"is",
"locked",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/cache/locks/file/lib.php#L205-L216
|
215,599
|
moodle/moodle
|
lib/mlbackend/php/phpml/src/Phpml/Math/Statistic/Covariance.php
|
Covariance.fromXYArrays
|
public static function fromXYArrays(array $x, array $y, $sample = true, float $meanX = null, float $meanY = null)
{
if (empty($x) || empty($y)) {
throw InvalidArgumentException::arrayCantBeEmpty();
}
$n = count($x);
if ($sample && $n === 1) {
throw InvalidArgumentException::arraySizeToSmall(2);
}
if ($meanX === null) {
$meanX = Mean::arithmetic($x);
}
if ($meanY === null) {
$meanY = Mean::arithmetic($y);
}
$sum = 0.0;
foreach ($x as $index => $xi) {
$yi = $y[$index];
$sum += ($xi - $meanX) * ($yi - $meanY);
}
if ($sample) {
--$n;
}
return $sum / $n;
}
|
php
|
public static function fromXYArrays(array $x, array $y, $sample = true, float $meanX = null, float $meanY = null)
{
if (empty($x) || empty($y)) {
throw InvalidArgumentException::arrayCantBeEmpty();
}
$n = count($x);
if ($sample && $n === 1) {
throw InvalidArgumentException::arraySizeToSmall(2);
}
if ($meanX === null) {
$meanX = Mean::arithmetic($x);
}
if ($meanY === null) {
$meanY = Mean::arithmetic($y);
}
$sum = 0.0;
foreach ($x as $index => $xi) {
$yi = $y[$index];
$sum += ($xi - $meanX) * ($yi - $meanY);
}
if ($sample) {
--$n;
}
return $sum / $n;
}
|
[
"public",
"static",
"function",
"fromXYArrays",
"(",
"array",
"$",
"x",
",",
"array",
"$",
"y",
",",
"$",
"sample",
"=",
"true",
",",
"float",
"$",
"meanX",
"=",
"null",
",",
"float",
"$",
"meanY",
"=",
"null",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"x",
")",
"||",
"empty",
"(",
"$",
"y",
")",
")",
"{",
"throw",
"InvalidArgumentException",
"::",
"arrayCantBeEmpty",
"(",
")",
";",
"}",
"$",
"n",
"=",
"count",
"(",
"$",
"x",
")",
";",
"if",
"(",
"$",
"sample",
"&&",
"$",
"n",
"===",
"1",
")",
"{",
"throw",
"InvalidArgumentException",
"::",
"arraySizeToSmall",
"(",
"2",
")",
";",
"}",
"if",
"(",
"$",
"meanX",
"===",
"null",
")",
"{",
"$",
"meanX",
"=",
"Mean",
"::",
"arithmetic",
"(",
"$",
"x",
")",
";",
"}",
"if",
"(",
"$",
"meanY",
"===",
"null",
")",
"{",
"$",
"meanY",
"=",
"Mean",
"::",
"arithmetic",
"(",
"$",
"y",
")",
";",
"}",
"$",
"sum",
"=",
"0.0",
";",
"foreach",
"(",
"$",
"x",
"as",
"$",
"index",
"=>",
"$",
"xi",
")",
"{",
"$",
"yi",
"=",
"$",
"y",
"[",
"$",
"index",
"]",
";",
"$",
"sum",
"+=",
"(",
"$",
"xi",
"-",
"$",
"meanX",
")",
"*",
"(",
"$",
"yi",
"-",
"$",
"meanY",
")",
";",
"}",
"if",
"(",
"$",
"sample",
")",
"{",
"--",
"$",
"n",
";",
"}",
"return",
"$",
"sum",
"/",
"$",
"n",
";",
"}"
] |
Calculates covariance from two given arrays, x and y, respectively
@param array $x
@param array $y
@param bool $sample
@param float $meanX
@param float $meanY
@return float
@throws InvalidArgumentException
|
[
"Calculates",
"covariance",
"from",
"two",
"given",
"arrays",
"x",
"and",
"y",
"respectively"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/mlbackend/php/phpml/src/Phpml/Math/Statistic/Covariance.php#L24-L54
|
Subsets and Splits
Yii Code Samples
Gathers all records from test, train, and validation sets that contain the word 'yii', providing a basic filtered view of the dataset relevant to Yii-related content.