本文整理汇总了PHP中core_availability\info::get_context方法的典型用法代码示例。如果您正苦于以下问题:PHP info::get_context方法的具体用法?PHP info::get_context怎么用?PHP info::get_context使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类core_availability\info
的用法示例。
在下文中一共展示了info::get_context方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: get_user_list_sql
/**
* Obtains SQL that returns a list of enrolled users that has been filtered
* by the conditions applied in the availability API, similar to calling
* get_enrolled_users and then filter_user_list. As for filter_user_list,
* this ONLY filteres out users with conditions that are marked as applying
* to user lists. For example, group conditions are included but date
* conditions are not included.
*
* The returned SQL is a query that returns a list of user IDs. It does not
* include brackets, so you neeed to add these to make it into a subquery.
* You would normally use it in an SQL phrase like "WHERE u.id IN ($sql)".
*
* The SQL will be complex and may be slow. It uses named parameters (sorry,
* I know they are annoying, but it was unavoidable here).
*
* If there are no conditions, the returned result is array('', array()).
*
* @param bool $not True if this condition is applying in negative mode
* @param \core_availability\info $info Item we're checking
* @param bool $onlyactive If true, only returns active enrolments
* @return array Array with two elements: SQL subquery and parameters array
* @throws \coding_exception If called on a condition that doesn't apply to user lists
*/
public function get_user_list_sql($not, \core_availability\info $info, $onlyactive)
{
if (!$this->is_applied_to_user_lists()) {
throw new \coding_exception('Not implemented (do not call unless ' . 'is_applied_to_user_lists is true)');
}
// Handle situation where plugin does not implement this, by returning a
// default (all enrolled users). This ensures compatibility with 2.7
// plugins and behaviour. Plugins should be updated to support this
// new function (if they return true to is_applied_to_user_lists).
debugging('Availability plugins that return true to is_applied_to_user_lists ' . 'should also now implement get_user_list_sql: ' . get_class($this), DEBUG_DEVELOPER);
return get_enrolled_sql($info->get_context(), '', 0, $onlyactive);
}
示例2: get_user_list_sql
public function get_user_list_sql($not, \core_availability\info $info, $onlyactive)
{
global $DB;
// Build suitable SQL depending on custom or standard field.
if ($this->customfield) {
$customfields = self::get_custom_profile_fields();
if (!array_key_exists($this->customfield, $customfields)) {
// If the field isn't found, nobody matches.
return array('SELECT id FROM {user} WHERE 0 = 1', array());
}
$customfield = $customfields[$this->customfield];
$mainparams = array();
$tablesql = "LEFT JOIN {user_info_data} uid ON uid.fieldid = " . self::unique_sql_parameter($mainparams, $customfield->id) . " AND uid.userid = userids.id";
list($condition, $conditionparams) = $this->get_condition_sql('uid.data');
$mainparams = array_merge($mainparams, $conditionparams);
// If default is true, then allow that too.
if ($this->is_field_condition_met($this->operator, $customfield->defaultdata, $this->value)) {
$where = "((uid.data IS NOT NULL AND {$condition}) OR (uid.data IS NULL))";
} else {
$where = "(uid.data IS NOT NULL AND {$condition})";
}
} else {
$tablesql = "JOIN {user} u ON u.id = userids.id";
list($where, $mainparams) = $this->get_condition_sql('u.' . $this->standardfield);
}
// Handle NOT.
if ($not) {
$where = 'NOT (' . $where . ')';
}
// Get enrolled user SQL and combine with this query.
list($enrolsql, $enrolparams) = get_enrolled_sql($info->get_context(), '', 0, $onlyactive);
$sql = "SELECT userids.id\n FROM ({$enrolsql}) userids\n {$tablesql}\n WHERE {$where}";
$params = array_merge($enrolparams, $mainparams);
return array($sql, $params);
}
示例3: is_available
public function is_available($not, \core_availability\info $info, $grabthelot, $userid)
{
global $DB;
// Should double-check with paypal everytime ?
$context = $info->get_context();
return $DB->record_exists('availability_paypal_tnx', array('userid' => $userid, 'contextid' => $context->id, 'payment_status' => 'Completed'));
}
示例4: get_user_list_sql
public function get_user_list_sql($not, \core_availability\info $info, $onlyactive)
{
global $DB;
// Get enrolled users with access all groups. These always are allowed.
list($aagsql, $aagparams) = get_enrolled_sql($info->get_context(), 'moodle/site:accessallgroups', 0, $onlyactive);
// Get all enrolled users.
list($enrolsql, $enrolparams) = get_enrolled_sql($info->get_context(), '', 0, $onlyactive);
// Condition for specified or any group.
$matchparams = array();
$matchsql = "SELECT 1\n FROM {groups_members} gm\n JOIN {groupings_groups} gg ON gg.groupid = gm.groupid\n WHERE gm.userid = userids.id\n AND gg.groupingid = " . self::unique_sql_parameter($matchparams, $this->get_grouping_id($info));
// Overall query combines all this.
$condition = $not ? 'NOT' : '';
$sql = "SELECT userids.id\n FROM ({$enrolsql}) userids\n WHERE (userids.id IN ({$aagsql})) OR {$condition} EXISTS ({$matchsql})";
return array($sql, array_merge($enrolparams, $aagparams, $matchparams));
}
示例5: get_description
/**
* Obtains a string describing this restriction (whether or not
* it actually applies).
*
* @param bool $full Set true if this is the 'full information' view
* @param bool $not Set true if we are inverting the condition
* @param info $info Item we're checking
* @return string Information string (for admin) about all restrictions on
* this item
*/
public function get_description($full, $not, \core_availability\info $info)
{
global $USER;
$logmanager = get_log_manager();
if (!($readers = $logmanager->get_readers('core\\log\\sql_reader'))) {
// Should be using 2.8, use old class.
$readers = $logmanager->get_readers('core\\log\\sql_select_reader');
}
$reader = array_pop($readers);
$context = $info->get_context();
$viewscount = $reader->get_events_select_count('contextid = :context AND userid = :userid AND crud = :crud', array('context' => $context->id, 'userid' => $USER->id, 'crud' => 'r'));
$a = new \stdclass();
$a->viewslimit = $this->viewslimit;
$a->viewscount = $viewscount;
if ($not) {
return get_string('eithernotdescription', 'availability_maxviews', $a);
} else {
return get_string('eitherdescription', 'availability_maxviews', $a);
}
}
示例6: get_user_list_sql
public function get_user_list_sql($not, \core_availability\info $info, $onlyactive)
{
global $DB;
// The data for this condition is not really stored in the database,
// so we return SQL that contains the hard-coded user list.
list($enrolsql, $enrolparams) = get_enrolled_sql($info->get_context(), '', 0, $onlyactive);
$condition = $not ? 'NOT' : '';
list($matchsql, $matchparams) = $DB->get_in_or_equal($this->filter, SQL_PARAMS_NAMED);
$sql = "SELECT userids.id\n FROM ({$enrolsql}) userids\n WHERE {$condition} (userids.id {$matchsql})";
return array($sql, array_merge($enrolparams, $matchparams));
}