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,300
|
moodle/moodle
|
mod/forum/classes/local/factories/exporter.php
|
exporter.get_forum_exporter
|
public function get_forum_exporter(
stdClass $user,
forum_entity $forum,
?int $currentgroup
) : forum_exporter {
return new forum_exporter($forum, [
'legacydatamapperfactory' => $this->legacydatamapperfactory,
'capabilitymanager' => $this->managerfactory->get_capability_manager($forum),
'urlfactory' => $this->urlfactory,
'user' => $user,
'currentgroup' => $currentgroup,
'vaultfactory' => $this->vaultfactory,
]);
}
|
php
|
public function get_forum_exporter(
stdClass $user,
forum_entity $forum,
?int $currentgroup
) : forum_exporter {
return new forum_exporter($forum, [
'legacydatamapperfactory' => $this->legacydatamapperfactory,
'capabilitymanager' => $this->managerfactory->get_capability_manager($forum),
'urlfactory' => $this->urlfactory,
'user' => $user,
'currentgroup' => $currentgroup,
'vaultfactory' => $this->vaultfactory,
]);
}
|
[
"public",
"function",
"get_forum_exporter",
"(",
"stdClass",
"$",
"user",
",",
"forum_entity",
"$",
"forum",
",",
"?",
"int",
"$",
"currentgroup",
")",
":",
"forum_exporter",
"{",
"return",
"new",
"forum_exporter",
"(",
"$",
"forum",
",",
"[",
"'legacydatamapperfactory'",
"=>",
"$",
"this",
"->",
"legacydatamapperfactory",
",",
"'capabilitymanager'",
"=>",
"$",
"this",
"->",
"managerfactory",
"->",
"get_capability_manager",
"(",
"$",
"forum",
")",
",",
"'urlfactory'",
"=>",
"$",
"this",
"->",
"urlfactory",
",",
"'user'",
"=>",
"$",
"user",
",",
"'currentgroup'",
"=>",
"$",
"currentgroup",
",",
"'vaultfactory'",
"=>",
"$",
"this",
"->",
"vaultfactory",
",",
"]",
")",
";",
"}"
] |
Construct a new forum exporter for the specified user and forum.
@param stdClass $user The user viewing the forum
@param forum_entity $forum The forum being viewed
@param int $currentgroup The group currently being viewed
@return forum_exporter
|
[
"Construct",
"a",
"new",
"forum",
"exporter",
"for",
"the",
"specified",
"user",
"and",
"forum",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/forum/classes/local/factories/exporter.php#L92-L105
|
215,301
|
moodle/moodle
|
mod/forum/classes/local/factories/exporter.php
|
exporter.get_discussion_exporter
|
public function get_discussion_exporter(
stdClass $user,
forum_entity $forum,
discussion_entity $discussion,
array $groupsbyid = [],
array $favouriteids = []
) : discussion_exporter {
return new discussion_exporter($discussion, [
'context' => $forum->get_context(),
'forum' => $forum,
'capabilitymanager' => $this->managerfactory->get_capability_manager($forum),
'urlfactory' => $this->urlfactory,
'user' => $user,
'legacydatamapperfactory' => $this->legacydatamapperfactory,
'latestpostid' => null,
'groupsbyid' => $groupsbyid,
'favouriteids' => $favouriteids
]);
}
|
php
|
public function get_discussion_exporter(
stdClass $user,
forum_entity $forum,
discussion_entity $discussion,
array $groupsbyid = [],
array $favouriteids = []
) : discussion_exporter {
return new discussion_exporter($discussion, [
'context' => $forum->get_context(),
'forum' => $forum,
'capabilitymanager' => $this->managerfactory->get_capability_manager($forum),
'urlfactory' => $this->urlfactory,
'user' => $user,
'legacydatamapperfactory' => $this->legacydatamapperfactory,
'latestpostid' => null,
'groupsbyid' => $groupsbyid,
'favouriteids' => $favouriteids
]);
}
|
[
"public",
"function",
"get_discussion_exporter",
"(",
"stdClass",
"$",
"user",
",",
"forum_entity",
"$",
"forum",
",",
"discussion_entity",
"$",
"discussion",
",",
"array",
"$",
"groupsbyid",
"=",
"[",
"]",
",",
"array",
"$",
"favouriteids",
"=",
"[",
"]",
")",
":",
"discussion_exporter",
"{",
"return",
"new",
"discussion_exporter",
"(",
"$",
"discussion",
",",
"[",
"'context'",
"=>",
"$",
"forum",
"->",
"get_context",
"(",
")",
",",
"'forum'",
"=>",
"$",
"forum",
",",
"'capabilitymanager'",
"=>",
"$",
"this",
"->",
"managerfactory",
"->",
"get_capability_manager",
"(",
"$",
"forum",
")",
",",
"'urlfactory'",
"=>",
"$",
"this",
"->",
"urlfactory",
",",
"'user'",
"=>",
"$",
"user",
",",
"'legacydatamapperfactory'",
"=>",
"$",
"this",
"->",
"legacydatamapperfactory",
",",
"'latestpostid'",
"=>",
"null",
",",
"'groupsbyid'",
"=>",
"$",
"groupsbyid",
",",
"'favouriteids'",
"=>",
"$",
"favouriteids",
"]",
")",
";",
"}"
] |
Construct a new discussion exporter for the specified user and forum discussion.
@param stdClass $user The user viewing the forum
@param forum_entity $forum The forum being viewed
@param discussion_entity $discussion The discussion being viewed
@param stdClass[] $groupsbyid The list of groups in the forum
@return discussion_exporter
|
[
"Construct",
"a",
"new",
"discussion",
"exporter",
"for",
"the",
"specified",
"user",
"and",
"forum",
"discussion",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/forum/classes/local/factories/exporter.php#L125-L143
|
215,302
|
moodle/moodle
|
mod/forum/classes/local/factories/exporter.php
|
exporter.get_discussion_summaries_exporter
|
public function get_discussion_summaries_exporter(
stdClass $user,
forum_entity $forum,
array $discussions,
array $groupsbyid = [],
array $groupsbyauthorid = [],
array $discussionreplycount = [],
array $discussionunreadcount = [],
array $latestpostids = [],
array $postauthorcontextids = [],
array $favourites = []
) : discussion_summaries_exporter {
return new discussion_summaries_exporter(
$discussions,
$groupsbyid,
$groupsbyauthorid,
$discussionreplycount,
$discussionunreadcount,
$latestpostids,
$postauthorcontextids,
[
'legacydatamapperfactory' => $this->legacydatamapperfactory,
'context' => $forum->get_context(),
'forum' => $forum,
'capabilitymanager' => $this->managerfactory->get_capability_manager($forum),
'urlfactory' => $this->urlfactory,
'user' => $user,
'favouriteids' => $favourites
]
);
}
|
php
|
public function get_discussion_summaries_exporter(
stdClass $user,
forum_entity $forum,
array $discussions,
array $groupsbyid = [],
array $groupsbyauthorid = [],
array $discussionreplycount = [],
array $discussionunreadcount = [],
array $latestpostids = [],
array $postauthorcontextids = [],
array $favourites = []
) : discussion_summaries_exporter {
return new discussion_summaries_exporter(
$discussions,
$groupsbyid,
$groupsbyauthorid,
$discussionreplycount,
$discussionunreadcount,
$latestpostids,
$postauthorcontextids,
[
'legacydatamapperfactory' => $this->legacydatamapperfactory,
'context' => $forum->get_context(),
'forum' => $forum,
'capabilitymanager' => $this->managerfactory->get_capability_manager($forum),
'urlfactory' => $this->urlfactory,
'user' => $user,
'favouriteids' => $favourites
]
);
}
|
[
"public",
"function",
"get_discussion_summaries_exporter",
"(",
"stdClass",
"$",
"user",
",",
"forum_entity",
"$",
"forum",
",",
"array",
"$",
"discussions",
",",
"array",
"$",
"groupsbyid",
"=",
"[",
"]",
",",
"array",
"$",
"groupsbyauthorid",
"=",
"[",
"]",
",",
"array",
"$",
"discussionreplycount",
"=",
"[",
"]",
",",
"array",
"$",
"discussionunreadcount",
"=",
"[",
"]",
",",
"array",
"$",
"latestpostids",
"=",
"[",
"]",
",",
"array",
"$",
"postauthorcontextids",
"=",
"[",
"]",
",",
"array",
"$",
"favourites",
"=",
"[",
"]",
")",
":",
"discussion_summaries_exporter",
"{",
"return",
"new",
"discussion_summaries_exporter",
"(",
"$",
"discussions",
",",
"$",
"groupsbyid",
",",
"$",
"groupsbyauthorid",
",",
"$",
"discussionreplycount",
",",
"$",
"discussionunreadcount",
",",
"$",
"latestpostids",
",",
"$",
"postauthorcontextids",
",",
"[",
"'legacydatamapperfactory'",
"=>",
"$",
"this",
"->",
"legacydatamapperfactory",
",",
"'context'",
"=>",
"$",
"forum",
"->",
"get_context",
"(",
")",
",",
"'forum'",
"=>",
"$",
"forum",
",",
"'capabilitymanager'",
"=>",
"$",
"this",
"->",
"managerfactory",
"->",
"get_capability_manager",
"(",
"$",
"forum",
")",
",",
"'urlfactory'",
"=>",
"$",
"this",
"->",
"urlfactory",
",",
"'user'",
"=>",
"$",
"user",
",",
"'favouriteids'",
"=>",
"$",
"favourites",
"]",
")",
";",
"}"
] |
Construct a new discussion summaries exporter for the specified user and set of discussions.
@param stdClass $user The user viewing the forum
@param forum_entity $forum The forum being viewed
@param discussion_summary_entity[] $discussions The set of discussion summaries to export
@param stdClass[] $groupsbyauthorid The set of groups in an associative array for each author
@param stdClass[] $groupsbyid The set of groups in the forum in an associative array for each group
@param int[] $discussionreplycount The number of replies for each discussion
@param int[] $discussionunreadcount The number of unread posts for each discussion
@param int[] $latestpostids The latest post id for each discussion
@param int[] $postauthorcontextids The context ids for the first and last post authors (indexed by author id)
@param int[] $favourites The list of discussion ids that have been favourited
@return discussion_summaries_exporter
|
[
"Construct",
"a",
"new",
"discussion",
"summaries",
"exporter",
"for",
"the",
"specified",
"user",
"and",
"set",
"of",
"discussions",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/forum/classes/local/factories/exporter.php#L169-L199
|
215,303
|
moodle/moodle
|
mod/forum/classes/local/factories/exporter.php
|
exporter.get_posts_exporter
|
public function get_posts_exporter(
stdClass $user,
forum_entity $forum,
discussion_entity $discussion,
array $posts,
array $authorsbyid = [],
array $authorcontextids = [],
array $attachmentsbypostid = [],
array $groupsbyauthorid = [],
post_read_receipt_collection_entity $readreceiptcollection = null,
array $tagsbypostid = [],
array $ratingbypostid = [],
bool $includehtml = false
) : posts_exporter {
return new posts_exporter(
$posts,
$authorsbyid,
$authorcontextids,
$attachmentsbypostid,
$groupsbyauthorid,
$tagsbypostid,
$ratingbypostid,
[
'capabilitymanager' => $this->managerfactory->get_capability_manager($forum),
'urlfactory' => $this->urlfactory,
'forum' => $forum,
'discussion' => $discussion,
'user' => $user,
'context' => $forum->get_context(),
'readreceiptcollection' => $readreceiptcollection,
'includehtml' => $includehtml
]
);
}
|
php
|
public function get_posts_exporter(
stdClass $user,
forum_entity $forum,
discussion_entity $discussion,
array $posts,
array $authorsbyid = [],
array $authorcontextids = [],
array $attachmentsbypostid = [],
array $groupsbyauthorid = [],
post_read_receipt_collection_entity $readreceiptcollection = null,
array $tagsbypostid = [],
array $ratingbypostid = [],
bool $includehtml = false
) : posts_exporter {
return new posts_exporter(
$posts,
$authorsbyid,
$authorcontextids,
$attachmentsbypostid,
$groupsbyauthorid,
$tagsbypostid,
$ratingbypostid,
[
'capabilitymanager' => $this->managerfactory->get_capability_manager($forum),
'urlfactory' => $this->urlfactory,
'forum' => $forum,
'discussion' => $discussion,
'user' => $user,
'context' => $forum->get_context(),
'readreceiptcollection' => $readreceiptcollection,
'includehtml' => $includehtml
]
);
}
|
[
"public",
"function",
"get_posts_exporter",
"(",
"stdClass",
"$",
"user",
",",
"forum_entity",
"$",
"forum",
",",
"discussion_entity",
"$",
"discussion",
",",
"array",
"$",
"posts",
",",
"array",
"$",
"authorsbyid",
"=",
"[",
"]",
",",
"array",
"$",
"authorcontextids",
"=",
"[",
"]",
",",
"array",
"$",
"attachmentsbypostid",
"=",
"[",
"]",
",",
"array",
"$",
"groupsbyauthorid",
"=",
"[",
"]",
",",
"post_read_receipt_collection_entity",
"$",
"readreceiptcollection",
"=",
"null",
",",
"array",
"$",
"tagsbypostid",
"=",
"[",
"]",
",",
"array",
"$",
"ratingbypostid",
"=",
"[",
"]",
",",
"bool",
"$",
"includehtml",
"=",
"false",
")",
":",
"posts_exporter",
"{",
"return",
"new",
"posts_exporter",
"(",
"$",
"posts",
",",
"$",
"authorsbyid",
",",
"$",
"authorcontextids",
",",
"$",
"attachmentsbypostid",
",",
"$",
"groupsbyauthorid",
",",
"$",
"tagsbypostid",
",",
"$",
"ratingbypostid",
",",
"[",
"'capabilitymanager'",
"=>",
"$",
"this",
"->",
"managerfactory",
"->",
"get_capability_manager",
"(",
"$",
"forum",
")",
",",
"'urlfactory'",
"=>",
"$",
"this",
"->",
"urlfactory",
",",
"'forum'",
"=>",
"$",
"forum",
",",
"'discussion'",
"=>",
"$",
"discussion",
",",
"'user'",
"=>",
"$",
"user",
",",
"'context'",
"=>",
"$",
"forum",
"->",
"get_context",
"(",
")",
",",
"'readreceiptcollection'",
"=>",
"$",
"readreceiptcollection",
",",
"'includehtml'",
"=>",
"$",
"includehtml",
"]",
")",
";",
"}"
] |
Construct a new post exporter for the specified user and set of post.
@param stdClass $user The user viewing the forum
@param forum_entity $forum The forum being viewed
@param discussion_entity $discussion The discussion that the post is in
@param post_entity[] $posts The set of posts to be exported
@param author_entity[] $authorsbyid List of authors indexed by author id
@param int[] $authorcontextids List of authors context ids indexed by author id
@param array $attachmentsbypostid List of attachments for each post indexed by post id
@param array $groupsbyauthorid List of groups for the post authors indexed by author id
@param post_read_receipt_collection_entity|null $readreceiptcollection Details of read receipts for each post
@param array $tagsbypostid List of tags for each post indexed by post id
@param rating[] $ratingbypostid List of ratings for each post indexed by post id
@param bool $includehtml Include some pre-constructed HTML in the export
@return post_exporter
|
[
"Construct",
"a",
"new",
"post",
"exporter",
"for",
"the",
"specified",
"user",
"and",
"set",
"of",
"post",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/forum/classes/local/factories/exporter.php#L227-L260
|
215,304
|
moodle/moodle
|
mod/forum/classes/local/data_mappers/legacy/forum.php
|
forum.to_legacy_objects
|
public function to_legacy_objects(array $forums) : array {
return array_map(function(forum_entity $forum) {
return (object) [
'id' => $forum->get_id(),
'course' => $forum->get_course_id(),
'type' => $forum->get_type(),
'name' => $forum->get_name(),
'intro' => $forum->get_intro(),
'introformat' => $forum->get_intro_format(),
'assessed' => $forum->get_rating_aggregate(),
'assesstimestart' => $forum->get_assess_time_start(),
'assesstimefinish' => $forum->get_assess_time_finish(),
'scale' => $forum->get_scale(),
'maxbytes' => $forum->get_max_bytes(),
'maxattachments' => $forum->get_max_attachments(),
'forcesubscribe' => $forum->get_subscription_mode(),
'trackingtype' => $forum->get_tracking_type(),
'rsstype' => $forum->get_rss_type(),
'rssarticles' => $forum->get_rss_articles(),
'timemodified' => $forum->get_time_modified(),
'warnafter' => $forum->get_warn_after(),
'blockafter' => $forum->get_block_after(),
'blockperiod' => $forum->get_block_period(),
'completiondiscussions' => $forum->get_completion_discussions(),
'completionreplies' => $forum->get_completion_replies(),
'completionposts' => $forum->get_completion_posts(),
'displaywordcount' => $forum->should_display_word_count(),
'lockdiscussionafter' => $forum->get_lock_discussions_after(),
'duedate' => $forum->get_due_date(),
'cutoffdate' => $forum->get_cutoff_date()
];
}, $forums);
}
|
php
|
public function to_legacy_objects(array $forums) : array {
return array_map(function(forum_entity $forum) {
return (object) [
'id' => $forum->get_id(),
'course' => $forum->get_course_id(),
'type' => $forum->get_type(),
'name' => $forum->get_name(),
'intro' => $forum->get_intro(),
'introformat' => $forum->get_intro_format(),
'assessed' => $forum->get_rating_aggregate(),
'assesstimestart' => $forum->get_assess_time_start(),
'assesstimefinish' => $forum->get_assess_time_finish(),
'scale' => $forum->get_scale(),
'maxbytes' => $forum->get_max_bytes(),
'maxattachments' => $forum->get_max_attachments(),
'forcesubscribe' => $forum->get_subscription_mode(),
'trackingtype' => $forum->get_tracking_type(),
'rsstype' => $forum->get_rss_type(),
'rssarticles' => $forum->get_rss_articles(),
'timemodified' => $forum->get_time_modified(),
'warnafter' => $forum->get_warn_after(),
'blockafter' => $forum->get_block_after(),
'blockperiod' => $forum->get_block_period(),
'completiondiscussions' => $forum->get_completion_discussions(),
'completionreplies' => $forum->get_completion_replies(),
'completionposts' => $forum->get_completion_posts(),
'displaywordcount' => $forum->should_display_word_count(),
'lockdiscussionafter' => $forum->get_lock_discussions_after(),
'duedate' => $forum->get_due_date(),
'cutoffdate' => $forum->get_cutoff_date()
];
}, $forums);
}
|
[
"public",
"function",
"to_legacy_objects",
"(",
"array",
"$",
"forums",
")",
":",
"array",
"{",
"return",
"array_map",
"(",
"function",
"(",
"forum_entity",
"$",
"forum",
")",
"{",
"return",
"(",
"object",
")",
"[",
"'id'",
"=>",
"$",
"forum",
"->",
"get_id",
"(",
")",
",",
"'course'",
"=>",
"$",
"forum",
"->",
"get_course_id",
"(",
")",
",",
"'type'",
"=>",
"$",
"forum",
"->",
"get_type",
"(",
")",
",",
"'name'",
"=>",
"$",
"forum",
"->",
"get_name",
"(",
")",
",",
"'intro'",
"=>",
"$",
"forum",
"->",
"get_intro",
"(",
")",
",",
"'introformat'",
"=>",
"$",
"forum",
"->",
"get_intro_format",
"(",
")",
",",
"'assessed'",
"=>",
"$",
"forum",
"->",
"get_rating_aggregate",
"(",
")",
",",
"'assesstimestart'",
"=>",
"$",
"forum",
"->",
"get_assess_time_start",
"(",
")",
",",
"'assesstimefinish'",
"=>",
"$",
"forum",
"->",
"get_assess_time_finish",
"(",
")",
",",
"'scale'",
"=>",
"$",
"forum",
"->",
"get_scale",
"(",
")",
",",
"'maxbytes'",
"=>",
"$",
"forum",
"->",
"get_max_bytes",
"(",
")",
",",
"'maxattachments'",
"=>",
"$",
"forum",
"->",
"get_max_attachments",
"(",
")",
",",
"'forcesubscribe'",
"=>",
"$",
"forum",
"->",
"get_subscription_mode",
"(",
")",
",",
"'trackingtype'",
"=>",
"$",
"forum",
"->",
"get_tracking_type",
"(",
")",
",",
"'rsstype'",
"=>",
"$",
"forum",
"->",
"get_rss_type",
"(",
")",
",",
"'rssarticles'",
"=>",
"$",
"forum",
"->",
"get_rss_articles",
"(",
")",
",",
"'timemodified'",
"=>",
"$",
"forum",
"->",
"get_time_modified",
"(",
")",
",",
"'warnafter'",
"=>",
"$",
"forum",
"->",
"get_warn_after",
"(",
")",
",",
"'blockafter'",
"=>",
"$",
"forum",
"->",
"get_block_after",
"(",
")",
",",
"'blockperiod'",
"=>",
"$",
"forum",
"->",
"get_block_period",
"(",
")",
",",
"'completiondiscussions'",
"=>",
"$",
"forum",
"->",
"get_completion_discussions",
"(",
")",
",",
"'completionreplies'",
"=>",
"$",
"forum",
"->",
"get_completion_replies",
"(",
")",
",",
"'completionposts'",
"=>",
"$",
"forum",
"->",
"get_completion_posts",
"(",
")",
",",
"'displaywordcount'",
"=>",
"$",
"forum",
"->",
"should_display_word_count",
"(",
")",
",",
"'lockdiscussionafter'",
"=>",
"$",
"forum",
"->",
"get_lock_discussions_after",
"(",
")",
",",
"'duedate'",
"=>",
"$",
"forum",
"->",
"get_due_date",
"(",
")",
",",
"'cutoffdate'",
"=>",
"$",
"forum",
"->",
"get_cutoff_date",
"(",
")",
"]",
";",
"}",
",",
"$",
"forums",
")",
";",
"}"
] |
Convert a list of forum entities into stdClasses.
@param forum_entity[] $forums The forums to convert.
@return stdClass[]
|
[
"Convert",
"a",
"list",
"of",
"forum",
"entities",
"into",
"stdClasses",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/forum/classes/local/data_mappers/legacy/forum.php#L45-L77
|
215,305
|
moodle/moodle
|
cache/stores/memcached/addinstanceform.php
|
cachestore_memcached_addinstance_form.validation
|
public function validation($data, $files) {
$errors = parent::validation($data, $files);
if (isset($data['clustered']) && ($data['clustered'] == 1)) {
// Set servers is required with in cluster mode.
if (!isset($data['setservers'])) {
$errors['setservers'] = get_string('required');
} else {
$trimmed = trim($data['setservers']);
if (empty($trimmed)) {
$errors['setservers'] = get_string('required');
}
}
$validservers = false;
if (isset($data['servers'])) {
$servers = trim($data['servers']);
$servers = explode("\n", $servers);
if (count($servers) === 1) {
$validservers = true;
}
}
if (!$validservers) {
$errors['servers'] = get_string('serversclusterinvalid', 'cachestore_memcached');
}
}
return $errors;
}
|
php
|
public function validation($data, $files) {
$errors = parent::validation($data, $files);
if (isset($data['clustered']) && ($data['clustered'] == 1)) {
// Set servers is required with in cluster mode.
if (!isset($data['setservers'])) {
$errors['setservers'] = get_string('required');
} else {
$trimmed = trim($data['setservers']);
if (empty($trimmed)) {
$errors['setservers'] = get_string('required');
}
}
$validservers = false;
if (isset($data['servers'])) {
$servers = trim($data['servers']);
$servers = explode("\n", $servers);
if (count($servers) === 1) {
$validservers = true;
}
}
if (!$validservers) {
$errors['servers'] = get_string('serversclusterinvalid', 'cachestore_memcached');
}
}
return $errors;
}
|
[
"public",
"function",
"validation",
"(",
"$",
"data",
",",
"$",
"files",
")",
"{",
"$",
"errors",
"=",
"parent",
"::",
"validation",
"(",
"$",
"data",
",",
"$",
"files",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"data",
"[",
"'clustered'",
"]",
")",
"&&",
"(",
"$",
"data",
"[",
"'clustered'",
"]",
"==",
"1",
")",
")",
"{",
"// Set servers is required with in cluster mode.",
"if",
"(",
"!",
"isset",
"(",
"$",
"data",
"[",
"'setservers'",
"]",
")",
")",
"{",
"$",
"errors",
"[",
"'setservers'",
"]",
"=",
"get_string",
"(",
"'required'",
")",
";",
"}",
"else",
"{",
"$",
"trimmed",
"=",
"trim",
"(",
"$",
"data",
"[",
"'setservers'",
"]",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"trimmed",
")",
")",
"{",
"$",
"errors",
"[",
"'setservers'",
"]",
"=",
"get_string",
"(",
"'required'",
")",
";",
"}",
"}",
"$",
"validservers",
"=",
"false",
";",
"if",
"(",
"isset",
"(",
"$",
"data",
"[",
"'servers'",
"]",
")",
")",
"{",
"$",
"servers",
"=",
"trim",
"(",
"$",
"data",
"[",
"'servers'",
"]",
")",
";",
"$",
"servers",
"=",
"explode",
"(",
"\"\\n\"",
",",
"$",
"servers",
")",
";",
"if",
"(",
"count",
"(",
"$",
"servers",
")",
"===",
"1",
")",
"{",
"$",
"validservers",
"=",
"true",
";",
"}",
"}",
"if",
"(",
"!",
"$",
"validservers",
")",
"{",
"$",
"errors",
"[",
"'servers'",
"]",
"=",
"get_string",
"(",
"'serversclusterinvalid'",
",",
"'cachestore_memcached'",
")",
";",
"}",
"}",
"return",
"$",
"errors",
";",
"}"
] |
Perform minimal validation on the settings form.
@param array $data
@param array $files
|
[
"Perform",
"minimal",
"validation",
"on",
"the",
"settings",
"form",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/cache/stores/memcached/addinstanceform.php#L117-L146
|
215,306
|
moodle/moodle
|
question/type/ddimageortext/edit_ddimageortext_form.php
|
qtype_ddimageortext_edit_form.definition_draggable_items
|
protected function definition_draggable_items($mform, $itemrepeatsatstart) {
$mform->addElement('header', 'draggableitemheader',
get_string('draggableitems', 'qtype_ddimageortext'));
$mform->addElement('advcheckbox', 'shuffleanswers', ' ',
get_string('shuffleimages', 'qtype_'.$this->qtype()));
$mform->setDefault('shuffleanswers', 0);
$this->repeat_elements($this->draggable_item($mform), $itemrepeatsatstart,
$this->draggable_items_repeated_options(),
'noitems', 'additems', self::ADD_NUM_ITEMS,
get_string('addmoreimages', 'qtype_ddimageortext'), true);
}
|
php
|
protected function definition_draggable_items($mform, $itemrepeatsatstart) {
$mform->addElement('header', 'draggableitemheader',
get_string('draggableitems', 'qtype_ddimageortext'));
$mform->addElement('advcheckbox', 'shuffleanswers', ' ',
get_string('shuffleimages', 'qtype_'.$this->qtype()));
$mform->setDefault('shuffleanswers', 0);
$this->repeat_elements($this->draggable_item($mform), $itemrepeatsatstart,
$this->draggable_items_repeated_options(),
'noitems', 'additems', self::ADD_NUM_ITEMS,
get_string('addmoreimages', 'qtype_ddimageortext'), true);
}
|
[
"protected",
"function",
"definition_draggable_items",
"(",
"$",
"mform",
",",
"$",
"itemrepeatsatstart",
")",
"{",
"$",
"mform",
"->",
"addElement",
"(",
"'header'",
",",
"'draggableitemheader'",
",",
"get_string",
"(",
"'draggableitems'",
",",
"'qtype_ddimageortext'",
")",
")",
";",
"$",
"mform",
"->",
"addElement",
"(",
"'advcheckbox'",
",",
"'shuffleanswers'",
",",
"' '",
",",
"get_string",
"(",
"'shuffleimages'",
",",
"'qtype_'",
".",
"$",
"this",
"->",
"qtype",
"(",
")",
")",
")",
";",
"$",
"mform",
"->",
"setDefault",
"(",
"'shuffleanswers'",
",",
"0",
")",
";",
"$",
"this",
"->",
"repeat_elements",
"(",
"$",
"this",
"->",
"draggable_item",
"(",
"$",
"mform",
")",
",",
"$",
"itemrepeatsatstart",
",",
"$",
"this",
"->",
"draggable_items_repeated_options",
"(",
")",
",",
"'noitems'",
",",
"'additems'",
",",
"self",
"::",
"ADD_NUM_ITEMS",
",",
"get_string",
"(",
"'addmoreimages'",
",",
"'qtype_ddimageortext'",
")",
",",
"true",
")",
";",
"}"
] |
Drag items.
|
[
"Drag",
"items",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/question/type/ddimageortext/edit_ddimageortext_form.php#L126-L136
|
215,307
|
moodle/moodle
|
question/type/ddimageortext/edit_ddimageortext_form.php
|
qtype_ddimageortext_edit_form.drop_zone
|
protected function drop_zone($mform, $imagerepeats) {
$dropzoneitem = array();
$grouparray = array();
$grouparray[] = $mform->createElement('text', 'xleft',
get_string('xleft', 'qtype_ddimageortext'),
array('size' => 5, 'class' => 'tweakcss'));
$grouparray[] = $mform->createElement('text', 'ytop',
get_string('ytop', 'qtype_ddimageortext'),
array('size' => 5, 'class' => 'tweakcss'));
$options = array();
$options[0] = '';
for ($i = 1; $i <= $imagerepeats; $i += 1) {
$options[$i] = $i;
}
$grouparray[] = $mform->createElement('select', 'choice',
get_string('draggableitem', 'qtype_ddimageortext'), $options);
$grouparray[] = $mform->createElement('text', 'droplabel',
get_string('label', 'qtype_ddimageortext'),
array('size' => 10, 'class' => 'tweakcss'));
$mform->setType('droplabel', PARAM_NOTAGS);
$dropzone = $mform->createElement('group', 'drops',
get_string('dropzone', 'qtype_ddimageortext', '{no}'), $grouparray);
return array($dropzone);
}
|
php
|
protected function drop_zone($mform, $imagerepeats) {
$dropzoneitem = array();
$grouparray = array();
$grouparray[] = $mform->createElement('text', 'xleft',
get_string('xleft', 'qtype_ddimageortext'),
array('size' => 5, 'class' => 'tweakcss'));
$grouparray[] = $mform->createElement('text', 'ytop',
get_string('ytop', 'qtype_ddimageortext'),
array('size' => 5, 'class' => 'tweakcss'));
$options = array();
$options[0] = '';
for ($i = 1; $i <= $imagerepeats; $i += 1) {
$options[$i] = $i;
}
$grouparray[] = $mform->createElement('select', 'choice',
get_string('draggableitem', 'qtype_ddimageortext'), $options);
$grouparray[] = $mform->createElement('text', 'droplabel',
get_string('label', 'qtype_ddimageortext'),
array('size' => 10, 'class' => 'tweakcss'));
$mform->setType('droplabel', PARAM_NOTAGS);
$dropzone = $mform->createElement('group', 'drops',
get_string('dropzone', 'qtype_ddimageortext', '{no}'), $grouparray);
return array($dropzone);
}
|
[
"protected",
"function",
"drop_zone",
"(",
"$",
"mform",
",",
"$",
"imagerepeats",
")",
"{",
"$",
"dropzoneitem",
"=",
"array",
"(",
")",
";",
"$",
"grouparray",
"=",
"array",
"(",
")",
";",
"$",
"grouparray",
"[",
"]",
"=",
"$",
"mform",
"->",
"createElement",
"(",
"'text'",
",",
"'xleft'",
",",
"get_string",
"(",
"'xleft'",
",",
"'qtype_ddimageortext'",
")",
",",
"array",
"(",
"'size'",
"=>",
"5",
",",
"'class'",
"=>",
"'tweakcss'",
")",
")",
";",
"$",
"grouparray",
"[",
"]",
"=",
"$",
"mform",
"->",
"createElement",
"(",
"'text'",
",",
"'ytop'",
",",
"get_string",
"(",
"'ytop'",
",",
"'qtype_ddimageortext'",
")",
",",
"array",
"(",
"'size'",
"=>",
"5",
",",
"'class'",
"=>",
"'tweakcss'",
")",
")",
";",
"$",
"options",
"=",
"array",
"(",
")",
";",
"$",
"options",
"[",
"0",
"]",
"=",
"''",
";",
"for",
"(",
"$",
"i",
"=",
"1",
";",
"$",
"i",
"<=",
"$",
"imagerepeats",
";",
"$",
"i",
"+=",
"1",
")",
"{",
"$",
"options",
"[",
"$",
"i",
"]",
"=",
"$",
"i",
";",
"}",
"$",
"grouparray",
"[",
"]",
"=",
"$",
"mform",
"->",
"createElement",
"(",
"'select'",
",",
"'choice'",
",",
"get_string",
"(",
"'draggableitem'",
",",
"'qtype_ddimageortext'",
")",
",",
"$",
"options",
")",
";",
"$",
"grouparray",
"[",
"]",
"=",
"$",
"mform",
"->",
"createElement",
"(",
"'text'",
",",
"'droplabel'",
",",
"get_string",
"(",
"'label'",
",",
"'qtype_ddimageortext'",
")",
",",
"array",
"(",
"'size'",
"=>",
"10",
",",
"'class'",
"=>",
"'tweakcss'",
")",
")",
";",
"$",
"mform",
"->",
"setType",
"(",
"'droplabel'",
",",
"PARAM_NOTAGS",
")",
";",
"$",
"dropzone",
"=",
"$",
"mform",
"->",
"createElement",
"(",
"'group'",
",",
"'drops'",
",",
"get_string",
"(",
"'dropzone'",
",",
"'qtype_ddimageortext'",
",",
"'{no}'",
")",
",",
"$",
"grouparray",
")",
";",
"return",
"array",
"(",
"$",
"dropzone",
")",
";",
"}"
] |
Drop zones.
|
[
"Drop",
"zones",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/question/type/ddimageortext/edit_ddimageortext_form.php#L179-L204
|
215,308
|
moodle/moodle
|
lib/google/src/Google/Cache/Memcache.php
|
Google_Cache_Memcache.connect
|
private function connect()
{
if ($this->connection) {
return;
}
if (class_exists("Memcached")) {
$this->mc = new Memcached();
$this->mc->addServer($this->host, $this->port);
$this->connection = true;
} else {
$this->connection = memcache_pconnect($this->host, $this->port);
}
if (! $this->connection) {
$error = "Couldn't connect to memcache server";
$this->client->getLogger()->error($error);
throw new Google_Cache_Exception($error);
}
}
|
php
|
private function connect()
{
if ($this->connection) {
return;
}
if (class_exists("Memcached")) {
$this->mc = new Memcached();
$this->mc->addServer($this->host, $this->port);
$this->connection = true;
} else {
$this->connection = memcache_pconnect($this->host, $this->port);
}
if (! $this->connection) {
$error = "Couldn't connect to memcache server";
$this->client->getLogger()->error($error);
throw new Google_Cache_Exception($error);
}
}
|
[
"private",
"function",
"connect",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"connection",
")",
"{",
"return",
";",
"}",
"if",
"(",
"class_exists",
"(",
"\"Memcached\"",
")",
")",
"{",
"$",
"this",
"->",
"mc",
"=",
"new",
"Memcached",
"(",
")",
";",
"$",
"this",
"->",
"mc",
"->",
"addServer",
"(",
"$",
"this",
"->",
"host",
",",
"$",
"this",
"->",
"port",
")",
";",
"$",
"this",
"->",
"connection",
"=",
"true",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"connection",
"=",
"memcache_pconnect",
"(",
"$",
"this",
"->",
"host",
",",
"$",
"this",
"->",
"port",
")",
";",
"}",
"if",
"(",
"!",
"$",
"this",
"->",
"connection",
")",
"{",
"$",
"error",
"=",
"\"Couldn't connect to memcache server\"",
";",
"$",
"this",
"->",
"client",
"->",
"getLogger",
"(",
")",
"->",
"error",
"(",
"$",
"error",
")",
";",
"throw",
"new",
"Google_Cache_Exception",
"(",
"$",
"error",
")",
";",
"}",
"}"
] |
Lazy initialiser for memcache connection. Uses pconnect for to take
advantage of the persistence pool where possible.
|
[
"Lazy",
"initialiser",
"for",
"memcache",
"connection",
".",
"Uses",
"pconnect",
"for",
"to",
"take",
"advantage",
"of",
"the",
"persistence",
"pool",
"where",
"possible",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/google/src/Google/Cache/Memcache.php#L163-L183
|
215,309
|
moodle/moodle
|
analytics/classes/user.php
|
user.instance
|
public static function instance($user, ?\context $context = null) {
$userid = $user;
if (!is_scalar($userid)) {
$userid = $user->id;
}
if (self::$cachedid === $userid) {
return self::$cachedinstance;
}
$cachedinstance = new \core_analytics\user($user, $context);
self::$cachedinstance = $cachedinstance;
self::$cachedid = (int)$userid;
return self::$cachedinstance;
}
|
php
|
public static function instance($user, ?\context $context = null) {
$userid = $user;
if (!is_scalar($userid)) {
$userid = $user->id;
}
if (self::$cachedid === $userid) {
return self::$cachedinstance;
}
$cachedinstance = new \core_analytics\user($user, $context);
self::$cachedinstance = $cachedinstance;
self::$cachedid = (int)$userid;
return self::$cachedinstance;
}
|
[
"public",
"static",
"function",
"instance",
"(",
"$",
"user",
",",
"?",
"\\",
"context",
"$",
"context",
"=",
"null",
")",
"{",
"$",
"userid",
"=",
"$",
"user",
";",
"if",
"(",
"!",
"is_scalar",
"(",
"$",
"userid",
")",
")",
"{",
"$",
"userid",
"=",
"$",
"user",
"->",
"id",
";",
"}",
"if",
"(",
"self",
"::",
"$",
"cachedid",
"===",
"$",
"userid",
")",
"{",
"return",
"self",
"::",
"$",
"cachedinstance",
";",
"}",
"$",
"cachedinstance",
"=",
"new",
"\\",
"core_analytics",
"\\",
"user",
"(",
"$",
"user",
",",
"$",
"context",
")",
";",
"self",
"::",
"$",
"cachedinstance",
"=",
"$",
"cachedinstance",
";",
"self",
"::",
"$",
"cachedid",
"=",
"(",
"int",
")",
"$",
"userid",
";",
"return",
"self",
"::",
"$",
"cachedinstance",
";",
"}"
] |
Returns an analytics user instance.
Lazy load of analysable data.
@param int|\stdClass $user User object or user id
@param \context|null $context
@return \core_analytics\user
|
[
"Returns",
"an",
"analytics",
"user",
"instance",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/analytics/classes/user.php#L100-L115
|
215,310
|
moodle/moodle
|
analytics/classes/user.php
|
user.load
|
protected function load() {
// The instance constructor could be already loaded with the full user object. Using email
// because it is a required user field.
if (empty($this->user->email)) {
$this->user = \core_user::get_user($this->user->id);
}
$this->usercontext = $this->get_context();
$this->now = time();
// Flag the instance as loaded.
$this->loaded = true;
}
|
php
|
protected function load() {
// The instance constructor could be already loaded with the full user object. Using email
// because it is a required user field.
if (empty($this->user->email)) {
$this->user = \core_user::get_user($this->user->id);
}
$this->usercontext = $this->get_context();
$this->now = time();
// Flag the instance as loaded.
$this->loaded = true;
}
|
[
"protected",
"function",
"load",
"(",
")",
"{",
"// The instance constructor could be already loaded with the full user object. Using email",
"// because it is a required user field.",
"if",
"(",
"empty",
"(",
"$",
"this",
"->",
"user",
"->",
"email",
")",
")",
"{",
"$",
"this",
"->",
"user",
"=",
"\\",
"core_user",
"::",
"get_user",
"(",
"$",
"this",
"->",
"user",
"->",
"id",
")",
";",
"}",
"$",
"this",
"->",
"usercontext",
"=",
"$",
"this",
"->",
"get_context",
"(",
")",
";",
"$",
"this",
"->",
"now",
"=",
"time",
"(",
")",
";",
"// Flag the instance as loaded.",
"$",
"this",
"->",
"loaded",
"=",
"true",
";",
"}"
] |
Loads the analytics user object.
@return void
|
[
"Loads",
"the",
"analytics",
"user",
"object",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/analytics/classes/user.php#L131-L145
|
215,311
|
moodle/moodle
|
auth/ldap/auth.php
|
auth_plugin_ldap.init_plugin
|
function init_plugin($authtype) {
$this->pluginconfig = 'auth_'.$authtype;
$this->config = get_config($this->pluginconfig);
if (empty($this->config->ldapencoding)) {
$this->config->ldapencoding = 'utf-8';
}
if (empty($this->config->user_type)) {
$this->config->user_type = 'default';
}
$ldap_usertypes = ldap_supported_usertypes();
$this->config->user_type_name = $ldap_usertypes[$this->config->user_type];
unset($ldap_usertypes);
$default = ldap_getdefaults();
// Use defaults if values not given
foreach ($default as $key => $value) {
// watch out - 0, false are correct values too
if (!isset($this->config->{$key}) or $this->config->{$key} == '') {
$this->config->{$key} = $value[$this->config->user_type];
}
}
// Hack prefix to objectclass
$this->config->objectclass = ldap_normalise_objectclass($this->config->objectclass);
}
|
php
|
function init_plugin($authtype) {
$this->pluginconfig = 'auth_'.$authtype;
$this->config = get_config($this->pluginconfig);
if (empty($this->config->ldapencoding)) {
$this->config->ldapencoding = 'utf-8';
}
if (empty($this->config->user_type)) {
$this->config->user_type = 'default';
}
$ldap_usertypes = ldap_supported_usertypes();
$this->config->user_type_name = $ldap_usertypes[$this->config->user_type];
unset($ldap_usertypes);
$default = ldap_getdefaults();
// Use defaults if values not given
foreach ($default as $key => $value) {
// watch out - 0, false are correct values too
if (!isset($this->config->{$key}) or $this->config->{$key} == '') {
$this->config->{$key} = $value[$this->config->user_type];
}
}
// Hack prefix to objectclass
$this->config->objectclass = ldap_normalise_objectclass($this->config->objectclass);
}
|
[
"function",
"init_plugin",
"(",
"$",
"authtype",
")",
"{",
"$",
"this",
"->",
"pluginconfig",
"=",
"'auth_'",
".",
"$",
"authtype",
";",
"$",
"this",
"->",
"config",
"=",
"get_config",
"(",
"$",
"this",
"->",
"pluginconfig",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"this",
"->",
"config",
"->",
"ldapencoding",
")",
")",
"{",
"$",
"this",
"->",
"config",
"->",
"ldapencoding",
"=",
"'utf-8'",
";",
"}",
"if",
"(",
"empty",
"(",
"$",
"this",
"->",
"config",
"->",
"user_type",
")",
")",
"{",
"$",
"this",
"->",
"config",
"->",
"user_type",
"=",
"'default'",
";",
"}",
"$",
"ldap_usertypes",
"=",
"ldap_supported_usertypes",
"(",
")",
";",
"$",
"this",
"->",
"config",
"->",
"user_type_name",
"=",
"$",
"ldap_usertypes",
"[",
"$",
"this",
"->",
"config",
"->",
"user_type",
"]",
";",
"unset",
"(",
"$",
"ldap_usertypes",
")",
";",
"$",
"default",
"=",
"ldap_getdefaults",
"(",
")",
";",
"// Use defaults if values not given",
"foreach",
"(",
"$",
"default",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"// watch out - 0, false are correct values too",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"config",
"->",
"{",
"$",
"key",
"}",
")",
"or",
"$",
"this",
"->",
"config",
"->",
"{",
"$",
"key",
"}",
"==",
"''",
")",
"{",
"$",
"this",
"->",
"config",
"->",
"{",
"$",
"key",
"}",
"=",
"$",
"value",
"[",
"$",
"this",
"->",
"config",
"->",
"user_type",
"]",
";",
"}",
"}",
"// Hack prefix to objectclass",
"$",
"this",
"->",
"config",
"->",
"objectclass",
"=",
"ldap_normalise_objectclass",
"(",
"$",
"this",
"->",
"config",
"->",
"objectclass",
")",
";",
"}"
] |
Init plugin config from database settings depending on the plugin auth type.
|
[
"Init",
"plugin",
"config",
"from",
"database",
"settings",
"depending",
"on",
"the",
"plugin",
"auth",
"type",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/auth/ldap/auth.php#L92-L118
|
215,312
|
moodle/moodle
|
auth/ldap/auth.php
|
auth_plugin_ldap.user_exists
|
function user_exists($username) {
$extusername = core_text::convert($username, 'utf-8', $this->config->ldapencoding);
// Returns true if given username exists on ldap
$users = $this->ldap_get_userlist('('.$this->config->user_attribute.'='.ldap_filter_addslashes($extusername).')');
return count($users);
}
|
php
|
function user_exists($username) {
$extusername = core_text::convert($username, 'utf-8', $this->config->ldapencoding);
// Returns true if given username exists on ldap
$users = $this->ldap_get_userlist('('.$this->config->user_attribute.'='.ldap_filter_addslashes($extusername).')');
return count($users);
}
|
[
"function",
"user_exists",
"(",
"$",
"username",
")",
"{",
"$",
"extusername",
"=",
"core_text",
"::",
"convert",
"(",
"$",
"username",
",",
"'utf-8'",
",",
"$",
"this",
"->",
"config",
"->",
"ldapencoding",
")",
";",
"// Returns true if given username exists on ldap",
"$",
"users",
"=",
"$",
"this",
"->",
"ldap_get_userlist",
"(",
"'('",
".",
"$",
"this",
"->",
"config",
"->",
"user_attribute",
".",
"'='",
".",
"ldap_filter_addslashes",
"(",
"$",
"extusername",
")",
".",
"')'",
")",
";",
"return",
"count",
"(",
"$",
"users",
")",
";",
"}"
] |
Checks if user exists on LDAP
@param string $username
|
[
"Checks",
"if",
"user",
"exists",
"on",
"LDAP"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/auth/ldap/auth.php#L339-L345
|
215,313
|
moodle/moodle
|
auth/ldap/auth.php
|
auth_plugin_ldap.user_signup
|
function user_signup($user, $notify=true) {
global $CFG, $DB, $PAGE, $OUTPUT;
require_once($CFG->dirroot.'/user/profile/lib.php');
require_once($CFG->dirroot.'/user/lib.php');
if ($this->user_exists($user->username)) {
print_error('auth_ldap_user_exists', 'auth_ldap');
}
$plainslashedpassword = $user->password;
unset($user->password);
if (! $this->user_create($user, $plainslashedpassword)) {
print_error('auth_ldap_create_error', 'auth_ldap');
}
$user->id = user_create_user($user, false, false);
user_add_password_history($user->id, $plainslashedpassword);
// Save any custom profile field information
profile_save_data($user);
$userinfo = $this->get_userinfo($user->username);
$this->update_user_record($user->username, false, false, $this->is_user_suspended((object) $userinfo));
// This will also update the stored hash to the latest algorithm
// if the existing hash is using an out-of-date algorithm (or the
// legacy md5 algorithm).
update_internal_user_password($user, $plainslashedpassword);
$user = $DB->get_record('user', array('id'=>$user->id));
\core\event\user_created::create_from_userid($user->id)->trigger();
if (! send_confirmation_email($user)) {
print_error('noemail', 'auth_ldap');
}
if ($notify) {
$emailconfirm = get_string('emailconfirm');
$PAGE->set_url('/auth/ldap/auth.php');
$PAGE->navbar->add($emailconfirm);
$PAGE->set_title($emailconfirm);
$PAGE->set_heading($emailconfirm);
echo $OUTPUT->header();
notice(get_string('emailconfirmsent', '', $user->email), "{$CFG->wwwroot}/index.php");
} else {
return true;
}
}
|
php
|
function user_signup($user, $notify=true) {
global $CFG, $DB, $PAGE, $OUTPUT;
require_once($CFG->dirroot.'/user/profile/lib.php');
require_once($CFG->dirroot.'/user/lib.php');
if ($this->user_exists($user->username)) {
print_error('auth_ldap_user_exists', 'auth_ldap');
}
$plainslashedpassword = $user->password;
unset($user->password);
if (! $this->user_create($user, $plainslashedpassword)) {
print_error('auth_ldap_create_error', 'auth_ldap');
}
$user->id = user_create_user($user, false, false);
user_add_password_history($user->id, $plainslashedpassword);
// Save any custom profile field information
profile_save_data($user);
$userinfo = $this->get_userinfo($user->username);
$this->update_user_record($user->username, false, false, $this->is_user_suspended((object) $userinfo));
// This will also update the stored hash to the latest algorithm
// if the existing hash is using an out-of-date algorithm (or the
// legacy md5 algorithm).
update_internal_user_password($user, $plainslashedpassword);
$user = $DB->get_record('user', array('id'=>$user->id));
\core\event\user_created::create_from_userid($user->id)->trigger();
if (! send_confirmation_email($user)) {
print_error('noemail', 'auth_ldap');
}
if ($notify) {
$emailconfirm = get_string('emailconfirm');
$PAGE->set_url('/auth/ldap/auth.php');
$PAGE->navbar->add($emailconfirm);
$PAGE->set_title($emailconfirm);
$PAGE->set_heading($emailconfirm);
echo $OUTPUT->header();
notice(get_string('emailconfirmsent', '', $user->email), "{$CFG->wwwroot}/index.php");
} else {
return true;
}
}
|
[
"function",
"user_signup",
"(",
"$",
"user",
",",
"$",
"notify",
"=",
"true",
")",
"{",
"global",
"$",
"CFG",
",",
"$",
"DB",
",",
"$",
"PAGE",
",",
"$",
"OUTPUT",
";",
"require_once",
"(",
"$",
"CFG",
"->",
"dirroot",
".",
"'/user/profile/lib.php'",
")",
";",
"require_once",
"(",
"$",
"CFG",
"->",
"dirroot",
".",
"'/user/lib.php'",
")",
";",
"if",
"(",
"$",
"this",
"->",
"user_exists",
"(",
"$",
"user",
"->",
"username",
")",
")",
"{",
"print_error",
"(",
"'auth_ldap_user_exists'",
",",
"'auth_ldap'",
")",
";",
"}",
"$",
"plainslashedpassword",
"=",
"$",
"user",
"->",
"password",
";",
"unset",
"(",
"$",
"user",
"->",
"password",
")",
";",
"if",
"(",
"!",
"$",
"this",
"->",
"user_create",
"(",
"$",
"user",
",",
"$",
"plainslashedpassword",
")",
")",
"{",
"print_error",
"(",
"'auth_ldap_create_error'",
",",
"'auth_ldap'",
")",
";",
"}",
"$",
"user",
"->",
"id",
"=",
"user_create_user",
"(",
"$",
"user",
",",
"false",
",",
"false",
")",
";",
"user_add_password_history",
"(",
"$",
"user",
"->",
"id",
",",
"$",
"plainslashedpassword",
")",
";",
"// Save any custom profile field information",
"profile_save_data",
"(",
"$",
"user",
")",
";",
"$",
"userinfo",
"=",
"$",
"this",
"->",
"get_userinfo",
"(",
"$",
"user",
"->",
"username",
")",
";",
"$",
"this",
"->",
"update_user_record",
"(",
"$",
"user",
"->",
"username",
",",
"false",
",",
"false",
",",
"$",
"this",
"->",
"is_user_suspended",
"(",
"(",
"object",
")",
"$",
"userinfo",
")",
")",
";",
"// This will also update the stored hash to the latest algorithm",
"// if the existing hash is using an out-of-date algorithm (or the",
"// legacy md5 algorithm).",
"update_internal_user_password",
"(",
"$",
"user",
",",
"$",
"plainslashedpassword",
")",
";",
"$",
"user",
"=",
"$",
"DB",
"->",
"get_record",
"(",
"'user'",
",",
"array",
"(",
"'id'",
"=>",
"$",
"user",
"->",
"id",
")",
")",
";",
"\\",
"core",
"\\",
"event",
"\\",
"user_created",
"::",
"create_from_userid",
"(",
"$",
"user",
"->",
"id",
")",
"->",
"trigger",
"(",
")",
";",
"if",
"(",
"!",
"send_confirmation_email",
"(",
"$",
"user",
")",
")",
"{",
"print_error",
"(",
"'noemail'",
",",
"'auth_ldap'",
")",
";",
"}",
"if",
"(",
"$",
"notify",
")",
"{",
"$",
"emailconfirm",
"=",
"get_string",
"(",
"'emailconfirm'",
")",
";",
"$",
"PAGE",
"->",
"set_url",
"(",
"'/auth/ldap/auth.php'",
")",
";",
"$",
"PAGE",
"->",
"navbar",
"->",
"add",
"(",
"$",
"emailconfirm",
")",
";",
"$",
"PAGE",
"->",
"set_title",
"(",
"$",
"emailconfirm",
")",
";",
"$",
"PAGE",
"->",
"set_heading",
"(",
"$",
"emailconfirm",
")",
";",
"echo",
"$",
"OUTPUT",
"->",
"header",
"(",
")",
";",
"notice",
"(",
"get_string",
"(",
"'emailconfirmsent'",
",",
"''",
",",
"$",
"user",
"->",
"email",
")",
",",
"\"{$CFG->wwwroot}/index.php\"",
")",
";",
"}",
"else",
"{",
"return",
"true",
";",
"}",
"}"
] |
Sign up a new user ready for confirmation.
Password is passed in plaintext.
@param object $user new user object
@param boolean $notify print notice with link and terminate
@return boolean success
|
[
"Sign",
"up",
"a",
"new",
"user",
"ready",
"for",
"confirmation",
".",
"Password",
"is",
"passed",
"in",
"plaintext",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/auth/ldap/auth.php#L524-L575
|
215,314
|
moodle/moodle
|
auth/ldap/auth.php
|
auth_plugin_ldap.password_expire
|
function password_expire($username) {
$result = 0;
$extusername = core_text::convert($username, 'utf-8', $this->config->ldapencoding);
$ldapconnection = $this->ldap_connect();
$user_dn = $this->ldap_find_userdn($ldapconnection, $extusername);
$search_attribs = array($this->config->expireattr);
$sr = ldap_read($ldapconnection, $user_dn, '(objectClass=*)', $search_attribs);
if ($sr) {
$info = ldap_get_entries_moodle($ldapconnection, $sr);
if (!empty ($info)) {
$info = $info[0];
if (isset($info[$this->config->expireattr][0])) {
$expiretime = $this->ldap_expirationtime2unix($info[$this->config->expireattr][0], $ldapconnection, $user_dn);
if ($expiretime != 0) {
$now = time();
if ($expiretime > $now) {
$result = ceil(($expiretime - $now) / DAYSECS);
} else {
$result = floor(($expiretime - $now) / DAYSECS);
}
}
}
}
} else {
error_log($this->errorlogtag.get_string('didtfindexpiretime', 'auth_ldap'));
}
return $result;
}
|
php
|
function password_expire($username) {
$result = 0;
$extusername = core_text::convert($username, 'utf-8', $this->config->ldapencoding);
$ldapconnection = $this->ldap_connect();
$user_dn = $this->ldap_find_userdn($ldapconnection, $extusername);
$search_attribs = array($this->config->expireattr);
$sr = ldap_read($ldapconnection, $user_dn, '(objectClass=*)', $search_attribs);
if ($sr) {
$info = ldap_get_entries_moodle($ldapconnection, $sr);
if (!empty ($info)) {
$info = $info[0];
if (isset($info[$this->config->expireattr][0])) {
$expiretime = $this->ldap_expirationtime2unix($info[$this->config->expireattr][0], $ldapconnection, $user_dn);
if ($expiretime != 0) {
$now = time();
if ($expiretime > $now) {
$result = ceil(($expiretime - $now) / DAYSECS);
} else {
$result = floor(($expiretime - $now) / DAYSECS);
}
}
}
}
} else {
error_log($this->errorlogtag.get_string('didtfindexpiretime', 'auth_ldap'));
}
return $result;
}
|
[
"function",
"password_expire",
"(",
"$",
"username",
")",
"{",
"$",
"result",
"=",
"0",
";",
"$",
"extusername",
"=",
"core_text",
"::",
"convert",
"(",
"$",
"username",
",",
"'utf-8'",
",",
"$",
"this",
"->",
"config",
"->",
"ldapencoding",
")",
";",
"$",
"ldapconnection",
"=",
"$",
"this",
"->",
"ldap_connect",
"(",
")",
";",
"$",
"user_dn",
"=",
"$",
"this",
"->",
"ldap_find_userdn",
"(",
"$",
"ldapconnection",
",",
"$",
"extusername",
")",
";",
"$",
"search_attribs",
"=",
"array",
"(",
"$",
"this",
"->",
"config",
"->",
"expireattr",
")",
";",
"$",
"sr",
"=",
"ldap_read",
"(",
"$",
"ldapconnection",
",",
"$",
"user_dn",
",",
"'(objectClass=*)'",
",",
"$",
"search_attribs",
")",
";",
"if",
"(",
"$",
"sr",
")",
"{",
"$",
"info",
"=",
"ldap_get_entries_moodle",
"(",
"$",
"ldapconnection",
",",
"$",
"sr",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"info",
")",
")",
"{",
"$",
"info",
"=",
"$",
"info",
"[",
"0",
"]",
";",
"if",
"(",
"isset",
"(",
"$",
"info",
"[",
"$",
"this",
"->",
"config",
"->",
"expireattr",
"]",
"[",
"0",
"]",
")",
")",
"{",
"$",
"expiretime",
"=",
"$",
"this",
"->",
"ldap_expirationtime2unix",
"(",
"$",
"info",
"[",
"$",
"this",
"->",
"config",
"->",
"expireattr",
"]",
"[",
"0",
"]",
",",
"$",
"ldapconnection",
",",
"$",
"user_dn",
")",
";",
"if",
"(",
"$",
"expiretime",
"!=",
"0",
")",
"{",
"$",
"now",
"=",
"time",
"(",
")",
";",
"if",
"(",
"$",
"expiretime",
">",
"$",
"now",
")",
"{",
"$",
"result",
"=",
"ceil",
"(",
"(",
"$",
"expiretime",
"-",
"$",
"now",
")",
"/",
"DAYSECS",
")",
";",
"}",
"else",
"{",
"$",
"result",
"=",
"floor",
"(",
"(",
"$",
"expiretime",
"-",
"$",
"now",
")",
"/",
"DAYSECS",
")",
";",
"}",
"}",
"}",
"}",
"}",
"else",
"{",
"error_log",
"(",
"$",
"this",
"->",
"errorlogtag",
".",
"get_string",
"(",
"'didtfindexpiretime'",
",",
"'auth_ldap'",
")",
")",
";",
"}",
"return",
"$",
"result",
";",
"}"
] |
Return number of days to user password expires
If userpassword does not expire it should return 0. If password is already expired
it should return negative value.
@param mixed $username username
@return integer
|
[
"Return",
"number",
"of",
"days",
"to",
"user",
"password",
"expires"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/auth/ldap/auth.php#L626-L656
|
215,315
|
moodle/moodle
|
auth/ldap/auth.php
|
auth_plugin_ldap.ldap_bulk_insert
|
function ldap_bulk_insert($username) {
global $DB, $CFG;
$username = core_text::strtolower($username); // usernames are __always__ lowercase.
$DB->insert_record_raw('tmp_extuser', array('username'=>$username,
'mnethostid'=>$CFG->mnet_localhost_id), false, true);
echo '.';
}
|
php
|
function ldap_bulk_insert($username) {
global $DB, $CFG;
$username = core_text::strtolower($username); // usernames are __always__ lowercase.
$DB->insert_record_raw('tmp_extuser', array('username'=>$username,
'mnethostid'=>$CFG->mnet_localhost_id), false, true);
echo '.';
}
|
[
"function",
"ldap_bulk_insert",
"(",
"$",
"username",
")",
"{",
"global",
"$",
"DB",
",",
"$",
"CFG",
";",
"$",
"username",
"=",
"core_text",
"::",
"strtolower",
"(",
"$",
"username",
")",
";",
"// usernames are __always__ lowercase.",
"$",
"DB",
"->",
"insert_record_raw",
"(",
"'tmp_extuser'",
",",
"array",
"(",
"'username'",
"=>",
"$",
"username",
",",
"'mnethostid'",
"=>",
"$",
"CFG",
"->",
"mnet_localhost_id",
")",
",",
"false",
",",
"true",
")",
";",
"echo",
"'.'",
";",
"}"
] |
Bulk insert in SQL's temp table
|
[
"Bulk",
"insert",
"in",
"SQL",
"s",
"temp",
"table"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/auth/ldap/auth.php#L954-L961
|
215,316
|
moodle/moodle
|
auth/ldap/auth.php
|
auth_plugin_ldap.is_role
|
private function is_role($username, $role) {
if (empty($this->config->{$role['settingname']}) or empty($this->config->memberattribute)) {
return null;
}
$extusername = core_text::convert($username, 'utf-8', $this->config->ldapencoding);
$ldapconnection = $this->ldap_connect();
if ($this->config->memberattribute_isdn) {
if (!($userid = $this->ldap_find_userdn($ldapconnection, $extusername))) {
return false;
}
} else {
$userid = $extusername;
}
$groupdns = explode(';', $this->config->{$role['settingname']});
$isrole = ldap_isgroupmember($ldapconnection, $userid, $groupdns, $this->config->memberattribute);
$this->ldap_close();
return $isrole;
}
|
php
|
private function is_role($username, $role) {
if (empty($this->config->{$role['settingname']}) or empty($this->config->memberattribute)) {
return null;
}
$extusername = core_text::convert($username, 'utf-8', $this->config->ldapencoding);
$ldapconnection = $this->ldap_connect();
if ($this->config->memberattribute_isdn) {
if (!($userid = $this->ldap_find_userdn($ldapconnection, $extusername))) {
return false;
}
} else {
$userid = $extusername;
}
$groupdns = explode(';', $this->config->{$role['settingname']});
$isrole = ldap_isgroupmember($ldapconnection, $userid, $groupdns, $this->config->memberattribute);
$this->ldap_close();
return $isrole;
}
|
[
"private",
"function",
"is_role",
"(",
"$",
"username",
",",
"$",
"role",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"this",
"->",
"config",
"->",
"{",
"$",
"role",
"[",
"'settingname'",
"]",
"}",
")",
"or",
"empty",
"(",
"$",
"this",
"->",
"config",
"->",
"memberattribute",
")",
")",
"{",
"return",
"null",
";",
"}",
"$",
"extusername",
"=",
"core_text",
"::",
"convert",
"(",
"$",
"username",
",",
"'utf-8'",
",",
"$",
"this",
"->",
"config",
"->",
"ldapencoding",
")",
";",
"$",
"ldapconnection",
"=",
"$",
"this",
"->",
"ldap_connect",
"(",
")",
";",
"if",
"(",
"$",
"this",
"->",
"config",
"->",
"memberattribute_isdn",
")",
"{",
"if",
"(",
"!",
"(",
"$",
"userid",
"=",
"$",
"this",
"->",
"ldap_find_userdn",
"(",
"$",
"ldapconnection",
",",
"$",
"extusername",
")",
")",
")",
"{",
"return",
"false",
";",
"}",
"}",
"else",
"{",
"$",
"userid",
"=",
"$",
"extusername",
";",
"}",
"$",
"groupdns",
"=",
"explode",
"(",
"';'",
",",
"$",
"this",
"->",
"config",
"->",
"{",
"$",
"role",
"[",
"'settingname'",
"]",
"}",
")",
";",
"$",
"isrole",
"=",
"ldap_isgroupmember",
"(",
"$",
"ldapconnection",
",",
"$",
"userid",
",",
"$",
"groupdns",
",",
"$",
"this",
"->",
"config",
"->",
"memberattribute",
")",
";",
"$",
"this",
"->",
"ldap_close",
"(",
")",
";",
"return",
"$",
"isrole",
";",
"}"
] |
Check if user has LDAP group membership.
Returns true if user should be assigned role.
@param mixed $username username (without system magic quotes).
@param array $role Array of role's shortname, localname, and settingname for the config value.
@return mixed result null if role/LDAP context is not configured, boolean otherwise.
|
[
"Check",
"if",
"user",
"has",
"LDAP",
"group",
"membership",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/auth/ldap/auth.php#L1053-L1076
|
215,317
|
moodle/moodle
|
auth/ldap/auth.php
|
auth_plugin_ldap.ldap_expirationtime2unix
|
function ldap_expirationtime2unix ($time, $ldapconnection, $user_dn) {
$result = false;
switch ($this->config->user_type) {
case 'edir':
$yr=substr($time, 0, 4);
$mo=substr($time, 4, 2);
$dt=substr($time, 6, 2);
$hr=substr($time, 8, 2);
$min=substr($time, 10, 2);
$sec=substr($time, 12, 2);
$result = mktime($hr, $min, $sec, $mo, $dt, $yr);
break;
case 'rfc2307':
case 'rfc2307bis':
$result = $time * DAYSECS; // The shadowExpire contains the number of DAYS between 01/01/1970 and the actual expiration date
break;
case 'ad':
$result = $this->ldap_get_ad_pwdexpire($time, $ldapconnection, $user_dn);
break;
default:
print_error('auth_ldap_usertypeundefined', 'auth_ldap');
}
return $result;
}
|
php
|
function ldap_expirationtime2unix ($time, $ldapconnection, $user_dn) {
$result = false;
switch ($this->config->user_type) {
case 'edir':
$yr=substr($time, 0, 4);
$mo=substr($time, 4, 2);
$dt=substr($time, 6, 2);
$hr=substr($time, 8, 2);
$min=substr($time, 10, 2);
$sec=substr($time, 12, 2);
$result = mktime($hr, $min, $sec, $mo, $dt, $yr);
break;
case 'rfc2307':
case 'rfc2307bis':
$result = $time * DAYSECS; // The shadowExpire contains the number of DAYS between 01/01/1970 and the actual expiration date
break;
case 'ad':
$result = $this->ldap_get_ad_pwdexpire($time, $ldapconnection, $user_dn);
break;
default:
print_error('auth_ldap_usertypeundefined', 'auth_ldap');
}
return $result;
}
|
[
"function",
"ldap_expirationtime2unix",
"(",
"$",
"time",
",",
"$",
"ldapconnection",
",",
"$",
"user_dn",
")",
"{",
"$",
"result",
"=",
"false",
";",
"switch",
"(",
"$",
"this",
"->",
"config",
"->",
"user_type",
")",
"{",
"case",
"'edir'",
":",
"$",
"yr",
"=",
"substr",
"(",
"$",
"time",
",",
"0",
",",
"4",
")",
";",
"$",
"mo",
"=",
"substr",
"(",
"$",
"time",
",",
"4",
",",
"2",
")",
";",
"$",
"dt",
"=",
"substr",
"(",
"$",
"time",
",",
"6",
",",
"2",
")",
";",
"$",
"hr",
"=",
"substr",
"(",
"$",
"time",
",",
"8",
",",
"2",
")",
";",
"$",
"min",
"=",
"substr",
"(",
"$",
"time",
",",
"10",
",",
"2",
")",
";",
"$",
"sec",
"=",
"substr",
"(",
"$",
"time",
",",
"12",
",",
"2",
")",
";",
"$",
"result",
"=",
"mktime",
"(",
"$",
"hr",
",",
"$",
"min",
",",
"$",
"sec",
",",
"$",
"mo",
",",
"$",
"dt",
",",
"$",
"yr",
")",
";",
"break",
";",
"case",
"'rfc2307'",
":",
"case",
"'rfc2307bis'",
":",
"$",
"result",
"=",
"$",
"time",
"*",
"DAYSECS",
";",
"// The shadowExpire contains the number of DAYS between 01/01/1970 and the actual expiration date",
"break",
";",
"case",
"'ad'",
":",
"$",
"result",
"=",
"$",
"this",
"->",
"ldap_get_ad_pwdexpire",
"(",
"$",
"time",
",",
"$",
"ldapconnection",
",",
"$",
"user_dn",
")",
";",
"break",
";",
"default",
":",
"print_error",
"(",
"'auth_ldap_usertypeundefined'",
",",
"'auth_ldap'",
")",
";",
"}",
"return",
"$",
"result",
";",
"}"
] |
Take expirationtime and return it as unix timestamp in seconds
Takes expiration timestamp as read from LDAP and returns it as unix timestamp in seconds
Depends on $this->config->user_type variable
@param mixed time Time stamp read from LDAP as it is.
@param string $ldapconnection Only needed for Active Directory.
@param string $user_dn User distinguished name for the user we are checking password expiration (only needed for Active Directory).
@return timestamp
|
[
"Take",
"expirationtime",
"and",
"return",
"it",
"as",
"unix",
"timestamp",
"in",
"seconds"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/auth/ldap/auth.php#L1417-L1440
|
215,318
|
moodle/moodle
|
auth/ldap/auth.php
|
auth_plugin_ldap.ldap_unix2expirationtime
|
function ldap_unix2expirationtime($time) {
$result = false;
switch ($this->config->user_type) {
case 'edir':
$result=date('YmdHis', $time).'Z';
break;
case 'rfc2307':
case 'rfc2307bis':
$result = $time ; // Already in correct format
break;
default:
print_error('auth_ldap_usertypeundefined2', 'auth_ldap');
}
return $result;
}
|
php
|
function ldap_unix2expirationtime($time) {
$result = false;
switch ($this->config->user_type) {
case 'edir':
$result=date('YmdHis', $time).'Z';
break;
case 'rfc2307':
case 'rfc2307bis':
$result = $time ; // Already in correct format
break;
default:
print_error('auth_ldap_usertypeundefined2', 'auth_ldap');
}
return $result;
}
|
[
"function",
"ldap_unix2expirationtime",
"(",
"$",
"time",
")",
"{",
"$",
"result",
"=",
"false",
";",
"switch",
"(",
"$",
"this",
"->",
"config",
"->",
"user_type",
")",
"{",
"case",
"'edir'",
":",
"$",
"result",
"=",
"date",
"(",
"'YmdHis'",
",",
"$",
"time",
")",
".",
"'Z'",
";",
"break",
";",
"case",
"'rfc2307'",
":",
"case",
"'rfc2307bis'",
":",
"$",
"result",
"=",
"$",
"time",
";",
"// Already in correct format",
"break",
";",
"default",
":",
"print_error",
"(",
"'auth_ldap_usertypeundefined2'",
",",
"'auth_ldap'",
")",
";",
"}",
"return",
"$",
"result",
";",
"}"
] |
Takes unix timestamp and returns it formated for storing in LDAP
@param integer unix time stamp
|
[
"Takes",
"unix",
"timestamp",
"and",
"returns",
"it",
"formated",
"for",
"storing",
"in",
"LDAP"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/auth/ldap/auth.php#L1447-L1462
|
215,319
|
moodle/moodle
|
auth/ldap/auth.php
|
auth_plugin_ldap.ldap_attributes
|
function ldap_attributes () {
$moodleattributes = array();
// If we have custom fields then merge them with user fields.
$customfields = $this->get_custom_user_profile_fields();
if (!empty($customfields) && !empty($this->userfields)) {
$userfields = array_merge($this->userfields, $customfields);
} else {
$userfields = $this->userfields;
}
foreach ($userfields as $field) {
if (!empty($this->config->{"field_map_$field"})) {
$moodleattributes[$field] = core_text::strtolower(trim($this->config->{"field_map_$field"}));
if (preg_match('/,/', $moodleattributes[$field])) {
$moodleattributes[$field] = explode(',', $moodleattributes[$field]); // split ?
}
}
}
$moodleattributes['username'] = core_text::strtolower(trim($this->config->user_attribute));
$moodleattributes['suspended'] = core_text::strtolower(trim($this->config->suspended_attribute));
return $moodleattributes;
}
|
php
|
function ldap_attributes () {
$moodleattributes = array();
// If we have custom fields then merge them with user fields.
$customfields = $this->get_custom_user_profile_fields();
if (!empty($customfields) && !empty($this->userfields)) {
$userfields = array_merge($this->userfields, $customfields);
} else {
$userfields = $this->userfields;
}
foreach ($userfields as $field) {
if (!empty($this->config->{"field_map_$field"})) {
$moodleattributes[$field] = core_text::strtolower(trim($this->config->{"field_map_$field"}));
if (preg_match('/,/', $moodleattributes[$field])) {
$moodleattributes[$field] = explode(',', $moodleattributes[$field]); // split ?
}
}
}
$moodleattributes['username'] = core_text::strtolower(trim($this->config->user_attribute));
$moodleattributes['suspended'] = core_text::strtolower(trim($this->config->suspended_attribute));
return $moodleattributes;
}
|
[
"function",
"ldap_attributes",
"(",
")",
"{",
"$",
"moodleattributes",
"=",
"array",
"(",
")",
";",
"// If we have custom fields then merge them with user fields.",
"$",
"customfields",
"=",
"$",
"this",
"->",
"get_custom_user_profile_fields",
"(",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"customfields",
")",
"&&",
"!",
"empty",
"(",
"$",
"this",
"->",
"userfields",
")",
")",
"{",
"$",
"userfields",
"=",
"array_merge",
"(",
"$",
"this",
"->",
"userfields",
",",
"$",
"customfields",
")",
";",
"}",
"else",
"{",
"$",
"userfields",
"=",
"$",
"this",
"->",
"userfields",
";",
"}",
"foreach",
"(",
"$",
"userfields",
"as",
"$",
"field",
")",
"{",
"if",
"(",
"!",
"empty",
"(",
"$",
"this",
"->",
"config",
"->",
"{",
"\"field_map_$field\"",
"}",
")",
")",
"{",
"$",
"moodleattributes",
"[",
"$",
"field",
"]",
"=",
"core_text",
"::",
"strtolower",
"(",
"trim",
"(",
"$",
"this",
"->",
"config",
"->",
"{",
"\"field_map_$field\"",
"}",
")",
")",
";",
"if",
"(",
"preg_match",
"(",
"'/,/'",
",",
"$",
"moodleattributes",
"[",
"$",
"field",
"]",
")",
")",
"{",
"$",
"moodleattributes",
"[",
"$",
"field",
"]",
"=",
"explode",
"(",
"','",
",",
"$",
"moodleattributes",
"[",
"$",
"field",
"]",
")",
";",
"// split ?",
"}",
"}",
"}",
"$",
"moodleattributes",
"[",
"'username'",
"]",
"=",
"core_text",
"::",
"strtolower",
"(",
"trim",
"(",
"$",
"this",
"->",
"config",
"->",
"user_attribute",
")",
")",
";",
"$",
"moodleattributes",
"[",
"'suspended'",
"]",
"=",
"core_text",
"::",
"strtolower",
"(",
"trim",
"(",
"$",
"this",
"->",
"config",
"->",
"suspended_attribute",
")",
")",
";",
"return",
"$",
"moodleattributes",
";",
"}"
] |
Returns user attribute mappings between moodle and LDAP
@return array
|
[
"Returns",
"user",
"attribute",
"mappings",
"between",
"moodle",
"and",
"LDAP"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/auth/ldap/auth.php#L1470-L1491
|
215,320
|
moodle/moodle
|
auth/ldap/auth.php
|
auth_plugin_ldap.ldap_get_userlist
|
function ldap_get_userlist($filter='*') {
$fresult = array();
$ldapconnection = $this->ldap_connect();
if ($filter == '*') {
$filter = '(&('.$this->config->user_attribute.'=*)'.$this->config->objectclass.')';
}
$contexts = explode(';', $this->config->contexts);
if (!empty($this->config->create_context)) {
array_push($contexts, $this->config->create_context);
}
$ldap_cookie = '';
$ldap_pagedresults = ldap_paged_results_supported($this->config->ldap_version, $ldapconnection);
foreach ($contexts as $context) {
$context = trim($context);
if (empty($context)) {
continue;
}
do {
if ($ldap_pagedresults) {
ldap_control_paged_result($ldapconnection, $this->config->pagesize, true, $ldap_cookie);
}
if ($this->config->search_sub) {
// Use ldap_search to find first user from subtree.
$ldap_result = ldap_search($ldapconnection, $context, $filter, array($this->config->user_attribute));
} else {
// Search only in this context.
$ldap_result = ldap_list($ldapconnection, $context, $filter, array($this->config->user_attribute));
}
if(!$ldap_result) {
continue;
}
if ($ldap_pagedresults) {
ldap_control_paged_result_response($ldapconnection, $ldap_result, $ldap_cookie);
}
$users = ldap_get_entries_moodle($ldapconnection, $ldap_result);
// Add found users to list.
for ($i = 0; $i < count($users); $i++) {
$extuser = core_text::convert($users[$i][$this->config->user_attribute][0],
$this->config->ldapencoding, 'utf-8');
array_push($fresult, $extuser);
}
unset($ldap_result); // Free mem.
} while ($ldap_pagedresults && !empty($ldap_cookie));
}
// If paged results were used, make sure the current connection is completely closed
$this->ldap_close($ldap_pagedresults);
return $fresult;
}
|
php
|
function ldap_get_userlist($filter='*') {
$fresult = array();
$ldapconnection = $this->ldap_connect();
if ($filter == '*') {
$filter = '(&('.$this->config->user_attribute.'=*)'.$this->config->objectclass.')';
}
$contexts = explode(';', $this->config->contexts);
if (!empty($this->config->create_context)) {
array_push($contexts, $this->config->create_context);
}
$ldap_cookie = '';
$ldap_pagedresults = ldap_paged_results_supported($this->config->ldap_version, $ldapconnection);
foreach ($contexts as $context) {
$context = trim($context);
if (empty($context)) {
continue;
}
do {
if ($ldap_pagedresults) {
ldap_control_paged_result($ldapconnection, $this->config->pagesize, true, $ldap_cookie);
}
if ($this->config->search_sub) {
// Use ldap_search to find first user from subtree.
$ldap_result = ldap_search($ldapconnection, $context, $filter, array($this->config->user_attribute));
} else {
// Search only in this context.
$ldap_result = ldap_list($ldapconnection, $context, $filter, array($this->config->user_attribute));
}
if(!$ldap_result) {
continue;
}
if ($ldap_pagedresults) {
ldap_control_paged_result_response($ldapconnection, $ldap_result, $ldap_cookie);
}
$users = ldap_get_entries_moodle($ldapconnection, $ldap_result);
// Add found users to list.
for ($i = 0; $i < count($users); $i++) {
$extuser = core_text::convert($users[$i][$this->config->user_attribute][0],
$this->config->ldapencoding, 'utf-8');
array_push($fresult, $extuser);
}
unset($ldap_result); // Free mem.
} while ($ldap_pagedresults && !empty($ldap_cookie));
}
// If paged results were used, make sure the current connection is completely closed
$this->ldap_close($ldap_pagedresults);
return $fresult;
}
|
[
"function",
"ldap_get_userlist",
"(",
"$",
"filter",
"=",
"'*'",
")",
"{",
"$",
"fresult",
"=",
"array",
"(",
")",
";",
"$",
"ldapconnection",
"=",
"$",
"this",
"->",
"ldap_connect",
"(",
")",
";",
"if",
"(",
"$",
"filter",
"==",
"'*'",
")",
"{",
"$",
"filter",
"=",
"'(&('",
".",
"$",
"this",
"->",
"config",
"->",
"user_attribute",
".",
"'=*)'",
".",
"$",
"this",
"->",
"config",
"->",
"objectclass",
".",
"')'",
";",
"}",
"$",
"contexts",
"=",
"explode",
"(",
"';'",
",",
"$",
"this",
"->",
"config",
"->",
"contexts",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"this",
"->",
"config",
"->",
"create_context",
")",
")",
"{",
"array_push",
"(",
"$",
"contexts",
",",
"$",
"this",
"->",
"config",
"->",
"create_context",
")",
";",
"}",
"$",
"ldap_cookie",
"=",
"''",
";",
"$",
"ldap_pagedresults",
"=",
"ldap_paged_results_supported",
"(",
"$",
"this",
"->",
"config",
"->",
"ldap_version",
",",
"$",
"ldapconnection",
")",
";",
"foreach",
"(",
"$",
"contexts",
"as",
"$",
"context",
")",
"{",
"$",
"context",
"=",
"trim",
"(",
"$",
"context",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"context",
")",
")",
"{",
"continue",
";",
"}",
"do",
"{",
"if",
"(",
"$",
"ldap_pagedresults",
")",
"{",
"ldap_control_paged_result",
"(",
"$",
"ldapconnection",
",",
"$",
"this",
"->",
"config",
"->",
"pagesize",
",",
"true",
",",
"$",
"ldap_cookie",
")",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"config",
"->",
"search_sub",
")",
"{",
"// Use ldap_search to find first user from subtree.",
"$",
"ldap_result",
"=",
"ldap_search",
"(",
"$",
"ldapconnection",
",",
"$",
"context",
",",
"$",
"filter",
",",
"array",
"(",
"$",
"this",
"->",
"config",
"->",
"user_attribute",
")",
")",
";",
"}",
"else",
"{",
"// Search only in this context.",
"$",
"ldap_result",
"=",
"ldap_list",
"(",
"$",
"ldapconnection",
",",
"$",
"context",
",",
"$",
"filter",
",",
"array",
"(",
"$",
"this",
"->",
"config",
"->",
"user_attribute",
")",
")",
";",
"}",
"if",
"(",
"!",
"$",
"ldap_result",
")",
"{",
"continue",
";",
"}",
"if",
"(",
"$",
"ldap_pagedresults",
")",
"{",
"ldap_control_paged_result_response",
"(",
"$",
"ldapconnection",
",",
"$",
"ldap_result",
",",
"$",
"ldap_cookie",
")",
";",
"}",
"$",
"users",
"=",
"ldap_get_entries_moodle",
"(",
"$",
"ldapconnection",
",",
"$",
"ldap_result",
")",
";",
"// Add found users to list.",
"for",
"(",
"$",
"i",
"=",
"0",
";",
"$",
"i",
"<",
"count",
"(",
"$",
"users",
")",
";",
"$",
"i",
"++",
")",
"{",
"$",
"extuser",
"=",
"core_text",
"::",
"convert",
"(",
"$",
"users",
"[",
"$",
"i",
"]",
"[",
"$",
"this",
"->",
"config",
"->",
"user_attribute",
"]",
"[",
"0",
"]",
",",
"$",
"this",
"->",
"config",
"->",
"ldapencoding",
",",
"'utf-8'",
")",
";",
"array_push",
"(",
"$",
"fresult",
",",
"$",
"extuser",
")",
";",
"}",
"unset",
"(",
"$",
"ldap_result",
")",
";",
"// Free mem.",
"}",
"while",
"(",
"$",
"ldap_pagedresults",
"&&",
"!",
"empty",
"(",
"$",
"ldap_cookie",
")",
")",
";",
"}",
"// If paged results were used, make sure the current connection is completely closed",
"$",
"this",
"->",
"ldap_close",
"(",
"$",
"ldap_pagedresults",
")",
";",
"return",
"$",
"fresult",
";",
"}"
] |
Returns all usernames from LDAP
@param $filter An LDAP search filter to select desired users
@return array of LDAP user names converted to UTF-8
|
[
"Returns",
"all",
"usernames",
"from",
"LDAP"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/auth/ldap/auth.php#L1499-L1552
|
215,321
|
moodle/moodle
|
auth/ldap/auth.php
|
auth_plugin_ldap.change_password_url
|
function change_password_url() {
if (empty($this->config->stdchangepassword)) {
if (!empty($this->config->changepasswordurl)) {
return new moodle_url($this->config->changepasswordurl);
} else {
return null;
}
} else {
return null;
}
}
|
php
|
function change_password_url() {
if (empty($this->config->stdchangepassword)) {
if (!empty($this->config->changepasswordurl)) {
return new moodle_url($this->config->changepasswordurl);
} else {
return null;
}
} else {
return null;
}
}
|
[
"function",
"change_password_url",
"(",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"this",
"->",
"config",
"->",
"stdchangepassword",
")",
")",
"{",
"if",
"(",
"!",
"empty",
"(",
"$",
"this",
"->",
"config",
"->",
"changepasswordurl",
")",
")",
"{",
"return",
"new",
"moodle_url",
"(",
"$",
"this",
"->",
"config",
"->",
"changepasswordurl",
")",
";",
"}",
"else",
"{",
"return",
"null",
";",
"}",
"}",
"else",
"{",
"return",
"null",
";",
"}",
"}"
] |
Returns the URL for changing the user's password, or empty if the default can
be used.
@return moodle_url
|
[
"Returns",
"the",
"URL",
"for",
"changing",
"the",
"user",
"s",
"password",
"or",
"empty",
"if",
"the",
"default",
"can",
"be",
"used",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/auth/ldap/auth.php#L1588-L1598
|
215,322
|
moodle/moodle
|
auth/ldap/auth.php
|
auth_plugin_ldap.loginpage_hook
|
function loginpage_hook() {
global $CFG, $SESSION;
// HTTPS is potentially required
//httpsrequired(); - this must be used before setting the URL, it is already done on the login/index.php
if (($_SERVER['REQUEST_METHOD'] === 'GET' // Only on initial GET of loginpage
|| ($_SERVER['REQUEST_METHOD'] === 'POST'
&& (get_local_referer() != strip_querystring(qualified_me()))))
// Or when POSTed from another place
// See MDL-14071
&& !empty($this->config->ntlmsso_enabled) // SSO enabled
&& !empty($this->config->ntlmsso_subnet) // have a subnet to test for
&& empty($_GET['authldap_skipntlmsso']) // haven't failed it yet
&& (isguestuser() || !isloggedin()) // guestuser or not-logged-in users
&& address_in_subnet(getremoteaddr(), $this->config->ntlmsso_subnet)) {
// First, let's remember where we were trying to get to before we got here
if (empty($SESSION->wantsurl)) {
$SESSION->wantsurl = null;
$referer = get_local_referer(false);
if ($referer &&
$referer != $CFG->wwwroot &&
$referer != $CFG->wwwroot . '/' &&
$referer != $CFG->wwwroot . '/login/' &&
$referer != $CFG->wwwroot . '/login/index.php') {
$SESSION->wantsurl = $referer;
}
}
// Now start the whole NTLM machinery.
if($this->config->ntlmsso_ie_fastpath == AUTH_NTLM_FASTPATH_YESATTEMPT ||
$this->config->ntlmsso_ie_fastpath == AUTH_NTLM_FASTPATH_YESFORM) {
if (core_useragent::is_ie()) {
$sesskey = sesskey();
redirect($CFG->wwwroot.'/auth/ldap/ntlmsso_magic.php?sesskey='.$sesskey);
} else if ($this->config->ntlmsso_ie_fastpath == AUTH_NTLM_FASTPATH_YESFORM) {
redirect($CFG->wwwroot.'/login/index.php?authldap_skipntlmsso=1');
}
}
redirect($CFG->wwwroot.'/auth/ldap/ntlmsso_attempt.php');
}
// No NTLM SSO, Use the normal login page instead.
// If $SESSION->wantsurl is empty and we have a 'Referer:' header, the login
// page insists on redirecting us to that page after user validation. If
// we clicked on the redirect link at the ntlmsso_finish.php page (instead
// of waiting for the redirection to happen) then we have a 'Referer:' header
// we don't want to use at all. As we can't get rid of it, just point
// $SESSION->wantsurl to $CFG->wwwroot (after all, we came from there).
if (empty($SESSION->wantsurl)
&& (get_local_referer() == $CFG->wwwroot.'/auth/ldap/ntlmsso_finish.php')) {
$SESSION->wantsurl = $CFG->wwwroot;
}
}
|
php
|
function loginpage_hook() {
global $CFG, $SESSION;
// HTTPS is potentially required
//httpsrequired(); - this must be used before setting the URL, it is already done on the login/index.php
if (($_SERVER['REQUEST_METHOD'] === 'GET' // Only on initial GET of loginpage
|| ($_SERVER['REQUEST_METHOD'] === 'POST'
&& (get_local_referer() != strip_querystring(qualified_me()))))
// Or when POSTed from another place
// See MDL-14071
&& !empty($this->config->ntlmsso_enabled) // SSO enabled
&& !empty($this->config->ntlmsso_subnet) // have a subnet to test for
&& empty($_GET['authldap_skipntlmsso']) // haven't failed it yet
&& (isguestuser() || !isloggedin()) // guestuser or not-logged-in users
&& address_in_subnet(getremoteaddr(), $this->config->ntlmsso_subnet)) {
// First, let's remember where we were trying to get to before we got here
if (empty($SESSION->wantsurl)) {
$SESSION->wantsurl = null;
$referer = get_local_referer(false);
if ($referer &&
$referer != $CFG->wwwroot &&
$referer != $CFG->wwwroot . '/' &&
$referer != $CFG->wwwroot . '/login/' &&
$referer != $CFG->wwwroot . '/login/index.php') {
$SESSION->wantsurl = $referer;
}
}
// Now start the whole NTLM machinery.
if($this->config->ntlmsso_ie_fastpath == AUTH_NTLM_FASTPATH_YESATTEMPT ||
$this->config->ntlmsso_ie_fastpath == AUTH_NTLM_FASTPATH_YESFORM) {
if (core_useragent::is_ie()) {
$sesskey = sesskey();
redirect($CFG->wwwroot.'/auth/ldap/ntlmsso_magic.php?sesskey='.$sesskey);
} else if ($this->config->ntlmsso_ie_fastpath == AUTH_NTLM_FASTPATH_YESFORM) {
redirect($CFG->wwwroot.'/login/index.php?authldap_skipntlmsso=1');
}
}
redirect($CFG->wwwroot.'/auth/ldap/ntlmsso_attempt.php');
}
// No NTLM SSO, Use the normal login page instead.
// If $SESSION->wantsurl is empty and we have a 'Referer:' header, the login
// page insists on redirecting us to that page after user validation. If
// we clicked on the redirect link at the ntlmsso_finish.php page (instead
// of waiting for the redirection to happen) then we have a 'Referer:' header
// we don't want to use at all. As we can't get rid of it, just point
// $SESSION->wantsurl to $CFG->wwwroot (after all, we came from there).
if (empty($SESSION->wantsurl)
&& (get_local_referer() == $CFG->wwwroot.'/auth/ldap/ntlmsso_finish.php')) {
$SESSION->wantsurl = $CFG->wwwroot;
}
}
|
[
"function",
"loginpage_hook",
"(",
")",
"{",
"global",
"$",
"CFG",
",",
"$",
"SESSION",
";",
"// HTTPS is potentially required",
"//httpsrequired(); - this must be used before setting the URL, it is already done on the login/index.php",
"if",
"(",
"(",
"$",
"_SERVER",
"[",
"'REQUEST_METHOD'",
"]",
"===",
"'GET'",
"// Only on initial GET of loginpage",
"||",
"(",
"$",
"_SERVER",
"[",
"'REQUEST_METHOD'",
"]",
"===",
"'POST'",
"&&",
"(",
"get_local_referer",
"(",
")",
"!=",
"strip_querystring",
"(",
"qualified_me",
"(",
")",
")",
")",
")",
")",
"// Or when POSTed from another place",
"// See MDL-14071",
"&&",
"!",
"empty",
"(",
"$",
"this",
"->",
"config",
"->",
"ntlmsso_enabled",
")",
"// SSO enabled",
"&&",
"!",
"empty",
"(",
"$",
"this",
"->",
"config",
"->",
"ntlmsso_subnet",
")",
"// have a subnet to test for",
"&&",
"empty",
"(",
"$",
"_GET",
"[",
"'authldap_skipntlmsso'",
"]",
")",
"// haven't failed it yet",
"&&",
"(",
"isguestuser",
"(",
")",
"||",
"!",
"isloggedin",
"(",
")",
")",
"// guestuser or not-logged-in users",
"&&",
"address_in_subnet",
"(",
"getremoteaddr",
"(",
")",
",",
"$",
"this",
"->",
"config",
"->",
"ntlmsso_subnet",
")",
")",
"{",
"// First, let's remember where we were trying to get to before we got here",
"if",
"(",
"empty",
"(",
"$",
"SESSION",
"->",
"wantsurl",
")",
")",
"{",
"$",
"SESSION",
"->",
"wantsurl",
"=",
"null",
";",
"$",
"referer",
"=",
"get_local_referer",
"(",
"false",
")",
";",
"if",
"(",
"$",
"referer",
"&&",
"$",
"referer",
"!=",
"$",
"CFG",
"->",
"wwwroot",
"&&",
"$",
"referer",
"!=",
"$",
"CFG",
"->",
"wwwroot",
".",
"'/'",
"&&",
"$",
"referer",
"!=",
"$",
"CFG",
"->",
"wwwroot",
".",
"'/login/'",
"&&",
"$",
"referer",
"!=",
"$",
"CFG",
"->",
"wwwroot",
".",
"'/login/index.php'",
")",
"{",
"$",
"SESSION",
"->",
"wantsurl",
"=",
"$",
"referer",
";",
"}",
"}",
"// Now start the whole NTLM machinery.",
"if",
"(",
"$",
"this",
"->",
"config",
"->",
"ntlmsso_ie_fastpath",
"==",
"AUTH_NTLM_FASTPATH_YESATTEMPT",
"||",
"$",
"this",
"->",
"config",
"->",
"ntlmsso_ie_fastpath",
"==",
"AUTH_NTLM_FASTPATH_YESFORM",
")",
"{",
"if",
"(",
"core_useragent",
"::",
"is_ie",
"(",
")",
")",
"{",
"$",
"sesskey",
"=",
"sesskey",
"(",
")",
";",
"redirect",
"(",
"$",
"CFG",
"->",
"wwwroot",
".",
"'/auth/ldap/ntlmsso_magic.php?sesskey='",
".",
"$",
"sesskey",
")",
";",
"}",
"else",
"if",
"(",
"$",
"this",
"->",
"config",
"->",
"ntlmsso_ie_fastpath",
"==",
"AUTH_NTLM_FASTPATH_YESFORM",
")",
"{",
"redirect",
"(",
"$",
"CFG",
"->",
"wwwroot",
".",
"'/login/index.php?authldap_skipntlmsso=1'",
")",
";",
"}",
"}",
"redirect",
"(",
"$",
"CFG",
"->",
"wwwroot",
".",
"'/auth/ldap/ntlmsso_attempt.php'",
")",
";",
"}",
"// No NTLM SSO, Use the normal login page instead.",
"// If $SESSION->wantsurl is empty and we have a 'Referer:' header, the login",
"// page insists on redirecting us to that page after user validation. If",
"// we clicked on the redirect link at the ntlmsso_finish.php page (instead",
"// of waiting for the redirection to happen) then we have a 'Referer:' header",
"// we don't want to use at all. As we can't get rid of it, just point",
"// $SESSION->wantsurl to $CFG->wwwroot (after all, we came from there).",
"if",
"(",
"empty",
"(",
"$",
"SESSION",
"->",
"wantsurl",
")",
"&&",
"(",
"get_local_referer",
"(",
")",
"==",
"$",
"CFG",
"->",
"wwwroot",
".",
"'/auth/ldap/ntlmsso_finish.php'",
")",
")",
"{",
"$",
"SESSION",
"->",
"wantsurl",
"=",
"$",
"CFG",
"->",
"wwwroot",
";",
"}",
"}"
] |
Will get called before the login page is shownr. Ff NTLM SSO
is enabled, and the user is in the right network, we'll redirect
to the magic NTLM page for SSO...
|
[
"Will",
"get",
"called",
"before",
"the",
"login",
"page",
"is",
"shownr",
".",
"Ff",
"NTLM",
"SSO",
"is",
"enabled",
"and",
"the",
"user",
"is",
"in",
"the",
"right",
"network",
"we",
"ll",
"redirect",
"to",
"the",
"magic",
"NTLM",
"page",
"for",
"SSO",
"..."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/auth/ldap/auth.php#L1606-L1662
|
215,323
|
moodle/moodle
|
auth/ldap/auth.php
|
auth_plugin_ldap.ntlmsso_magic
|
function ntlmsso_magic($sesskey) {
if (isset($_SERVER['REMOTE_USER']) && !empty($_SERVER['REMOTE_USER'])) {
// HTTP __headers__ seem to be sent in ISO-8859-1 encoding
// (according to my reading of RFC-1945, RFC-2616 and RFC-2617 and
// my local tests), so we need to convert the REMOTE_USER value
// (i.e., what we got from the HTTP WWW-Authenticate header) into UTF-8
$username = core_text::convert($_SERVER['REMOTE_USER'], 'iso-8859-1', 'utf-8');
switch ($this->config->ntlmsso_type) {
case 'ntlm':
// The format is now configurable, so try to extract the username
$username = $this->get_ntlm_remote_user($username);
if (empty($username)) {
return false;
}
break;
case 'kerberos':
// Format is username@DOMAIN
$username = substr($username, 0, strpos($username, '@'));
break;
default:
error_log($this->errorlogtag.get_string ('ntlmsso_unknowntype', 'auth_ldap'));
return false; // Should never happen!
}
$username = core_text::strtolower($username); // Compatibility hack
set_cache_flag($this->pluginconfig.'/ntlmsess', $sesskey, $username, AUTH_NTLMTIMEOUT);
return true;
}
return false;
}
|
php
|
function ntlmsso_magic($sesskey) {
if (isset($_SERVER['REMOTE_USER']) && !empty($_SERVER['REMOTE_USER'])) {
// HTTP __headers__ seem to be sent in ISO-8859-1 encoding
// (according to my reading of RFC-1945, RFC-2616 and RFC-2617 and
// my local tests), so we need to convert the REMOTE_USER value
// (i.e., what we got from the HTTP WWW-Authenticate header) into UTF-8
$username = core_text::convert($_SERVER['REMOTE_USER'], 'iso-8859-1', 'utf-8');
switch ($this->config->ntlmsso_type) {
case 'ntlm':
// The format is now configurable, so try to extract the username
$username = $this->get_ntlm_remote_user($username);
if (empty($username)) {
return false;
}
break;
case 'kerberos':
// Format is username@DOMAIN
$username = substr($username, 0, strpos($username, '@'));
break;
default:
error_log($this->errorlogtag.get_string ('ntlmsso_unknowntype', 'auth_ldap'));
return false; // Should never happen!
}
$username = core_text::strtolower($username); // Compatibility hack
set_cache_flag($this->pluginconfig.'/ntlmsess', $sesskey, $username, AUTH_NTLMTIMEOUT);
return true;
}
return false;
}
|
[
"function",
"ntlmsso_magic",
"(",
"$",
"sesskey",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"_SERVER",
"[",
"'REMOTE_USER'",
"]",
")",
"&&",
"!",
"empty",
"(",
"$",
"_SERVER",
"[",
"'REMOTE_USER'",
"]",
")",
")",
"{",
"// HTTP __headers__ seem to be sent in ISO-8859-1 encoding",
"// (according to my reading of RFC-1945, RFC-2616 and RFC-2617 and",
"// my local tests), so we need to convert the REMOTE_USER value",
"// (i.e., what we got from the HTTP WWW-Authenticate header) into UTF-8",
"$",
"username",
"=",
"core_text",
"::",
"convert",
"(",
"$",
"_SERVER",
"[",
"'REMOTE_USER'",
"]",
",",
"'iso-8859-1'",
",",
"'utf-8'",
")",
";",
"switch",
"(",
"$",
"this",
"->",
"config",
"->",
"ntlmsso_type",
")",
"{",
"case",
"'ntlm'",
":",
"// The format is now configurable, so try to extract the username",
"$",
"username",
"=",
"$",
"this",
"->",
"get_ntlm_remote_user",
"(",
"$",
"username",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"username",
")",
")",
"{",
"return",
"false",
";",
"}",
"break",
";",
"case",
"'kerberos'",
":",
"// Format is username@DOMAIN",
"$",
"username",
"=",
"substr",
"(",
"$",
"username",
",",
"0",
",",
"strpos",
"(",
"$",
"username",
",",
"'@'",
")",
")",
";",
"break",
";",
"default",
":",
"error_log",
"(",
"$",
"this",
"->",
"errorlogtag",
".",
"get_string",
"(",
"'ntlmsso_unknowntype'",
",",
"'auth_ldap'",
")",
")",
";",
"return",
"false",
";",
"// Should never happen!",
"}",
"$",
"username",
"=",
"core_text",
"::",
"strtolower",
"(",
"$",
"username",
")",
";",
"// Compatibility hack",
"set_cache_flag",
"(",
"$",
"this",
"->",
"pluginconfig",
".",
"'/ntlmsess'",
",",
"$",
"sesskey",
",",
"$",
"username",
",",
"AUTH_NTLMTIMEOUT",
")",
";",
"return",
"true",
";",
"}",
"return",
"false",
";",
"}"
] |
To be called from a page running under NTLM's
"Integrated Windows Authentication".
If successful, it will set a special "cookie" (not an HTTP cookie!)
in cache_flags under the $this->pluginconfig/ntlmsess "plugin" and return true.
The "cookie" will be picked up by ntlmsso_finish() to complete the
process.
On failure it will return false for the caller to display an appropriate
error message (probably saying that Integrated Windows Auth isn't enabled!)
NOTE that this code will execute under the OS user credentials,
so we MUST avoid dealing with files -- such as session files.
(The caller should define('NO_MOODLE_COOKIES', true) before including config.php)
|
[
"To",
"be",
"called",
"from",
"a",
"page",
"running",
"under",
"NTLM",
"s",
"Integrated",
"Windows",
"Authentication",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/auth/ldap/auth.php#L1681-L1712
|
215,324
|
moodle/moodle
|
auth/ldap/auth.php
|
auth_plugin_ldap.sync_roles
|
function sync_roles($user) {
global $DB;
$roles = get_ldap_assignable_role_names(2); // Admin user.
foreach ($roles as $role) {
$isrole = $this->is_role($user->username, $role);
if ($isrole === null) {
continue; // Nothing to sync - role/LDAP contexts not configured.
}
// Sync user.
$systemcontext = context_system::instance();
if ($isrole) {
// Following calls will not create duplicates.
role_assign($role['id'], $user->id, $systemcontext->id, $this->roleauth);
} else {
// Unassign only if previously assigned by this plugin.
role_unassign($role['id'], $user->id, $systemcontext->id, $this->roleauth);
}
}
}
|
php
|
function sync_roles($user) {
global $DB;
$roles = get_ldap_assignable_role_names(2); // Admin user.
foreach ($roles as $role) {
$isrole = $this->is_role($user->username, $role);
if ($isrole === null) {
continue; // Nothing to sync - role/LDAP contexts not configured.
}
// Sync user.
$systemcontext = context_system::instance();
if ($isrole) {
// Following calls will not create duplicates.
role_assign($role['id'], $user->id, $systemcontext->id, $this->roleauth);
} else {
// Unassign only if previously assigned by this plugin.
role_unassign($role['id'], $user->id, $systemcontext->id, $this->roleauth);
}
}
}
|
[
"function",
"sync_roles",
"(",
"$",
"user",
")",
"{",
"global",
"$",
"DB",
";",
"$",
"roles",
"=",
"get_ldap_assignable_role_names",
"(",
"2",
")",
";",
"// Admin user.",
"foreach",
"(",
"$",
"roles",
"as",
"$",
"role",
")",
"{",
"$",
"isrole",
"=",
"$",
"this",
"->",
"is_role",
"(",
"$",
"user",
"->",
"username",
",",
"$",
"role",
")",
";",
"if",
"(",
"$",
"isrole",
"===",
"null",
")",
"{",
"continue",
";",
"// Nothing to sync - role/LDAP contexts not configured.",
"}",
"// Sync user.",
"$",
"systemcontext",
"=",
"context_system",
"::",
"instance",
"(",
")",
";",
"if",
"(",
"$",
"isrole",
")",
"{",
"// Following calls will not create duplicates.",
"role_assign",
"(",
"$",
"role",
"[",
"'id'",
"]",
",",
"$",
"user",
"->",
"id",
",",
"$",
"systemcontext",
"->",
"id",
",",
"$",
"this",
"->",
"roleauth",
")",
";",
"}",
"else",
"{",
"// Unassign only if previously assigned by this plugin.",
"role_unassign",
"(",
"$",
"role",
"[",
"'id'",
"]",
",",
"$",
"user",
"->",
"id",
",",
"$",
"systemcontext",
"->",
"id",
",",
"$",
"this",
"->",
"roleauth",
")",
";",
"}",
"}",
"}"
] |
Sync roles for this user.
@param object $user The user to sync (without system magic quotes).
|
[
"Sync",
"roles",
"for",
"this",
"user",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/auth/ldap/auth.php#L1770-L1791
|
215,325
|
moodle/moodle
|
auth/ldap/auth.php
|
auth_plugin_ldap.ldap_get_ad_pwdexpire
|
function ldap_get_ad_pwdexpire($pwdlastset, $ldapconn, $user_dn){
global $CFG;
if (!function_exists('bcsub')) {
error_log($this->errorlogtag.get_string ('needbcmath', 'auth_ldap'));
return 0;
}
// If UF_DONT_EXPIRE_PASSWD flag is set in user's
// userAccountControl attribute, the password doesn't expire.
$sr = ldap_read($ldapconn, $user_dn, '(objectClass=*)',
array('userAccountControl'));
if (!$sr) {
error_log($this->errorlogtag.get_string ('useracctctrlerror', 'auth_ldap', $user_dn));
// Don't expire password, as we are not sure if it has to be
// expired or not.
return 0;
}
$entry = ldap_get_entries_moodle($ldapconn, $sr);
$info = $entry[0];
$useraccountcontrol = $info['useraccountcontrol'][0];
if ($useraccountcontrol & UF_DONT_EXPIRE_PASSWD) {
// Password doesn't expire.
return 0;
}
// If pwdLastSet is zero, the user must change his/her password now
// (unless UF_DONT_EXPIRE_PASSWD flag is set, but we already
// tested this above)
if ($pwdlastset === '0') {
// Password has expired
return -1;
}
// ----------------------------------------------------------------
// Password expiration time in Active Directory is the composition of
// two values:
//
// - User's pwdLastSet attribute, that stores the last time
// the password was changed.
//
// - Domain's maxPwdAge attribute, that sets how long
// passwords last in this domain.
//
// We already have the first value (passed in as a parameter). We
// need to get the second one. As we don't know the domain DN, we
// have to query rootDSE's defaultNamingContext attribute to get
// it. Then we have to query that DN's maxPwdAge attribute to get
// the real value.
//
// Once we have both values, we just need to combine them. But MS
// chose to use a different base and unit for time measurements.
// So we need to convert the values to Unix timestamps (see
// details below).
// ----------------------------------------------------------------
$sr = ldap_read($ldapconn, ROOTDSE, '(objectClass=*)',
array('defaultNamingContext'));
if (!$sr) {
error_log($this->errorlogtag.get_string ('rootdseerror', 'auth_ldap'));
return 0;
}
$entry = ldap_get_entries_moodle($ldapconn, $sr);
$info = $entry[0];
$domaindn = $info['defaultnamingcontext'][0];
$sr = ldap_read ($ldapconn, $domaindn, '(objectClass=*)',
array('maxPwdAge'));
$entry = ldap_get_entries_moodle($ldapconn, $sr);
$info = $entry[0];
$maxpwdage = $info['maxpwdage'][0];
if ($sr = ldap_read($ldapconn, $user_dn, '(objectClass=*)', array('msDS-ResultantPSO'))) {
if ($entry = ldap_get_entries_moodle($ldapconn, $sr)) {
$info = $entry[0];
$userpso = $info['msds-resultantpso'][0];
// If a PSO exists, FGPP is being utilized.
// Grab the new maxpwdage from the msDS-MaximumPasswordAge attribute of the PSO.
if (!empty($userpso)) {
$sr = ldap_read($ldapconn, $userpso, '(objectClass=*)', array('msDS-MaximumPasswordAge'));
if ($entry = ldap_get_entries_moodle($ldapconn, $sr)) {
$info = $entry[0];
// Default value of msds-maximumpasswordage is 42 and is always set.
$maxpwdage = $info['msds-maximumpasswordage'][0];
}
}
}
}
// ----------------------------------------------------------------
// MSDN says that "pwdLastSet contains the number of 100 nanosecond
// intervals since January 1, 1601 (UTC), stored in a 64 bit integer".
//
// According to Perl's Date::Manip, the number of seconds between
// this date and Unix epoch is 11644473600. So we have to
// substract this value to calculate a Unix time, once we have
// scaled pwdLastSet to seconds. This is the script used to
// calculate the value shown above:
//
// #!/usr/bin/perl -w
//
// use Date::Manip;
//
// $date1 = ParseDate ("160101010000 UTC");
// $date2 = ParseDate ("197001010000 UTC");
// $delta = DateCalc($date1, $date2, \$err);
// $secs = Delta_Format($delta, 0, "%st");
// print "$secs \n";
//
// MSDN also says that "maxPwdAge is stored as a large integer that
// represents the number of 100 nanosecond intervals from the time
// the password was set before the password expires." We also need
// to scale this to seconds. Bear in mind that this value is stored
// as a _negative_ quantity (at least in my AD domain).
//
// As a last remark, if the low 32 bits of maxPwdAge are equal to 0,
// the maximum password age in the domain is set to 0, which means
// passwords do not expire (see
// http://msdn2.microsoft.com/en-us/library/ms974598.aspx)
//
// As the quantities involved are too big for PHP integers, we
// need to use BCMath functions to work with arbitrary precision
// numbers.
// ----------------------------------------------------------------
// If the low order 32 bits are 0, then passwords do not expire in
// the domain. Just do '$maxpwdage mod 2^32' and check the result
// (2^32 = 4294967296)
if (bcmod ($maxpwdage, 4294967296) === '0') {
return 0;
}
// Add up pwdLastSet and maxPwdAge to get password expiration
// time, in MS time units. Remember maxPwdAge is stored as a
// _negative_ quantity, so we need to substract it in fact.
$pwdexpire = bcsub ($pwdlastset, $maxpwdage);
// Scale the result to convert it to Unix time units and return
// that value.
return bcsub( bcdiv($pwdexpire, '10000000'), '11644473600');
}
|
php
|
function ldap_get_ad_pwdexpire($pwdlastset, $ldapconn, $user_dn){
global $CFG;
if (!function_exists('bcsub')) {
error_log($this->errorlogtag.get_string ('needbcmath', 'auth_ldap'));
return 0;
}
// If UF_DONT_EXPIRE_PASSWD flag is set in user's
// userAccountControl attribute, the password doesn't expire.
$sr = ldap_read($ldapconn, $user_dn, '(objectClass=*)',
array('userAccountControl'));
if (!$sr) {
error_log($this->errorlogtag.get_string ('useracctctrlerror', 'auth_ldap', $user_dn));
// Don't expire password, as we are not sure if it has to be
// expired or not.
return 0;
}
$entry = ldap_get_entries_moodle($ldapconn, $sr);
$info = $entry[0];
$useraccountcontrol = $info['useraccountcontrol'][0];
if ($useraccountcontrol & UF_DONT_EXPIRE_PASSWD) {
// Password doesn't expire.
return 0;
}
// If pwdLastSet is zero, the user must change his/her password now
// (unless UF_DONT_EXPIRE_PASSWD flag is set, but we already
// tested this above)
if ($pwdlastset === '0') {
// Password has expired
return -1;
}
// ----------------------------------------------------------------
// Password expiration time in Active Directory is the composition of
// two values:
//
// - User's pwdLastSet attribute, that stores the last time
// the password was changed.
//
// - Domain's maxPwdAge attribute, that sets how long
// passwords last in this domain.
//
// We already have the first value (passed in as a parameter). We
// need to get the second one. As we don't know the domain DN, we
// have to query rootDSE's defaultNamingContext attribute to get
// it. Then we have to query that DN's maxPwdAge attribute to get
// the real value.
//
// Once we have both values, we just need to combine them. But MS
// chose to use a different base and unit for time measurements.
// So we need to convert the values to Unix timestamps (see
// details below).
// ----------------------------------------------------------------
$sr = ldap_read($ldapconn, ROOTDSE, '(objectClass=*)',
array('defaultNamingContext'));
if (!$sr) {
error_log($this->errorlogtag.get_string ('rootdseerror', 'auth_ldap'));
return 0;
}
$entry = ldap_get_entries_moodle($ldapconn, $sr);
$info = $entry[0];
$domaindn = $info['defaultnamingcontext'][0];
$sr = ldap_read ($ldapconn, $domaindn, '(objectClass=*)',
array('maxPwdAge'));
$entry = ldap_get_entries_moodle($ldapconn, $sr);
$info = $entry[0];
$maxpwdage = $info['maxpwdage'][0];
if ($sr = ldap_read($ldapconn, $user_dn, '(objectClass=*)', array('msDS-ResultantPSO'))) {
if ($entry = ldap_get_entries_moodle($ldapconn, $sr)) {
$info = $entry[0];
$userpso = $info['msds-resultantpso'][0];
// If a PSO exists, FGPP is being utilized.
// Grab the new maxpwdage from the msDS-MaximumPasswordAge attribute of the PSO.
if (!empty($userpso)) {
$sr = ldap_read($ldapconn, $userpso, '(objectClass=*)', array('msDS-MaximumPasswordAge'));
if ($entry = ldap_get_entries_moodle($ldapconn, $sr)) {
$info = $entry[0];
// Default value of msds-maximumpasswordage is 42 and is always set.
$maxpwdage = $info['msds-maximumpasswordage'][0];
}
}
}
}
// ----------------------------------------------------------------
// MSDN says that "pwdLastSet contains the number of 100 nanosecond
// intervals since January 1, 1601 (UTC), stored in a 64 bit integer".
//
// According to Perl's Date::Manip, the number of seconds between
// this date and Unix epoch is 11644473600. So we have to
// substract this value to calculate a Unix time, once we have
// scaled pwdLastSet to seconds. This is the script used to
// calculate the value shown above:
//
// #!/usr/bin/perl -w
//
// use Date::Manip;
//
// $date1 = ParseDate ("160101010000 UTC");
// $date2 = ParseDate ("197001010000 UTC");
// $delta = DateCalc($date1, $date2, \$err);
// $secs = Delta_Format($delta, 0, "%st");
// print "$secs \n";
//
// MSDN also says that "maxPwdAge is stored as a large integer that
// represents the number of 100 nanosecond intervals from the time
// the password was set before the password expires." We also need
// to scale this to seconds. Bear in mind that this value is stored
// as a _negative_ quantity (at least in my AD domain).
//
// As a last remark, if the low 32 bits of maxPwdAge are equal to 0,
// the maximum password age in the domain is set to 0, which means
// passwords do not expire (see
// http://msdn2.microsoft.com/en-us/library/ms974598.aspx)
//
// As the quantities involved are too big for PHP integers, we
// need to use BCMath functions to work with arbitrary precision
// numbers.
// ----------------------------------------------------------------
// If the low order 32 bits are 0, then passwords do not expire in
// the domain. Just do '$maxpwdage mod 2^32' and check the result
// (2^32 = 4294967296)
if (bcmod ($maxpwdage, 4294967296) === '0') {
return 0;
}
// Add up pwdLastSet and maxPwdAge to get password expiration
// time, in MS time units. Remember maxPwdAge is stored as a
// _negative_ quantity, so we need to substract it in fact.
$pwdexpire = bcsub ($pwdlastset, $maxpwdage);
// Scale the result to convert it to Unix time units and return
// that value.
return bcsub( bcdiv($pwdexpire, '10000000'), '11644473600');
}
|
[
"function",
"ldap_get_ad_pwdexpire",
"(",
"$",
"pwdlastset",
",",
"$",
"ldapconn",
",",
"$",
"user_dn",
")",
"{",
"global",
"$",
"CFG",
";",
"if",
"(",
"!",
"function_exists",
"(",
"'bcsub'",
")",
")",
"{",
"error_log",
"(",
"$",
"this",
"->",
"errorlogtag",
".",
"get_string",
"(",
"'needbcmath'",
",",
"'auth_ldap'",
")",
")",
";",
"return",
"0",
";",
"}",
"// If UF_DONT_EXPIRE_PASSWD flag is set in user's",
"// userAccountControl attribute, the password doesn't expire.",
"$",
"sr",
"=",
"ldap_read",
"(",
"$",
"ldapconn",
",",
"$",
"user_dn",
",",
"'(objectClass=*)'",
",",
"array",
"(",
"'userAccountControl'",
")",
")",
";",
"if",
"(",
"!",
"$",
"sr",
")",
"{",
"error_log",
"(",
"$",
"this",
"->",
"errorlogtag",
".",
"get_string",
"(",
"'useracctctrlerror'",
",",
"'auth_ldap'",
",",
"$",
"user_dn",
")",
")",
";",
"// Don't expire password, as we are not sure if it has to be",
"// expired or not.",
"return",
"0",
";",
"}",
"$",
"entry",
"=",
"ldap_get_entries_moodle",
"(",
"$",
"ldapconn",
",",
"$",
"sr",
")",
";",
"$",
"info",
"=",
"$",
"entry",
"[",
"0",
"]",
";",
"$",
"useraccountcontrol",
"=",
"$",
"info",
"[",
"'useraccountcontrol'",
"]",
"[",
"0",
"]",
";",
"if",
"(",
"$",
"useraccountcontrol",
"&",
"UF_DONT_EXPIRE_PASSWD",
")",
"{",
"// Password doesn't expire.",
"return",
"0",
";",
"}",
"// If pwdLastSet is zero, the user must change his/her password now",
"// (unless UF_DONT_EXPIRE_PASSWD flag is set, but we already",
"// tested this above)",
"if",
"(",
"$",
"pwdlastset",
"===",
"'0'",
")",
"{",
"// Password has expired",
"return",
"-",
"1",
";",
"}",
"// ----------------------------------------------------------------",
"// Password expiration time in Active Directory is the composition of",
"// two values:",
"//",
"// - User's pwdLastSet attribute, that stores the last time",
"// the password was changed.",
"//",
"// - Domain's maxPwdAge attribute, that sets how long",
"// passwords last in this domain.",
"//",
"// We already have the first value (passed in as a parameter). We",
"// need to get the second one. As we don't know the domain DN, we",
"// have to query rootDSE's defaultNamingContext attribute to get",
"// it. Then we have to query that DN's maxPwdAge attribute to get",
"// the real value.",
"//",
"// Once we have both values, we just need to combine them. But MS",
"// chose to use a different base and unit for time measurements.",
"// So we need to convert the values to Unix timestamps (see",
"// details below).",
"// ----------------------------------------------------------------",
"$",
"sr",
"=",
"ldap_read",
"(",
"$",
"ldapconn",
",",
"ROOTDSE",
",",
"'(objectClass=*)'",
",",
"array",
"(",
"'defaultNamingContext'",
")",
")",
";",
"if",
"(",
"!",
"$",
"sr",
")",
"{",
"error_log",
"(",
"$",
"this",
"->",
"errorlogtag",
".",
"get_string",
"(",
"'rootdseerror'",
",",
"'auth_ldap'",
")",
")",
";",
"return",
"0",
";",
"}",
"$",
"entry",
"=",
"ldap_get_entries_moodle",
"(",
"$",
"ldapconn",
",",
"$",
"sr",
")",
";",
"$",
"info",
"=",
"$",
"entry",
"[",
"0",
"]",
";",
"$",
"domaindn",
"=",
"$",
"info",
"[",
"'defaultnamingcontext'",
"]",
"[",
"0",
"]",
";",
"$",
"sr",
"=",
"ldap_read",
"(",
"$",
"ldapconn",
",",
"$",
"domaindn",
",",
"'(objectClass=*)'",
",",
"array",
"(",
"'maxPwdAge'",
")",
")",
";",
"$",
"entry",
"=",
"ldap_get_entries_moodle",
"(",
"$",
"ldapconn",
",",
"$",
"sr",
")",
";",
"$",
"info",
"=",
"$",
"entry",
"[",
"0",
"]",
";",
"$",
"maxpwdage",
"=",
"$",
"info",
"[",
"'maxpwdage'",
"]",
"[",
"0",
"]",
";",
"if",
"(",
"$",
"sr",
"=",
"ldap_read",
"(",
"$",
"ldapconn",
",",
"$",
"user_dn",
",",
"'(objectClass=*)'",
",",
"array",
"(",
"'msDS-ResultantPSO'",
")",
")",
")",
"{",
"if",
"(",
"$",
"entry",
"=",
"ldap_get_entries_moodle",
"(",
"$",
"ldapconn",
",",
"$",
"sr",
")",
")",
"{",
"$",
"info",
"=",
"$",
"entry",
"[",
"0",
"]",
";",
"$",
"userpso",
"=",
"$",
"info",
"[",
"'msds-resultantpso'",
"]",
"[",
"0",
"]",
";",
"// If a PSO exists, FGPP is being utilized.",
"// Grab the new maxpwdage from the msDS-MaximumPasswordAge attribute of the PSO.",
"if",
"(",
"!",
"empty",
"(",
"$",
"userpso",
")",
")",
"{",
"$",
"sr",
"=",
"ldap_read",
"(",
"$",
"ldapconn",
",",
"$",
"userpso",
",",
"'(objectClass=*)'",
",",
"array",
"(",
"'msDS-MaximumPasswordAge'",
")",
")",
";",
"if",
"(",
"$",
"entry",
"=",
"ldap_get_entries_moodle",
"(",
"$",
"ldapconn",
",",
"$",
"sr",
")",
")",
"{",
"$",
"info",
"=",
"$",
"entry",
"[",
"0",
"]",
";",
"// Default value of msds-maximumpasswordage is 42 and is always set.",
"$",
"maxpwdage",
"=",
"$",
"info",
"[",
"'msds-maximumpasswordage'",
"]",
"[",
"0",
"]",
";",
"}",
"}",
"}",
"}",
"// ----------------------------------------------------------------",
"// MSDN says that \"pwdLastSet contains the number of 100 nanosecond",
"// intervals since January 1, 1601 (UTC), stored in a 64 bit integer\".",
"//",
"// According to Perl's Date::Manip, the number of seconds between",
"// this date and Unix epoch is 11644473600. So we have to",
"// substract this value to calculate a Unix time, once we have",
"// scaled pwdLastSet to seconds. This is the script used to",
"// calculate the value shown above:",
"//",
"// #!/usr/bin/perl -w",
"//",
"// use Date::Manip;",
"//",
"// $date1 = ParseDate (\"160101010000 UTC\");",
"// $date2 = ParseDate (\"197001010000 UTC\");",
"// $delta = DateCalc($date1, $date2, \\$err);",
"// $secs = Delta_Format($delta, 0, \"%st\");",
"// print \"$secs \\n\";",
"//",
"// MSDN also says that \"maxPwdAge is stored as a large integer that",
"// represents the number of 100 nanosecond intervals from the time",
"// the password was set before the password expires.\" We also need",
"// to scale this to seconds. Bear in mind that this value is stored",
"// as a _negative_ quantity (at least in my AD domain).",
"//",
"// As a last remark, if the low 32 bits of maxPwdAge are equal to 0,",
"// the maximum password age in the domain is set to 0, which means",
"// passwords do not expire (see",
"// http://msdn2.microsoft.com/en-us/library/ms974598.aspx)",
"//",
"// As the quantities involved are too big for PHP integers, we",
"// need to use BCMath functions to work with arbitrary precision",
"// numbers.",
"// ----------------------------------------------------------------",
"// If the low order 32 bits are 0, then passwords do not expire in",
"// the domain. Just do '$maxpwdage mod 2^32' and check the result",
"// (2^32 = 4294967296)",
"if",
"(",
"bcmod",
"(",
"$",
"maxpwdage",
",",
"4294967296",
")",
"===",
"'0'",
")",
"{",
"return",
"0",
";",
"}",
"// Add up pwdLastSet and maxPwdAge to get password expiration",
"// time, in MS time units. Remember maxPwdAge is stored as a",
"// _negative_ quantity, so we need to substract it in fact.",
"$",
"pwdexpire",
"=",
"bcsub",
"(",
"$",
"pwdlastset",
",",
"$",
"maxpwdage",
")",
";",
"// Scale the result to convert it to Unix time units and return",
"// that value.",
"return",
"bcsub",
"(",
"bcdiv",
"(",
"$",
"pwdexpire",
",",
"'10000000'",
")",
",",
"'11644473600'",
")",
";",
"}"
] |
Get password expiration time for a given user from Active Directory
@param string $pwdlastset The time last time we changed the password.
@param resource $lcapconn The open LDAP connection.
@param string $user_dn The distinguished name of the user we are checking.
@return string $unixtime
|
[
"Get",
"password",
"expiration",
"time",
"for",
"a",
"given",
"user",
"from",
"Active",
"Directory"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/auth/ldap/auth.php#L1802-L1943
|
215,326
|
moodle/moodle
|
auth/ldap/auth.php
|
auth_plugin_ldap.is_user_suspended
|
protected function is_user_suspended($user) {
if (!$this->config->suspended_attribute || !isset($user->suspended)) {
return false;
}
if ($this->config->suspended_attribute == 'useraccountcontrol' && $this->config->user_type == 'ad') {
return (bool)($user->suspended & AUTH_AD_ACCOUNTDISABLE);
}
return (bool)$user->suspended;
}
|
php
|
protected function is_user_suspended($user) {
if (!$this->config->suspended_attribute || !isset($user->suspended)) {
return false;
}
if ($this->config->suspended_attribute == 'useraccountcontrol' && $this->config->user_type == 'ad') {
return (bool)($user->suspended & AUTH_AD_ACCOUNTDISABLE);
}
return (bool)$user->suspended;
}
|
[
"protected",
"function",
"is_user_suspended",
"(",
"$",
"user",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"config",
"->",
"suspended_attribute",
"||",
"!",
"isset",
"(",
"$",
"user",
"->",
"suspended",
")",
")",
"{",
"return",
"false",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"config",
"->",
"suspended_attribute",
"==",
"'useraccountcontrol'",
"&&",
"$",
"this",
"->",
"config",
"->",
"user_type",
"==",
"'ad'",
")",
"{",
"return",
"(",
"bool",
")",
"(",
"$",
"user",
"->",
"suspended",
"&",
"AUTH_AD_ACCOUNTDISABLE",
")",
";",
"}",
"return",
"(",
"bool",
")",
"$",
"user",
"->",
"suspended",
";",
"}"
] |
Check if a user is suspended. This function is intended to be used after calling
get_userinfo_asobj. This is needed because LDAP doesn't have a notion of disabled
users, however things like MS Active Directory support it and expose information
through a field.
@param object $user the user object returned by get_userinfo_asobj
@return boolean
|
[
"Check",
"if",
"a",
"user",
"is",
"suspended",
".",
"This",
"function",
"is",
"intended",
"to",
"be",
"used",
"after",
"calling",
"get_userinfo_asobj",
".",
"This",
"is",
"needed",
"because",
"LDAP",
"doesn",
"t",
"have",
"a",
"notion",
"of",
"disabled",
"users",
"however",
"things",
"like",
"MS",
"Active",
"Directory",
"support",
"it",
"and",
"expose",
"information",
"through",
"a",
"field",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/auth/ldap/auth.php#L2081-L2090
|
215,327
|
moodle/moodle
|
auth/ldap/auth.php
|
auth_plugin_ldap.get_profile_keys
|
protected function get_profile_keys($fetchall = false) {
$keys = array_keys(get_object_vars($this->config));
$updatekeys = [];
foreach ($keys as $key) {
if (preg_match('/^field_updatelocal_(.+)$/', $key, $match)) {
// If we have a field to update it from and it must be updated 'onlogin' we update it on cron.
if (!empty($this->config->{'field_map_'.$match[1]})) {
if ($fetchall || $this->config->{$match[0]} === 'onlogin') {
array_push($updatekeys, $match[1]); // the actual key name
}
}
}
}
if ($this->config->suspended_attribute && $this->config->sync_suspended) {
$updatekeys[] = 'suspended';
}
return $updatekeys;
}
|
php
|
protected function get_profile_keys($fetchall = false) {
$keys = array_keys(get_object_vars($this->config));
$updatekeys = [];
foreach ($keys as $key) {
if (preg_match('/^field_updatelocal_(.+)$/', $key, $match)) {
// If we have a field to update it from and it must be updated 'onlogin' we update it on cron.
if (!empty($this->config->{'field_map_'.$match[1]})) {
if ($fetchall || $this->config->{$match[0]} === 'onlogin') {
array_push($updatekeys, $match[1]); // the actual key name
}
}
}
}
if ($this->config->suspended_attribute && $this->config->sync_suspended) {
$updatekeys[] = 'suspended';
}
return $updatekeys;
}
|
[
"protected",
"function",
"get_profile_keys",
"(",
"$",
"fetchall",
"=",
"false",
")",
"{",
"$",
"keys",
"=",
"array_keys",
"(",
"get_object_vars",
"(",
"$",
"this",
"->",
"config",
")",
")",
";",
"$",
"updatekeys",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"keys",
"as",
"$",
"key",
")",
"{",
"if",
"(",
"preg_match",
"(",
"'/^field_updatelocal_(.+)$/'",
",",
"$",
"key",
",",
"$",
"match",
")",
")",
"{",
"// If we have a field to update it from and it must be updated 'onlogin' we update it on cron.",
"if",
"(",
"!",
"empty",
"(",
"$",
"this",
"->",
"config",
"->",
"{",
"'field_map_'",
".",
"$",
"match",
"[",
"1",
"]",
"}",
")",
")",
"{",
"if",
"(",
"$",
"fetchall",
"||",
"$",
"this",
"->",
"config",
"->",
"{",
"$",
"match",
"[",
"0",
"]",
"}",
"===",
"'onlogin'",
")",
"{",
"array_push",
"(",
"$",
"updatekeys",
",",
"$",
"match",
"[",
"1",
"]",
")",
";",
"// the actual key name",
"}",
"}",
"}",
"}",
"if",
"(",
"$",
"this",
"->",
"config",
"->",
"suspended_attribute",
"&&",
"$",
"this",
"->",
"config",
"->",
"sync_suspended",
")",
"{",
"$",
"updatekeys",
"[",
"]",
"=",
"'suspended'",
";",
"}",
"return",
"$",
"updatekeys",
";",
"}"
] |
Get the list of profile fields.
@param bool $fetchall Fetch all, not just those for update.
@return array
|
[
"Get",
"the",
"list",
"of",
"profile",
"fields",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/auth/ldap/auth.php#L2192-L2211
|
215,328
|
moodle/moodle
|
lib/htmlpurifier/HTMLPurifier/ConfigSchema/Validator.php
|
HTMLPurifier_ConfigSchema_Validator.validate
|
public function validate($interchange)
{
$this->interchange = $interchange;
$this->aliases = array();
// PHP is a bit lax with integer <=> string conversions in
// arrays, so we don't use the identical !== comparison
foreach ($interchange->directives as $i => $directive) {
$id = $directive->id->toString();
if ($i != $id) {
$this->error(false, "Integrity violation: key '$i' does not match internal id '$id'");
}
$this->validateDirective($directive);
}
return true;
}
|
php
|
public function validate($interchange)
{
$this->interchange = $interchange;
$this->aliases = array();
// PHP is a bit lax with integer <=> string conversions in
// arrays, so we don't use the identical !== comparison
foreach ($interchange->directives as $i => $directive) {
$id = $directive->id->toString();
if ($i != $id) {
$this->error(false, "Integrity violation: key '$i' does not match internal id '$id'");
}
$this->validateDirective($directive);
}
return true;
}
|
[
"public",
"function",
"validate",
"(",
"$",
"interchange",
")",
"{",
"$",
"this",
"->",
"interchange",
"=",
"$",
"interchange",
";",
"$",
"this",
"->",
"aliases",
"=",
"array",
"(",
")",
";",
"// PHP is a bit lax with integer <=> string conversions in",
"// arrays, so we don't use the identical !== comparison",
"foreach",
"(",
"$",
"interchange",
"->",
"directives",
"as",
"$",
"i",
"=>",
"$",
"directive",
")",
"{",
"$",
"id",
"=",
"$",
"directive",
"->",
"id",
"->",
"toString",
"(",
")",
";",
"if",
"(",
"$",
"i",
"!=",
"$",
"id",
")",
"{",
"$",
"this",
"->",
"error",
"(",
"false",
",",
"\"Integrity violation: key '$i' does not match internal id '$id'\"",
")",
";",
"}",
"$",
"this",
"->",
"validateDirective",
"(",
"$",
"directive",
")",
";",
"}",
"return",
"true",
";",
"}"
] |
Validates a fully-formed interchange object.
@param HTMLPurifier_ConfigSchema_Interchange $interchange
@return bool
|
[
"Validates",
"a",
"fully",
"-",
"formed",
"interchange",
"object",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/htmlpurifier/HTMLPurifier/ConfigSchema/Validator.php#L46-L60
|
215,329
|
moodle/moodle
|
lib/htmlpurifier/HTMLPurifier/ConfigSchema/Validator.php
|
HTMLPurifier_ConfigSchema_Validator.validateId
|
public function validateId($id)
{
$id_string = $id->toString();
$this->context[] = "id '$id_string'";
if (!$id instanceof HTMLPurifier_ConfigSchema_Interchange_Id) {
// handled by InterchangeBuilder
$this->error(false, 'is not an instance of HTMLPurifier_ConfigSchema_Interchange_Id');
}
// keys are now unconstrained (we might want to narrow down to A-Za-z0-9.)
// we probably should check that it has at least one namespace
$this->with($id, 'key')
->assertNotEmpty()
->assertIsString(); // implicit assertIsString handled by InterchangeBuilder
array_pop($this->context);
}
|
php
|
public function validateId($id)
{
$id_string = $id->toString();
$this->context[] = "id '$id_string'";
if (!$id instanceof HTMLPurifier_ConfigSchema_Interchange_Id) {
// handled by InterchangeBuilder
$this->error(false, 'is not an instance of HTMLPurifier_ConfigSchema_Interchange_Id');
}
// keys are now unconstrained (we might want to narrow down to A-Za-z0-9.)
// we probably should check that it has at least one namespace
$this->with($id, 'key')
->assertNotEmpty()
->assertIsString(); // implicit assertIsString handled by InterchangeBuilder
array_pop($this->context);
}
|
[
"public",
"function",
"validateId",
"(",
"$",
"id",
")",
"{",
"$",
"id_string",
"=",
"$",
"id",
"->",
"toString",
"(",
")",
";",
"$",
"this",
"->",
"context",
"[",
"]",
"=",
"\"id '$id_string'\"",
";",
"if",
"(",
"!",
"$",
"id",
"instanceof",
"HTMLPurifier_ConfigSchema_Interchange_Id",
")",
"{",
"// handled by InterchangeBuilder",
"$",
"this",
"->",
"error",
"(",
"false",
",",
"'is not an instance of HTMLPurifier_ConfigSchema_Interchange_Id'",
")",
";",
"}",
"// keys are now unconstrained (we might want to narrow down to A-Za-z0-9.)",
"// we probably should check that it has at least one namespace",
"$",
"this",
"->",
"with",
"(",
"$",
"id",
",",
"'key'",
")",
"->",
"assertNotEmpty",
"(",
")",
"->",
"assertIsString",
"(",
")",
";",
"// implicit assertIsString handled by InterchangeBuilder",
"array_pop",
"(",
"$",
"this",
"->",
"context",
")",
";",
"}"
] |
Validates a HTMLPurifier_ConfigSchema_Interchange_Id object.
@param HTMLPurifier_ConfigSchema_Interchange_Id $id
|
[
"Validates",
"a",
"HTMLPurifier_ConfigSchema_Interchange_Id",
"object",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/htmlpurifier/HTMLPurifier/ConfigSchema/Validator.php#L66-L80
|
215,330
|
moodle/moodle
|
lib/htmlpurifier/HTMLPurifier/ConfigSchema/Validator.php
|
HTMLPurifier_ConfigSchema_Validator.validateDirective
|
public function validateDirective($d)
{
$id = $d->id->toString();
$this->context[] = "directive '$id'";
$this->validateId($d->id);
$this->with($d, 'description')
->assertNotEmpty();
// BEGIN - handled by InterchangeBuilder
$this->with($d, 'type')
->assertNotEmpty();
$this->with($d, 'typeAllowsNull')
->assertIsBool();
try {
// This also tests validity of $d->type
$this->parser->parse($d->default, $d->type, $d->typeAllowsNull);
} catch (HTMLPurifier_VarParserException $e) {
$this->error('default', 'had error: ' . $e->getMessage());
}
// END - handled by InterchangeBuilder
if (!is_null($d->allowed) || !empty($d->valueAliases)) {
// allowed and valueAliases require that we be dealing with
// strings, so check for that early.
$d_int = HTMLPurifier_VarParser::$types[$d->type];
if (!isset(HTMLPurifier_VarParser::$stringTypes[$d_int])) {
$this->error('type', 'must be a string type when used with allowed or value aliases');
}
}
$this->validateDirectiveAllowed($d);
$this->validateDirectiveValueAliases($d);
$this->validateDirectiveAliases($d);
array_pop($this->context);
}
|
php
|
public function validateDirective($d)
{
$id = $d->id->toString();
$this->context[] = "directive '$id'";
$this->validateId($d->id);
$this->with($d, 'description')
->assertNotEmpty();
// BEGIN - handled by InterchangeBuilder
$this->with($d, 'type')
->assertNotEmpty();
$this->with($d, 'typeAllowsNull')
->assertIsBool();
try {
// This also tests validity of $d->type
$this->parser->parse($d->default, $d->type, $d->typeAllowsNull);
} catch (HTMLPurifier_VarParserException $e) {
$this->error('default', 'had error: ' . $e->getMessage());
}
// END - handled by InterchangeBuilder
if (!is_null($d->allowed) || !empty($d->valueAliases)) {
// allowed and valueAliases require that we be dealing with
// strings, so check for that early.
$d_int = HTMLPurifier_VarParser::$types[$d->type];
if (!isset(HTMLPurifier_VarParser::$stringTypes[$d_int])) {
$this->error('type', 'must be a string type when used with allowed or value aliases');
}
}
$this->validateDirectiveAllowed($d);
$this->validateDirectiveValueAliases($d);
$this->validateDirectiveAliases($d);
array_pop($this->context);
}
|
[
"public",
"function",
"validateDirective",
"(",
"$",
"d",
")",
"{",
"$",
"id",
"=",
"$",
"d",
"->",
"id",
"->",
"toString",
"(",
")",
";",
"$",
"this",
"->",
"context",
"[",
"]",
"=",
"\"directive '$id'\"",
";",
"$",
"this",
"->",
"validateId",
"(",
"$",
"d",
"->",
"id",
")",
";",
"$",
"this",
"->",
"with",
"(",
"$",
"d",
",",
"'description'",
")",
"->",
"assertNotEmpty",
"(",
")",
";",
"// BEGIN - handled by InterchangeBuilder",
"$",
"this",
"->",
"with",
"(",
"$",
"d",
",",
"'type'",
")",
"->",
"assertNotEmpty",
"(",
")",
";",
"$",
"this",
"->",
"with",
"(",
"$",
"d",
",",
"'typeAllowsNull'",
")",
"->",
"assertIsBool",
"(",
")",
";",
"try",
"{",
"// This also tests validity of $d->type",
"$",
"this",
"->",
"parser",
"->",
"parse",
"(",
"$",
"d",
"->",
"default",
",",
"$",
"d",
"->",
"type",
",",
"$",
"d",
"->",
"typeAllowsNull",
")",
";",
"}",
"catch",
"(",
"HTMLPurifier_VarParserException",
"$",
"e",
")",
"{",
"$",
"this",
"->",
"error",
"(",
"'default'",
",",
"'had error: '",
".",
"$",
"e",
"->",
"getMessage",
"(",
")",
")",
";",
"}",
"// END - handled by InterchangeBuilder",
"if",
"(",
"!",
"is_null",
"(",
"$",
"d",
"->",
"allowed",
")",
"||",
"!",
"empty",
"(",
"$",
"d",
"->",
"valueAliases",
")",
")",
"{",
"// allowed and valueAliases require that we be dealing with",
"// strings, so check for that early.",
"$",
"d_int",
"=",
"HTMLPurifier_VarParser",
"::",
"$",
"types",
"[",
"$",
"d",
"->",
"type",
"]",
";",
"if",
"(",
"!",
"isset",
"(",
"HTMLPurifier_VarParser",
"::",
"$",
"stringTypes",
"[",
"$",
"d_int",
"]",
")",
")",
"{",
"$",
"this",
"->",
"error",
"(",
"'type'",
",",
"'must be a string type when used with allowed or value aliases'",
")",
";",
"}",
"}",
"$",
"this",
"->",
"validateDirectiveAllowed",
"(",
"$",
"d",
")",
";",
"$",
"this",
"->",
"validateDirectiveValueAliases",
"(",
"$",
"d",
")",
";",
"$",
"this",
"->",
"validateDirectiveAliases",
"(",
"$",
"d",
")",
";",
"array_pop",
"(",
"$",
"this",
"->",
"context",
")",
";",
"}"
] |
Validates a HTMLPurifier_ConfigSchema_Interchange_Directive object.
@param HTMLPurifier_ConfigSchema_Interchange_Directive $d
|
[
"Validates",
"a",
"HTMLPurifier_ConfigSchema_Interchange_Directive",
"object",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/htmlpurifier/HTMLPurifier/ConfigSchema/Validator.php#L86-L122
|
215,331
|
moodle/moodle
|
lib/htmlpurifier/HTMLPurifier/ConfigSchema/Validator.php
|
HTMLPurifier_ConfigSchema_Validator.error
|
protected function error($target, $msg)
{
if ($target !== false) {
$prefix = ucfirst($target) . ' in ' . $this->getFormattedContext();
} else {
$prefix = ucfirst($this->getFormattedContext());
}
throw new HTMLPurifier_ConfigSchema_Exception(trim($prefix . ' ' . $msg));
}
|
php
|
protected function error($target, $msg)
{
if ($target !== false) {
$prefix = ucfirst($target) . ' in ' . $this->getFormattedContext();
} else {
$prefix = ucfirst($this->getFormattedContext());
}
throw new HTMLPurifier_ConfigSchema_Exception(trim($prefix . ' ' . $msg));
}
|
[
"protected",
"function",
"error",
"(",
"$",
"target",
",",
"$",
"msg",
")",
"{",
"if",
"(",
"$",
"target",
"!==",
"false",
")",
"{",
"$",
"prefix",
"=",
"ucfirst",
"(",
"$",
"target",
")",
".",
"' in '",
".",
"$",
"this",
"->",
"getFormattedContext",
"(",
")",
";",
"}",
"else",
"{",
"$",
"prefix",
"=",
"ucfirst",
"(",
"$",
"this",
"->",
"getFormattedContext",
"(",
")",
")",
";",
"}",
"throw",
"new",
"HTMLPurifier_ConfigSchema_Exception",
"(",
"trim",
"(",
"$",
"prefix",
".",
"' '",
".",
"$",
"msg",
")",
")",
";",
"}"
] |
Emits an error, providing helpful context.
@throws HTMLPurifier_ConfigSchema_Exception
|
[
"Emits",
"an",
"error",
"providing",
"helpful",
"context",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/htmlpurifier/HTMLPurifier/ConfigSchema/Validator.php#L228-L236
|
215,332
|
moodle/moodle
|
blocks/recent_activity/renderer.php
|
block_recent_activity_renderer.recent_activity
|
public function recent_activity($course, $timestart, $recentenrolments, $structuralchanges,
$modulesrecentactivity) {
$output = html_writer::tag('div',
get_string('activitysince', '', userdate($timestart)),
array('class' => 'activityhead'));
$output .= html_writer::tag('div',
html_writer::link(new moodle_url('/course/recent.php', array('id' => $course->id)),
get_string('recentactivityreport')),
array('class' => 'activityhead'));
$content = false;
// Firstly, have there been any new enrolments?
if ($recentenrolments) {
$content = true;
$context = context_course::instance($course->id);
$viewfullnames = has_capability('moodle/site:viewfullnames', $context);
$output .= html_writer::start_tag('div', array('class' => 'newusers'));
$output .= $this->heading(get_string("newusers").':', 3);
//Accessibility: new users now appear in an <OL> list.
$output .= html_writer::start_tag('ol', array('class' => 'list'));
foreach ($recentenrolments as $user) {
$output .= html_writer::tag('li',
html_writer::link(new moodle_url('/user/view.php', array('id' => $user->id, 'course' => $course->id)),
fullname($user, $viewfullnames)),
array('class' => 'name'));
}
$output .= html_writer::end_tag('ol');
$output .= html_writer::end_tag('div');
}
// Next, have there been any modifications to the course structure?
if (!empty($structuralchanges)) {
$content = true;
$output .= $this->heading(get_string("courseupdates").':', 3);
foreach ($structuralchanges as $changeinfo => $change) {
$output .= $this->structural_change($change);
}
}
// Now display new things from each module
foreach ($modulesrecentactivity as $modname => $moduleactivity) {
$content = true;
$output .= $moduleactivity;
}
if (! $content) {
$output .= html_writer::tag('p', get_string('nothingnew'), array('class' => 'message'));
}
return $output;
}
|
php
|
public function recent_activity($course, $timestart, $recentenrolments, $structuralchanges,
$modulesrecentactivity) {
$output = html_writer::tag('div',
get_string('activitysince', '', userdate($timestart)),
array('class' => 'activityhead'));
$output .= html_writer::tag('div',
html_writer::link(new moodle_url('/course/recent.php', array('id' => $course->id)),
get_string('recentactivityreport')),
array('class' => 'activityhead'));
$content = false;
// Firstly, have there been any new enrolments?
if ($recentenrolments) {
$content = true;
$context = context_course::instance($course->id);
$viewfullnames = has_capability('moodle/site:viewfullnames', $context);
$output .= html_writer::start_tag('div', array('class' => 'newusers'));
$output .= $this->heading(get_string("newusers").':', 3);
//Accessibility: new users now appear in an <OL> list.
$output .= html_writer::start_tag('ol', array('class' => 'list'));
foreach ($recentenrolments as $user) {
$output .= html_writer::tag('li',
html_writer::link(new moodle_url('/user/view.php', array('id' => $user->id, 'course' => $course->id)),
fullname($user, $viewfullnames)),
array('class' => 'name'));
}
$output .= html_writer::end_tag('ol');
$output .= html_writer::end_tag('div');
}
// Next, have there been any modifications to the course structure?
if (!empty($structuralchanges)) {
$content = true;
$output .= $this->heading(get_string("courseupdates").':', 3);
foreach ($structuralchanges as $changeinfo => $change) {
$output .= $this->structural_change($change);
}
}
// Now display new things from each module
foreach ($modulesrecentactivity as $modname => $moduleactivity) {
$content = true;
$output .= $moduleactivity;
}
if (! $content) {
$output .= html_writer::tag('p', get_string('nothingnew'), array('class' => 'message'));
}
return $output;
}
|
[
"public",
"function",
"recent_activity",
"(",
"$",
"course",
",",
"$",
"timestart",
",",
"$",
"recentenrolments",
",",
"$",
"structuralchanges",
",",
"$",
"modulesrecentactivity",
")",
"{",
"$",
"output",
"=",
"html_writer",
"::",
"tag",
"(",
"'div'",
",",
"get_string",
"(",
"'activitysince'",
",",
"''",
",",
"userdate",
"(",
"$",
"timestart",
")",
")",
",",
"array",
"(",
"'class'",
"=>",
"'activityhead'",
")",
")",
";",
"$",
"output",
".=",
"html_writer",
"::",
"tag",
"(",
"'div'",
",",
"html_writer",
"::",
"link",
"(",
"new",
"moodle_url",
"(",
"'/course/recent.php'",
",",
"array",
"(",
"'id'",
"=>",
"$",
"course",
"->",
"id",
")",
")",
",",
"get_string",
"(",
"'recentactivityreport'",
")",
")",
",",
"array",
"(",
"'class'",
"=>",
"'activityhead'",
")",
")",
";",
"$",
"content",
"=",
"false",
";",
"// Firstly, have there been any new enrolments?",
"if",
"(",
"$",
"recentenrolments",
")",
"{",
"$",
"content",
"=",
"true",
";",
"$",
"context",
"=",
"context_course",
"::",
"instance",
"(",
"$",
"course",
"->",
"id",
")",
";",
"$",
"viewfullnames",
"=",
"has_capability",
"(",
"'moodle/site:viewfullnames'",
",",
"$",
"context",
")",
";",
"$",
"output",
".=",
"html_writer",
"::",
"start_tag",
"(",
"'div'",
",",
"array",
"(",
"'class'",
"=>",
"'newusers'",
")",
")",
";",
"$",
"output",
".=",
"$",
"this",
"->",
"heading",
"(",
"get_string",
"(",
"\"newusers\"",
")",
".",
"':'",
",",
"3",
")",
";",
"//Accessibility: new users now appear in an <OL> list.",
"$",
"output",
".=",
"html_writer",
"::",
"start_tag",
"(",
"'ol'",
",",
"array",
"(",
"'class'",
"=>",
"'list'",
")",
")",
";",
"foreach",
"(",
"$",
"recentenrolments",
"as",
"$",
"user",
")",
"{",
"$",
"output",
".=",
"html_writer",
"::",
"tag",
"(",
"'li'",
",",
"html_writer",
"::",
"link",
"(",
"new",
"moodle_url",
"(",
"'/user/view.php'",
",",
"array",
"(",
"'id'",
"=>",
"$",
"user",
"->",
"id",
",",
"'course'",
"=>",
"$",
"course",
"->",
"id",
")",
")",
",",
"fullname",
"(",
"$",
"user",
",",
"$",
"viewfullnames",
")",
")",
",",
"array",
"(",
"'class'",
"=>",
"'name'",
")",
")",
";",
"}",
"$",
"output",
".=",
"html_writer",
"::",
"end_tag",
"(",
"'ol'",
")",
";",
"$",
"output",
".=",
"html_writer",
"::",
"end_tag",
"(",
"'div'",
")",
";",
"}",
"// Next, have there been any modifications to the course structure?",
"if",
"(",
"!",
"empty",
"(",
"$",
"structuralchanges",
")",
")",
"{",
"$",
"content",
"=",
"true",
";",
"$",
"output",
".=",
"$",
"this",
"->",
"heading",
"(",
"get_string",
"(",
"\"courseupdates\"",
")",
".",
"':'",
",",
"3",
")",
";",
"foreach",
"(",
"$",
"structuralchanges",
"as",
"$",
"changeinfo",
"=>",
"$",
"change",
")",
"{",
"$",
"output",
".=",
"$",
"this",
"->",
"structural_change",
"(",
"$",
"change",
")",
";",
"}",
"}",
"// Now display new things from each module",
"foreach",
"(",
"$",
"modulesrecentactivity",
"as",
"$",
"modname",
"=>",
"$",
"moduleactivity",
")",
"{",
"$",
"content",
"=",
"true",
";",
"$",
"output",
".=",
"$",
"moduleactivity",
";",
"}",
"if",
"(",
"!",
"$",
"content",
")",
"{",
"$",
"output",
".=",
"html_writer",
"::",
"tag",
"(",
"'p'",
",",
"get_string",
"(",
"'nothingnew'",
")",
",",
"array",
"(",
"'class'",
"=>",
"'message'",
")",
")",
";",
"}",
"return",
"$",
"output",
";",
"}"
] |
Renders HTML to display recent_activity block
@param stdClass $course
@param int $timestart
@param array $recentenrolments array of changes in enrolments
@param array $structuralchanges array of changes in course structure
@param array $modulesrecentactivity array of changes in modules (provided by modules)
@return string
|
[
"Renders",
"HTML",
"to",
"display",
"recent_activity",
"block"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/blocks/recent_activity/renderer.php#L46-L98
|
215,333
|
moodle/moodle
|
blocks/recent_activity/renderer.php
|
block_recent_activity_renderer.structural_change
|
protected function structural_change($change) {
$cm = $change['module'];
switch ($change['action']) {
case 'delete mod':
$text = get_string('deletedactivity', 'moodle', $cm->modfullname);
break;
case 'add mod':
$text = get_string('added', 'moodle', $cm->modfullname). '<br />'.
html_writer::link($cm->url, format_string($cm->name, true));
break;
case 'update mod':
$text = get_string('updated', 'moodle', $cm->modfullname). '<br />'.
html_writer::link($cm->url, format_string($cm->name, true));
break;
default:
return '';
}
return html_writer::tag('p', $text, array('class' => 'activity'));
}
|
php
|
protected function structural_change($change) {
$cm = $change['module'];
switch ($change['action']) {
case 'delete mod':
$text = get_string('deletedactivity', 'moodle', $cm->modfullname);
break;
case 'add mod':
$text = get_string('added', 'moodle', $cm->modfullname). '<br />'.
html_writer::link($cm->url, format_string($cm->name, true));
break;
case 'update mod':
$text = get_string('updated', 'moodle', $cm->modfullname). '<br />'.
html_writer::link($cm->url, format_string($cm->name, true));
break;
default:
return '';
}
return html_writer::tag('p', $text, array('class' => 'activity'));
}
|
[
"protected",
"function",
"structural_change",
"(",
"$",
"change",
")",
"{",
"$",
"cm",
"=",
"$",
"change",
"[",
"'module'",
"]",
";",
"switch",
"(",
"$",
"change",
"[",
"'action'",
"]",
")",
"{",
"case",
"'delete mod'",
":",
"$",
"text",
"=",
"get_string",
"(",
"'deletedactivity'",
",",
"'moodle'",
",",
"$",
"cm",
"->",
"modfullname",
")",
";",
"break",
";",
"case",
"'add mod'",
":",
"$",
"text",
"=",
"get_string",
"(",
"'added'",
",",
"'moodle'",
",",
"$",
"cm",
"->",
"modfullname",
")",
".",
"'<br />'",
".",
"html_writer",
"::",
"link",
"(",
"$",
"cm",
"->",
"url",
",",
"format_string",
"(",
"$",
"cm",
"->",
"name",
",",
"true",
")",
")",
";",
"break",
";",
"case",
"'update mod'",
":",
"$",
"text",
"=",
"get_string",
"(",
"'updated'",
",",
"'moodle'",
",",
"$",
"cm",
"->",
"modfullname",
")",
".",
"'<br />'",
".",
"html_writer",
"::",
"link",
"(",
"$",
"cm",
"->",
"url",
",",
"format_string",
"(",
"$",
"cm",
"->",
"name",
",",
"true",
")",
")",
";",
"break",
";",
"default",
":",
"return",
"''",
";",
"}",
"return",
"html_writer",
"::",
"tag",
"(",
"'p'",
",",
"$",
"text",
",",
"array",
"(",
"'class'",
"=>",
"'activity'",
")",
")",
";",
"}"
] |
Renders HTML for one change in course structure
@see block_recent_activity::get_structural_changes()
@param array $change array containing attributes
'action' - one of: 'add mod', 'update mod', 'delete mod'
'module' - instance of cm_info (for 'delete mod' it is an object with attributes modname and modfullname)
@return string
|
[
"Renders",
"HTML",
"for",
"one",
"change",
"in",
"course",
"structure"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/blocks/recent_activity/renderer.php#L109-L127
|
215,334
|
moodle/moodle
|
repository/merlot/lib.php
|
repository_merlot.search
|
public function search($search_text, $page = 0) {
$ret = array();
$ret['nologin'] = true;
$ret['list'] = $this->_get_collection($this->keyword, $this->author);
return $ret;
}
|
php
|
public function search($search_text, $page = 0) {
$ret = array();
$ret['nologin'] = true;
$ret['list'] = $this->_get_collection($this->keyword, $this->author);
return $ret;
}
|
[
"public",
"function",
"search",
"(",
"$",
"search_text",
",",
"$",
"page",
"=",
"0",
")",
"{",
"$",
"ret",
"=",
"array",
"(",
")",
";",
"$",
"ret",
"[",
"'nologin'",
"]",
"=",
"true",
";",
"$",
"ret",
"[",
"'list'",
"]",
"=",
"$",
"this",
"->",
"_get_collection",
"(",
"$",
"this",
"->",
"keyword",
",",
"$",
"this",
"->",
"author",
")",
";",
"return",
"$",
"ret",
";",
"}"
] |
Look for a link in merlot.org
@param string $search_text
@return array
|
[
"Look",
"for",
"a",
"link",
"in",
"merlot",
".",
"org"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/repository/merlot/lib.php#L67-L72
|
215,335
|
moodle/moodle
|
repository/merlot/lib.php
|
repository_merlot.get_listing
|
public function get_listing($path = '', $page = '') {
$ret = array();
$ret['nologin'] = true;
$ret['list'] = $this->_get_collection($this->keyword);
return $ret;
}
|
php
|
public function get_listing($path = '', $page = '') {
$ret = array();
$ret['nologin'] = true;
$ret['list'] = $this->_get_collection($this->keyword);
return $ret;
}
|
[
"public",
"function",
"get_listing",
"(",
"$",
"path",
"=",
"''",
",",
"$",
"page",
"=",
"''",
")",
"{",
"$",
"ret",
"=",
"array",
"(",
")",
";",
"$",
"ret",
"[",
"'nologin'",
"]",
"=",
"true",
";",
"$",
"ret",
"[",
"'list'",
"]",
"=",
"$",
"this",
"->",
"_get_collection",
"(",
"$",
"this",
"->",
"keyword",
")",
";",
"return",
"$",
"ret",
";",
"}"
] |
Get a list of links
@return array
|
[
"Get",
"a",
"list",
"of",
"links"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/repository/merlot/lib.php#L78-L83
|
215,336
|
moodle/moodle
|
repository/merlot/lib.php
|
repository_merlot.print_login
|
public function print_login(){
$ret = array();
$search = new stdClass();
$search->type = 'text';
$search->id = 'merlog_search';
$search->name = 'merlot_keyword';
$search->label = get_string('search').': ';
$author = new stdClass();
$author->type = 'text';
$author->id = 'merlog_author';
$author->name = 'merlot_author';
$author->label = get_string('author', 'search').': ';
$ret['login'] = array($search, $author);
$ret['login_btn_label'] = get_string('search');
$ret['login_btn_action'] = 'search';
return $ret;
}
|
php
|
public function print_login(){
$ret = array();
$search = new stdClass();
$search->type = 'text';
$search->id = 'merlog_search';
$search->name = 'merlot_keyword';
$search->label = get_string('search').': ';
$author = new stdClass();
$author->type = 'text';
$author->id = 'merlog_author';
$author->name = 'merlot_author';
$author->label = get_string('author', 'search').': ';
$ret['login'] = array($search, $author);
$ret['login_btn_label'] = get_string('search');
$ret['login_btn_action'] = 'search';
return $ret;
}
|
[
"public",
"function",
"print_login",
"(",
")",
"{",
"$",
"ret",
"=",
"array",
"(",
")",
";",
"$",
"search",
"=",
"new",
"stdClass",
"(",
")",
";",
"$",
"search",
"->",
"type",
"=",
"'text'",
";",
"$",
"search",
"->",
"id",
"=",
"'merlog_search'",
";",
"$",
"search",
"->",
"name",
"=",
"'merlot_keyword'",
";",
"$",
"search",
"->",
"label",
"=",
"get_string",
"(",
"'search'",
")",
".",
"': '",
";",
"$",
"author",
"=",
"new",
"stdClass",
"(",
")",
";",
"$",
"author",
"->",
"type",
"=",
"'text'",
";",
"$",
"author",
"->",
"id",
"=",
"'merlog_author'",
";",
"$",
"author",
"->",
"name",
"=",
"'merlot_author'",
";",
"$",
"author",
"->",
"label",
"=",
"get_string",
"(",
"'author'",
",",
"'search'",
")",
".",
"': '",
";",
"$",
"ret",
"[",
"'login'",
"]",
"=",
"array",
"(",
"$",
"search",
",",
"$",
"author",
")",
";",
"$",
"ret",
"[",
"'login_btn_label'",
"]",
"=",
"get_string",
"(",
"'search'",
")",
";",
"$",
"ret",
"[",
"'login_btn_action'",
"]",
"=",
"'search'",
";",
"return",
"$",
"ret",
";",
"}"
] |
Define a search form
@return array
|
[
"Define",
"a",
"search",
"form"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/repository/merlot/lib.php#L109-L126
|
215,337
|
moodle/moodle
|
lib/spout/src/Spout/Common/Helper/FileSystemHelper.php
|
FileSystemHelper.createFolder
|
public function createFolder($parentFolderPath, $folderName)
{
$this->throwIfOperationNotInBaseFolder($parentFolderPath);
$folderPath = $parentFolderPath . '/' . $folderName;
$wasCreationSuccessful = mkdir($folderPath, 0777, true);
if (!$wasCreationSuccessful) {
throw new IOException("Unable to create folder: $folderPath");
}
return $folderPath;
}
|
php
|
public function createFolder($parentFolderPath, $folderName)
{
$this->throwIfOperationNotInBaseFolder($parentFolderPath);
$folderPath = $parentFolderPath . '/' . $folderName;
$wasCreationSuccessful = mkdir($folderPath, 0777, true);
if (!$wasCreationSuccessful) {
throw new IOException("Unable to create folder: $folderPath");
}
return $folderPath;
}
|
[
"public",
"function",
"createFolder",
"(",
"$",
"parentFolderPath",
",",
"$",
"folderName",
")",
"{",
"$",
"this",
"->",
"throwIfOperationNotInBaseFolder",
"(",
"$",
"parentFolderPath",
")",
";",
"$",
"folderPath",
"=",
"$",
"parentFolderPath",
".",
"'/'",
".",
"$",
"folderName",
";",
"$",
"wasCreationSuccessful",
"=",
"mkdir",
"(",
"$",
"folderPath",
",",
"0777",
",",
"true",
")",
";",
"if",
"(",
"!",
"$",
"wasCreationSuccessful",
")",
"{",
"throw",
"new",
"IOException",
"(",
"\"Unable to create folder: $folderPath\"",
")",
";",
"}",
"return",
"$",
"folderPath",
";",
"}"
] |
Creates an empty folder with the given name under the given parent folder.
@param string $parentFolderPath The parent folder path under which the folder is going to be created
@param string $folderName The name of the folder to create
@return string Path of the created folder
@throws \Box\Spout\Common\Exception\IOException If unable to create the folder or if the folder path is not inside of the base folder
|
[
"Creates",
"an",
"empty",
"folder",
"with",
"the",
"given",
"name",
"under",
"the",
"given",
"parent",
"folder",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/spout/src/Spout/Common/Helper/FileSystemHelper.php#L35-L47
|
215,338
|
moodle/moodle
|
lib/spout/src/Spout/Common/Helper/FileSystemHelper.php
|
FileSystemHelper.createFileWithContents
|
public function createFileWithContents($parentFolderPath, $fileName, $fileContents)
{
$this->throwIfOperationNotInBaseFolder($parentFolderPath);
$filePath = $parentFolderPath . '/' . $fileName;
$wasCreationSuccessful = file_put_contents($filePath, $fileContents);
if ($wasCreationSuccessful === false) {
throw new IOException("Unable to create file: $filePath");
}
return $filePath;
}
|
php
|
public function createFileWithContents($parentFolderPath, $fileName, $fileContents)
{
$this->throwIfOperationNotInBaseFolder($parentFolderPath);
$filePath = $parentFolderPath . '/' . $fileName;
$wasCreationSuccessful = file_put_contents($filePath, $fileContents);
if ($wasCreationSuccessful === false) {
throw new IOException("Unable to create file: $filePath");
}
return $filePath;
}
|
[
"public",
"function",
"createFileWithContents",
"(",
"$",
"parentFolderPath",
",",
"$",
"fileName",
",",
"$",
"fileContents",
")",
"{",
"$",
"this",
"->",
"throwIfOperationNotInBaseFolder",
"(",
"$",
"parentFolderPath",
")",
";",
"$",
"filePath",
"=",
"$",
"parentFolderPath",
".",
"'/'",
".",
"$",
"fileName",
";",
"$",
"wasCreationSuccessful",
"=",
"file_put_contents",
"(",
"$",
"filePath",
",",
"$",
"fileContents",
")",
";",
"if",
"(",
"$",
"wasCreationSuccessful",
"===",
"false",
")",
"{",
"throw",
"new",
"IOException",
"(",
"\"Unable to create file: $filePath\"",
")",
";",
"}",
"return",
"$",
"filePath",
";",
"}"
] |
Creates a file with the given name and content in the given folder.
The parent folder must exist.
@param string $parentFolderPath The parent folder path where the file is going to be created
@param string $fileName The name of the file to create
@param string $fileContents The contents of the file to create
@return string Path of the created file
@throws \Box\Spout\Common\Exception\IOException If unable to create the file or if the file path is not inside of the base folder
|
[
"Creates",
"a",
"file",
"with",
"the",
"given",
"name",
"and",
"content",
"in",
"the",
"given",
"folder",
".",
"The",
"parent",
"folder",
"must",
"exist",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/spout/src/Spout/Common/Helper/FileSystemHelper.php#L59-L71
|
215,339
|
moodle/moodle
|
lib/spout/src/Spout/Common/Helper/FileSystemHelper.php
|
FileSystemHelper.deleteFile
|
public function deleteFile($filePath)
{
$this->throwIfOperationNotInBaseFolder($filePath);
if (file_exists($filePath) && is_file($filePath)) {
unlink($filePath);
}
}
|
php
|
public function deleteFile($filePath)
{
$this->throwIfOperationNotInBaseFolder($filePath);
if (file_exists($filePath) && is_file($filePath)) {
unlink($filePath);
}
}
|
[
"public",
"function",
"deleteFile",
"(",
"$",
"filePath",
")",
"{",
"$",
"this",
"->",
"throwIfOperationNotInBaseFolder",
"(",
"$",
"filePath",
")",
";",
"if",
"(",
"file_exists",
"(",
"$",
"filePath",
")",
"&&",
"is_file",
"(",
"$",
"filePath",
")",
")",
"{",
"unlink",
"(",
"$",
"filePath",
")",
";",
"}",
"}"
] |
Delete the file at the given path
@param string $filePath Path of the file to delete
@return void
@throws \Box\Spout\Common\Exception\IOException If the file path is not inside of the base folder
|
[
"Delete",
"the",
"file",
"at",
"the",
"given",
"path"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/spout/src/Spout/Common/Helper/FileSystemHelper.php#L80-L87
|
215,340
|
moodle/moodle
|
lib/spout/src/Spout/Common/Helper/FileSystemHelper.php
|
FileSystemHelper.deleteFolderRecursively
|
public function deleteFolderRecursively($folderPath)
{
$this->throwIfOperationNotInBaseFolder($folderPath);
$itemIterator = new \RecursiveIteratorIterator(
new \RecursiveDirectoryIterator($folderPath, \RecursiveDirectoryIterator::SKIP_DOTS),
\RecursiveIteratorIterator::CHILD_FIRST
);
foreach ($itemIterator as $item) {
if ($item->isDir()) {
rmdir($item->getPathname());
} else {
unlink($item->getPathname());
}
}
rmdir($folderPath);
}
|
php
|
public function deleteFolderRecursively($folderPath)
{
$this->throwIfOperationNotInBaseFolder($folderPath);
$itemIterator = new \RecursiveIteratorIterator(
new \RecursiveDirectoryIterator($folderPath, \RecursiveDirectoryIterator::SKIP_DOTS),
\RecursiveIteratorIterator::CHILD_FIRST
);
foreach ($itemIterator as $item) {
if ($item->isDir()) {
rmdir($item->getPathname());
} else {
unlink($item->getPathname());
}
}
rmdir($folderPath);
}
|
[
"public",
"function",
"deleteFolderRecursively",
"(",
"$",
"folderPath",
")",
"{",
"$",
"this",
"->",
"throwIfOperationNotInBaseFolder",
"(",
"$",
"folderPath",
")",
";",
"$",
"itemIterator",
"=",
"new",
"\\",
"RecursiveIteratorIterator",
"(",
"new",
"\\",
"RecursiveDirectoryIterator",
"(",
"$",
"folderPath",
",",
"\\",
"RecursiveDirectoryIterator",
"::",
"SKIP_DOTS",
")",
",",
"\\",
"RecursiveIteratorIterator",
"::",
"CHILD_FIRST",
")",
";",
"foreach",
"(",
"$",
"itemIterator",
"as",
"$",
"item",
")",
"{",
"if",
"(",
"$",
"item",
"->",
"isDir",
"(",
")",
")",
"{",
"rmdir",
"(",
"$",
"item",
"->",
"getPathname",
"(",
")",
")",
";",
"}",
"else",
"{",
"unlink",
"(",
"$",
"item",
"->",
"getPathname",
"(",
")",
")",
";",
"}",
"}",
"rmdir",
"(",
"$",
"folderPath",
")",
";",
"}"
] |
Delete the folder at the given path as well as all its contents
@param string $folderPath Path of the folder to delete
@return void
@throws \Box\Spout\Common\Exception\IOException If the folder path is not inside of the base folder
|
[
"Delete",
"the",
"folder",
"at",
"the",
"given",
"path",
"as",
"well",
"as",
"all",
"its",
"contents"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/spout/src/Spout/Common/Helper/FileSystemHelper.php#L96-L114
|
215,341
|
moodle/moodle
|
lib/phpexcel/PHPExcel/Worksheet.php
|
PHPExcel_Worksheet.getChartByIndex
|
public function getChartByIndex($index = null)
{
$chartCount = count($this->chartCollection);
if ($chartCount == 0) {
return false;
}
if (is_null($index)) {
$index = --$chartCount;
}
if (!isset($this->chartCollection[$index])) {
return false;
}
return $this->chartCollection[$index];
}
|
php
|
public function getChartByIndex($index = null)
{
$chartCount = count($this->chartCollection);
if ($chartCount == 0) {
return false;
}
if (is_null($index)) {
$index = --$chartCount;
}
if (!isset($this->chartCollection[$index])) {
return false;
}
return $this->chartCollection[$index];
}
|
[
"public",
"function",
"getChartByIndex",
"(",
"$",
"index",
"=",
"null",
")",
"{",
"$",
"chartCount",
"=",
"count",
"(",
"$",
"this",
"->",
"chartCollection",
")",
";",
"if",
"(",
"$",
"chartCount",
"==",
"0",
")",
"{",
"return",
"false",
";",
"}",
"if",
"(",
"is_null",
"(",
"$",
"index",
")",
")",
"{",
"$",
"index",
"=",
"--",
"$",
"chartCount",
";",
"}",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"chartCollection",
"[",
"$",
"index",
"]",
")",
")",
"{",
"return",
"false",
";",
"}",
"return",
"$",
"this",
"->",
"chartCollection",
"[",
"$",
"index",
"]",
";",
"}"
] |
Get a chart by its index position
@param string $index Chart index position
@return false|PHPExcel_Chart
@throws PHPExcel_Exception
|
[
"Get",
"a",
"chart",
"by",
"its",
"index",
"position"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/phpexcel/PHPExcel/Worksheet.php#L590-L604
|
215,342
|
moodle/moodle
|
lib/phpexcel/PHPExcel/Worksheet.php
|
PHPExcel_Worksheet.getChartByName
|
public function getChartByName($chartName = '')
{
$chartCount = count($this->chartCollection);
if ($chartCount == 0) {
return false;
}
foreach ($this->chartCollection as $index => $chart) {
if ($chart->getName() == $chartName) {
return $this->chartCollection[$index];
}
}
return false;
}
|
php
|
public function getChartByName($chartName = '')
{
$chartCount = count($this->chartCollection);
if ($chartCount == 0) {
return false;
}
foreach ($this->chartCollection as $index => $chart) {
if ($chart->getName() == $chartName) {
return $this->chartCollection[$index];
}
}
return false;
}
|
[
"public",
"function",
"getChartByName",
"(",
"$",
"chartName",
"=",
"''",
")",
"{",
"$",
"chartCount",
"=",
"count",
"(",
"$",
"this",
"->",
"chartCollection",
")",
";",
"if",
"(",
"$",
"chartCount",
"==",
"0",
")",
"{",
"return",
"false",
";",
"}",
"foreach",
"(",
"$",
"this",
"->",
"chartCollection",
"as",
"$",
"index",
"=>",
"$",
"chart",
")",
"{",
"if",
"(",
"$",
"chart",
"->",
"getName",
"(",
")",
"==",
"$",
"chartName",
")",
"{",
"return",
"$",
"this",
"->",
"chartCollection",
"[",
"$",
"index",
"]",
";",
"}",
"}",
"return",
"false",
";",
"}"
] |
Get a chart by name
@param string $chartName Chart name
@return false|PHPExcel_Chart
@throws PHPExcel_Exception
|
[
"Get",
"a",
"chart",
"by",
"name"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/phpexcel/PHPExcel/Worksheet.php#L628-L640
|
215,343
|
moodle/moodle
|
lib/phpexcel/PHPExcel/Worksheet.php
|
PHPExcel_Worksheet.refreshColumnDimensions
|
public function refreshColumnDimensions()
{
$currentColumnDimensions = $this->getColumnDimensions();
$newColumnDimensions = array();
foreach ($currentColumnDimensions as $objColumnDimension) {
$newColumnDimensions[$objColumnDimension->getColumnIndex()] = $objColumnDimension;
}
$this->columnDimensions = $newColumnDimensions;
return $this;
}
|
php
|
public function refreshColumnDimensions()
{
$currentColumnDimensions = $this->getColumnDimensions();
$newColumnDimensions = array();
foreach ($currentColumnDimensions as $objColumnDimension) {
$newColumnDimensions[$objColumnDimension->getColumnIndex()] = $objColumnDimension;
}
$this->columnDimensions = $newColumnDimensions;
return $this;
}
|
[
"public",
"function",
"refreshColumnDimensions",
"(",
")",
"{",
"$",
"currentColumnDimensions",
"=",
"$",
"this",
"->",
"getColumnDimensions",
"(",
")",
";",
"$",
"newColumnDimensions",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"currentColumnDimensions",
"as",
"$",
"objColumnDimension",
")",
"{",
"$",
"newColumnDimensions",
"[",
"$",
"objColumnDimension",
"->",
"getColumnIndex",
"(",
")",
"]",
"=",
"$",
"objColumnDimension",
";",
"}",
"$",
"this",
"->",
"columnDimensions",
"=",
"$",
"newColumnDimensions",
";",
"return",
"$",
"this",
";",
"}"
] |
Refresh column dimensions
@return PHPExcel_Worksheet
|
[
"Refresh",
"column",
"dimensions"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/phpexcel/PHPExcel/Worksheet.php#L647-L659
|
215,344
|
moodle/moodle
|
lib/phpexcel/PHPExcel/Worksheet.php
|
PHPExcel_Worksheet.cellExists
|
public function cellExists($pCoordinate = 'A1')
{
// Worksheet reference?
if (strpos($pCoordinate, '!') !== false) {
$worksheetReference = PHPExcel_Worksheet::extractSheetTitle($pCoordinate, true);
return $this->parent->getSheetByName($worksheetReference[0])->cellExists(strtoupper($worksheetReference[1]));
}
// Named range?
if ((!preg_match('/^'.PHPExcel_Calculation::CALCULATION_REGEXP_CELLREF.'$/i', $pCoordinate, $matches)) &&
(preg_match('/^'.PHPExcel_Calculation::CALCULATION_REGEXP_NAMEDRANGE.'$/i', $pCoordinate, $matches))) {
$namedRange = PHPExcel_NamedRange::resolveRange($pCoordinate, $this);
if ($namedRange !== null) {
$pCoordinate = $namedRange->getRange();
if ($this->getHashCode() != $namedRange->getWorksheet()->getHashCode()) {
if (!$namedRange->getLocalOnly()) {
return $namedRange->getWorksheet()->cellExists($pCoordinate);
} else {
throw new PHPExcel_Exception('Named range ' . $namedRange->getName() . ' is not accessible from within sheet ' . $this->getTitle());
}
}
} else {
return false;
}
}
// Uppercase coordinate
$pCoordinate = strtoupper($pCoordinate);
if (strpos($pCoordinate, ':') !== false || strpos($pCoordinate, ',') !== false) {
throw new PHPExcel_Exception('Cell coordinate can not be a range of cells.');
} elseif (strpos($pCoordinate, '$') !== false) {
throw new PHPExcel_Exception('Cell coordinate must not be absolute.');
} else {
// Coordinates
$aCoordinates = PHPExcel_Cell::coordinateFromString($pCoordinate);
// Cell exists?
return $this->cellCollection->isDataSet($pCoordinate);
}
}
|
php
|
public function cellExists($pCoordinate = 'A1')
{
// Worksheet reference?
if (strpos($pCoordinate, '!') !== false) {
$worksheetReference = PHPExcel_Worksheet::extractSheetTitle($pCoordinate, true);
return $this->parent->getSheetByName($worksheetReference[0])->cellExists(strtoupper($worksheetReference[1]));
}
// Named range?
if ((!preg_match('/^'.PHPExcel_Calculation::CALCULATION_REGEXP_CELLREF.'$/i', $pCoordinate, $matches)) &&
(preg_match('/^'.PHPExcel_Calculation::CALCULATION_REGEXP_NAMEDRANGE.'$/i', $pCoordinate, $matches))) {
$namedRange = PHPExcel_NamedRange::resolveRange($pCoordinate, $this);
if ($namedRange !== null) {
$pCoordinate = $namedRange->getRange();
if ($this->getHashCode() != $namedRange->getWorksheet()->getHashCode()) {
if (!$namedRange->getLocalOnly()) {
return $namedRange->getWorksheet()->cellExists($pCoordinate);
} else {
throw new PHPExcel_Exception('Named range ' . $namedRange->getName() . ' is not accessible from within sheet ' . $this->getTitle());
}
}
} else {
return false;
}
}
// Uppercase coordinate
$pCoordinate = strtoupper($pCoordinate);
if (strpos($pCoordinate, ':') !== false || strpos($pCoordinate, ',') !== false) {
throw new PHPExcel_Exception('Cell coordinate can not be a range of cells.');
} elseif (strpos($pCoordinate, '$') !== false) {
throw new PHPExcel_Exception('Cell coordinate must not be absolute.');
} else {
// Coordinates
$aCoordinates = PHPExcel_Cell::coordinateFromString($pCoordinate);
// Cell exists?
return $this->cellCollection->isDataSet($pCoordinate);
}
}
|
[
"public",
"function",
"cellExists",
"(",
"$",
"pCoordinate",
"=",
"'A1'",
")",
"{",
"// Worksheet reference?",
"if",
"(",
"strpos",
"(",
"$",
"pCoordinate",
",",
"'!'",
")",
"!==",
"false",
")",
"{",
"$",
"worksheetReference",
"=",
"PHPExcel_Worksheet",
"::",
"extractSheetTitle",
"(",
"$",
"pCoordinate",
",",
"true",
")",
";",
"return",
"$",
"this",
"->",
"parent",
"->",
"getSheetByName",
"(",
"$",
"worksheetReference",
"[",
"0",
"]",
")",
"->",
"cellExists",
"(",
"strtoupper",
"(",
"$",
"worksheetReference",
"[",
"1",
"]",
")",
")",
";",
"}",
"// Named range?",
"if",
"(",
"(",
"!",
"preg_match",
"(",
"'/^'",
".",
"PHPExcel_Calculation",
"::",
"CALCULATION_REGEXP_CELLREF",
".",
"'$/i'",
",",
"$",
"pCoordinate",
",",
"$",
"matches",
")",
")",
"&&",
"(",
"preg_match",
"(",
"'/^'",
".",
"PHPExcel_Calculation",
"::",
"CALCULATION_REGEXP_NAMEDRANGE",
".",
"'$/i'",
",",
"$",
"pCoordinate",
",",
"$",
"matches",
")",
")",
")",
"{",
"$",
"namedRange",
"=",
"PHPExcel_NamedRange",
"::",
"resolveRange",
"(",
"$",
"pCoordinate",
",",
"$",
"this",
")",
";",
"if",
"(",
"$",
"namedRange",
"!==",
"null",
")",
"{",
"$",
"pCoordinate",
"=",
"$",
"namedRange",
"->",
"getRange",
"(",
")",
";",
"if",
"(",
"$",
"this",
"->",
"getHashCode",
"(",
")",
"!=",
"$",
"namedRange",
"->",
"getWorksheet",
"(",
")",
"->",
"getHashCode",
"(",
")",
")",
"{",
"if",
"(",
"!",
"$",
"namedRange",
"->",
"getLocalOnly",
"(",
")",
")",
"{",
"return",
"$",
"namedRange",
"->",
"getWorksheet",
"(",
")",
"->",
"cellExists",
"(",
"$",
"pCoordinate",
")",
";",
"}",
"else",
"{",
"throw",
"new",
"PHPExcel_Exception",
"(",
"'Named range '",
".",
"$",
"namedRange",
"->",
"getName",
"(",
")",
".",
"' is not accessible from within sheet '",
".",
"$",
"this",
"->",
"getTitle",
"(",
")",
")",
";",
"}",
"}",
"}",
"else",
"{",
"return",
"false",
";",
"}",
"}",
"// Uppercase coordinate",
"$",
"pCoordinate",
"=",
"strtoupper",
"(",
"$",
"pCoordinate",
")",
";",
"if",
"(",
"strpos",
"(",
"$",
"pCoordinate",
",",
"':'",
")",
"!==",
"false",
"||",
"strpos",
"(",
"$",
"pCoordinate",
",",
"','",
")",
"!==",
"false",
")",
"{",
"throw",
"new",
"PHPExcel_Exception",
"(",
"'Cell coordinate can not be a range of cells.'",
")",
";",
"}",
"elseif",
"(",
"strpos",
"(",
"$",
"pCoordinate",
",",
"'$'",
")",
"!==",
"false",
")",
"{",
"throw",
"new",
"PHPExcel_Exception",
"(",
"'Cell coordinate must not be absolute.'",
")",
";",
"}",
"else",
"{",
"// Coordinates",
"$",
"aCoordinates",
"=",
"PHPExcel_Cell",
"::",
"coordinateFromString",
"(",
"$",
"pCoordinate",
")",
";",
"// Cell exists?",
"return",
"$",
"this",
"->",
"cellCollection",
"->",
"isDataSet",
"(",
"$",
"pCoordinate",
")",
";",
"}",
"}"
] |
Does the cell at a specific coordinate exist?
@param string $pCoordinate Coordinate of the cell
@throws PHPExcel_Exception
@return boolean
|
[
"Does",
"the",
"cell",
"at",
"a",
"specific",
"coordinate",
"exist?"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/phpexcel/PHPExcel/Worksheet.php#L1242-L1282
|
215,345
|
moodle/moodle
|
lib/phpexcel/PHPExcel/Worksheet.php
|
PHPExcel_Worksheet.setDefaultStyle
|
public function setDefaultStyle(PHPExcel_Style $pValue)
{
$this->parent->getDefaultStyle()->applyFromArray(array(
'font' => array(
'name' => $pValue->getFont()->getName(),
'size' => $pValue->getFont()->getSize(),
),
));
return $this;
}
|
php
|
public function setDefaultStyle(PHPExcel_Style $pValue)
{
$this->parent->getDefaultStyle()->applyFromArray(array(
'font' => array(
'name' => $pValue->getFont()->getName(),
'size' => $pValue->getFont()->getSize(),
),
));
return $this;
}
|
[
"public",
"function",
"setDefaultStyle",
"(",
"PHPExcel_Style",
"$",
"pValue",
")",
"{",
"$",
"this",
"->",
"parent",
"->",
"getDefaultStyle",
"(",
")",
"->",
"applyFromArray",
"(",
"array",
"(",
"'font'",
"=>",
"array",
"(",
"'name'",
"=>",
"$",
"pValue",
"->",
"getFont",
"(",
")",
"->",
"getName",
"(",
")",
",",
"'size'",
"=>",
"$",
"pValue",
"->",
"getFont",
"(",
")",
"->",
"getSize",
"(",
")",
",",
")",
",",
")",
")",
";",
"return",
"$",
"this",
";",
"}"
] |
Set default style - should only be used by PHPExcel_IReader implementations!
@deprecated
@param PHPExcel_Style $pValue
@throws PHPExcel_Exception
@return PHPExcel_Worksheet
|
[
"Set",
"default",
"style",
"-",
"should",
"only",
"be",
"used",
"by",
"PHPExcel_IReader",
"implementations!"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/phpexcel/PHPExcel/Worksheet.php#L1385-L1394
|
215,346
|
moodle/moodle
|
lib/phpexcel/PHPExcel/Worksheet.php
|
PHPExcel_Worksheet.getStyleByColumnAndRow
|
public function getStyleByColumnAndRow($pColumn = 0, $pRow = 1, $pColumn2 = null, $pRow2 = null)
{
if (!is_null($pColumn2) && !is_null($pRow2)) {
$cellRange = PHPExcel_Cell::stringFromColumnIndex($pColumn) . $pRow . ':' . PHPExcel_Cell::stringFromColumnIndex($pColumn2) . $pRow2;
return $this->getStyle($cellRange);
}
return $this->getStyle(PHPExcel_Cell::stringFromColumnIndex($pColumn) . $pRow);
}
|
php
|
public function getStyleByColumnAndRow($pColumn = 0, $pRow = 1, $pColumn2 = null, $pRow2 = null)
{
if (!is_null($pColumn2) && !is_null($pRow2)) {
$cellRange = PHPExcel_Cell::stringFromColumnIndex($pColumn) . $pRow . ':' . PHPExcel_Cell::stringFromColumnIndex($pColumn2) . $pRow2;
return $this->getStyle($cellRange);
}
return $this->getStyle(PHPExcel_Cell::stringFromColumnIndex($pColumn) . $pRow);
}
|
[
"public",
"function",
"getStyleByColumnAndRow",
"(",
"$",
"pColumn",
"=",
"0",
",",
"$",
"pRow",
"=",
"1",
",",
"$",
"pColumn2",
"=",
"null",
",",
"$",
"pRow2",
"=",
"null",
")",
"{",
"if",
"(",
"!",
"is_null",
"(",
"$",
"pColumn2",
")",
"&&",
"!",
"is_null",
"(",
"$",
"pRow2",
")",
")",
"{",
"$",
"cellRange",
"=",
"PHPExcel_Cell",
"::",
"stringFromColumnIndex",
"(",
"$",
"pColumn",
")",
".",
"$",
"pRow",
".",
"':'",
".",
"PHPExcel_Cell",
"::",
"stringFromColumnIndex",
"(",
"$",
"pColumn2",
")",
".",
"$",
"pRow2",
";",
"return",
"$",
"this",
"->",
"getStyle",
"(",
"$",
"cellRange",
")",
";",
"}",
"return",
"$",
"this",
"->",
"getStyle",
"(",
"PHPExcel_Cell",
"::",
"stringFromColumnIndex",
"(",
"$",
"pColumn",
")",
".",
"$",
"pRow",
")",
";",
"}"
] |
Get style for cell by using numeric cell coordinates
@param int $pColumn Numeric column coordinate of the cell
@param int $pRow Numeric row coordinate of the cell
@param int pColumn2 Numeric column coordinate of the range cell
@param int pRow2 Numeric row coordinate of the range cell
@return PHPExcel_Style
|
[
"Get",
"style",
"for",
"cell",
"by",
"using",
"numeric",
"cell",
"coordinates"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/phpexcel/PHPExcel/Worksheet.php#L1487-L1495
|
215,347
|
moodle/moodle
|
lib/phpexcel/PHPExcel/Worksheet.php
|
PHPExcel_Worksheet.setSharedStyle
|
public function setSharedStyle(PHPExcel_Style $pSharedCellStyle = null, $pRange = '')
{
$this->duplicateStyle($pSharedCellStyle, $pRange);
return $this;
}
|
php
|
public function setSharedStyle(PHPExcel_Style $pSharedCellStyle = null, $pRange = '')
{
$this->duplicateStyle($pSharedCellStyle, $pRange);
return $this;
}
|
[
"public",
"function",
"setSharedStyle",
"(",
"PHPExcel_Style",
"$",
"pSharedCellStyle",
"=",
"null",
",",
"$",
"pRange",
"=",
"''",
")",
"{",
"$",
"this",
"->",
"duplicateStyle",
"(",
"$",
"pSharedCellStyle",
",",
"$",
"pRange",
")",
";",
"return",
"$",
"this",
";",
"}"
] |
Set shared cell style to a range of cells
Please note that this will overwrite existing cell styles for cells in range!
@deprecated
@param PHPExcel_Style $pSharedCellStyle Cell style to share
@param string $pRange Range of cells (i.e. "A1:B10"), or just one cell (i.e. "A1")
@throws PHPExcel_Exception
@return PHPExcel_Worksheet
|
[
"Set",
"shared",
"cell",
"style",
"to",
"a",
"range",
"of",
"cells"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/phpexcel/PHPExcel/Worksheet.php#L1508-L1512
|
215,348
|
moodle/moodle
|
lib/phpexcel/PHPExcel/Worksheet.php
|
PHPExcel_Worksheet.duplicateStyleArray
|
public function duplicateStyleArray($pStyles = null, $pRange = '', $pAdvanced = true)
{
$this->getStyle($pRange)->applyFromArray($pStyles, $pAdvanced);
return $this;
}
|
php
|
public function duplicateStyleArray($pStyles = null, $pRange = '', $pAdvanced = true)
{
$this->getStyle($pRange)->applyFromArray($pStyles, $pAdvanced);
return $this;
}
|
[
"public",
"function",
"duplicateStyleArray",
"(",
"$",
"pStyles",
"=",
"null",
",",
"$",
"pRange",
"=",
"''",
",",
"$",
"pAdvanced",
"=",
"true",
")",
"{",
"$",
"this",
"->",
"getStyle",
"(",
"$",
"pRange",
")",
"->",
"applyFromArray",
"(",
"$",
"pStyles",
",",
"$",
"pAdvanced",
")",
";",
"return",
"$",
"this",
";",
"}"
] |
Duplicate cell style array to a range of cells
Please note that this will overwrite existing cell styles for cells in range,
if they are in the styles array. For example, if you decide to set a range of
cells to font bold, only include font bold in the styles array.
@deprecated
@param array $pStyles Array containing style information
@param string $pRange Range of cells (i.e. "A1:B10"), or just one cell (i.e. "A1")
@param boolean $pAdvanced Advanced mode for setting borders.
@throws PHPExcel_Exception
@return PHPExcel_Worksheet
|
[
"Duplicate",
"cell",
"style",
"array",
"to",
"a",
"range",
"of",
"cells"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/phpexcel/PHPExcel/Worksheet.php#L1612-L1616
|
215,349
|
moodle/moodle
|
lib/phpexcel/PHPExcel/Worksheet.php
|
PHPExcel_Worksheet.setBreakByColumnAndRow
|
public function setBreakByColumnAndRow($pColumn = 0, $pRow = 1, $pBreak = PHPExcel_Worksheet::BREAK_NONE)
{
return $this->setBreak(PHPExcel_Cell::stringFromColumnIndex($pColumn) . $pRow, $pBreak);
}
|
php
|
public function setBreakByColumnAndRow($pColumn = 0, $pRow = 1, $pBreak = PHPExcel_Worksheet::BREAK_NONE)
{
return $this->setBreak(PHPExcel_Cell::stringFromColumnIndex($pColumn) . $pRow, $pBreak);
}
|
[
"public",
"function",
"setBreakByColumnAndRow",
"(",
"$",
"pColumn",
"=",
"0",
",",
"$",
"pRow",
"=",
"1",
",",
"$",
"pBreak",
"=",
"PHPExcel_Worksheet",
"::",
"BREAK_NONE",
")",
"{",
"return",
"$",
"this",
"->",
"setBreak",
"(",
"PHPExcel_Cell",
"::",
"stringFromColumnIndex",
"(",
"$",
"pColumn",
")",
".",
"$",
"pRow",
",",
"$",
"pBreak",
")",
";",
"}"
] |
Set break on a cell by using numeric cell coordinates
@param integer $pColumn Numeric column coordinate of the cell
@param integer $pRow Numeric row coordinate of the cell
@param integer $pBreak Break type (type of PHPExcel_Worksheet::BREAK_*)
@return PHPExcel_Worksheet
|
[
"Set",
"break",
"on",
"a",
"cell",
"by",
"using",
"numeric",
"cell",
"coordinates"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/phpexcel/PHPExcel/Worksheet.php#L1654-L1657
|
215,350
|
moodle/moodle
|
lib/phpexcel/PHPExcel/Worksheet.php
|
PHPExcel_Worksheet.mergeCellsByColumnAndRow
|
public function mergeCellsByColumnAndRow($pColumn1 = 0, $pRow1 = 1, $pColumn2 = 0, $pRow2 = 1)
{
$cellRange = PHPExcel_Cell::stringFromColumnIndex($pColumn1) . $pRow1 . ':' . PHPExcel_Cell::stringFromColumnIndex($pColumn2) . $pRow2;
return $this->mergeCells($cellRange);
}
|
php
|
public function mergeCellsByColumnAndRow($pColumn1 = 0, $pRow1 = 1, $pColumn2 = 0, $pRow2 = 1)
{
$cellRange = PHPExcel_Cell::stringFromColumnIndex($pColumn1) . $pRow1 . ':' . PHPExcel_Cell::stringFromColumnIndex($pColumn2) . $pRow2;
return $this->mergeCells($cellRange);
}
|
[
"public",
"function",
"mergeCellsByColumnAndRow",
"(",
"$",
"pColumn1",
"=",
"0",
",",
"$",
"pRow1",
"=",
"1",
",",
"$",
"pColumn2",
"=",
"0",
",",
"$",
"pRow2",
"=",
"1",
")",
"{",
"$",
"cellRange",
"=",
"PHPExcel_Cell",
"::",
"stringFromColumnIndex",
"(",
"$",
"pColumn1",
")",
".",
"$",
"pRow1",
".",
"':'",
".",
"PHPExcel_Cell",
"::",
"stringFromColumnIndex",
"(",
"$",
"pColumn2",
")",
".",
"$",
"pRow2",
";",
"return",
"$",
"this",
"->",
"mergeCells",
"(",
"$",
"cellRange",
")",
";",
"}"
] |
Set merge on a cell range by using numeric cell coordinates
@param int $pColumn1 Numeric column coordinate of the first cell
@param int $pRow1 Numeric row coordinate of the first cell
@param int $pColumn2 Numeric column coordinate of the last cell
@param int $pRow2 Numeric row coordinate of the last cell
@throws PHPExcel_Exception
@return PHPExcel_Worksheet
|
[
"Set",
"merge",
"on",
"a",
"cell",
"range",
"by",
"using",
"numeric",
"cell",
"coordinates"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/phpexcel/PHPExcel/Worksheet.php#L1717-L1721
|
215,351
|
moodle/moodle
|
lib/phpexcel/PHPExcel/Worksheet.php
|
PHPExcel_Worksheet.unmergeCells
|
public function unmergeCells($pRange = 'A1:A1')
{
// Uppercase coordinate
$pRange = strtoupper($pRange);
if (strpos($pRange, ':') !== false) {
if (isset($this->mergeCells[$pRange])) {
unset($this->mergeCells[$pRange]);
} else {
throw new PHPExcel_Exception('Cell range ' . $pRange . ' not known as merged.');
}
} else {
throw new PHPExcel_Exception('Merge can only be removed from a range of cells.');
}
return $this;
}
|
php
|
public function unmergeCells($pRange = 'A1:A1')
{
// Uppercase coordinate
$pRange = strtoupper($pRange);
if (strpos($pRange, ':') !== false) {
if (isset($this->mergeCells[$pRange])) {
unset($this->mergeCells[$pRange]);
} else {
throw new PHPExcel_Exception('Cell range ' . $pRange . ' not known as merged.');
}
} else {
throw new PHPExcel_Exception('Merge can only be removed from a range of cells.');
}
return $this;
}
|
[
"public",
"function",
"unmergeCells",
"(",
"$",
"pRange",
"=",
"'A1:A1'",
")",
"{",
"// Uppercase coordinate",
"$",
"pRange",
"=",
"strtoupper",
"(",
"$",
"pRange",
")",
";",
"if",
"(",
"strpos",
"(",
"$",
"pRange",
",",
"':'",
")",
"!==",
"false",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"mergeCells",
"[",
"$",
"pRange",
"]",
")",
")",
"{",
"unset",
"(",
"$",
"this",
"->",
"mergeCells",
"[",
"$",
"pRange",
"]",
")",
";",
"}",
"else",
"{",
"throw",
"new",
"PHPExcel_Exception",
"(",
"'Cell range '",
".",
"$",
"pRange",
".",
"' not known as merged.'",
")",
";",
"}",
"}",
"else",
"{",
"throw",
"new",
"PHPExcel_Exception",
"(",
"'Merge can only be removed from a range of cells.'",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
] |
Remove merge on a cell range
@param string $pRange Cell range (e.g. A1:E1)
@throws PHPExcel_Exception
@return PHPExcel_Worksheet
|
[
"Remove",
"merge",
"on",
"a",
"cell",
"range"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/phpexcel/PHPExcel/Worksheet.php#L1730-L1746
|
215,352
|
moodle/moodle
|
lib/phpexcel/PHPExcel/Worksheet.php
|
PHPExcel_Worksheet.unmergeCellsByColumnAndRow
|
public function unmergeCellsByColumnAndRow($pColumn1 = 0, $pRow1 = 1, $pColumn2 = 0, $pRow2 = 1)
{
$cellRange = PHPExcel_Cell::stringFromColumnIndex($pColumn1) . $pRow1 . ':' . PHPExcel_Cell::stringFromColumnIndex($pColumn2) . $pRow2;
return $this->unmergeCells($cellRange);
}
|
php
|
public function unmergeCellsByColumnAndRow($pColumn1 = 0, $pRow1 = 1, $pColumn2 = 0, $pRow2 = 1)
{
$cellRange = PHPExcel_Cell::stringFromColumnIndex($pColumn1) . $pRow1 . ':' . PHPExcel_Cell::stringFromColumnIndex($pColumn2) . $pRow2;
return $this->unmergeCells($cellRange);
}
|
[
"public",
"function",
"unmergeCellsByColumnAndRow",
"(",
"$",
"pColumn1",
"=",
"0",
",",
"$",
"pRow1",
"=",
"1",
",",
"$",
"pColumn2",
"=",
"0",
",",
"$",
"pRow2",
"=",
"1",
")",
"{",
"$",
"cellRange",
"=",
"PHPExcel_Cell",
"::",
"stringFromColumnIndex",
"(",
"$",
"pColumn1",
")",
".",
"$",
"pRow1",
".",
"':'",
".",
"PHPExcel_Cell",
"::",
"stringFromColumnIndex",
"(",
"$",
"pColumn2",
")",
".",
"$",
"pRow2",
";",
"return",
"$",
"this",
"->",
"unmergeCells",
"(",
"$",
"cellRange",
")",
";",
"}"
] |
Remove merge on a cell range by using numeric cell coordinates
@param int $pColumn1 Numeric column coordinate of the first cell
@param int $pRow1 Numeric row coordinate of the first cell
@param int $pColumn2 Numeric column coordinate of the last cell
@param int $pRow2 Numeric row coordinate of the last cell
@throws PHPExcel_Exception
@return PHPExcel_Worksheet
|
[
"Remove",
"merge",
"on",
"a",
"cell",
"range",
"by",
"using",
"numeric",
"cell",
"coordinates"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/phpexcel/PHPExcel/Worksheet.php#L1758-L1762
|
215,353
|
moodle/moodle
|
lib/phpexcel/PHPExcel/Worksheet.php
|
PHPExcel_Worksheet.protectCells
|
public function protectCells($pRange = 'A1', $pPassword = '', $pAlreadyHashed = false)
{
// Uppercase coordinate
$pRange = strtoupper($pRange);
if (!$pAlreadyHashed) {
$pPassword = PHPExcel_Shared_PasswordHasher::hashPassword($pPassword);
}
$this->protectedCells[$pRange] = $pPassword;
return $this;
}
|
php
|
public function protectCells($pRange = 'A1', $pPassword = '', $pAlreadyHashed = false)
{
// Uppercase coordinate
$pRange = strtoupper($pRange);
if (!$pAlreadyHashed) {
$pPassword = PHPExcel_Shared_PasswordHasher::hashPassword($pPassword);
}
$this->protectedCells[$pRange] = $pPassword;
return $this;
}
|
[
"public",
"function",
"protectCells",
"(",
"$",
"pRange",
"=",
"'A1'",
",",
"$",
"pPassword",
"=",
"''",
",",
"$",
"pAlreadyHashed",
"=",
"false",
")",
"{",
"// Uppercase coordinate",
"$",
"pRange",
"=",
"strtoupper",
"(",
"$",
"pRange",
")",
";",
"if",
"(",
"!",
"$",
"pAlreadyHashed",
")",
"{",
"$",
"pPassword",
"=",
"PHPExcel_Shared_PasswordHasher",
"::",
"hashPassword",
"(",
"$",
"pPassword",
")",
";",
"}",
"$",
"this",
"->",
"protectedCells",
"[",
"$",
"pRange",
"]",
"=",
"$",
"pPassword",
";",
"return",
"$",
"this",
";",
"}"
] |
Set protection on a cell range
@param string $pRange Cell (e.g. A1) or cell range (e.g. A1:E1)
@param string $pPassword Password to unlock the protection
@param boolean $pAlreadyHashed If the password has already been hashed, set this to true
@throws PHPExcel_Exception
@return PHPExcel_Worksheet
|
[
"Set",
"protection",
"on",
"a",
"cell",
"range"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/phpexcel/PHPExcel/Worksheet.php#L1795-L1806
|
215,354
|
moodle/moodle
|
lib/phpexcel/PHPExcel/Worksheet.php
|
PHPExcel_Worksheet.protectCellsByColumnAndRow
|
public function protectCellsByColumnAndRow($pColumn1 = 0, $pRow1 = 1, $pColumn2 = 0, $pRow2 = 1, $pPassword = '', $pAlreadyHashed = false)
{
$cellRange = PHPExcel_Cell::stringFromColumnIndex($pColumn1) . $pRow1 . ':' . PHPExcel_Cell::stringFromColumnIndex($pColumn2) . $pRow2;
return $this->protectCells($cellRange, $pPassword, $pAlreadyHashed);
}
|
php
|
public function protectCellsByColumnAndRow($pColumn1 = 0, $pRow1 = 1, $pColumn2 = 0, $pRow2 = 1, $pPassword = '', $pAlreadyHashed = false)
{
$cellRange = PHPExcel_Cell::stringFromColumnIndex($pColumn1) . $pRow1 . ':' . PHPExcel_Cell::stringFromColumnIndex($pColumn2) . $pRow2;
return $this->protectCells($cellRange, $pPassword, $pAlreadyHashed);
}
|
[
"public",
"function",
"protectCellsByColumnAndRow",
"(",
"$",
"pColumn1",
"=",
"0",
",",
"$",
"pRow1",
"=",
"1",
",",
"$",
"pColumn2",
"=",
"0",
",",
"$",
"pRow2",
"=",
"1",
",",
"$",
"pPassword",
"=",
"''",
",",
"$",
"pAlreadyHashed",
"=",
"false",
")",
"{",
"$",
"cellRange",
"=",
"PHPExcel_Cell",
"::",
"stringFromColumnIndex",
"(",
"$",
"pColumn1",
")",
".",
"$",
"pRow1",
".",
"':'",
".",
"PHPExcel_Cell",
"::",
"stringFromColumnIndex",
"(",
"$",
"pColumn2",
")",
".",
"$",
"pRow2",
";",
"return",
"$",
"this",
"->",
"protectCells",
"(",
"$",
"cellRange",
",",
"$",
"pPassword",
",",
"$",
"pAlreadyHashed",
")",
";",
"}"
] |
Set protection on a cell range by using numeric cell coordinates
@param int $pColumn1 Numeric column coordinate of the first cell
@param int $pRow1 Numeric row coordinate of the first cell
@param int $pColumn2 Numeric column coordinate of the last cell
@param int $pRow2 Numeric row coordinate of the last cell
@param string $pPassword Password to unlock the protection
@param boolean $pAlreadyHashed If the password has already been hashed, set this to true
@throws PHPExcel_Exception
@return PHPExcel_Worksheet
|
[
"Set",
"protection",
"on",
"a",
"cell",
"range",
"by",
"using",
"numeric",
"cell",
"coordinates"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/phpexcel/PHPExcel/Worksheet.php#L1820-L1824
|
215,355
|
moodle/moodle
|
lib/phpexcel/PHPExcel/Worksheet.php
|
PHPExcel_Worksheet.unprotectCellsByColumnAndRow
|
public function unprotectCellsByColumnAndRow($pColumn1 = 0, $pRow1 = 1, $pColumn2 = 0, $pRow2 = 1, $pPassword = '', $pAlreadyHashed = false)
{
$cellRange = PHPExcel_Cell::stringFromColumnIndex($pColumn1) . $pRow1 . ':' . PHPExcel_Cell::stringFromColumnIndex($pColumn2) . $pRow2;
return $this->unprotectCells($cellRange, $pPassword, $pAlreadyHashed);
}
|
php
|
public function unprotectCellsByColumnAndRow($pColumn1 = 0, $pRow1 = 1, $pColumn2 = 0, $pRow2 = 1, $pPassword = '', $pAlreadyHashed = false)
{
$cellRange = PHPExcel_Cell::stringFromColumnIndex($pColumn1) . $pRow1 . ':' . PHPExcel_Cell::stringFromColumnIndex($pColumn2) . $pRow2;
return $this->unprotectCells($cellRange, $pPassword, $pAlreadyHashed);
}
|
[
"public",
"function",
"unprotectCellsByColumnAndRow",
"(",
"$",
"pColumn1",
"=",
"0",
",",
"$",
"pRow1",
"=",
"1",
",",
"$",
"pColumn2",
"=",
"0",
",",
"$",
"pRow2",
"=",
"1",
",",
"$",
"pPassword",
"=",
"''",
",",
"$",
"pAlreadyHashed",
"=",
"false",
")",
"{",
"$",
"cellRange",
"=",
"PHPExcel_Cell",
"::",
"stringFromColumnIndex",
"(",
"$",
"pColumn1",
")",
".",
"$",
"pRow1",
".",
"':'",
".",
"PHPExcel_Cell",
"::",
"stringFromColumnIndex",
"(",
"$",
"pColumn2",
")",
".",
"$",
"pRow2",
";",
"return",
"$",
"this",
"->",
"unprotectCells",
"(",
"$",
"cellRange",
",",
"$",
"pPassword",
",",
"$",
"pAlreadyHashed",
")",
";",
"}"
] |
Remove protection on a cell range by using numeric cell coordinates
@param int $pColumn1 Numeric column coordinate of the first cell
@param int $pRow1 Numeric row coordinate of the first cell
@param int $pColumn2 Numeric column coordinate of the last cell
@param int $pRow2 Numeric row coordinate of the last cell
@param string $pPassword Password to unlock the protection
@param boolean $pAlreadyHashed If the password has already been hashed, set this to true
@throws PHPExcel_Exception
@return PHPExcel_Worksheet
|
[
"Remove",
"protection",
"on",
"a",
"cell",
"range",
"by",
"using",
"numeric",
"cell",
"coordinates"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/phpexcel/PHPExcel/Worksheet.php#L1858-L1862
|
215,356
|
moodle/moodle
|
lib/phpexcel/PHPExcel/Worksheet.php
|
PHPExcel_Worksheet.setAutoFilterByColumnAndRow
|
public function setAutoFilterByColumnAndRow($pColumn1 = 0, $pRow1 = 1, $pColumn2 = 0, $pRow2 = 1)
{
return $this->setAutoFilter(
PHPExcel_Cell::stringFromColumnIndex($pColumn1) . $pRow1
. ':' .
PHPExcel_Cell::stringFromColumnIndex($pColumn2) . $pRow2
);
}
|
php
|
public function setAutoFilterByColumnAndRow($pColumn1 = 0, $pRow1 = 1, $pColumn2 = 0, $pRow2 = 1)
{
return $this->setAutoFilter(
PHPExcel_Cell::stringFromColumnIndex($pColumn1) . $pRow1
. ':' .
PHPExcel_Cell::stringFromColumnIndex($pColumn2) . $pRow2
);
}
|
[
"public",
"function",
"setAutoFilterByColumnAndRow",
"(",
"$",
"pColumn1",
"=",
"0",
",",
"$",
"pRow1",
"=",
"1",
",",
"$",
"pColumn2",
"=",
"0",
",",
"$",
"pRow2",
"=",
"1",
")",
"{",
"return",
"$",
"this",
"->",
"setAutoFilter",
"(",
"PHPExcel_Cell",
"::",
"stringFromColumnIndex",
"(",
"$",
"pColumn1",
")",
".",
"$",
"pRow1",
".",
"':'",
".",
"PHPExcel_Cell",
"::",
"stringFromColumnIndex",
"(",
"$",
"pColumn2",
")",
".",
"$",
"pRow2",
")",
";",
"}"
] |
Set Autofilter Range by using numeric cell coordinates
@param integer $pColumn1 Numeric column coordinate of the first cell
@param integer $pRow1 Numeric row coordinate of the first cell
@param integer $pColumn2 Numeric column coordinate of the second cell
@param integer $pRow2 Numeric row coordinate of the second cell
@throws PHPExcel_Exception
@return PHPExcel_Worksheet
|
[
"Set",
"Autofilter",
"Range",
"by",
"using",
"numeric",
"cell",
"coordinates"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/phpexcel/PHPExcel/Worksheet.php#L1913-L1920
|
215,357
|
moodle/moodle
|
lib/phpexcel/PHPExcel/Worksheet.php
|
PHPExcel_Worksheet.insertNewRowBefore
|
public function insertNewRowBefore($pBefore = 1, $pNumRows = 1)
{
if ($pBefore >= 1) {
$objReferenceHelper = PHPExcel_ReferenceHelper::getInstance();
$objReferenceHelper->insertNewBefore('A' . $pBefore, 0, $pNumRows, $this);
} else {
throw new PHPExcel_Exception("Rows can only be inserted before at least row 1.");
}
return $this;
}
|
php
|
public function insertNewRowBefore($pBefore = 1, $pNumRows = 1)
{
if ($pBefore >= 1) {
$objReferenceHelper = PHPExcel_ReferenceHelper::getInstance();
$objReferenceHelper->insertNewBefore('A' . $pBefore, 0, $pNumRows, $this);
} else {
throw new PHPExcel_Exception("Rows can only be inserted before at least row 1.");
}
return $this;
}
|
[
"public",
"function",
"insertNewRowBefore",
"(",
"$",
"pBefore",
"=",
"1",
",",
"$",
"pNumRows",
"=",
"1",
")",
"{",
"if",
"(",
"$",
"pBefore",
">=",
"1",
")",
"{",
"$",
"objReferenceHelper",
"=",
"PHPExcel_ReferenceHelper",
"::",
"getInstance",
"(",
")",
";",
"$",
"objReferenceHelper",
"->",
"insertNewBefore",
"(",
"'A'",
".",
"$",
"pBefore",
",",
"0",
",",
"$",
"pNumRows",
",",
"$",
"this",
")",
";",
"}",
"else",
"{",
"throw",
"new",
"PHPExcel_Exception",
"(",
"\"Rows can only be inserted before at least row 1.\"",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
] |
Insert a new row, updating all possible related data
@param int $pBefore Insert before this one
@param int $pNumRows Number of rows to insert
@throws PHPExcel_Exception
@return PHPExcel_Worksheet
|
[
"Insert",
"a",
"new",
"row",
"updating",
"all",
"possible",
"related",
"data"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/phpexcel/PHPExcel/Worksheet.php#L1998-L2007
|
215,358
|
moodle/moodle
|
lib/phpexcel/PHPExcel/Worksheet.php
|
PHPExcel_Worksheet.getComment
|
public function getComment($pCellCoordinate = 'A1')
{
// Uppercase coordinate
$pCellCoordinate = strtoupper($pCellCoordinate);
if (strpos($pCellCoordinate, ':') !== false || strpos($pCellCoordinate, ',') !== false) {
throw new PHPExcel_Exception('Cell coordinate string can not be a range of cells.');
} elseif (strpos($pCellCoordinate, '$') !== false) {
throw new PHPExcel_Exception('Cell coordinate string must not be absolute.');
} elseif ($pCellCoordinate == '') {
throw new PHPExcel_Exception('Cell coordinate can not be zero-length string.');
} else {
// Check if we already have a comment for this cell.
// If not, create a new comment.
if (isset($this->comments[$pCellCoordinate])) {
return $this->comments[$pCellCoordinate];
} else {
$newComment = new PHPExcel_Comment();
$this->comments[$pCellCoordinate] = $newComment;
return $newComment;
}
}
}
|
php
|
public function getComment($pCellCoordinate = 'A1')
{
// Uppercase coordinate
$pCellCoordinate = strtoupper($pCellCoordinate);
if (strpos($pCellCoordinate, ':') !== false || strpos($pCellCoordinate, ',') !== false) {
throw new PHPExcel_Exception('Cell coordinate string can not be a range of cells.');
} elseif (strpos($pCellCoordinate, '$') !== false) {
throw new PHPExcel_Exception('Cell coordinate string must not be absolute.');
} elseif ($pCellCoordinate == '') {
throw new PHPExcel_Exception('Cell coordinate can not be zero-length string.');
} else {
// Check if we already have a comment for this cell.
// If not, create a new comment.
if (isset($this->comments[$pCellCoordinate])) {
return $this->comments[$pCellCoordinate];
} else {
$newComment = new PHPExcel_Comment();
$this->comments[$pCellCoordinate] = $newComment;
return $newComment;
}
}
}
|
[
"public",
"function",
"getComment",
"(",
"$",
"pCellCoordinate",
"=",
"'A1'",
")",
"{",
"// Uppercase coordinate",
"$",
"pCellCoordinate",
"=",
"strtoupper",
"(",
"$",
"pCellCoordinate",
")",
";",
"if",
"(",
"strpos",
"(",
"$",
"pCellCoordinate",
",",
"':'",
")",
"!==",
"false",
"||",
"strpos",
"(",
"$",
"pCellCoordinate",
",",
"','",
")",
"!==",
"false",
")",
"{",
"throw",
"new",
"PHPExcel_Exception",
"(",
"'Cell coordinate string can not be a range of cells.'",
")",
";",
"}",
"elseif",
"(",
"strpos",
"(",
"$",
"pCellCoordinate",
",",
"'$'",
")",
"!==",
"false",
")",
"{",
"throw",
"new",
"PHPExcel_Exception",
"(",
"'Cell coordinate string must not be absolute.'",
")",
";",
"}",
"elseif",
"(",
"$",
"pCellCoordinate",
"==",
"''",
")",
"{",
"throw",
"new",
"PHPExcel_Exception",
"(",
"'Cell coordinate can not be zero-length string.'",
")",
";",
"}",
"else",
"{",
"// Check if we already have a comment for this cell.",
"// If not, create a new comment.",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"comments",
"[",
"$",
"pCellCoordinate",
"]",
")",
")",
"{",
"return",
"$",
"this",
"->",
"comments",
"[",
"$",
"pCellCoordinate",
"]",
";",
"}",
"else",
"{",
"$",
"newComment",
"=",
"new",
"PHPExcel_Comment",
"(",
")",
";",
"$",
"this",
"->",
"comments",
"[",
"$",
"pCellCoordinate",
"]",
"=",
"$",
"newComment",
";",
"return",
"$",
"newComment",
";",
"}",
"}",
"}"
] |
Get comment for cell
@param string $pCellCoordinate Cell coordinate to get comment for
@return PHPExcel_Comment
@throws PHPExcel_Exception
|
[
"Get",
"comment",
"for",
"cell"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/phpexcel/PHPExcel/Worksheet.php#L2251-L2273
|
215,359
|
moodle/moodle
|
lib/phpexcel/PHPExcel/Worksheet.php
|
PHPExcel_Worksheet.toArray
|
public function toArray($nullValue = null, $calculateFormulas = true, $formatData = true, $returnCellRef = false)
{
// Garbage collect...
$this->garbageCollect();
// Identify the range that we need to extract from the worksheet
$maxCol = $this->getHighestColumn();
$maxRow = $this->getHighestRow();
// Return
return $this->rangeToArray('A1:'.$maxCol.$maxRow, $nullValue, $calculateFormulas, $formatData, $returnCellRef);
}
|
php
|
public function toArray($nullValue = null, $calculateFormulas = true, $formatData = true, $returnCellRef = false)
{
// Garbage collect...
$this->garbageCollect();
// Identify the range that we need to extract from the worksheet
$maxCol = $this->getHighestColumn();
$maxRow = $this->getHighestRow();
// Return
return $this->rangeToArray('A1:'.$maxCol.$maxRow, $nullValue, $calculateFormulas, $formatData, $returnCellRef);
}
|
[
"public",
"function",
"toArray",
"(",
"$",
"nullValue",
"=",
"null",
",",
"$",
"calculateFormulas",
"=",
"true",
",",
"$",
"formatData",
"=",
"true",
",",
"$",
"returnCellRef",
"=",
"false",
")",
"{",
"// Garbage collect...",
"$",
"this",
"->",
"garbageCollect",
"(",
")",
";",
"// Identify the range that we need to extract from the worksheet",
"$",
"maxCol",
"=",
"$",
"this",
"->",
"getHighestColumn",
"(",
")",
";",
"$",
"maxRow",
"=",
"$",
"this",
"->",
"getHighestRow",
"(",
")",
";",
"// Return",
"return",
"$",
"this",
"->",
"rangeToArray",
"(",
"'A1:'",
".",
"$",
"maxCol",
".",
"$",
"maxRow",
",",
"$",
"nullValue",
",",
"$",
"calculateFormulas",
",",
"$",
"formatData",
",",
"$",
"returnCellRef",
")",
";",
"}"
] |
Create array from worksheet
@param mixed $nullValue Value returned in the array entry if a cell doesn't exist
@param boolean $calculateFormulas Should formulas be calculated?
@param boolean $formatData Should formatting be applied to cell values?
@param boolean $returnCellRef False - Return a simple array of rows and columns indexed by number counting from zero
True - Return rows and columns indexed by their actual row and column IDs
@return array
|
[
"Create",
"array",
"from",
"worksheet"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/phpexcel/PHPExcel/Worksheet.php#L2550-L2560
|
215,360
|
moodle/moodle
|
lib/phpexcel/PHPExcel/Worksheet.php
|
PHPExcel_Worksheet.extractSheetTitle
|
public static function extractSheetTitle($pRange, $returnRange = false)
{
// Sheet title included?
if (($sep = strpos($pRange, '!')) === false) {
return '';
}
if ($returnRange) {
return array(trim(substr($pRange, 0, $sep), "'"), substr($pRange, $sep + 1));
}
return substr($pRange, $sep + 1);
}
|
php
|
public static function extractSheetTitle($pRange, $returnRange = false)
{
// Sheet title included?
if (($sep = strpos($pRange, '!')) === false) {
return '';
}
if ($returnRange) {
return array(trim(substr($pRange, 0, $sep), "'"), substr($pRange, $sep + 1));
}
return substr($pRange, $sep + 1);
}
|
[
"public",
"static",
"function",
"extractSheetTitle",
"(",
"$",
"pRange",
",",
"$",
"returnRange",
"=",
"false",
")",
"{",
"// Sheet title included?",
"if",
"(",
"(",
"$",
"sep",
"=",
"strpos",
"(",
"$",
"pRange",
",",
"'!'",
")",
")",
"===",
"false",
")",
"{",
"return",
"''",
";",
"}",
"if",
"(",
"$",
"returnRange",
")",
"{",
"return",
"array",
"(",
"trim",
"(",
"substr",
"(",
"$",
"pRange",
",",
"0",
",",
"$",
"sep",
")",
",",
"\"'\"",
")",
",",
"substr",
"(",
"$",
"pRange",
",",
"$",
"sep",
"+",
"1",
")",
")",
";",
"}",
"return",
"substr",
"(",
"$",
"pRange",
",",
"$",
"sep",
"+",
"1",
")",
";",
"}"
] |
Extract worksheet title from range.
Example: extractSheetTitle("testSheet!A1") ==> 'A1'
Example: extractSheetTitle("'testSheet 1'!A1", true) ==> array('testSheet 1', 'A1');
@param string $pRange Range to extract title from
@param bool $returnRange Return range? (see example)
@return mixed
|
[
"Extract",
"worksheet",
"title",
"from",
"range",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/phpexcel/PHPExcel/Worksheet.php#L2657-L2669
|
215,361
|
moodle/moodle
|
backup/util/helper/backup_file_manager.class.php
|
backup_file_manager.copy_file_moodle2backup
|
public static function copy_file_moodle2backup($backupid, $filerecorid) {
global $DB;
if (!backup_controller_dbops::backup_includes_files($backupid)) {
// Only include the files if required by the controller.
return;
}
// Normalise param
if (!is_object($filerecorid)) {
$filerecorid = $DB->get_record('files', array('id' => $filerecorid));
}
// Directory, nothing to do
if ($filerecorid->filename === '.') {
return;
}
$fs = get_file_storage();
$file = $fs->get_file_instance($filerecorid);
// If the file is external file, skip copying.
if ($file->is_external_file()) {
return;
}
// Calculate source and target paths (use same subdirs strategy for both)
$targetfilepath = self::get_backup_storage_base_dir($backupid) . '/' .
self::get_backup_content_file_location($filerecorid->contenthash);
// Create target dir if necessary
if (!file_exists(dirname($targetfilepath))) {
if (!check_dir_exists(dirname($targetfilepath), true, true)) {
throw new backup_helper_exception('cannot_create_directory', dirname($targetfilepath));
}
}
// And copy the file (if doesn't exist already)
if (!file_exists($targetfilepath)) {
$file->copy_content_to($targetfilepath);
}
}
|
php
|
public static function copy_file_moodle2backup($backupid, $filerecorid) {
global $DB;
if (!backup_controller_dbops::backup_includes_files($backupid)) {
// Only include the files if required by the controller.
return;
}
// Normalise param
if (!is_object($filerecorid)) {
$filerecorid = $DB->get_record('files', array('id' => $filerecorid));
}
// Directory, nothing to do
if ($filerecorid->filename === '.') {
return;
}
$fs = get_file_storage();
$file = $fs->get_file_instance($filerecorid);
// If the file is external file, skip copying.
if ($file->is_external_file()) {
return;
}
// Calculate source and target paths (use same subdirs strategy for both)
$targetfilepath = self::get_backup_storage_base_dir($backupid) . '/' .
self::get_backup_content_file_location($filerecorid->contenthash);
// Create target dir if necessary
if (!file_exists(dirname($targetfilepath))) {
if (!check_dir_exists(dirname($targetfilepath), true, true)) {
throw new backup_helper_exception('cannot_create_directory', dirname($targetfilepath));
}
}
// And copy the file (if doesn't exist already)
if (!file_exists($targetfilepath)) {
$file->copy_content_to($targetfilepath);
}
}
|
[
"public",
"static",
"function",
"copy_file_moodle2backup",
"(",
"$",
"backupid",
",",
"$",
"filerecorid",
")",
"{",
"global",
"$",
"DB",
";",
"if",
"(",
"!",
"backup_controller_dbops",
"::",
"backup_includes_files",
"(",
"$",
"backupid",
")",
")",
"{",
"// Only include the files if required by the controller.",
"return",
";",
"}",
"// Normalise param",
"if",
"(",
"!",
"is_object",
"(",
"$",
"filerecorid",
")",
")",
"{",
"$",
"filerecorid",
"=",
"$",
"DB",
"->",
"get_record",
"(",
"'files'",
",",
"array",
"(",
"'id'",
"=>",
"$",
"filerecorid",
")",
")",
";",
"}",
"// Directory, nothing to do",
"if",
"(",
"$",
"filerecorid",
"->",
"filename",
"===",
"'.'",
")",
"{",
"return",
";",
"}",
"$",
"fs",
"=",
"get_file_storage",
"(",
")",
";",
"$",
"file",
"=",
"$",
"fs",
"->",
"get_file_instance",
"(",
"$",
"filerecorid",
")",
";",
"// If the file is external file, skip copying.",
"if",
"(",
"$",
"file",
"->",
"is_external_file",
"(",
")",
")",
"{",
"return",
";",
"}",
"// Calculate source and target paths (use same subdirs strategy for both)",
"$",
"targetfilepath",
"=",
"self",
"::",
"get_backup_storage_base_dir",
"(",
"$",
"backupid",
")",
".",
"'/'",
".",
"self",
"::",
"get_backup_content_file_location",
"(",
"$",
"filerecorid",
"->",
"contenthash",
")",
";",
"// Create target dir if necessary",
"if",
"(",
"!",
"file_exists",
"(",
"dirname",
"(",
"$",
"targetfilepath",
")",
")",
")",
"{",
"if",
"(",
"!",
"check_dir_exists",
"(",
"dirname",
"(",
"$",
"targetfilepath",
")",
",",
"true",
",",
"true",
")",
")",
"{",
"throw",
"new",
"backup_helper_exception",
"(",
"'cannot_create_directory'",
",",
"dirname",
"(",
"$",
"targetfilepath",
")",
")",
";",
"}",
"}",
"// And copy the file (if doesn't exist already)",
"if",
"(",
"!",
"file_exists",
"(",
"$",
"targetfilepath",
")",
")",
"{",
"$",
"file",
"->",
"copy_content_to",
"(",
"$",
"targetfilepath",
")",
";",
"}",
"}"
] |
Copy one file from moodle storage to backup storage
|
[
"Copy",
"one",
"file",
"from",
"moodle",
"storage",
"to",
"backup",
"storage"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/backup/util/helper/backup_file_manager.class.php#L62-L102
|
215,362
|
moodle/moodle
|
lib/classes/task/asynchronous_restore_task.php
|
asynchronous_restore_task.execute
|
public function execute() {
global $DB;
$started = time();
$restoreid = $this->get_custom_data()->backupid;
$restorerecordid = $DB->get_field('backup_controllers', 'id', array('backupid' => $restoreid), MUST_EXIST);
mtrace('Processing asynchronous restore for id: ' . $restoreid);
// Get the restore controller by backup id.
$rc = \restore_controller::load_controller($restoreid);
$rc->set_progress(new \core\progress\db_updater($restorerecordid, 'backup_controllers', 'progress'));
// Do some preflight checks on the restore.
$status = $rc->get_status();
$execution = $rc->get_execution();
// Check that the restore is in the correct status and
// that is set for asynchronous execution.
if ($status == \backup::STATUS_AWAITING && $execution == \backup::EXECUTION_DELAYED) {
// Execute the restore.
$rc->execute_plan();
// Send message to user if enabled.
$messageenabled = (bool)get_config('backup', 'backup_async_message_users');
if ($messageenabled && $rc->get_status() == \backup::STATUS_FINISHED_OK) {
$asynchelper = new async_helper('restore', $restoreid);
$asynchelper->send_message();
}
} else {
// If status isn't 700, it means the process has failed.
// Retrying isn't going to fix it, so marked operation as failed.
$rc->set_status(\backup::STATUS_FINISHED_ERR);
mtrace('Bad backup controller status, is: ' . $status . ' should be 700, marking job as failed.');
}
// Cleanup.
$rc->destroy();
$duration = time() - $started;
mtrace('Restore completed in: ' . $duration . ' seconds');
}
|
php
|
public function execute() {
global $DB;
$started = time();
$restoreid = $this->get_custom_data()->backupid;
$restorerecordid = $DB->get_field('backup_controllers', 'id', array('backupid' => $restoreid), MUST_EXIST);
mtrace('Processing asynchronous restore for id: ' . $restoreid);
// Get the restore controller by backup id.
$rc = \restore_controller::load_controller($restoreid);
$rc->set_progress(new \core\progress\db_updater($restorerecordid, 'backup_controllers', 'progress'));
// Do some preflight checks on the restore.
$status = $rc->get_status();
$execution = $rc->get_execution();
// Check that the restore is in the correct status and
// that is set for asynchronous execution.
if ($status == \backup::STATUS_AWAITING && $execution == \backup::EXECUTION_DELAYED) {
// Execute the restore.
$rc->execute_plan();
// Send message to user if enabled.
$messageenabled = (bool)get_config('backup', 'backup_async_message_users');
if ($messageenabled && $rc->get_status() == \backup::STATUS_FINISHED_OK) {
$asynchelper = new async_helper('restore', $restoreid);
$asynchelper->send_message();
}
} else {
// If status isn't 700, it means the process has failed.
// Retrying isn't going to fix it, so marked operation as failed.
$rc->set_status(\backup::STATUS_FINISHED_ERR);
mtrace('Bad backup controller status, is: ' . $status . ' should be 700, marking job as failed.');
}
// Cleanup.
$rc->destroy();
$duration = time() - $started;
mtrace('Restore completed in: ' . $duration . ' seconds');
}
|
[
"public",
"function",
"execute",
"(",
")",
"{",
"global",
"$",
"DB",
";",
"$",
"started",
"=",
"time",
"(",
")",
";",
"$",
"restoreid",
"=",
"$",
"this",
"->",
"get_custom_data",
"(",
")",
"->",
"backupid",
";",
"$",
"restorerecordid",
"=",
"$",
"DB",
"->",
"get_field",
"(",
"'backup_controllers'",
",",
"'id'",
",",
"array",
"(",
"'backupid'",
"=>",
"$",
"restoreid",
")",
",",
"MUST_EXIST",
")",
";",
"mtrace",
"(",
"'Processing asynchronous restore for id: '",
".",
"$",
"restoreid",
")",
";",
"// Get the restore controller by backup id.",
"$",
"rc",
"=",
"\\",
"restore_controller",
"::",
"load_controller",
"(",
"$",
"restoreid",
")",
";",
"$",
"rc",
"->",
"set_progress",
"(",
"new",
"\\",
"core",
"\\",
"progress",
"\\",
"db_updater",
"(",
"$",
"restorerecordid",
",",
"'backup_controllers'",
",",
"'progress'",
")",
")",
";",
"// Do some preflight checks on the restore.",
"$",
"status",
"=",
"$",
"rc",
"->",
"get_status",
"(",
")",
";",
"$",
"execution",
"=",
"$",
"rc",
"->",
"get_execution",
"(",
")",
";",
"// Check that the restore is in the correct status and",
"// that is set for asynchronous execution.",
"if",
"(",
"$",
"status",
"==",
"\\",
"backup",
"::",
"STATUS_AWAITING",
"&&",
"$",
"execution",
"==",
"\\",
"backup",
"::",
"EXECUTION_DELAYED",
")",
"{",
"// Execute the restore.",
"$",
"rc",
"->",
"execute_plan",
"(",
")",
";",
"// Send message to user if enabled.",
"$",
"messageenabled",
"=",
"(",
"bool",
")",
"get_config",
"(",
"'backup'",
",",
"'backup_async_message_users'",
")",
";",
"if",
"(",
"$",
"messageenabled",
"&&",
"$",
"rc",
"->",
"get_status",
"(",
")",
"==",
"\\",
"backup",
"::",
"STATUS_FINISHED_OK",
")",
"{",
"$",
"asynchelper",
"=",
"new",
"async_helper",
"(",
"'restore'",
",",
"$",
"restoreid",
")",
";",
"$",
"asynchelper",
"->",
"send_message",
"(",
")",
";",
"}",
"}",
"else",
"{",
"// If status isn't 700, it means the process has failed.",
"// Retrying isn't going to fix it, so marked operation as failed.",
"$",
"rc",
"->",
"set_status",
"(",
"\\",
"backup",
"::",
"STATUS_FINISHED_ERR",
")",
";",
"mtrace",
"(",
"'Bad backup controller status, is: '",
".",
"$",
"status",
".",
"' should be 700, marking job as failed.'",
")",
";",
"}",
"// Cleanup.",
"$",
"rc",
"->",
"destroy",
"(",
")",
";",
"$",
"duration",
"=",
"time",
"(",
")",
"-",
"$",
"started",
";",
"mtrace",
"(",
"'Restore completed in: '",
".",
"$",
"duration",
".",
"' seconds'",
")",
";",
"}"
] |
Run the adhoc task and preform the restore.
|
[
"Run",
"the",
"adhoc",
"task",
"and",
"preform",
"the",
"restore",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/classes/task/asynchronous_restore_task.php#L45-L87
|
215,363
|
moodle/moodle
|
lib/adodb/adodb-xmlschema03.inc.php
|
dbObject.supportedPlatform
|
function supportedPlatform( $platform = NULL ) {
return is_object( $this->parent ) ? $this->parent->supportedPlatform( $platform ) : TRUE;
}
|
php
|
function supportedPlatform( $platform = NULL ) {
return is_object( $this->parent ) ? $this->parent->supportedPlatform( $platform ) : TRUE;
}
|
[
"function",
"supportedPlatform",
"(",
"$",
"platform",
"=",
"NULL",
")",
"{",
"return",
"is_object",
"(",
"$",
"this",
"->",
"parent",
")",
"?",
"$",
"this",
"->",
"parent",
"->",
"supportedPlatform",
"(",
"$",
"platform",
")",
":",
"TRUE",
";",
"}"
] |
Checks whether the specified RDBMS is supported by the current
database object or its ranking ancestor.
@param string $platform RDBMS platform name (from ADODB platform list).
@return boolean TRUE if RDBMS is supported; otherwise returns FALSE.
|
[
"Checks",
"whether",
"the",
"specified",
"RDBMS",
"is",
"supported",
"by",
"the",
"current",
"database",
"object",
"or",
"its",
"ranking",
"ancestor",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/adodb/adodb-xmlschema03.inc.php#L187-L189
|
215,364
|
moodle/moodle
|
lib/adodb/adodb-xmlschema03.inc.php
|
dbObject.prefix
|
function prefix( $name = '' ) {
return is_object( $this->parent ) ? $this->parent->prefix( $name ) : $name;
}
|
php
|
function prefix( $name = '' ) {
return is_object( $this->parent ) ? $this->parent->prefix( $name ) : $name;
}
|
[
"function",
"prefix",
"(",
"$",
"name",
"=",
"''",
")",
"{",
"return",
"is_object",
"(",
"$",
"this",
"->",
"parent",
")",
"?",
"$",
"this",
"->",
"parent",
"->",
"prefix",
"(",
"$",
"name",
")",
":",
"$",
"name",
";",
"}"
] |
Returns the prefix set by the ranking ancestor of the database object.
@param string $name Prefix string.
@return string Prefix.
|
[
"Returns",
"the",
"prefix",
"set",
"by",
"the",
"ranking",
"ancestor",
"of",
"the",
"database",
"object",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/adodb/adodb-xmlschema03.inc.php#L197-L199
|
215,365
|
moodle/moodle
|
lib/adodb/adodb-xmlschema03.inc.php
|
dbTable.addIndex
|
function addIndex( $attributes ) {
$name = strtoupper( $attributes['NAME'] );
$this->indexes[$name] = new dbIndex( $this, $attributes );
return $this->indexes[$name];
}
|
php
|
function addIndex( $attributes ) {
$name = strtoupper( $attributes['NAME'] );
$this->indexes[$name] = new dbIndex( $this, $attributes );
return $this->indexes[$name];
}
|
[
"function",
"addIndex",
"(",
"$",
"attributes",
")",
"{",
"$",
"name",
"=",
"strtoupper",
"(",
"$",
"attributes",
"[",
"'NAME'",
"]",
")",
";",
"$",
"this",
"->",
"indexes",
"[",
"$",
"name",
"]",
"=",
"new",
"dbIndex",
"(",
"$",
"this",
",",
"$",
"attributes",
")",
";",
"return",
"$",
"this",
"->",
"indexes",
"[",
"$",
"name",
"]",
";",
"}"
] |
Adds an index to a table object
@param array $attributes Index attributes
@return object dbIndex object
|
[
"Adds",
"an",
"index",
"to",
"a",
"table",
"object"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/adodb/adodb-xmlschema03.inc.php#L403-L407
|
215,366
|
moodle/moodle
|
lib/adodb/adodb-xmlschema03.inc.php
|
dbTable.addData
|
function addData( $attributes ) {
if( !isset( $this->data ) ) {
$this->data = new dbData( $this, $attributes );
}
return $this->data;
}
|
php
|
function addData( $attributes ) {
if( !isset( $this->data ) ) {
$this->data = new dbData( $this, $attributes );
}
return $this->data;
}
|
[
"function",
"addData",
"(",
"$",
"attributes",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"data",
")",
")",
"{",
"$",
"this",
"->",
"data",
"=",
"new",
"dbData",
"(",
"$",
"this",
",",
"$",
"attributes",
")",
";",
"}",
"return",
"$",
"this",
"->",
"data",
";",
"}"
] |
Adds data to a table object
@param array $attributes Data attributes
@return object dbData object
|
[
"Adds",
"data",
"to",
"a",
"table",
"object"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/adodb/adodb-xmlschema03.inc.php#L415-L420
|
215,367
|
moodle/moodle
|
lib/adodb/adodb-xmlschema03.inc.php
|
dbTable.addField
|
function addField( $name, $type, $size = NULL, $opts = NULL ) {
$field_id = $this->FieldID( $name );
// Set the field index so we know where we are
$this->current_field = $field_id;
// Set the field name (required)
$this->fields[$field_id]['NAME'] = $name;
// Set the field type (required)
$this->fields[$field_id]['TYPE'] = $type;
// Set the field size (optional)
if( isset( $size ) ) {
$this->fields[$field_id]['SIZE'] = $size;
}
// Set the field options
if( isset( $opts ) ) {
$this->fields[$field_id]['OPTS'] = array($opts);
} else {
$this->fields[$field_id]['OPTS'] = array();
}
}
|
php
|
function addField( $name, $type, $size = NULL, $opts = NULL ) {
$field_id = $this->FieldID( $name );
// Set the field index so we know where we are
$this->current_field = $field_id;
// Set the field name (required)
$this->fields[$field_id]['NAME'] = $name;
// Set the field type (required)
$this->fields[$field_id]['TYPE'] = $type;
// Set the field size (optional)
if( isset( $size ) ) {
$this->fields[$field_id]['SIZE'] = $size;
}
// Set the field options
if( isset( $opts ) ) {
$this->fields[$field_id]['OPTS'] = array($opts);
} else {
$this->fields[$field_id]['OPTS'] = array();
}
}
|
[
"function",
"addField",
"(",
"$",
"name",
",",
"$",
"type",
",",
"$",
"size",
"=",
"NULL",
",",
"$",
"opts",
"=",
"NULL",
")",
"{",
"$",
"field_id",
"=",
"$",
"this",
"->",
"FieldID",
"(",
"$",
"name",
")",
";",
"// Set the field index so we know where we are",
"$",
"this",
"->",
"current_field",
"=",
"$",
"field_id",
";",
"// Set the field name (required)",
"$",
"this",
"->",
"fields",
"[",
"$",
"field_id",
"]",
"[",
"'NAME'",
"]",
"=",
"$",
"name",
";",
"// Set the field type (required)",
"$",
"this",
"->",
"fields",
"[",
"$",
"field_id",
"]",
"[",
"'TYPE'",
"]",
"=",
"$",
"type",
";",
"// Set the field size (optional)",
"if",
"(",
"isset",
"(",
"$",
"size",
")",
")",
"{",
"$",
"this",
"->",
"fields",
"[",
"$",
"field_id",
"]",
"[",
"'SIZE'",
"]",
"=",
"$",
"size",
";",
"}",
"// Set the field options",
"if",
"(",
"isset",
"(",
"$",
"opts",
")",
")",
"{",
"$",
"this",
"->",
"fields",
"[",
"$",
"field_id",
"]",
"[",
"'OPTS'",
"]",
"=",
"array",
"(",
"$",
"opts",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"fields",
"[",
"$",
"field_id",
"]",
"[",
"'OPTS'",
"]",
"=",
"array",
"(",
")",
";",
"}",
"}"
] |
Adds a field to a table object
$name is the name of the table to which the field should be added.
$type is an ADODB datadict field type. The following field types
are supported as of ADODB 3.40:
- C: varchar
- X: CLOB (character large object) or largest varchar size
if CLOB is not supported
- C2: Multibyte varchar
- X2: Multibyte CLOB
- B: BLOB (binary large object)
- D: Date (some databases do not support this, and we return a datetime type)
- T: Datetime or Timestamp
- L: Integer field suitable for storing booleans (0 or 1)
- I: Integer (mapped to I4)
- I1: 1-byte integer
- I2: 2-byte integer
- I4: 4-byte integer
- I8: 8-byte integer
- F: Floating point number
- N: Numeric or decimal number
@param string $name Name of the table to which the field will be added.
@param string $type ADODB datadict field type.
@param string $size Field size
@param array $opts Field options array
@return array Field specifier array
|
[
"Adds",
"a",
"field",
"to",
"a",
"table",
"object"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/adodb/adodb-xmlschema03.inc.php#L451-L474
|
215,368
|
moodle/moodle
|
lib/adodb/adodb-xmlschema03.inc.php
|
dbTable.addFieldOpt
|
function addFieldOpt( $field, $opt, $value = NULL ) {
if( $this->currentPlatform ) {
if( !isset( $value ) ) {
$this->fields[$this->FieldID( $field )]['OPTS'][] = $opt;
// Add the option and value
} else {
$this->fields[$this->FieldID( $field )]['OPTS'][] = array( $opt => $value );
}
}
}
|
php
|
function addFieldOpt( $field, $opt, $value = NULL ) {
if( $this->currentPlatform ) {
if( !isset( $value ) ) {
$this->fields[$this->FieldID( $field )]['OPTS'][] = $opt;
// Add the option and value
} else {
$this->fields[$this->FieldID( $field )]['OPTS'][] = array( $opt => $value );
}
}
}
|
[
"function",
"addFieldOpt",
"(",
"$",
"field",
",",
"$",
"opt",
",",
"$",
"value",
"=",
"NULL",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"currentPlatform",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"value",
")",
")",
"{",
"$",
"this",
"->",
"fields",
"[",
"$",
"this",
"->",
"FieldID",
"(",
"$",
"field",
")",
"]",
"[",
"'OPTS'",
"]",
"[",
"]",
"=",
"$",
"opt",
";",
"// Add the option and value",
"}",
"else",
"{",
"$",
"this",
"->",
"fields",
"[",
"$",
"this",
"->",
"FieldID",
"(",
"$",
"field",
")",
"]",
"[",
"'OPTS'",
"]",
"[",
"]",
"=",
"array",
"(",
"$",
"opt",
"=>",
"$",
"value",
")",
";",
"}",
"}",
"}"
] |
Adds a field option to the current field specifier
This method adds a field option allowed by the ADOdb datadict
and appends it to the given field.
@param string $field Field name
@param string $opt ADOdb field option
@param mixed $value Field option value
@return array Field specifier array
|
[
"Adds",
"a",
"field",
"option",
"to",
"the",
"current",
"field",
"specifier"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/adodb/adodb-xmlschema03.inc.php#L487-L496
|
215,369
|
moodle/moodle
|
lib/adodb/adodb-xmlschema03.inc.php
|
dbTable.addTableOpt
|
function addTableOpt( $opt ) {
if(isset($this->currentPlatform)) {
$this->opts[$this->parent->db->databaseType] = $opt;
}
return $this->opts;
}
|
php
|
function addTableOpt( $opt ) {
if(isset($this->currentPlatform)) {
$this->opts[$this->parent->db->databaseType] = $opt;
}
return $this->opts;
}
|
[
"function",
"addTableOpt",
"(",
"$",
"opt",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"currentPlatform",
")",
")",
"{",
"$",
"this",
"->",
"opts",
"[",
"$",
"this",
"->",
"parent",
"->",
"db",
"->",
"databaseType",
"]",
"=",
"$",
"opt",
";",
"}",
"return",
"$",
"this",
"->",
"opts",
";",
"}"
] |
Adds an option to the table
This method takes a comma-separated list of table-level options
and appends them to the table object.
@param string $opt Table option
@return array Options
|
[
"Adds",
"an",
"option",
"to",
"the",
"table"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/adodb/adodb-xmlschema03.inc.php#L507-L512
|
215,370
|
moodle/moodle
|
lib/adodb/adodb-xmlschema03.inc.php
|
dbTable.drop
|
function drop() {
if( isset( $this->current_field ) ) {
// Drop the current field
logMsg( "Dropping field '{$this->current_field}' from table '{$this->name}'" );
// $this->drop_field[$this->current_field] = $xmls->dict->DropColumnSQL( $this->name, $this->current_field );
$this->drop_field[$this->current_field] = $this->current_field;
} else {
// Drop the current table
logMsg( "Dropping table '{$this->name}'" );
// $this->drop_table = $xmls->dict->DropTableSQL( $this->name );
$this->drop_table = TRUE;
}
}
|
php
|
function drop() {
if( isset( $this->current_field ) ) {
// Drop the current field
logMsg( "Dropping field '{$this->current_field}' from table '{$this->name}'" );
// $this->drop_field[$this->current_field] = $xmls->dict->DropColumnSQL( $this->name, $this->current_field );
$this->drop_field[$this->current_field] = $this->current_field;
} else {
// Drop the current table
logMsg( "Dropping table '{$this->name}'" );
// $this->drop_table = $xmls->dict->DropTableSQL( $this->name );
$this->drop_table = TRUE;
}
}
|
[
"function",
"drop",
"(",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"current_field",
")",
")",
"{",
"// Drop the current field",
"logMsg",
"(",
"\"Dropping field '{$this->current_field}' from table '{$this->name}'\"",
")",
";",
"// $this->drop_field[$this->current_field] = $xmls->dict->DropColumnSQL( $this->name, $this->current_field );",
"$",
"this",
"->",
"drop_field",
"[",
"$",
"this",
"->",
"current_field",
"]",
"=",
"$",
"this",
"->",
"current_field",
";",
"}",
"else",
"{",
"// Drop the current table",
"logMsg",
"(",
"\"Dropping table '{$this->name}'\"",
")",
";",
"// $this->drop_table = $xmls->dict->DropTableSQL( $this->name );",
"$",
"this",
"->",
"drop_table",
"=",
"TRUE",
";",
"}",
"}"
] |
Marks a field or table for destruction
|
[
"Marks",
"a",
"field",
"or",
"table",
"for",
"destruction"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/adodb/adodb-xmlschema03.inc.php#L630-L642
|
215,371
|
moodle/moodle
|
lib/adodb/adodb-xmlschema03.inc.php
|
dbData.addField
|
function addField( $attributes ) {
// check we're in a valid row
if( !isset( $this->row ) || !isset( $this->data[$this->row] ) ) {
return;
}
// Set the field index so we know where we are
if( isset( $attributes['NAME'] ) ) {
$this->current_field = $this->FieldID( $attributes['NAME'] );
} else {
$this->current_field = count( $this->data[$this->row] );
}
// initialise data
if( !isset( $this->data[$this->row][$this->current_field] ) ) {
$this->data[$this->row][$this->current_field] = '';
}
}
|
php
|
function addField( $attributes ) {
// check we're in a valid row
if( !isset( $this->row ) || !isset( $this->data[$this->row] ) ) {
return;
}
// Set the field index so we know where we are
if( isset( $attributes['NAME'] ) ) {
$this->current_field = $this->FieldID( $attributes['NAME'] );
} else {
$this->current_field = count( $this->data[$this->row] );
}
// initialise data
if( !isset( $this->data[$this->row][$this->current_field] ) ) {
$this->data[$this->row][$this->current_field] = '';
}
}
|
[
"function",
"addField",
"(",
"$",
"attributes",
")",
"{",
"// check we're in a valid row",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"row",
")",
"||",
"!",
"isset",
"(",
"$",
"this",
"->",
"data",
"[",
"$",
"this",
"->",
"row",
"]",
")",
")",
"{",
"return",
";",
"}",
"// Set the field index so we know where we are",
"if",
"(",
"isset",
"(",
"$",
"attributes",
"[",
"'NAME'",
"]",
")",
")",
"{",
"$",
"this",
"->",
"current_field",
"=",
"$",
"this",
"->",
"FieldID",
"(",
"$",
"attributes",
"[",
"'NAME'",
"]",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"current_field",
"=",
"count",
"(",
"$",
"this",
"->",
"data",
"[",
"$",
"this",
"->",
"row",
"]",
")",
";",
"}",
"// initialise data",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"data",
"[",
"$",
"this",
"->",
"row",
"]",
"[",
"$",
"this",
"->",
"current_field",
"]",
")",
")",
"{",
"$",
"this",
"->",
"data",
"[",
"$",
"this",
"->",
"row",
"]",
"[",
"$",
"this",
"->",
"current_field",
"]",
"=",
"''",
";",
"}",
"}"
] |
Adds a field to the insert
@param string $name Field name
@return string Field list
|
[
"Adds",
"a",
"field",
"to",
"the",
"insert"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/adodb/adodb-xmlschema03.inc.php#L898-L915
|
215,372
|
moodle/moodle
|
lib/adodb/adodb-xmlschema03.inc.php
|
dbQuerySet.buildQuery
|
function buildQuery( $sql = NULL ) {
if( !isset( $this->query ) OR empty( $sql ) ) {
return FALSE;
}
$this->query .= $sql;
return $this->query;
}
|
php
|
function buildQuery( $sql = NULL ) {
if( !isset( $this->query ) OR empty( $sql ) ) {
return FALSE;
}
$this->query .= $sql;
return $this->query;
}
|
[
"function",
"buildQuery",
"(",
"$",
"sql",
"=",
"NULL",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"query",
")",
"OR",
"empty",
"(",
"$",
"sql",
")",
")",
"{",
"return",
"FALSE",
";",
"}",
"$",
"this",
"->",
"query",
".=",
"$",
"sql",
";",
"return",
"$",
"this",
"->",
"query",
";",
"}"
] |
Appends a line to a query that is being built line by line
@param string $data Line of SQL data or NULL to initialize a new query
@return string SQL query string.
|
[
"Appends",
"a",
"line",
"to",
"a",
"query",
"that",
"is",
"being",
"built",
"line",
"by",
"line"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/adodb/adodb-xmlschema03.inc.php#L1202-L1210
|
215,373
|
moodle/moodle
|
lib/adodb/adodb-xmlschema03.inc.php
|
dbQuerySet.addQuery
|
function addQuery() {
if( !isset( $this->query ) ) {
return FALSE;
}
$this->queries[] = $return = trim($this->query);
unset( $this->query );
return $return;
}
|
php
|
function addQuery() {
if( !isset( $this->query ) ) {
return FALSE;
}
$this->queries[] = $return = trim($this->query);
unset( $this->query );
return $return;
}
|
[
"function",
"addQuery",
"(",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"query",
")",
")",
"{",
"return",
"FALSE",
";",
"}",
"$",
"this",
"->",
"queries",
"[",
"]",
"=",
"$",
"return",
"=",
"trim",
"(",
"$",
"this",
"->",
"query",
")",
";",
"unset",
"(",
"$",
"this",
"->",
"query",
")",
";",
"return",
"$",
"return",
";",
"}"
] |
Adds a completed query to the query list
@return string SQL of added query
|
[
"Adds",
"a",
"completed",
"query",
"to",
"the",
"query",
"list"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/adodb/adodb-xmlschema03.inc.php#L1217-L1227
|
215,374
|
moodle/moodle
|
lib/adodb/adodb-xmlschema03.inc.php
|
dbQuerySet.create
|
function create( &$xmls ) {
foreach( $this->queries as $id => $query ) {
switch( $this->prefixMethod ) {
case 'AUTO':
// Enable auto prefix replacement
// Process object prefix.
// Evaluate SQL statements to prepend prefix to objects
$query = $this->prefixQuery( '/^\s*((?is)INSERT\s+(INTO\s+)?)((\w+\s*,?\s*)+)(\s.*$)/', $query, $xmls->objectPrefix );
$query = $this->prefixQuery( '/^\s*((?is)UPDATE\s+(FROM\s+)?)((\w+\s*,?\s*)+)(\s.*$)/', $query, $xmls->objectPrefix );
$query = $this->prefixQuery( '/^\s*((?is)DELETE\s+(FROM\s+)?)((\w+\s*,?\s*)+)(\s.*$)/', $query, $xmls->objectPrefix );
// SELECT statements aren't working yet
#$data = preg_replace( '/(?ias)(^\s*SELECT\s+.*\s+FROM)\s+(\W\s*,?\s*)+((?i)\s+WHERE.*$)/', "\1 $prefix\2 \3", $data );
case 'MANUAL':
// If prefixKey is set and has a value then we use it to override the default constant XMLS_PREFIX.
// If prefixKey is not set, we use the default constant XMLS_PREFIX
if( isset( $this->prefixKey ) AND( $this->prefixKey !== '' ) ) {
// Enable prefix override
$query = str_replace( $this->prefixKey, $xmls->objectPrefix, $query );
} else {
// Use default replacement
$query = str_replace( XMLS_PREFIX , $xmls->objectPrefix, $query );
}
}
$this->queries[$id] = trim( $query );
}
// Return the query set array
return $this->queries;
}
|
php
|
function create( &$xmls ) {
foreach( $this->queries as $id => $query ) {
switch( $this->prefixMethod ) {
case 'AUTO':
// Enable auto prefix replacement
// Process object prefix.
// Evaluate SQL statements to prepend prefix to objects
$query = $this->prefixQuery( '/^\s*((?is)INSERT\s+(INTO\s+)?)((\w+\s*,?\s*)+)(\s.*$)/', $query, $xmls->objectPrefix );
$query = $this->prefixQuery( '/^\s*((?is)UPDATE\s+(FROM\s+)?)((\w+\s*,?\s*)+)(\s.*$)/', $query, $xmls->objectPrefix );
$query = $this->prefixQuery( '/^\s*((?is)DELETE\s+(FROM\s+)?)((\w+\s*,?\s*)+)(\s.*$)/', $query, $xmls->objectPrefix );
// SELECT statements aren't working yet
#$data = preg_replace( '/(?ias)(^\s*SELECT\s+.*\s+FROM)\s+(\W\s*,?\s*)+((?i)\s+WHERE.*$)/', "\1 $prefix\2 \3", $data );
case 'MANUAL':
// If prefixKey is set and has a value then we use it to override the default constant XMLS_PREFIX.
// If prefixKey is not set, we use the default constant XMLS_PREFIX
if( isset( $this->prefixKey ) AND( $this->prefixKey !== '' ) ) {
// Enable prefix override
$query = str_replace( $this->prefixKey, $xmls->objectPrefix, $query );
} else {
// Use default replacement
$query = str_replace( XMLS_PREFIX , $xmls->objectPrefix, $query );
}
}
$this->queries[$id] = trim( $query );
}
// Return the query set array
return $this->queries;
}
|
[
"function",
"create",
"(",
"&",
"$",
"xmls",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"queries",
"as",
"$",
"id",
"=>",
"$",
"query",
")",
"{",
"switch",
"(",
"$",
"this",
"->",
"prefixMethod",
")",
"{",
"case",
"'AUTO'",
":",
"// Enable auto prefix replacement",
"// Process object prefix.",
"// Evaluate SQL statements to prepend prefix to objects",
"$",
"query",
"=",
"$",
"this",
"->",
"prefixQuery",
"(",
"'/^\\s*((?is)INSERT\\s+(INTO\\s+)?)((\\w+\\s*,?\\s*)+)(\\s.*$)/'",
",",
"$",
"query",
",",
"$",
"xmls",
"->",
"objectPrefix",
")",
";",
"$",
"query",
"=",
"$",
"this",
"->",
"prefixQuery",
"(",
"'/^\\s*((?is)UPDATE\\s+(FROM\\s+)?)((\\w+\\s*,?\\s*)+)(\\s.*$)/'",
",",
"$",
"query",
",",
"$",
"xmls",
"->",
"objectPrefix",
")",
";",
"$",
"query",
"=",
"$",
"this",
"->",
"prefixQuery",
"(",
"'/^\\s*((?is)DELETE\\s+(FROM\\s+)?)((\\w+\\s*,?\\s*)+)(\\s.*$)/'",
",",
"$",
"query",
",",
"$",
"xmls",
"->",
"objectPrefix",
")",
";",
"// SELECT statements aren't working yet",
"#$data = preg_replace( '/(?ias)(^\\s*SELECT\\s+.*\\s+FROM)\\s+(\\W\\s*,?\\s*)+((?i)\\s+WHERE.*$)/', \"\\1 $prefix\\2 \\3\", $data );",
"case",
"'MANUAL'",
":",
"// If prefixKey is set and has a value then we use it to override the default constant XMLS_PREFIX.",
"// If prefixKey is not set, we use the default constant XMLS_PREFIX",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"prefixKey",
")",
"AND",
"(",
"$",
"this",
"->",
"prefixKey",
"!==",
"''",
")",
")",
"{",
"// Enable prefix override",
"$",
"query",
"=",
"str_replace",
"(",
"$",
"this",
"->",
"prefixKey",
",",
"$",
"xmls",
"->",
"objectPrefix",
",",
"$",
"query",
")",
";",
"}",
"else",
"{",
"// Use default replacement",
"$",
"query",
"=",
"str_replace",
"(",
"XMLS_PREFIX",
",",
"$",
"xmls",
"->",
"objectPrefix",
",",
"$",
"query",
")",
";",
"}",
"}",
"$",
"this",
"->",
"queries",
"[",
"$",
"id",
"]",
"=",
"trim",
"(",
"$",
"query",
")",
";",
"}",
"// Return the query set array",
"return",
"$",
"this",
"->",
"queries",
";",
"}"
] |
Creates and returns the current query set
@param object $xmls adoSchema object
@return array Query set
|
[
"Creates",
"and",
"returns",
"the",
"current",
"query",
"set"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/adodb/adodb-xmlschema03.inc.php#L1235-L1267
|
215,375
|
moodle/moodle
|
lib/adodb/adodb-xmlschema03.inc.php
|
dbQuerySet.prefixQuery
|
function prefixQuery( $regex, $query, $prefix = NULL ) {
if( !isset( $prefix ) ) {
return $query;
}
if( preg_match( $regex, $query, $match ) ) {
$preamble = $match[1];
$postamble = $match[5];
$objectList = explode( ',', $match[3] );
// $prefix = $prefix . '_';
$prefixedList = '';
foreach( $objectList as $object ) {
if( $prefixedList !== '' ) {
$prefixedList .= ', ';
}
$prefixedList .= $prefix . trim( $object );
}
$query = $preamble . ' ' . $prefixedList . ' ' . $postamble;
}
return $query;
}
|
php
|
function prefixQuery( $regex, $query, $prefix = NULL ) {
if( !isset( $prefix ) ) {
return $query;
}
if( preg_match( $regex, $query, $match ) ) {
$preamble = $match[1];
$postamble = $match[5];
$objectList = explode( ',', $match[3] );
// $prefix = $prefix . '_';
$prefixedList = '';
foreach( $objectList as $object ) {
if( $prefixedList !== '' ) {
$prefixedList .= ', ';
}
$prefixedList .= $prefix . trim( $object );
}
$query = $preamble . ' ' . $prefixedList . ' ' . $postamble;
}
return $query;
}
|
[
"function",
"prefixQuery",
"(",
"$",
"regex",
",",
"$",
"query",
",",
"$",
"prefix",
"=",
"NULL",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"prefix",
")",
")",
"{",
"return",
"$",
"query",
";",
"}",
"if",
"(",
"preg_match",
"(",
"$",
"regex",
",",
"$",
"query",
",",
"$",
"match",
")",
")",
"{",
"$",
"preamble",
"=",
"$",
"match",
"[",
"1",
"]",
";",
"$",
"postamble",
"=",
"$",
"match",
"[",
"5",
"]",
";",
"$",
"objectList",
"=",
"explode",
"(",
"','",
",",
"$",
"match",
"[",
"3",
"]",
")",
";",
"// $prefix = $prefix . '_';",
"$",
"prefixedList",
"=",
"''",
";",
"foreach",
"(",
"$",
"objectList",
"as",
"$",
"object",
")",
"{",
"if",
"(",
"$",
"prefixedList",
"!==",
"''",
")",
"{",
"$",
"prefixedList",
".=",
"', '",
";",
"}",
"$",
"prefixedList",
".=",
"$",
"prefix",
".",
"trim",
"(",
"$",
"object",
")",
";",
"}",
"$",
"query",
"=",
"$",
"preamble",
".",
"' '",
".",
"$",
"prefixedList",
".",
"' '",
".",
"$",
"postamble",
";",
"}",
"return",
"$",
"query",
";",
"}"
] |
Rebuilds the query with the prefix attached to any objects
@param string $regex Regex used to add prefix
@param string $query SQL query string
@param string $prefix Prefix to be appended to tables, indices, etc.
@return string Prefixed SQL query string.
|
[
"Rebuilds",
"the",
"query",
"with",
"the",
"prefix",
"attached",
"to",
"any",
"objects"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/adodb/adodb-xmlschema03.inc.php#L1277-L1302
|
215,376
|
moodle/moodle
|
backup/moodle2/backup_activity_task.class.php
|
backup_activity_task.define_settings
|
protected function define_settings() {
global $CFG;
require_once($CFG->libdir.'/questionlib.php');
// All the settings related to this activity will include this prefix
$settingprefix = $this->modulename . '_' . $this->moduleid . '_';
// All these are common settings to be shared by all activities
// Define activity_include (to decide if the whole task must be really executed)
// Dependent of:
// - activities root setting
// - section_included setting (if exists)
$settingname = $settingprefix . 'included';
$activity_included = new backup_activity_generic_setting($settingname, base_setting::IS_BOOLEAN, true);
$activity_included->get_ui()->set_icon(new image_icon('icon', get_string('pluginname', $this->modulename),
$this->modulename, array('class' => 'iconlarge icon-post')));
$this->add_setting($activity_included);
// Look for "activities" root setting
$activities = $this->plan->get_setting('activities');
$activities->add_dependency($activity_included);
if (question_module_uses_questions($this->modulename)) {
$questionbank = $this->plan->get_setting('questionbank');
$questionbank->add_dependency($activity_included);
}
// Look for "section_included" section setting (if exists)
$settingname = 'section_' . $this->sectionid . '_included';
if ($this->plan->setting_exists($settingname)) {
$section_included = $this->plan->get_setting($settingname);
$section_included->add_dependency($activity_included);
}
// Define activity_userinfo. Dependent of:
// - users root setting
// - section_userinfo setting (if exists)
// - activity_included setting
$settingname = $settingprefix . 'userinfo';
$activity_userinfo = new backup_activity_userinfo_setting($settingname, base_setting::IS_BOOLEAN, true);
//$activity_userinfo->get_ui()->set_label(get_string('includeuserinfo','backup'));
$activity_userinfo->get_ui()->set_label('-');
$this->add_setting($activity_userinfo);
// Look for "users" root setting
$users = $this->plan->get_setting('users');
$users->add_dependency($activity_userinfo);
// Look for "section_userinfo" section setting (if exists)
$settingname = 'section_' . $this->sectionid . '_userinfo';
if ($this->plan->setting_exists($settingname)) {
$section_userinfo = $this->plan->get_setting($settingname);
$section_userinfo->add_dependency($activity_userinfo);
}
// Look for "activity_included" setting
$activity_included->add_dependency($activity_userinfo);
// End of common activity settings, let's add the particular ones
$this->define_my_settings();
}
|
php
|
protected function define_settings() {
global $CFG;
require_once($CFG->libdir.'/questionlib.php');
// All the settings related to this activity will include this prefix
$settingprefix = $this->modulename . '_' . $this->moduleid . '_';
// All these are common settings to be shared by all activities
// Define activity_include (to decide if the whole task must be really executed)
// Dependent of:
// - activities root setting
// - section_included setting (if exists)
$settingname = $settingprefix . 'included';
$activity_included = new backup_activity_generic_setting($settingname, base_setting::IS_BOOLEAN, true);
$activity_included->get_ui()->set_icon(new image_icon('icon', get_string('pluginname', $this->modulename),
$this->modulename, array('class' => 'iconlarge icon-post')));
$this->add_setting($activity_included);
// Look for "activities" root setting
$activities = $this->plan->get_setting('activities');
$activities->add_dependency($activity_included);
if (question_module_uses_questions($this->modulename)) {
$questionbank = $this->plan->get_setting('questionbank');
$questionbank->add_dependency($activity_included);
}
// Look for "section_included" section setting (if exists)
$settingname = 'section_' . $this->sectionid . '_included';
if ($this->plan->setting_exists($settingname)) {
$section_included = $this->plan->get_setting($settingname);
$section_included->add_dependency($activity_included);
}
// Define activity_userinfo. Dependent of:
// - users root setting
// - section_userinfo setting (if exists)
// - activity_included setting
$settingname = $settingprefix . 'userinfo';
$activity_userinfo = new backup_activity_userinfo_setting($settingname, base_setting::IS_BOOLEAN, true);
//$activity_userinfo->get_ui()->set_label(get_string('includeuserinfo','backup'));
$activity_userinfo->get_ui()->set_label('-');
$this->add_setting($activity_userinfo);
// Look for "users" root setting
$users = $this->plan->get_setting('users');
$users->add_dependency($activity_userinfo);
// Look for "section_userinfo" section setting (if exists)
$settingname = 'section_' . $this->sectionid . '_userinfo';
if ($this->plan->setting_exists($settingname)) {
$section_userinfo = $this->plan->get_setting($settingname);
$section_userinfo->add_dependency($activity_userinfo);
}
// Look for "activity_included" setting
$activity_included->add_dependency($activity_userinfo);
// End of common activity settings, let's add the particular ones
$this->define_my_settings();
}
|
[
"protected",
"function",
"define_settings",
"(",
")",
"{",
"global",
"$",
"CFG",
";",
"require_once",
"(",
"$",
"CFG",
"->",
"libdir",
".",
"'/questionlib.php'",
")",
";",
"// All the settings related to this activity will include this prefix",
"$",
"settingprefix",
"=",
"$",
"this",
"->",
"modulename",
".",
"'_'",
".",
"$",
"this",
"->",
"moduleid",
".",
"'_'",
";",
"// All these are common settings to be shared by all activities",
"// Define activity_include (to decide if the whole task must be really executed)",
"// Dependent of:",
"// - activities root setting",
"// - section_included setting (if exists)",
"$",
"settingname",
"=",
"$",
"settingprefix",
".",
"'included'",
";",
"$",
"activity_included",
"=",
"new",
"backup_activity_generic_setting",
"(",
"$",
"settingname",
",",
"base_setting",
"::",
"IS_BOOLEAN",
",",
"true",
")",
";",
"$",
"activity_included",
"->",
"get_ui",
"(",
")",
"->",
"set_icon",
"(",
"new",
"image_icon",
"(",
"'icon'",
",",
"get_string",
"(",
"'pluginname'",
",",
"$",
"this",
"->",
"modulename",
")",
",",
"$",
"this",
"->",
"modulename",
",",
"array",
"(",
"'class'",
"=>",
"'iconlarge icon-post'",
")",
")",
")",
";",
"$",
"this",
"->",
"add_setting",
"(",
"$",
"activity_included",
")",
";",
"// Look for \"activities\" root setting",
"$",
"activities",
"=",
"$",
"this",
"->",
"plan",
"->",
"get_setting",
"(",
"'activities'",
")",
";",
"$",
"activities",
"->",
"add_dependency",
"(",
"$",
"activity_included",
")",
";",
"if",
"(",
"question_module_uses_questions",
"(",
"$",
"this",
"->",
"modulename",
")",
")",
"{",
"$",
"questionbank",
"=",
"$",
"this",
"->",
"plan",
"->",
"get_setting",
"(",
"'questionbank'",
")",
";",
"$",
"questionbank",
"->",
"add_dependency",
"(",
"$",
"activity_included",
")",
";",
"}",
"// Look for \"section_included\" section setting (if exists)",
"$",
"settingname",
"=",
"'section_'",
".",
"$",
"this",
"->",
"sectionid",
".",
"'_included'",
";",
"if",
"(",
"$",
"this",
"->",
"plan",
"->",
"setting_exists",
"(",
"$",
"settingname",
")",
")",
"{",
"$",
"section_included",
"=",
"$",
"this",
"->",
"plan",
"->",
"get_setting",
"(",
"$",
"settingname",
")",
";",
"$",
"section_included",
"->",
"add_dependency",
"(",
"$",
"activity_included",
")",
";",
"}",
"// Define activity_userinfo. Dependent of:",
"// - users root setting",
"// - section_userinfo setting (if exists)",
"// - activity_included setting",
"$",
"settingname",
"=",
"$",
"settingprefix",
".",
"'userinfo'",
";",
"$",
"activity_userinfo",
"=",
"new",
"backup_activity_userinfo_setting",
"(",
"$",
"settingname",
",",
"base_setting",
"::",
"IS_BOOLEAN",
",",
"true",
")",
";",
"//$activity_userinfo->get_ui()->set_label(get_string('includeuserinfo','backup'));",
"$",
"activity_userinfo",
"->",
"get_ui",
"(",
")",
"->",
"set_label",
"(",
"'-'",
")",
";",
"$",
"this",
"->",
"add_setting",
"(",
"$",
"activity_userinfo",
")",
";",
"// Look for \"users\" root setting",
"$",
"users",
"=",
"$",
"this",
"->",
"plan",
"->",
"get_setting",
"(",
"'users'",
")",
";",
"$",
"users",
"->",
"add_dependency",
"(",
"$",
"activity_userinfo",
")",
";",
"// Look for \"section_userinfo\" section setting (if exists)",
"$",
"settingname",
"=",
"'section_'",
".",
"$",
"this",
"->",
"sectionid",
".",
"'_userinfo'",
";",
"if",
"(",
"$",
"this",
"->",
"plan",
"->",
"setting_exists",
"(",
"$",
"settingname",
")",
")",
"{",
"$",
"section_userinfo",
"=",
"$",
"this",
"->",
"plan",
"->",
"get_setting",
"(",
"$",
"settingname",
")",
";",
"$",
"section_userinfo",
"->",
"add_dependency",
"(",
"$",
"activity_userinfo",
")",
";",
"}",
"// Look for \"activity_included\" setting",
"$",
"activity_included",
"->",
"add_dependency",
"(",
"$",
"activity_userinfo",
")",
";",
"// End of common activity settings, let's add the particular ones",
"$",
"this",
"->",
"define_my_settings",
"(",
")",
";",
"}"
] |
Defines the common setting that any backup activity will have
|
[
"Defines",
"the",
"common",
"setting",
"that",
"any",
"backup",
"activity",
"will",
"have"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/backup/moodle2/backup_activity_task.class.php#L259-L316
|
215,377
|
moodle/moodle
|
course/format/topics/lib.php
|
format_topics.update_course_format_options
|
public function update_course_format_options($data, $oldcourse = null) {
$data = (array)$data;
if ($oldcourse !== null) {
$oldcourse = (array)$oldcourse;
$options = $this->course_format_options();
foreach ($options as $key => $unused) {
if (!array_key_exists($key, $data)) {
if (array_key_exists($key, $oldcourse)) {
$data[$key] = $oldcourse[$key];
}
}
}
}
return $this->update_format_options($data);
}
|
php
|
public function update_course_format_options($data, $oldcourse = null) {
$data = (array)$data;
if ($oldcourse !== null) {
$oldcourse = (array)$oldcourse;
$options = $this->course_format_options();
foreach ($options as $key => $unused) {
if (!array_key_exists($key, $data)) {
if (array_key_exists($key, $oldcourse)) {
$data[$key] = $oldcourse[$key];
}
}
}
}
return $this->update_format_options($data);
}
|
[
"public",
"function",
"update_course_format_options",
"(",
"$",
"data",
",",
"$",
"oldcourse",
"=",
"null",
")",
"{",
"$",
"data",
"=",
"(",
"array",
")",
"$",
"data",
";",
"if",
"(",
"$",
"oldcourse",
"!==",
"null",
")",
"{",
"$",
"oldcourse",
"=",
"(",
"array",
")",
"$",
"oldcourse",
";",
"$",
"options",
"=",
"$",
"this",
"->",
"course_format_options",
"(",
")",
";",
"foreach",
"(",
"$",
"options",
"as",
"$",
"key",
"=>",
"$",
"unused",
")",
"{",
"if",
"(",
"!",
"array_key_exists",
"(",
"$",
"key",
",",
"$",
"data",
")",
")",
"{",
"if",
"(",
"array_key_exists",
"(",
"$",
"key",
",",
"$",
"oldcourse",
")",
")",
"{",
"$",
"data",
"[",
"$",
"key",
"]",
"=",
"$",
"oldcourse",
"[",
"$",
"key",
"]",
";",
"}",
"}",
"}",
"}",
"return",
"$",
"this",
"->",
"update_format_options",
"(",
"$",
"data",
")",
";",
"}"
] |
Updates format options for a course
In case if course format was changed to 'topics', we try to copy options
'coursedisplay' and 'hiddensections' from the previous format.
@param stdClass|array $data return value from {@link moodleform::get_data()} or array with data
@param stdClass $oldcourse if this function is called from {@link update_course()}
this object contains information about the course before update
@return bool whether there were any changes to the options values
|
[
"Updates",
"format",
"options",
"for",
"a",
"course"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/course/format/topics/lib.php#L314-L328
|
215,378
|
moodle/moodle
|
admin/tool/dataprivacy/classes/event/user_deleted_observer.php
|
user_deleted_observer.create_delete_data_request
|
public static function create_delete_data_request(\core\event\user_deleted $event) {
// Automatic creation of deletion requests must be enabled.
if (get_config('tool_dataprivacy', 'automaticdeletionrequests')) {
$requesttypes = [api::DATAREQUEST_TYPE_DELETE];
$requeststatuses = [api::DATAREQUEST_STATUS_COMPLETE, api::DATAREQUEST_STATUS_DELETED];
$hasongoingdeleterequests = api::has_ongoing_request($event->objectid, $requesttypes[0]);
$hascompleteddeleterequest = (api::get_data_requests_count($event->objectid, $requeststatuses,
$requesttypes) > 0) ? true : false;
if (!$hasongoingdeleterequests && !$hascompleteddeleterequest) {
api::create_data_request($event->objectid, $requesttypes[0],
get_string('datarequestcreatedupondelete', 'tool_dataprivacy'),
data_request::DATAREQUEST_CREATION_AUTO);
}
}
}
|
php
|
public static function create_delete_data_request(\core\event\user_deleted $event) {
// Automatic creation of deletion requests must be enabled.
if (get_config('tool_dataprivacy', 'automaticdeletionrequests')) {
$requesttypes = [api::DATAREQUEST_TYPE_DELETE];
$requeststatuses = [api::DATAREQUEST_STATUS_COMPLETE, api::DATAREQUEST_STATUS_DELETED];
$hasongoingdeleterequests = api::has_ongoing_request($event->objectid, $requesttypes[0]);
$hascompleteddeleterequest = (api::get_data_requests_count($event->objectid, $requeststatuses,
$requesttypes) > 0) ? true : false;
if (!$hasongoingdeleterequests && !$hascompleteddeleterequest) {
api::create_data_request($event->objectid, $requesttypes[0],
get_string('datarequestcreatedupondelete', 'tool_dataprivacy'),
data_request::DATAREQUEST_CREATION_AUTO);
}
}
}
|
[
"public",
"static",
"function",
"create_delete_data_request",
"(",
"\\",
"core",
"\\",
"event",
"\\",
"user_deleted",
"$",
"event",
")",
"{",
"// Automatic creation of deletion requests must be enabled.",
"if",
"(",
"get_config",
"(",
"'tool_dataprivacy'",
",",
"'automaticdeletionrequests'",
")",
")",
"{",
"$",
"requesttypes",
"=",
"[",
"api",
"::",
"DATAREQUEST_TYPE_DELETE",
"]",
";",
"$",
"requeststatuses",
"=",
"[",
"api",
"::",
"DATAREQUEST_STATUS_COMPLETE",
",",
"api",
"::",
"DATAREQUEST_STATUS_DELETED",
"]",
";",
"$",
"hasongoingdeleterequests",
"=",
"api",
"::",
"has_ongoing_request",
"(",
"$",
"event",
"->",
"objectid",
",",
"$",
"requesttypes",
"[",
"0",
"]",
")",
";",
"$",
"hascompleteddeleterequest",
"=",
"(",
"api",
"::",
"get_data_requests_count",
"(",
"$",
"event",
"->",
"objectid",
",",
"$",
"requeststatuses",
",",
"$",
"requesttypes",
")",
">",
"0",
")",
"?",
"true",
":",
"false",
";",
"if",
"(",
"!",
"$",
"hasongoingdeleterequests",
"&&",
"!",
"$",
"hascompleteddeleterequest",
")",
"{",
"api",
"::",
"create_data_request",
"(",
"$",
"event",
"->",
"objectid",
",",
"$",
"requesttypes",
"[",
"0",
"]",
",",
"get_string",
"(",
"'datarequestcreatedupondelete'",
",",
"'tool_dataprivacy'",
")",
",",
"data_request",
"::",
"DATAREQUEST_CREATION_AUTO",
")",
";",
"}",
"}",
"}"
] |
Create user data deletion request when the user is deleted.
@param \core\event\user_deleted $event
|
[
"Create",
"user",
"data",
"deletion",
"request",
"when",
"the",
"user",
"is",
"deleted",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/dataprivacy/classes/event/user_deleted_observer.php#L46-L62
|
215,379
|
moodle/moodle
|
mod/feedback/classes/analytics/indicator/activity_base.php
|
activity_base.feedback_viewed
|
protected function feedback_viewed(\cm_info $cm, $contextid, $userid, $after = null) {
// If stats are published any write action counts as viewed feedback.
if (!empty($this->instancedata[$cm->instance]->publish_stats)) {
$user = (object)['id' => $userid];
return $this->any_write_log($contextid, $user);
}
return parent::feedback_viewed($cm, $contextid, $userid, $after);
}
|
php
|
protected function feedback_viewed(\cm_info $cm, $contextid, $userid, $after = null) {
// If stats are published any write action counts as viewed feedback.
if (!empty($this->instancedata[$cm->instance]->publish_stats)) {
$user = (object)['id' => $userid];
return $this->any_write_log($contextid, $user);
}
return parent::feedback_viewed($cm, $contextid, $userid, $after);
}
|
[
"protected",
"function",
"feedback_viewed",
"(",
"\\",
"cm_info",
"$",
"cm",
",",
"$",
"contextid",
",",
"$",
"userid",
",",
"$",
"after",
"=",
"null",
")",
"{",
"// If stats are published any write action counts as viewed feedback.",
"if",
"(",
"!",
"empty",
"(",
"$",
"this",
"->",
"instancedata",
"[",
"$",
"cm",
"->",
"instance",
"]",
"->",
"publish_stats",
")",
")",
"{",
"$",
"user",
"=",
"(",
"object",
")",
"[",
"'id'",
"=>",
"$",
"userid",
"]",
";",
"return",
"$",
"this",
"->",
"any_write_log",
"(",
"$",
"contextid",
",",
"$",
"user",
")",
";",
"}",
"return",
"parent",
"::",
"feedback_viewed",
"(",
"$",
"cm",
",",
"$",
"contextid",
",",
"$",
"userid",
",",
"$",
"after",
")",
";",
"}"
] |
Overwritten to mark as viewed if stats are published.
@param \cm_info $cm
@param int $contextid
@param int $userid
@param int $after
@return bool
|
[
"Overwritten",
"to",
"mark",
"as",
"viewed",
"if",
"stats",
"are",
"published",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/feedback/classes/analytics/indicator/activity_base.php#L47-L55
|
215,380
|
moodle/moodle
|
lib/lessphp/Autoloader.php
|
Less_Autoloader.register
|
public static function register(){
if( self::$registered ){
return;
}
self::$libDir = dirname(__FILE__);
if(false === spl_autoload_register(array('Less_Autoloader', 'loadClass'))){
throw new Exception('Unable to register Less_Autoloader::loadClass as an autoloading method.');
}
self::$registered = true;
}
|
php
|
public static function register(){
if( self::$registered ){
return;
}
self::$libDir = dirname(__FILE__);
if(false === spl_autoload_register(array('Less_Autoloader', 'loadClass'))){
throw new Exception('Unable to register Less_Autoloader::loadClass as an autoloading method.');
}
self::$registered = true;
}
|
[
"public",
"static",
"function",
"register",
"(",
")",
"{",
"if",
"(",
"self",
"::",
"$",
"registered",
")",
"{",
"return",
";",
"}",
"self",
"::",
"$",
"libDir",
"=",
"dirname",
"(",
"__FILE__",
")",
";",
"if",
"(",
"false",
"===",
"spl_autoload_register",
"(",
"array",
"(",
"'Less_Autoloader'",
",",
"'loadClass'",
")",
")",
")",
"{",
"throw",
"new",
"Exception",
"(",
"'Unable to register Less_Autoloader::loadClass as an autoloading method.'",
")",
";",
"}",
"self",
"::",
"$",
"registered",
"=",
"true",
";",
"}"
] |
Register the autoloader in the spl autoloader
@return void
@throws Exception If there was an error in registration
|
[
"Register",
"the",
"autoloader",
"in",
"the",
"spl",
"autoloader"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/lessphp/Autoloader.php#L31-L43
|
215,381
|
moodle/moodle
|
lib/lessphp/Autoloader.php
|
Less_Autoloader.loadClass
|
public static function loadClass($className){
// handle only package classes
if(strpos($className, 'Less_') !== 0){
return;
}
$className = substr($className,5);
$fileName = self::$libDir . DIRECTORY_SEPARATOR . str_replace('_', DIRECTORY_SEPARATOR, $className) . '.php';
if(file_exists($fileName)){
require $fileName;
return true;
}else{
throw new Exception('file not loadable '.$fileName);
}
}
|
php
|
public static function loadClass($className){
// handle only package classes
if(strpos($className, 'Less_') !== 0){
return;
}
$className = substr($className,5);
$fileName = self::$libDir . DIRECTORY_SEPARATOR . str_replace('_', DIRECTORY_SEPARATOR, $className) . '.php';
if(file_exists($fileName)){
require $fileName;
return true;
}else{
throw new Exception('file not loadable '.$fileName);
}
}
|
[
"public",
"static",
"function",
"loadClass",
"(",
"$",
"className",
")",
"{",
"// handle only package classes",
"if",
"(",
"strpos",
"(",
"$",
"className",
",",
"'Less_'",
")",
"!==",
"0",
")",
"{",
"return",
";",
"}",
"$",
"className",
"=",
"substr",
"(",
"$",
"className",
",",
"5",
")",
";",
"$",
"fileName",
"=",
"self",
"::",
"$",
"libDir",
".",
"DIRECTORY_SEPARATOR",
".",
"str_replace",
"(",
"'_'",
",",
"DIRECTORY_SEPARATOR",
",",
"$",
"className",
")",
".",
"'.php'",
";",
"if",
"(",
"file_exists",
"(",
"$",
"fileName",
")",
")",
"{",
"require",
"$",
"fileName",
";",
"return",
"true",
";",
"}",
"else",
"{",
"throw",
"new",
"Exception",
"(",
"'file not loadable '",
".",
"$",
"fileName",
")",
";",
"}",
"}"
] |
Loads the class
@param string $className The class to load
|
[
"Loads",
"the",
"class"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/lessphp/Autoloader.php#L60-L77
|
215,382
|
moodle/moodle
|
privacy/classes/local/request/moodle_content_writer.php
|
moodle_content_writer.export_data
|
public function export_data(array $subcontext, \stdClass $data) : content_writer {
$path = $this->get_path($subcontext, 'data.json');
$this->write_data($path, json_encode($data, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT));
return $this;
}
|
php
|
public function export_data(array $subcontext, \stdClass $data) : content_writer {
$path = $this->get_path($subcontext, 'data.json');
$this->write_data($path, json_encode($data, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT));
return $this;
}
|
[
"public",
"function",
"export_data",
"(",
"array",
"$",
"subcontext",
",",
"\\",
"stdClass",
"$",
"data",
")",
":",
"content_writer",
"{",
"$",
"path",
"=",
"$",
"this",
"->",
"get_path",
"(",
"$",
"subcontext",
",",
"'data.json'",
")",
";",
"$",
"this",
"->",
"write_data",
"(",
"$",
"path",
",",
"json_encode",
"(",
"$",
"data",
",",
"JSON_UNESCAPED_UNICODE",
"|",
"JSON_PRETTY_PRINT",
")",
")",
";",
"return",
"$",
"this",
";",
"}"
] |
Export the supplied data within the current context, at the supplied subcontext.
@param array $subcontext The location within the current context that this data belongs.
@param \stdClass $data The data to be exported
@return content_writer
|
[
"Export",
"the",
"supplied",
"data",
"within",
"the",
"current",
"context",
"at",
"the",
"supplied",
"subcontext",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/privacy/classes/local/request/moodle_content_writer.php#L94-L100
|
215,383
|
moodle/moodle
|
privacy/classes/local/request/moodle_content_writer.php
|
moodle_content_writer.export_metadata
|
public function export_metadata(array $subcontext, string $key, $value, string $description) : content_writer {
$path = $this->get_full_path($subcontext, 'metadata.json');
if (file_exists($path)) {
$data = json_decode(file_get_contents($path));
} else {
$data = (object) [];
}
$data->$key = (object) [
'value' => $value,
'description' => $description,
];
$path = $this->get_path($subcontext, 'metadata.json');
$this->write_data($path, json_encode($data, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT));
return $this;
}
|
php
|
public function export_metadata(array $subcontext, string $key, $value, string $description) : content_writer {
$path = $this->get_full_path($subcontext, 'metadata.json');
if (file_exists($path)) {
$data = json_decode(file_get_contents($path));
} else {
$data = (object) [];
}
$data->$key = (object) [
'value' => $value,
'description' => $description,
];
$path = $this->get_path($subcontext, 'metadata.json');
$this->write_data($path, json_encode($data, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT));
return $this;
}
|
[
"public",
"function",
"export_metadata",
"(",
"array",
"$",
"subcontext",
",",
"string",
"$",
"key",
",",
"$",
"value",
",",
"string",
"$",
"description",
")",
":",
"content_writer",
"{",
"$",
"path",
"=",
"$",
"this",
"->",
"get_full_path",
"(",
"$",
"subcontext",
",",
"'metadata.json'",
")",
";",
"if",
"(",
"file_exists",
"(",
"$",
"path",
")",
")",
"{",
"$",
"data",
"=",
"json_decode",
"(",
"file_get_contents",
"(",
"$",
"path",
")",
")",
";",
"}",
"else",
"{",
"$",
"data",
"=",
"(",
"object",
")",
"[",
"]",
";",
"}",
"$",
"data",
"->",
"$",
"key",
"=",
"(",
"object",
")",
"[",
"'value'",
"=>",
"$",
"value",
",",
"'description'",
"=>",
"$",
"description",
",",
"]",
";",
"$",
"path",
"=",
"$",
"this",
"->",
"get_path",
"(",
"$",
"subcontext",
",",
"'metadata.json'",
")",
";",
"$",
"this",
"->",
"write_data",
"(",
"$",
"path",
",",
"json_encode",
"(",
"$",
"data",
",",
"JSON_UNESCAPED_UNICODE",
"|",
"JSON_PRETTY_PRINT",
")",
")",
";",
"return",
"$",
"this",
";",
"}"
] |
Export metadata about the supplied subcontext.
Metadata consists of a key/value pair and a description of the value.
@param array $subcontext The location within the current context that this data belongs.
@param string $key The metadata name.
@param string $value The metadata value.
@param string $description The description of the value.
@return content_writer
|
[
"Export",
"metadata",
"about",
"the",
"supplied",
"subcontext",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/privacy/classes/local/request/moodle_content_writer.php#L113-L131
|
215,384
|
moodle/moodle
|
privacy/classes/local/request/moodle_content_writer.php
|
moodle_content_writer.export_related_data
|
public function export_related_data(array $subcontext, $name, $data) : content_writer {
$path = $this->get_path($subcontext, "{$name}.json");
$this->write_data($path, json_encode($data, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT));
return $this;
}
|
php
|
public function export_related_data(array $subcontext, $name, $data) : content_writer {
$path = $this->get_path($subcontext, "{$name}.json");
$this->write_data($path, json_encode($data, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT));
return $this;
}
|
[
"public",
"function",
"export_related_data",
"(",
"array",
"$",
"subcontext",
",",
"$",
"name",
",",
"$",
"data",
")",
":",
"content_writer",
"{",
"$",
"path",
"=",
"$",
"this",
"->",
"get_path",
"(",
"$",
"subcontext",
",",
"\"{$name}.json\"",
")",
";",
"$",
"this",
"->",
"write_data",
"(",
"$",
"path",
",",
"json_encode",
"(",
"$",
"data",
",",
"JSON_UNESCAPED_UNICODE",
"|",
"JSON_PRETTY_PRINT",
")",
")",
";",
"return",
"$",
"this",
";",
"}"
] |
Export a piece of related data.
@param array $subcontext The location within the current context that this data belongs.
@param string $name The name of the file to be exported.
@param \stdClass $data The related data to export.
@return content_writer
|
[
"Export",
"a",
"piece",
"of",
"related",
"data",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/privacy/classes/local/request/moodle_content_writer.php#L141-L147
|
215,385
|
moodle/moodle
|
privacy/classes/local/request/moodle_content_writer.php
|
moodle_content_writer.export_custom_file
|
public function export_custom_file(array $subcontext, $filename, $filecontent) : content_writer {
$filename = clean_param($filename, PARAM_FILE);
$path = $this->get_path($subcontext, $filename);
$this->write_data($path, $filecontent);
return $this;
}
|
php
|
public function export_custom_file(array $subcontext, $filename, $filecontent) : content_writer {
$filename = clean_param($filename, PARAM_FILE);
$path = $this->get_path($subcontext, $filename);
$this->write_data($path, $filecontent);
return $this;
}
|
[
"public",
"function",
"export_custom_file",
"(",
"array",
"$",
"subcontext",
",",
"$",
"filename",
",",
"$",
"filecontent",
")",
":",
"content_writer",
"{",
"$",
"filename",
"=",
"clean_param",
"(",
"$",
"filename",
",",
"PARAM_FILE",
")",
";",
"$",
"path",
"=",
"$",
"this",
"->",
"get_path",
"(",
"$",
"subcontext",
",",
"$",
"filename",
")",
";",
"$",
"this",
"->",
"write_data",
"(",
"$",
"path",
",",
"$",
"filecontent",
")",
";",
"return",
"$",
"this",
";",
"}"
] |
Export a piece of data in a custom format.
@param array $subcontext The location within the current context that this data belongs.
@param string $filename The name of the file to be exported.
@param string $filecontent The content to be exported.
|
[
"Export",
"a",
"piece",
"of",
"data",
"in",
"a",
"custom",
"format",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/privacy/classes/local/request/moodle_content_writer.php#L156-L162
|
215,386
|
moodle/moodle
|
privacy/classes/local/request/moodle_content_writer.php
|
moodle_content_writer.rewrite_pluginfile_urls
|
public function rewrite_pluginfile_urls(array $subcontext, $component, $filearea, $itemid, $text) : string {
// Need to take into consideration the subcontext to provide the full path to this file.
$subcontextpath = '';
if (!empty($subcontext)) {
$subcontextpath = DIRECTORY_SEPARATOR . implode(DIRECTORY_SEPARATOR, $subcontext);
}
$path = $this->get_context_path();
$path = implode(DIRECTORY_SEPARATOR, $path) . $subcontextpath;
$returnstring = $path . DIRECTORY_SEPARATOR . $this->get_files_target_url($component, $filearea, $itemid) . '/';
$returnstring = clean_param($returnstring, PARAM_PATH);
return str_replace('@@PLUGINFILE@@/', $returnstring, $text);
}
|
php
|
public function rewrite_pluginfile_urls(array $subcontext, $component, $filearea, $itemid, $text) : string {
// Need to take into consideration the subcontext to provide the full path to this file.
$subcontextpath = '';
if (!empty($subcontext)) {
$subcontextpath = DIRECTORY_SEPARATOR . implode(DIRECTORY_SEPARATOR, $subcontext);
}
$path = $this->get_context_path();
$path = implode(DIRECTORY_SEPARATOR, $path) . $subcontextpath;
$returnstring = $path . DIRECTORY_SEPARATOR . $this->get_files_target_url($component, $filearea, $itemid) . '/';
$returnstring = clean_param($returnstring, PARAM_PATH);
return str_replace('@@PLUGINFILE@@/', $returnstring, $text);
}
|
[
"public",
"function",
"rewrite_pluginfile_urls",
"(",
"array",
"$",
"subcontext",
",",
"$",
"component",
",",
"$",
"filearea",
",",
"$",
"itemid",
",",
"$",
"text",
")",
":",
"string",
"{",
"// Need to take into consideration the subcontext to provide the full path to this file.",
"$",
"subcontextpath",
"=",
"''",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"subcontext",
")",
")",
"{",
"$",
"subcontextpath",
"=",
"DIRECTORY_SEPARATOR",
".",
"implode",
"(",
"DIRECTORY_SEPARATOR",
",",
"$",
"subcontext",
")",
";",
"}",
"$",
"path",
"=",
"$",
"this",
"->",
"get_context_path",
"(",
")",
";",
"$",
"path",
"=",
"implode",
"(",
"DIRECTORY_SEPARATOR",
",",
"$",
"path",
")",
".",
"$",
"subcontextpath",
";",
"$",
"returnstring",
"=",
"$",
"path",
".",
"DIRECTORY_SEPARATOR",
".",
"$",
"this",
"->",
"get_files_target_url",
"(",
"$",
"component",
",",
"$",
"filearea",
",",
"$",
"itemid",
")",
".",
"'/'",
";",
"$",
"returnstring",
"=",
"clean_param",
"(",
"$",
"returnstring",
",",
"PARAM_PATH",
")",
";",
"return",
"str_replace",
"(",
"'@@PLUGINFILE@@/'",
",",
"$",
"returnstring",
",",
"$",
"text",
")",
";",
"}"
] |
Prepare a text area by processing pluginfile URLs within it.
@param array $subcontext The location within the current context that this data belongs.
@param string $component The name of the component that the files belong to.
@param string $filearea The filearea within that component.
@param string $itemid Which item those files belong to.
@param string $text The text to be processed
@return string The processed string
|
[
"Prepare",
"a",
"text",
"area",
"by",
"processing",
"pluginfile",
"URLs",
"within",
"it",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/privacy/classes/local/request/moodle_content_writer.php#L174-L186
|
215,387
|
moodle/moodle
|
privacy/classes/local/request/moodle_content_writer.php
|
moodle_content_writer.export_area_files
|
public function export_area_files(array $subcontext, $component, $filearea, $itemid) : content_writer {
$fs = get_file_storage();
$files = $fs->get_area_files($this->context->id, $component, $filearea, $itemid);
foreach ($files as $file) {
$this->export_file($subcontext, $file);
}
return $this;
}
|
php
|
public function export_area_files(array $subcontext, $component, $filearea, $itemid) : content_writer {
$fs = get_file_storage();
$files = $fs->get_area_files($this->context->id, $component, $filearea, $itemid);
foreach ($files as $file) {
$this->export_file($subcontext, $file);
}
return $this;
}
|
[
"public",
"function",
"export_area_files",
"(",
"array",
"$",
"subcontext",
",",
"$",
"component",
",",
"$",
"filearea",
",",
"$",
"itemid",
")",
":",
"content_writer",
"{",
"$",
"fs",
"=",
"get_file_storage",
"(",
")",
";",
"$",
"files",
"=",
"$",
"fs",
"->",
"get_area_files",
"(",
"$",
"this",
"->",
"context",
"->",
"id",
",",
"$",
"component",
",",
"$",
"filearea",
",",
"$",
"itemid",
")",
";",
"foreach",
"(",
"$",
"files",
"as",
"$",
"file",
")",
"{",
"$",
"this",
"->",
"export_file",
"(",
"$",
"subcontext",
",",
"$",
"file",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
] |
Export all files within the specified component, filearea, itemid combination.
@param array $subcontext The location within the current context that this data belongs.
@param string $component The name of the component that the files belong to.
@param string $filearea The filearea within that component.
@param string $itemid Which item those files belong to.
|
[
"Export",
"all",
"files",
"within",
"the",
"specified",
"component",
"filearea",
"itemid",
"combination",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/privacy/classes/local/request/moodle_content_writer.php#L196-L204
|
215,388
|
moodle/moodle
|
privacy/classes/local/request/moodle_content_writer.php
|
moodle_content_writer.export_file
|
public function export_file(array $subcontext, \stored_file $file) : content_writer {
if (!$file->is_directory()) {
$pathitems = array_merge(
$subcontext,
[$this->get_files_target_path($file->get_component(), $file->get_filearea(), $file->get_itemid())],
[$file->get_filepath()]
);
$path = $this->get_path($pathitems, $file->get_filename());
$fullpath = $this->get_full_path($pathitems, $file->get_filename());
check_dir_exists(dirname($fullpath), true, true);
$this->files[$path] = $file;
}
return $this;
}
|
php
|
public function export_file(array $subcontext, \stored_file $file) : content_writer {
if (!$file->is_directory()) {
$pathitems = array_merge(
$subcontext,
[$this->get_files_target_path($file->get_component(), $file->get_filearea(), $file->get_itemid())],
[$file->get_filepath()]
);
$path = $this->get_path($pathitems, $file->get_filename());
$fullpath = $this->get_full_path($pathitems, $file->get_filename());
check_dir_exists(dirname($fullpath), true, true);
$this->files[$path] = $file;
}
return $this;
}
|
[
"public",
"function",
"export_file",
"(",
"array",
"$",
"subcontext",
",",
"\\",
"stored_file",
"$",
"file",
")",
":",
"content_writer",
"{",
"if",
"(",
"!",
"$",
"file",
"->",
"is_directory",
"(",
")",
")",
"{",
"$",
"pathitems",
"=",
"array_merge",
"(",
"$",
"subcontext",
",",
"[",
"$",
"this",
"->",
"get_files_target_path",
"(",
"$",
"file",
"->",
"get_component",
"(",
")",
",",
"$",
"file",
"->",
"get_filearea",
"(",
")",
",",
"$",
"file",
"->",
"get_itemid",
"(",
")",
")",
"]",
",",
"[",
"$",
"file",
"->",
"get_filepath",
"(",
")",
"]",
")",
";",
"$",
"path",
"=",
"$",
"this",
"->",
"get_path",
"(",
"$",
"pathitems",
",",
"$",
"file",
"->",
"get_filename",
"(",
")",
")",
";",
"$",
"fullpath",
"=",
"$",
"this",
"->",
"get_full_path",
"(",
"$",
"pathitems",
",",
"$",
"file",
"->",
"get_filename",
"(",
")",
")",
";",
"check_dir_exists",
"(",
"dirname",
"(",
"$",
"fullpath",
")",
",",
"true",
",",
"true",
")",
";",
"$",
"this",
"->",
"files",
"[",
"$",
"path",
"]",
"=",
"$",
"file",
";",
"}",
"return",
"$",
"this",
";",
"}"
] |
Export the specified file in the target location.
@param array $subcontext The location within the current context that this data belongs.
@param \stored_file $file The file to be exported.
|
[
"Export",
"the",
"specified",
"file",
"in",
"the",
"target",
"location",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/privacy/classes/local/request/moodle_content_writer.php#L212-L226
|
215,389
|
moodle/moodle
|
privacy/classes/local/request/moodle_content_writer.php
|
moodle_content_writer.get_context_path
|
protected function get_context_path() : array {
$path = [];
$contexts = array_reverse($this->context->get_parent_contexts(true));
foreach ($contexts as $context) {
$name = $context->get_context_name();
$id = ' _.' . $context->id;
$path[] = shorten_text(clean_param($name, PARAM_FILE),
self::MAX_CONTEXT_NAME_LENGTH, true, json_decode('"' . '\u2026' . '"')) . $id;
}
return $path;
}
|
php
|
protected function get_context_path() : array {
$path = [];
$contexts = array_reverse($this->context->get_parent_contexts(true));
foreach ($contexts as $context) {
$name = $context->get_context_name();
$id = ' _.' . $context->id;
$path[] = shorten_text(clean_param($name, PARAM_FILE),
self::MAX_CONTEXT_NAME_LENGTH, true, json_decode('"' . '\u2026' . '"')) . $id;
}
return $path;
}
|
[
"protected",
"function",
"get_context_path",
"(",
")",
":",
"array",
"{",
"$",
"path",
"=",
"[",
"]",
";",
"$",
"contexts",
"=",
"array_reverse",
"(",
"$",
"this",
"->",
"context",
"->",
"get_parent_contexts",
"(",
"true",
")",
")",
";",
"foreach",
"(",
"$",
"contexts",
"as",
"$",
"context",
")",
"{",
"$",
"name",
"=",
"$",
"context",
"->",
"get_context_name",
"(",
")",
";",
"$",
"id",
"=",
"' _.'",
".",
"$",
"context",
"->",
"id",
";",
"$",
"path",
"[",
"]",
"=",
"shorten_text",
"(",
"clean_param",
"(",
"$",
"name",
",",
"PARAM_FILE",
")",
",",
"self",
"::",
"MAX_CONTEXT_NAME_LENGTH",
",",
"true",
",",
"json_decode",
"(",
"'\"'",
".",
"'\\u2026'",
".",
"'\"'",
")",
")",
".",
"$",
"id",
";",
"}",
"return",
"$",
"path",
";",
"}"
] |
Determine the path for the current context.
@return array The context path.
@throws \coding_exception
|
[
"Determine",
"the",
"path",
"for",
"the",
"current",
"context",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/privacy/classes/local/request/moodle_content_writer.php#L265-L276
|
215,390
|
moodle/moodle
|
privacy/classes/local/request/moodle_content_writer.php
|
moodle_content_writer.get_path
|
protected function get_path(array $subcontext, string $name) : string {
$subcontext = shorten_filenames($subcontext, MAX_FILENAME_SIZE, true);
$name = shorten_filename($name, MAX_FILENAME_SIZE, true);
// This weird code is to look for a subcontext that contains a number and append an '_' to the front.
// This is because there seems to be some weird problem with array_merge_recursive used in finalise_content().
$subcontext = array_map(function($data) {
if (stripos($data, DIRECTORY_SEPARATOR) !== false) {
$newpath = explode(DIRECTORY_SEPARATOR, $data);
$newpath = array_map(function($value) {
if (is_numeric($value)) {
return '_' . $value;
}
return $value;
}, $newpath);
return implode(DIRECTORY_SEPARATOR, $newpath);
} else if (is_numeric($data)) {
$data = '_' . $data;
}
return $data;
}, $subcontext);
// Combine the context path, and the subcontext data.
$path = array_merge(
$this->get_context_path(),
$subcontext
);
// Join the directory together with the name.
$filepath = implode(DIRECTORY_SEPARATOR, $path) . DIRECTORY_SEPARATOR . $name;
// To use backslash, it must be doubled ("\\\\" PHP string).
$separator = str_replace('\\', '\\\\', DIRECTORY_SEPARATOR);
return preg_replace('@(' . $separator . '|/)+@', $separator, $filepath);
}
|
php
|
protected function get_path(array $subcontext, string $name) : string {
$subcontext = shorten_filenames($subcontext, MAX_FILENAME_SIZE, true);
$name = shorten_filename($name, MAX_FILENAME_SIZE, true);
// This weird code is to look for a subcontext that contains a number and append an '_' to the front.
// This is because there seems to be some weird problem with array_merge_recursive used in finalise_content().
$subcontext = array_map(function($data) {
if (stripos($data, DIRECTORY_SEPARATOR) !== false) {
$newpath = explode(DIRECTORY_SEPARATOR, $data);
$newpath = array_map(function($value) {
if (is_numeric($value)) {
return '_' . $value;
}
return $value;
}, $newpath);
return implode(DIRECTORY_SEPARATOR, $newpath);
} else if (is_numeric($data)) {
$data = '_' . $data;
}
return $data;
}, $subcontext);
// Combine the context path, and the subcontext data.
$path = array_merge(
$this->get_context_path(),
$subcontext
);
// Join the directory together with the name.
$filepath = implode(DIRECTORY_SEPARATOR, $path) . DIRECTORY_SEPARATOR . $name;
// To use backslash, it must be doubled ("\\\\" PHP string).
$separator = str_replace('\\', '\\\\', DIRECTORY_SEPARATOR);
return preg_replace('@(' . $separator . '|/)+@', $separator, $filepath);
}
|
[
"protected",
"function",
"get_path",
"(",
"array",
"$",
"subcontext",
",",
"string",
"$",
"name",
")",
":",
"string",
"{",
"$",
"subcontext",
"=",
"shorten_filenames",
"(",
"$",
"subcontext",
",",
"MAX_FILENAME_SIZE",
",",
"true",
")",
";",
"$",
"name",
"=",
"shorten_filename",
"(",
"$",
"name",
",",
"MAX_FILENAME_SIZE",
",",
"true",
")",
";",
"// This weird code is to look for a subcontext that contains a number and append an '_' to the front.",
"// This is because there seems to be some weird problem with array_merge_recursive used in finalise_content().",
"$",
"subcontext",
"=",
"array_map",
"(",
"function",
"(",
"$",
"data",
")",
"{",
"if",
"(",
"stripos",
"(",
"$",
"data",
",",
"DIRECTORY_SEPARATOR",
")",
"!==",
"false",
")",
"{",
"$",
"newpath",
"=",
"explode",
"(",
"DIRECTORY_SEPARATOR",
",",
"$",
"data",
")",
";",
"$",
"newpath",
"=",
"array_map",
"(",
"function",
"(",
"$",
"value",
")",
"{",
"if",
"(",
"is_numeric",
"(",
"$",
"value",
")",
")",
"{",
"return",
"'_'",
".",
"$",
"value",
";",
"}",
"return",
"$",
"value",
";",
"}",
",",
"$",
"newpath",
")",
";",
"return",
"implode",
"(",
"DIRECTORY_SEPARATOR",
",",
"$",
"newpath",
")",
";",
"}",
"else",
"if",
"(",
"is_numeric",
"(",
"$",
"data",
")",
")",
"{",
"$",
"data",
"=",
"'_'",
".",
"$",
"data",
";",
"}",
"return",
"$",
"data",
";",
"}",
",",
"$",
"subcontext",
")",
";",
"// Combine the context path, and the subcontext data.",
"$",
"path",
"=",
"array_merge",
"(",
"$",
"this",
"->",
"get_context_path",
"(",
")",
",",
"$",
"subcontext",
")",
";",
"// Join the directory together with the name.",
"$",
"filepath",
"=",
"implode",
"(",
"DIRECTORY_SEPARATOR",
",",
"$",
"path",
")",
".",
"DIRECTORY_SEPARATOR",
".",
"$",
"name",
";",
"// To use backslash, it must be doubled (\"\\\\\\\\\" PHP string).",
"$",
"separator",
"=",
"str_replace",
"(",
"'\\\\'",
",",
"'\\\\\\\\'",
",",
"DIRECTORY_SEPARATOR",
")",
";",
"return",
"preg_replace",
"(",
"'@('",
".",
"$",
"separator",
".",
"'|/)+@'",
",",
"$",
"separator",
",",
"$",
"filepath",
")",
";",
"}"
] |
Get the relative file path within the current context, and subcontext, using the specified filename.
@param string[] $subcontext The location within the current context to export this data.
@param string $name The intended filename, including any extensions.
@return string The fully-qualfiied file path.
|
[
"Get",
"the",
"relative",
"file",
"path",
"within",
"the",
"current",
"context",
"and",
"subcontext",
"using",
"the",
"specified",
"filename",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/privacy/classes/local/request/moodle_content_writer.php#L285-L319
|
215,391
|
moodle/moodle
|
privacy/classes/local/request/moodle_content_writer.php
|
moodle_content_writer.get_full_path
|
protected function get_full_path(array $subcontext, string $name) : string {
$path = array_merge(
[$this->path],
[$this->get_path($subcontext, $name)]
);
// Join the directory together with the name.
$filepath = implode(DIRECTORY_SEPARATOR, $path);
// To use backslash, it must be doubled ("\\\\" PHP string).
$separator = str_replace('\\', '\\\\', DIRECTORY_SEPARATOR);
return preg_replace('@(' . $separator . '|/)+@', $separator, $filepath);
}
|
php
|
protected function get_full_path(array $subcontext, string $name) : string {
$path = array_merge(
[$this->path],
[$this->get_path($subcontext, $name)]
);
// Join the directory together with the name.
$filepath = implode(DIRECTORY_SEPARATOR, $path);
// To use backslash, it must be doubled ("\\\\" PHP string).
$separator = str_replace('\\', '\\\\', DIRECTORY_SEPARATOR);
return preg_replace('@(' . $separator . '|/)+@', $separator, $filepath);
}
|
[
"protected",
"function",
"get_full_path",
"(",
"array",
"$",
"subcontext",
",",
"string",
"$",
"name",
")",
":",
"string",
"{",
"$",
"path",
"=",
"array_merge",
"(",
"[",
"$",
"this",
"->",
"path",
"]",
",",
"[",
"$",
"this",
"->",
"get_path",
"(",
"$",
"subcontext",
",",
"$",
"name",
")",
"]",
")",
";",
"// Join the directory together with the name.",
"$",
"filepath",
"=",
"implode",
"(",
"DIRECTORY_SEPARATOR",
",",
"$",
"path",
")",
";",
"// To use backslash, it must be doubled (\"\\\\\\\\\" PHP string).",
"$",
"separator",
"=",
"str_replace",
"(",
"'\\\\'",
",",
"'\\\\\\\\'",
",",
"DIRECTORY_SEPARATOR",
")",
";",
"return",
"preg_replace",
"(",
"'@('",
".",
"$",
"separator",
".",
"'|/)+@'",
",",
"$",
"separator",
",",
"$",
"filepath",
")",
";",
"}"
] |
Get the fully-qualified file path within the current context, and subcontext, using the specified filename.
@param string[] $subcontext The location within the current context to export this data.
@param string $name The intended filename, including any extensions.
@return string The fully-qualfiied file path.
|
[
"Get",
"the",
"fully",
"-",
"qualified",
"file",
"path",
"within",
"the",
"current",
"context",
"and",
"subcontext",
"using",
"the",
"specified",
"filename",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/privacy/classes/local/request/moodle_content_writer.php#L328-L340
|
215,392
|
moodle/moodle
|
privacy/classes/local/request/moodle_content_writer.php
|
moodle_content_writer.get_files_target_path
|
protected function get_files_target_path($component, $filearea, $itemid) : string {
// We do not need to include the component because we organise things by context.
$parts = ['_files', $filearea];
if (!empty($itemid)) {
$parts[] = $itemid;
}
return implode(DIRECTORY_SEPARATOR, $parts);
}
|
php
|
protected function get_files_target_path($component, $filearea, $itemid) : string {
// We do not need to include the component because we organise things by context.
$parts = ['_files', $filearea];
if (!empty($itemid)) {
$parts[] = $itemid;
}
return implode(DIRECTORY_SEPARATOR, $parts);
}
|
[
"protected",
"function",
"get_files_target_path",
"(",
"$",
"component",
",",
"$",
"filearea",
",",
"$",
"itemid",
")",
":",
"string",
"{",
"// We do not need to include the component because we organise things by context.",
"$",
"parts",
"=",
"[",
"'_files'",
",",
"$",
"filearea",
"]",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"itemid",
")",
")",
"{",
"$",
"parts",
"[",
"]",
"=",
"$",
"itemid",
";",
"}",
"return",
"implode",
"(",
"DIRECTORY_SEPARATOR",
",",
"$",
"parts",
")",
";",
"}"
] |
Get a path within a subcontext where exported files should be written to.
@param string $component The name of the component that the files belong to.
@param string $filearea The filearea within that component.
@param string $itemid Which item those files belong to.
@return string The path
|
[
"Get",
"a",
"path",
"within",
"a",
"subcontext",
"where",
"exported",
"files",
"should",
"be",
"written",
"to",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/privacy/classes/local/request/moodle_content_writer.php#L350-L360
|
215,393
|
moodle/moodle
|
privacy/classes/local/request/moodle_content_writer.php
|
moodle_content_writer.get_files_target_url
|
protected function get_files_target_url($component, $filearea, $itemid) : string {
// We do not need to include the component because we organise things by context.
$parts = ['_files', $filearea];
if (!empty($itemid)) {
$parts[] = '_' . $itemid;
}
return implode('/', $parts);
}
|
php
|
protected function get_files_target_url($component, $filearea, $itemid) : string {
// We do not need to include the component because we organise things by context.
$parts = ['_files', $filearea];
if (!empty($itemid)) {
$parts[] = '_' . $itemid;
}
return implode('/', $parts);
}
|
[
"protected",
"function",
"get_files_target_url",
"(",
"$",
"component",
",",
"$",
"filearea",
",",
"$",
"itemid",
")",
":",
"string",
"{",
"// We do not need to include the component because we organise things by context.",
"$",
"parts",
"=",
"[",
"'_files'",
",",
"$",
"filearea",
"]",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"itemid",
")",
")",
"{",
"$",
"parts",
"[",
"]",
"=",
"'_'",
".",
"$",
"itemid",
";",
"}",
"return",
"implode",
"(",
"'/'",
",",
"$",
"parts",
")",
";",
"}"
] |
Get a relative url to the directory of the exported files within a subcontext.
@param string $component The name of the component that the files belong to.
@param string $filearea The filearea within that component.
@param string $itemid Which item those files belong to.
@return string The url
|
[
"Get",
"a",
"relative",
"url",
"to",
"the",
"directory",
"of",
"the",
"exported",
"files",
"within",
"a",
"subcontext",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/privacy/classes/local/request/moodle_content_writer.php#L370-L379
|
215,394
|
moodle/moodle
|
privacy/classes/local/request/moodle_content_writer.php
|
moodle_content_writer.write_data
|
protected function write_data(string $path, string $data) {
$targetpath = $this->path . DIRECTORY_SEPARATOR . $path;
check_dir_exists(dirname($targetpath), true, true);
if (file_put_contents($targetpath, $data) === false) {
throw new \moodle_exception('cannotsavefile', 'error', '', $targetpath);
}
$this->files[$path] = $targetpath;
}
|
php
|
protected function write_data(string $path, string $data) {
$targetpath = $this->path . DIRECTORY_SEPARATOR . $path;
check_dir_exists(dirname($targetpath), true, true);
if (file_put_contents($targetpath, $data) === false) {
throw new \moodle_exception('cannotsavefile', 'error', '', $targetpath);
}
$this->files[$path] = $targetpath;
}
|
[
"protected",
"function",
"write_data",
"(",
"string",
"$",
"path",
",",
"string",
"$",
"data",
")",
"{",
"$",
"targetpath",
"=",
"$",
"this",
"->",
"path",
".",
"DIRECTORY_SEPARATOR",
".",
"$",
"path",
";",
"check_dir_exists",
"(",
"dirname",
"(",
"$",
"targetpath",
")",
",",
"true",
",",
"true",
")",
";",
"if",
"(",
"file_put_contents",
"(",
"$",
"targetpath",
",",
"$",
"data",
")",
"===",
"false",
")",
"{",
"throw",
"new",
"\\",
"moodle_exception",
"(",
"'cannotsavefile'",
",",
"'error'",
",",
"''",
",",
"$",
"targetpath",
")",
";",
"}",
"$",
"this",
"->",
"files",
"[",
"$",
"path",
"]",
"=",
"$",
"targetpath",
";",
"}"
] |
Write the data to the specified path.
@param string $path The path to export the data at.
@param string $data The data to be exported.
@throws \moodle_exception If the file cannot be written for some reason.
|
[
"Write",
"the",
"data",
"to",
"the",
"specified",
"path",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/privacy/classes/local/request/moodle_content_writer.php#L388-L395
|
215,395
|
moodle/moodle
|
privacy/classes/local/request/moodle_content_writer.php
|
moodle_content_writer.copy_data
|
protected function copy_data(array $path, array $destination) {
global $CFG;
$filename = array_pop($destination);
$destdirectory = implode(DIRECTORY_SEPARATOR, $destination);
$fulldestination = $this->path . DIRECTORY_SEPARATOR . $destdirectory;
check_dir_exists($fulldestination, true, true);
$fulldestination .= $filename;
$currentpath = $CFG->dirroot . DIRECTORY_SEPARATOR . implode(DIRECTORY_SEPARATOR, $path);
copy($currentpath, $fulldestination);
$this->files[$destdirectory . DIRECTORY_SEPARATOR . $filename] = $fulldestination;
}
|
php
|
protected function copy_data(array $path, array $destination) {
global $CFG;
$filename = array_pop($destination);
$destdirectory = implode(DIRECTORY_SEPARATOR, $destination);
$fulldestination = $this->path . DIRECTORY_SEPARATOR . $destdirectory;
check_dir_exists($fulldestination, true, true);
$fulldestination .= $filename;
$currentpath = $CFG->dirroot . DIRECTORY_SEPARATOR . implode(DIRECTORY_SEPARATOR, $path);
copy($currentpath, $fulldestination);
$this->files[$destdirectory . DIRECTORY_SEPARATOR . $filename] = $fulldestination;
}
|
[
"protected",
"function",
"copy_data",
"(",
"array",
"$",
"path",
",",
"array",
"$",
"destination",
")",
"{",
"global",
"$",
"CFG",
";",
"$",
"filename",
"=",
"array_pop",
"(",
"$",
"destination",
")",
";",
"$",
"destdirectory",
"=",
"implode",
"(",
"DIRECTORY_SEPARATOR",
",",
"$",
"destination",
")",
";",
"$",
"fulldestination",
"=",
"$",
"this",
"->",
"path",
".",
"DIRECTORY_SEPARATOR",
".",
"$",
"destdirectory",
";",
"check_dir_exists",
"(",
"$",
"fulldestination",
",",
"true",
",",
"true",
")",
";",
"$",
"fulldestination",
".=",
"$",
"filename",
";",
"$",
"currentpath",
"=",
"$",
"CFG",
"->",
"dirroot",
".",
"DIRECTORY_SEPARATOR",
".",
"implode",
"(",
"DIRECTORY_SEPARATOR",
",",
"$",
"path",
")",
";",
"copy",
"(",
"$",
"currentpath",
",",
"$",
"fulldestination",
")",
";",
"$",
"this",
"->",
"files",
"[",
"$",
"destdirectory",
".",
"DIRECTORY_SEPARATOR",
".",
"$",
"filename",
"]",
"=",
"$",
"fulldestination",
";",
"}"
] |
Copy a file to the specified path.
@param array $path Current location of the file.
@param array $destination Destination path to copy the file to.
|
[
"Copy",
"a",
"file",
"to",
"the",
"specified",
"path",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/privacy/classes/local/request/moodle_content_writer.php#L403-L413
|
215,396
|
moodle/moodle
|
privacy/classes/local/request/moodle_content_writer.php
|
moodle_content_writer.make_tree_object
|
protected function make_tree_object(array $tree, array $treekey, array $currentkey = []) : Array {
$newtree = [];
// Try to extract the context id and then add the context object.
$addcontext = function($index, $object) {
if (stripos($index, '_.') !== false) {
$namearray = explode('_.', $index);
$contextid = array_pop($namearray);
if (is_numeric($contextid)) {
$object[$index]->name = implode('_.', $namearray);
$object[$index]->context = \context::instance_by_id($contextid);
}
} else {
$object[$index]->name = $index;
}
};
// Just add the final data to the tree object.
$addfinalfile = function($directory, $treeleaf, $file) use ($treekey) {
$url = implode(DIRECTORY_SEPARATOR, $directory);
$url = clean_param($url, PARAM_PATH);
$treeleaf->name = $file;
$treeleaf->itemtype = 'item';
$gokey = clean_param($url . '/' . $file, PARAM_PATH);
if (isset($treekey[$gokey]) && $treekey[$gokey] !== 'No var') {
$treeleaf->datavar = $treekey[$gokey];
} else {
$treeleaf->url = new \moodle_url($url . '/' . $file);
}
};
foreach ($tree as $key => $value) {
$newtree[$key] = new \stdClass();
if (is_array($value)) {
$newtree[$key]->itemtype = 'treeitem';
// The array merge recursive adds a numeric index, and so we only add to the current
// key if it is now numeric.
$currentkey = is_numeric($key) ? $currentkey : array_merge($currentkey, [$key]);
// Try to extract the context id and then add the context object.
$addcontext($key, $newtree);
$newtree[$key]->children = $this->make_tree_object($value, $treekey, $currentkey);
if (!is_numeric($key)) {
// We're heading back down the tree, so remove the last key.
array_pop($currentkey);
}
} else {
// If the key is not numeric then we want to add a directory and put the file under that.
if (!is_numeric($key)) {
$newtree[$key]->itemtype = 'treeitem';
// Try to extract the context id and then add the context object.
$addcontext($key, $newtree);
array_push($currentkey, $key);
$newtree[$key]->children[$value] = new \stdClass();
$addfinalfile($currentkey, $newtree[$key]->children[$value], $value);
array_pop($currentkey);
} else {
// If the key is just a number then we just want to show the file instead.
$addfinalfile($currentkey, $newtree[$key], $value);
}
}
}
return $newtree;
}
|
php
|
protected function make_tree_object(array $tree, array $treekey, array $currentkey = []) : Array {
$newtree = [];
// Try to extract the context id and then add the context object.
$addcontext = function($index, $object) {
if (stripos($index, '_.') !== false) {
$namearray = explode('_.', $index);
$contextid = array_pop($namearray);
if (is_numeric($contextid)) {
$object[$index]->name = implode('_.', $namearray);
$object[$index]->context = \context::instance_by_id($contextid);
}
} else {
$object[$index]->name = $index;
}
};
// Just add the final data to the tree object.
$addfinalfile = function($directory, $treeleaf, $file) use ($treekey) {
$url = implode(DIRECTORY_SEPARATOR, $directory);
$url = clean_param($url, PARAM_PATH);
$treeleaf->name = $file;
$treeleaf->itemtype = 'item';
$gokey = clean_param($url . '/' . $file, PARAM_PATH);
if (isset($treekey[$gokey]) && $treekey[$gokey] !== 'No var') {
$treeleaf->datavar = $treekey[$gokey];
} else {
$treeleaf->url = new \moodle_url($url . '/' . $file);
}
};
foreach ($tree as $key => $value) {
$newtree[$key] = new \stdClass();
if (is_array($value)) {
$newtree[$key]->itemtype = 'treeitem';
// The array merge recursive adds a numeric index, and so we only add to the current
// key if it is now numeric.
$currentkey = is_numeric($key) ? $currentkey : array_merge($currentkey, [$key]);
// Try to extract the context id and then add the context object.
$addcontext($key, $newtree);
$newtree[$key]->children = $this->make_tree_object($value, $treekey, $currentkey);
if (!is_numeric($key)) {
// We're heading back down the tree, so remove the last key.
array_pop($currentkey);
}
} else {
// If the key is not numeric then we want to add a directory and put the file under that.
if (!is_numeric($key)) {
$newtree[$key]->itemtype = 'treeitem';
// Try to extract the context id and then add the context object.
$addcontext($key, $newtree);
array_push($currentkey, $key);
$newtree[$key]->children[$value] = new \stdClass();
$addfinalfile($currentkey, $newtree[$key]->children[$value], $value);
array_pop($currentkey);
} else {
// If the key is just a number then we just want to show the file instead.
$addfinalfile($currentkey, $newtree[$key], $value);
}
}
}
return $newtree;
}
|
[
"protected",
"function",
"make_tree_object",
"(",
"array",
"$",
"tree",
",",
"array",
"$",
"treekey",
",",
"array",
"$",
"currentkey",
"=",
"[",
"]",
")",
":",
"Array",
"{",
"$",
"newtree",
"=",
"[",
"]",
";",
"// Try to extract the context id and then add the context object.",
"$",
"addcontext",
"=",
"function",
"(",
"$",
"index",
",",
"$",
"object",
")",
"{",
"if",
"(",
"stripos",
"(",
"$",
"index",
",",
"'_.'",
")",
"!==",
"false",
")",
"{",
"$",
"namearray",
"=",
"explode",
"(",
"'_.'",
",",
"$",
"index",
")",
";",
"$",
"contextid",
"=",
"array_pop",
"(",
"$",
"namearray",
")",
";",
"if",
"(",
"is_numeric",
"(",
"$",
"contextid",
")",
")",
"{",
"$",
"object",
"[",
"$",
"index",
"]",
"->",
"name",
"=",
"implode",
"(",
"'_.'",
",",
"$",
"namearray",
")",
";",
"$",
"object",
"[",
"$",
"index",
"]",
"->",
"context",
"=",
"\\",
"context",
"::",
"instance_by_id",
"(",
"$",
"contextid",
")",
";",
"}",
"}",
"else",
"{",
"$",
"object",
"[",
"$",
"index",
"]",
"->",
"name",
"=",
"$",
"index",
";",
"}",
"}",
";",
"// Just add the final data to the tree object.",
"$",
"addfinalfile",
"=",
"function",
"(",
"$",
"directory",
",",
"$",
"treeleaf",
",",
"$",
"file",
")",
"use",
"(",
"$",
"treekey",
")",
"{",
"$",
"url",
"=",
"implode",
"(",
"DIRECTORY_SEPARATOR",
",",
"$",
"directory",
")",
";",
"$",
"url",
"=",
"clean_param",
"(",
"$",
"url",
",",
"PARAM_PATH",
")",
";",
"$",
"treeleaf",
"->",
"name",
"=",
"$",
"file",
";",
"$",
"treeleaf",
"->",
"itemtype",
"=",
"'item'",
";",
"$",
"gokey",
"=",
"clean_param",
"(",
"$",
"url",
".",
"'/'",
".",
"$",
"file",
",",
"PARAM_PATH",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"treekey",
"[",
"$",
"gokey",
"]",
")",
"&&",
"$",
"treekey",
"[",
"$",
"gokey",
"]",
"!==",
"'No var'",
")",
"{",
"$",
"treeleaf",
"->",
"datavar",
"=",
"$",
"treekey",
"[",
"$",
"gokey",
"]",
";",
"}",
"else",
"{",
"$",
"treeleaf",
"->",
"url",
"=",
"new",
"\\",
"moodle_url",
"(",
"$",
"url",
".",
"'/'",
".",
"$",
"file",
")",
";",
"}",
"}",
";",
"foreach",
"(",
"$",
"tree",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"$",
"newtree",
"[",
"$",
"key",
"]",
"=",
"new",
"\\",
"stdClass",
"(",
")",
";",
"if",
"(",
"is_array",
"(",
"$",
"value",
")",
")",
"{",
"$",
"newtree",
"[",
"$",
"key",
"]",
"->",
"itemtype",
"=",
"'treeitem'",
";",
"// The array merge recursive adds a numeric index, and so we only add to the current",
"// key if it is now numeric.",
"$",
"currentkey",
"=",
"is_numeric",
"(",
"$",
"key",
")",
"?",
"$",
"currentkey",
":",
"array_merge",
"(",
"$",
"currentkey",
",",
"[",
"$",
"key",
"]",
")",
";",
"// Try to extract the context id and then add the context object.",
"$",
"addcontext",
"(",
"$",
"key",
",",
"$",
"newtree",
")",
";",
"$",
"newtree",
"[",
"$",
"key",
"]",
"->",
"children",
"=",
"$",
"this",
"->",
"make_tree_object",
"(",
"$",
"value",
",",
"$",
"treekey",
",",
"$",
"currentkey",
")",
";",
"if",
"(",
"!",
"is_numeric",
"(",
"$",
"key",
")",
")",
"{",
"// We're heading back down the tree, so remove the last key.",
"array_pop",
"(",
"$",
"currentkey",
")",
";",
"}",
"}",
"else",
"{",
"// If the key is not numeric then we want to add a directory and put the file under that.",
"if",
"(",
"!",
"is_numeric",
"(",
"$",
"key",
")",
")",
"{",
"$",
"newtree",
"[",
"$",
"key",
"]",
"->",
"itemtype",
"=",
"'treeitem'",
";",
"// Try to extract the context id and then add the context object.",
"$",
"addcontext",
"(",
"$",
"key",
",",
"$",
"newtree",
")",
";",
"array_push",
"(",
"$",
"currentkey",
",",
"$",
"key",
")",
";",
"$",
"newtree",
"[",
"$",
"key",
"]",
"->",
"children",
"[",
"$",
"value",
"]",
"=",
"new",
"\\",
"stdClass",
"(",
")",
";",
"$",
"addfinalfile",
"(",
"$",
"currentkey",
",",
"$",
"newtree",
"[",
"$",
"key",
"]",
"->",
"children",
"[",
"$",
"value",
"]",
",",
"$",
"value",
")",
";",
"array_pop",
"(",
"$",
"currentkey",
")",
";",
"}",
"else",
"{",
"// If the key is just a number then we just want to show the file instead.",
"$",
"addfinalfile",
"(",
"$",
"currentkey",
",",
"$",
"newtree",
"[",
"$",
"key",
"]",
",",
"$",
"value",
")",
";",
"}",
"}",
"}",
"return",
"$",
"newtree",
";",
"}"
] |
Add more detail to the tree to help with sorting and display in the renderer.
@param array $tree The file structure currently as a multidimensional array.
@param array $treekey An array of the current file paths.
@param array $currentkey The current short path of the tree.
@return array An array of objects that has additional data.
|
[
"Add",
"more",
"detail",
"to",
"the",
"tree",
"to",
"help",
"with",
"sorting",
"and",
"display",
"in",
"the",
"renderer",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/privacy/classes/local/request/moodle_content_writer.php#L481-L544
|
215,397
|
moodle/moodle
|
privacy/classes/local/request/moodle_content_writer.php
|
moodle_content_writer.check_plugin_is_installed
|
protected function check_plugin_is_installed(string $component) : Bool {
if (!isset($this->checkedplugins[$component])) {
$pluginmanager = \core_plugin_manager::instance();
$plugin = $pluginmanager->get_plugin_info($component);
$this->checkedplugins[$component] = !is_null($plugin);
}
return $this->checkedplugins[$component];
}
|
php
|
protected function check_plugin_is_installed(string $component) : Bool {
if (!isset($this->checkedplugins[$component])) {
$pluginmanager = \core_plugin_manager::instance();
$plugin = $pluginmanager->get_plugin_info($component);
$this->checkedplugins[$component] = !is_null($plugin);
}
return $this->checkedplugins[$component];
}
|
[
"protected",
"function",
"check_plugin_is_installed",
"(",
"string",
"$",
"component",
")",
":",
"Bool",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"checkedplugins",
"[",
"$",
"component",
"]",
")",
")",
"{",
"$",
"pluginmanager",
"=",
"\\",
"core_plugin_manager",
"::",
"instance",
"(",
")",
";",
"$",
"plugin",
"=",
"$",
"pluginmanager",
"->",
"get_plugin_info",
"(",
"$",
"component",
")",
";",
"$",
"this",
"->",
"checkedplugins",
"[",
"$",
"component",
"]",
"=",
"!",
"is_null",
"(",
"$",
"plugin",
")",
";",
"}",
"return",
"$",
"this",
"->",
"checkedplugins",
"[",
"$",
"component",
"]",
";",
"}"
] |
Check to see if a specified plugin is installed.
@param string $component The component name e.g. tool_log
@return bool Whether this component is installed.
|
[
"Check",
"to",
"see",
"if",
"a",
"specified",
"plugin",
"is",
"installed",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/privacy/classes/local/request/moodle_content_writer.php#L599-L606
|
215,398
|
moodle/moodle
|
privacy/classes/local/request/moodle_content_writer.php
|
moodle_content_writer.finalise_content
|
public function finalise_content() : string {
$this->write_html_data();
$exportfile = make_request_directory() . '/export.zip';
$fp = get_file_packer();
$fp->archive_to_pathname($this->files, $exportfile);
// Reset the writer to prevent any further writes.
writer::reset();
return $exportfile;
}
|
php
|
public function finalise_content() : string {
$this->write_html_data();
$exportfile = make_request_directory() . '/export.zip';
$fp = get_file_packer();
$fp->archive_to_pathname($this->files, $exportfile);
// Reset the writer to prevent any further writes.
writer::reset();
return $exportfile;
}
|
[
"public",
"function",
"finalise_content",
"(",
")",
":",
"string",
"{",
"$",
"this",
"->",
"write_html_data",
"(",
")",
";",
"$",
"exportfile",
"=",
"make_request_directory",
"(",
")",
".",
"'/export.zip'",
";",
"$",
"fp",
"=",
"get_file_packer",
"(",
")",
";",
"$",
"fp",
"->",
"archive_to_pathname",
"(",
"$",
"this",
"->",
"files",
",",
"$",
"exportfile",
")",
";",
"// Reset the writer to prevent any further writes.",
"writer",
"::",
"reset",
"(",
")",
";",
"return",
"$",
"exportfile",
";",
"}"
] |
Perform any required finalisation steps and return the location of the finalised export.
@return string
|
[
"Perform",
"any",
"required",
"finalisation",
"steps",
"and",
"return",
"the",
"location",
"of",
"the",
"finalised",
"export",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/privacy/classes/local/request/moodle_content_writer.php#L684-L696
|
215,399
|
moodle/moodle
|
mod/forum/classes/local/vaults/discussion_list.php
|
discussion_list.generate_count_records_sql
|
protected function generate_count_records_sql(string $wheresql = null) : string {
$alias = $this->get_table_alias();
$db = $this->get_db();
$selectsql = "SELECT COUNT(1) FROM {" . self::TABLE . "} {$alias}";
$selectsql .= $wheresql ? ' WHERE ' . $wheresql : '';
return $selectsql;
}
|
php
|
protected function generate_count_records_sql(string $wheresql = null) : string {
$alias = $this->get_table_alias();
$db = $this->get_db();
$selectsql = "SELECT COUNT(1) FROM {" . self::TABLE . "} {$alias}";
$selectsql .= $wheresql ? ' WHERE ' . $wheresql : '';
return $selectsql;
}
|
[
"protected",
"function",
"generate_count_records_sql",
"(",
"string",
"$",
"wheresql",
"=",
"null",
")",
":",
"string",
"{",
"$",
"alias",
"=",
"$",
"this",
"->",
"get_table_alias",
"(",
")",
";",
"$",
"db",
"=",
"$",
"this",
"->",
"get_db",
"(",
")",
";",
"$",
"selectsql",
"=",
"\"SELECT COUNT(1) FROM {\"",
".",
"self",
"::",
"TABLE",
".",
"\"} {$alias}\"",
";",
"$",
"selectsql",
".=",
"$",
"wheresql",
"?",
"' WHERE '",
".",
"$",
"wheresql",
":",
"''",
";",
"return",
"$",
"selectsql",
";",
"}"
] |
Build the SQL to be used in count_records_sql.
@param string|null $wheresql Where conditions for the SQL
@return string
|
[
"Build",
"the",
"SQL",
"to",
"be",
"used",
"in",
"count_records_sql",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/forum/classes/local/vaults/discussion_list.php#L169-L177
|
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.