当前位置: 首页>>代码示例>>PHP>>正文


PHP badge::get_context方法代码示例

本文整理汇总了PHP中badge::get_context方法的典型用法代码示例。如果您正苦于以下问题:PHP badge::get_context方法的具体用法?PHP badge::get_context怎么用?PHP badge::get_context使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在badge的用法示例。


在下文中一共展示了badge::get_context方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: config_form_criteria

 /**
  * Add appropriate form elements to the criteria form
  *
  * @param stdClass $data details of overall criterion
  */
 public function config_form_criteria($data)
 {
     global $OUTPUT;
     $prefix = 'criteria-' . $this->id;
     if (count($data->criteria) > 2) {
         echo $OUTPUT->box_start();
         if (!empty($this->description)) {
             $badge = new badge($this->badgeid);
             echo $OUTPUT->box(format_text($this->description, $this->descriptionformat, array('context' => $badge->get_context())), 'criteria-description');
         }
         echo $OUTPUT->heading($this->get_title(), 2);
         $agg = $data->get_aggregation_methods();
         if (!$data->is_locked() && !$data->is_active()) {
             $editurl = new moodle_url('/badges/criteria_settings.php', array('badgeid' => $this->badgeid, 'edit' => true, 'type' => $this->criteriatype, 'crit' => $this->id));
             $editaction = $OUTPUT->action_icon($editurl, new pix_icon('t/edit', get_string('edit')), null, array('class' => 'criteria-action'));
             echo $OUTPUT->box($editaction, array('criteria-header'));
             $url = new moodle_url('criteria.php', array('id' => $data->id, 'sesskey' => sesskey()));
             echo $OUTPUT->single_select($url, 'update', $agg, $data->get_aggregation_method($this->criteriatype), null, null, array('aria-describedby' => 'overall'));
             echo html_writer::span(get_string('overallcrit', 'badges'), '', array('id' => 'overall'));
         } else {
             echo $OUTPUT->box(get_string('criteria_descr_' . $this->criteriatype, 'badges', core_text::strtoupper($agg[$data->get_aggregation_method()])), 'clearfix');
         }
         echo $OUTPUT->box_end();
     }
 }
开发者ID:evltuma,项目名称:moodle,代码行数:30,代码来源:award_criteria_overall.php

示例2: test_badge_created

 /**
  * Test the badge created event.
  *
  * There is no external API for creating a badge, so the unit test will simply
  * create and trigger the event and ensure data is returned as expected.
  */
 public function test_badge_created()
 {
     $badge = new badge($this->badgeid);
     // Trigger an event: badge created.
     $eventparams = array('userid' => $badge->usercreated, 'objectid' => $badge->id, 'context' => $badge->get_context());
     $event = \core\event\badge_created::create($eventparams);
     // Trigger and capture the event.
     $sink = $this->redirectEvents();
     $event->trigger();
     $events = $sink->get_events();
     $event = reset($events);
     // Check that the event data is valid.
     $this->assertInstanceOf('\\core\\event\\badge_created', $event);
     $this->assertEquals($badge->usercreated, $event->userid);
     $this->assertEquals($badge->id, $event->objectid);
     $this->assertDebuggingNotCalled();
     $sink->close();
 }
开发者ID:evltuma,项目名称:moodle,代码行数:24,代码来源:events_test.php

示例3: print_badge_status_box

 /**
  * Prints badge status box.
  * @return Either the status box html as a string or null
  */
 public function print_badge_status_box(badge $badge)
 {
     if (has_capability('moodle/badges:configurecriteria', $badge->get_context())) {
         $table = new html_table();
         $table->attributes['class'] = 'boxaligncenter statustable';
         if (!$badge->has_criteria()) {
             $criteriaurl = new moodle_url('/badges/criteria.php', array('id' => $badge->id));
             $status = get_string('nocriteria', 'badges');
             if ($this->page->url != $criteriaurl) {
                 $action = $this->output->single_button($criteriaurl, get_string('addcriteria', 'badges'), 'POST', array('class' => 'activatebadge'));
             } else {
                 $action = '';
             }
             $row = array($status, $action);
         } else {
             $status = get_string('statusmessage_' . $badge->status, 'badges');
             if ($badge->is_active()) {
                 $action = $this->output->single_button(new moodle_url('/badges/action.php', array('id' => $badge->id, 'lock' => 1, 'sesskey' => sesskey(), 'return' => $this->page->url->out_as_local_url(false))), get_string('deactivate', 'badges'), 'POST', array('class' => 'activatebadge'));
             } else {
                 $action = $this->output->single_button(new moodle_url('/badges/action.php', array('id' => $badge->id, 'activate' => 1, 'sesskey' => sesskey(), 'return' => $this->page->url->out_as_local_url(false))), get_string('activate', 'badges'), 'POST', array('class' => 'activatebadge'));
             }
             $row = array($status . $this->output->help_icon('status', 'badges'), $action);
         }
         $table->data[] = $row;
         $style = $badge->is_active() ? 'generalbox statusbox active' : 'generalbox statusbox inactive';
         return $this->output->box(html_writer::table($table), $style);
     }
     return null;
 }
开发者ID:Jtgadbois,项目名称:Pedadida,代码行数:33,代码来源:renderer.php

示例4: dirname

 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
 * @author     Yuliya Bozhko <yuliya.bozhko@totaralms.com>
 */
require_once dirname(dirname(__FILE__)) . '/config.php';
require_once $CFG->libdir . '/badgeslib.php';
$badgeid = optional_param('badgeid', 0, PARAM_INT);
// Badge ID.
$crit = optional_param('crit', 0, PARAM_INT);
$type = optional_param('type', 0, PARAM_INT);
// Criteria type.
$delete = optional_param('delete', 0, PARAM_BOOL);
$confirm = optional_param('confirm', 0, PARAM_BOOL);
require_login();
$return = new moodle_url('/badges/criteria.php', array('id' => $badgeid));
$badge = new badge($badgeid);
$context = $badge->get_context();
$navurl = new moodle_url('/badges/index.php', array('type' => $badge->type));
// Make sure that no actions available for locked or active badges.
if ($badge->is_active() || $badge->is_locked()) {
    redirect($return);
}
if ($badge->type == BADGE_TYPE_COURSE) {
    require_login($badge->courseid);
    $navurl = new moodle_url('/badges/index.php', array('type' => $badge->type, 'id' => $badge->courseid));
}
$PAGE->set_context($context);
$PAGE->set_url('/badges/criteria_action.php');
$PAGE->set_pagelayout('standard');
$PAGE->set_heading($badge->name);
$PAGE->set_title($badge->name);
navigation_node::override_active_url($navurl);
开发者ID:masaterutakeno,项目名称:MoodleMobile,代码行数:31,代码来源:criteria_action.php

示例5: print_badge_criteria

 /**
  * Returns information about badge criteria in a list form.
  *
  * @param badge $badge Badge objects
  * @param string $short Indicates whether to print full info about this badge
  * @return string $output HTML string to output
  */
 public function print_badge_criteria(badge $badge, $short = '')
 {
     $agg = $badge->get_aggregation_methods();
     if (empty($badge->criteria)) {
         return get_string('nocriteria', 'badges');
     }
     $overalldescr = '';
     $overall = $badge->criteria[BADGE_CRITERIA_TYPE_OVERALL];
     if (!$short && !empty($overall->description)) {
         $overalldescr = $this->output->box(format_text($overall->description, $overall->descriptionformat, array('context' => $badge->get_context())), 'criteria-description');
     }
     // Get the condition string.
     if (count($badge->criteria) == 2) {
         $condition = '';
         if (!$short) {
             $condition = get_string('criteria_descr', 'badges');
         }
     } else {
         $condition = get_string('criteria_descr_' . $short . BADGE_CRITERIA_TYPE_OVERALL, 'badges', core_text::strtoupper($agg[$badge->get_aggregation_method()]));
     }
     unset($badge->criteria[BADGE_CRITERIA_TYPE_OVERALL]);
     $items = array();
     // If only one criterion left, make sure its description goe to the top.
     if (count($badge->criteria) == 1) {
         $c = reset($badge->criteria);
         if (!$short && !empty($c->description)) {
             $overalldescr = $this->output->box(format_text($c->description, $c->descriptionformat, array('context' => $badge->get_context())), 'criteria-description');
         }
         if (count($c->params) == 1) {
             $items[] = get_string('criteria_descr_single_' . $short . $c->criteriatype, 'badges') . $c->get_details($short);
         } else {
             $items[] = get_string('criteria_descr_' . $short . $c->criteriatype, 'badges', core_text::strtoupper($agg[$badge->get_aggregation_method($c->criteriatype)])) . $c->get_details($short);
         }
     } else {
         foreach ($badge->criteria as $type => $c) {
             $criteriadescr = '';
             if (!$short && !empty($c->description)) {
                 $criteriadescr = $this->output->box(format_text($c->description, $c->descriptionformat, array('context' => $badge->get_context())), 'criteria-description');
             }
             if (count($c->params) == 1) {
                 $items[] = get_string('criteria_descr_single_' . $short . $type, 'badges') . $c->get_details($short) . $criteriadescr;
             } else {
                 $items[] = get_string('criteria_descr_' . $short . $type, 'badges', core_text::strtoupper($agg[$badge->get_aggregation_method($type)])) . $c->get_details($short) . $criteriadescr;
             }
         }
     }
     return $overalldescr . $condition . html_writer::alist($items, array(), 'ul');
 }
开发者ID:evltuma,项目名称:moodle,代码行数:55,代码来源:renderer.php

示例6: badges_bake

/**
 * Bake issued badge.
 *
 * @param string $hash Unique hash of an issued badge.
 * @param int $badgeid ID of the original badge.
 * @param int $userid ID of badge recipient (optional).
 * @param boolean $pathhash Return file pathhash instead of image url (optional).
 * @return string|url Returns either new file path hash or new file URL
 */
function badges_bake($hash, $badgeid, $userid = 0, $pathhash = false)
{
    global $CFG, $USER;
    require_once dirname(dirname(__FILE__)) . '/badges/lib/bakerlib.php';
    $badge = new badge($badgeid);
    $badge_context = $badge->get_context();
    $userid = $userid ? $userid : $USER->id;
    $user_context = context_user::instance($userid);
    $fs = get_file_storage();
    if (!$fs->file_exists($user_context->id, 'badges', 'userbadge', $badge->id, '/', $hash . '.png')) {
        if ($file = $fs->get_file($badge_context->id, 'badges', 'badgeimage', $badge->id, '/', 'f1.png')) {
            $contents = $file->get_content();
            $filehandler = new PNG_MetaDataHandler($contents);
            $assertion = new moodle_url('/badges/assertion.php', array('b' => $hash));
            if ($filehandler->check_chunks("tEXt", "openbadges")) {
                // Add assertion URL tExt chunk.
                $newcontents = $filehandler->add_chunks("tEXt", "openbadges", $assertion->out(false));
                $fileinfo = array('contextid' => $user_context->id, 'component' => 'badges', 'filearea' => 'userbadge', 'itemid' => $badge->id, 'filepath' => '/', 'filename' => $hash . '.png');
                // Create a file with added contents.
                $newfile = $fs->create_file_from_string($fileinfo, $newcontents);
                if ($pathhash) {
                    return $newfile->get_pathnamehash();
                }
            }
        } else {
            debugging('Error baking badge image!', DEBUG_DEVELOPER);
            return;
        }
    }
    // If file exists and we just need its path hash, return it.
    if ($pathhash) {
        $file = $fs->get_file($user_context->id, 'badges', 'userbadge', $badge->id, '/', $hash . '.png');
        return $file->get_pathnamehash();
    }
    $fileurl = moodle_url::make_pluginfile_url($user_context->id, 'badges', 'userbadge', $badge->id, '/', $hash, true);
    return $fileurl;
}
开发者ID:Gavinthisisit,项目名称:Moodle,代码行数:46,代码来源:badgeslib.php

示例7: config_form_criteria

 /**
  * Add appropriate criteria elements
  *
  * @param stdClass $data details of various criteria
  */
 public function config_form_criteria($data)
 {
     global $OUTPUT;
     $agg = $data->get_aggregation_methods();
     $editurl = new moodle_url('/badges/criteria_settings.php', array('badgeid' => $this->badgeid, 'edit' => true, 'type' => $this->criteriatype, 'crit' => $this->id));
     $deleteurl = new moodle_url('/badges/criteria_action.php', array('badgeid' => $this->badgeid, 'delete' => true, 'type' => $this->criteriatype));
     $editaction = $OUTPUT->action_icon($editurl, new pix_icon('t/edit', get_string('edit')), null, array('class' => 'criteria-action'));
     $deleteaction = $OUTPUT->action_icon($deleteurl, new pix_icon('t/delete', get_string('delete')), null, array('class' => 'criteria-action'));
     echo $OUTPUT->box_start();
     if (!$data->is_locked() && !$data->is_active()) {
         echo $OUTPUT->box($deleteaction . $editaction, array('criteria-header'));
     }
     echo $OUTPUT->heading($this->get_title() . $OUTPUT->help_icon('criteria_' . $this->criteriatype, 'badges'), 3, 'main help');
     if (!empty($this->description)) {
         $badge = new badge($this->badgeid);
         echo $OUTPUT->box(format_text($this->description, $this->descriptionformat, array('context' => $badge->get_context())), 'criteria-description');
     }
     if (!empty($this->params)) {
         if (count($this->params) > 1) {
             echo $OUTPUT->box(get_string('criteria_descr_' . $this->criteriatype, 'badges', core_text::strtoupper($agg[$data->get_aggregation_method($this->criteriatype)])), array('clearfix'));
         } else {
             echo $OUTPUT->box(get_string('criteria_descr_single_' . $this->criteriatype, 'badges'), array('clearfix'));
         }
         echo $OUTPUT->box($this->get_details(), array('clearfix'));
     }
     echo $OUTPUT->box_end();
 }
开发者ID:evltuma,项目名称:moodle,代码行数:32,代码来源:award_criteria.php

示例8: test_badge_viewed

 /**
  * Test the badge viewed event.
  *
  * There is no external API for viewing a badge, so the unit test will simply
  * create and trigger the event and ensure data is returned as expected.
  */
 public function test_badge_viewed()
 {
     $badge = new badge($this->badgeid);
     // Trigger an event: badge viewed.
     $other = array('badgeid' => $badge->id, 'badgehash' => '12345678');
     $eventparams = array('context' => $badge->get_context(), 'other' => $other);
     $event = \core\event\badge_viewed::create($eventparams);
     // Trigger and capture the event.
     $sink = $this->redirectEvents();
     $event->trigger();
     $events = $sink->get_events();
     $event = reset($events);
     // Check that the event data is valid.
     $this->assertInstanceOf('\\core\\event\\badge_viewed', $event);
     $this->assertEquals('12345678', $event->other['badgehash']);
     $this->assertEquals($badge->id, $event->other['badgeid']);
     $this->assertDebuggingNotCalled();
     $sink->close();
 }
开发者ID:janeklb,项目名称:moodle,代码行数:25,代码来源:events_test.php


注:本文中的badge::get_context方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。