Ignore:
Timestamp:
May 2, 2016, 12:09:23 PM (3 years ago)
Author:
jrpelegrina
Message:

Updated to moodle 3.0.3

Location:
moodle/trunk/fuentes/badges
Files:
2 added
24 edited

Legend:

Unmodified
Added
Removed
  • moodle/trunk/fuentes/badges/award.php

    r136 r1331  
    111111            $pageurl = new moodle_url('/badges/award.php', array('id' => $badgeid));
    112112            echo $OUTPUT->header();
    113             echo $OUTPUT->box(get_string('selectaward', 'badges') . $OUTPUT->single_select(new moodle_url($pageurl), 'role', $select));
     113            echo $OUTPUT->box($OUTPUT->single_select(new moodle_url($pageurl), 'role', $select, '', array('' => 'choosedots'),
     114                null, array('label' => get_string('selectaward', 'badges'))));
    114115            echo $OUTPUT->footer();
    115116            die();
     
    118119            $issuerrole = new stdClass();
    119120            $issuerrole->roleid = $role;
    120             $roleselect = get_string('selectaward', 'badges') . $OUTPUT->single_select(new moodle_url($pageurl), 'role', $select, $role, null);
     121            $roleselect = $OUTPUT->single_select(new moodle_url($pageurl), 'role', $select, $role, null, null,
     122                array('label' => get_string('selectaward', 'badges')));
    121123        }
    122124    } else {
  • moodle/trunk/fuentes/badges/backpack_form.php

    r136 r1331  
    4646        $mform->addElement('header', 'backpackheader', get_string('backpackconnection', 'badges'));
    4747        $mform->addHelpButton('backpackheader', 'backpackconnection', 'badges');
    48         $mform->addElement('static', 'url', get_string('url'), 'http://' . BADGE_BACKPACKURL);
     48        $mform->addElement('static', 'url', get_string('url'), BADGE_BACKPACKURL);
    4949        $status = html_writer::tag('span', get_string('notconnected', 'badges'),
    5050            array('class' => 'notconnected', 'id' => 'connection-status'));
     
    6868        $mform->setType('userid', PARAM_INT);
    6969
    70         $mform->addElement('hidden', 'backpackurl', 'http://' . BADGE_BACKPACKURL);
     70        $mform->addElement('hidden', 'backpackurl', BADGE_BACKPACKURL);
    7171        $mform->setType('backpackurl', PARAM_URL);
    7272
     
    119119        $mform->addElement('header', 'backpackheader', get_string('backpackconnection', 'badges'));
    120120        $mform->addHelpButton('backpackheader', 'backpackconnection', 'badges');
    121         $mform->addElement('static', 'url', get_string('url'), 'http://' . BADGE_BACKPACKURL);
     121        $mform->addElement('static', 'url', get_string('url'), BADGE_BACKPACKURL);
    122122
    123123        $status = html_writer::tag('span', get_string('connected', 'badges'), array('class' => 'connected'));
  • moodle/trunk/fuentes/badges/backpackconnect.php

    r136 r1331  
    5050$wwwparts = parse_url($CFG->wwwroot);
    5151$audience = $wwwparts['scheme'] . '://' . $wwwparts['host'];
    52 $audience .= isset($wwwparts['port']) ? $wwwparts['port'] : '';
     52$audience .= isset($wwwparts['port']) ? ':' . $wwwparts['port'] : '';
    5353$params = 'assertion=' . urlencode($assertion) . '&audience=' .
    5454           urlencode($audience);
     
    8888// Make sure email matches a backpack.
    8989$check = new stdClass();
    90 $check->backpackurl = 'http://' . BADGE_BACKPACKURL;
     90$check->backpackurl = BADGE_BACKPACKURL;
    9191$check->email = $data->email;
    9292
     
    107107$obj->userid = $USER->id;
    108108$obj->email = $data->email;
    109 $obj->backpackurl = 'http://' . BADGE_BACKPACKURL;
     109$obj->backpackurl = BADGE_BACKPACKURL;
    110110$obj->backpackuid = $backpackuid;
    111111$obj->autosync = 0;
  • moodle/trunk/fuentes/badges/badge.php

    r136 r1331  
    2727require_once(dirname(dirname(__FILE__)) . '/config.php');
    2828require_once($CFG->libdir . '/badgeslib.php');
     29require_once($CFG->libdir . '/filelib.php');
    2930
    3031$id = required_param('hash', PARAM_ALPHANUM);
     
    3839if ($bake && ($badge->recipient->id == $USER->id)) {
    3940    $name = str_replace(' ', '_', $badge->badgeclass['name']) . '.png';
    40     ob_start();
    41     $file = badges_bake($id, $badge->badgeid);
    42     header('Content-Type: image/png');
    43     header('Content-Disposition: attachment; filename="'. $name .'"');
    44     readfile($file);
    45     ob_flush();
     41    $filehash = badges_bake($id, $badge->badgeid, $USER->id, true);
     42    $fs = get_file_storage();
     43    $file = $fs->get_file_by_hash($filehash);
     44    send_stored_file($file, 0, 0, true, array('filename' => $name));
    4645}
    4746
  • moodle/trunk/fuentes/badges/criteria/award_criteria.php

    r136 r1331  
    8989abstract class award_criteria {
    9090
     91    /**
     92     * ID of the criterion.
     93     * @var integer
     94     */
    9195    public $id;
     96
     97    /**
     98     * Aggregation method [BADGE_CRITERIA_AGGREGATION_ANY, BADGE_CRITERIA_AGGREGATION_ALL].
     99     * @var integer
     100     */
    92101    public $method;
     102
     103    /**
     104     * ID of a badge this criterion belongs to.
     105     * @var integer
     106     */
    93107    public $badgeid;
     108
     109    /**
     110     * Criterion HTML/plain text description.
     111     * @var string
     112     */
     113    public $description;
     114
     115    /**
     116     * Format of the criterion description.
     117     * @var integer
     118     */
     119    public $descriptionformat;
     120
     121    /**
     122     * Any additional parameters.
     123     * @var array
     124     */
    94125    public $params = array();
    95126
     
    103134        $this->method = isset($params['method']) ? $params['method'] : BADGE_CRITERIA_AGGREGATION_ANY;
    104135        $this->badgeid = $params['badgeid'];
     136        $this->description = isset($params['description']) ? $params['description'] : '';
     137        $this->descriptionformat = isset($params['descriptionformat']) ? $params['descriptionformat'] : FORMAT_HTML;
    105138        if (isset($params['id'])) {
    106139            $this->params = $this->get_params($params['id']);
     
    220253        }
    221254        echo $OUTPUT->heading($this->get_title() . $OUTPUT->help_icon('criteria_' . $this->criteriatype, 'badges'), 3, 'main help');
     255
     256        if (!empty($this->description)) {
     257            $badge = new badge($this->badgeid);
     258            echo $OUTPUT->box(
     259                format_text($this->description, $this->descriptionformat, array('context' => $badge->get_context())),
     260                'criteria-description'
     261                );
     262        }
    222263
    223264        if (!empty($this->params)) {
     
    306347    /**
    307348     * Saves intial criteria records with required parameters set up.
     349     *
     350     * @param array $params Values from the form or any other array.
    308351     */
    309352    public function save($params = array()) {
    310353        global $DB;
     354
     355        // Figure out criteria description.
     356        // If it is coming from the form editor, it is an array(text, format).
     357        $description = '';
     358        $descriptionformat = FORMAT_HTML;
     359        if (isset($params['description']['text'])) {
     360            $description = $params['description']['text'];
     361            $descriptionformat = $params['description']['format'];
     362        } else if (isset($params['description'])) {
     363            $description = $params['description'];
     364        }
     365
    311366        $fordb = new stdClass();
    312367        $fordb->criteriatype = $this->criteriatype;
    313         $fordb->method = isset($params->agg) ? $params->agg : $params['agg'];
     368        $fordb->method = isset($params['agg']) ? $params['agg'] : BADGE_CRITERIA_AGGREGATION_ALL;
    314369        $fordb->badgeid = $this->badgeid;
     370        $fordb->description = $description;
     371        $fordb->descriptionformat = $descriptionformat;
    315372        $t = $DB->start_delegated_transaction();
    316373
    317         // Unset unnecessary parameters supplied with form.
    318         if (isset($params->agg)) {
    319             unset($params->agg);
    320         } else {
    321             unset($params['agg']);
    322         }
    323         unset($params->submitbutton);
    324         $params = array_filter((array)$params);
     374        // Pick only params that are required by this criterion.
     375        // Filter out empty values first.
     376        $params = array_filter($params);
     377        // Find out which param matches optional and required ones.
     378        $match = array_merge($this->optional_params, array($this->required_param));
     379        $regex = implode('|', array_map(create_function('$a', 'return $a . "_";'), $match));
     380        $requiredkeys = preg_grep('/^(' . $regex . ').*$/', array_keys($params));
    325381
    326382        if ($this->id !== 0) {
     
    332388
    333389            $existing = $DB->get_fieldset_select('badge_criteria_param', 'name', 'critid = ?', array($cid));
    334             $todelete = array_diff($existing, array_keys($params));
     390            $todelete = array_diff($existing, $requiredkeys);
    335391
    336392            if (!empty($todelete)) {
     
    350406            }
    351407
    352             foreach ($params as $key => $value) {
     408            foreach ($requiredkeys as $key) {
    353409                if (in_array($key, $existing)) {
    354410                    $updp = $DB->get_record('badge_criteria_param', array('name' => $key, 'critid' => $cid));
    355                     $updp->value = $value;
     411                    $updp->value = $params[$key];
    356412                    $DB->update_record('badge_criteria_param', $updp, true);
    357413                } else {
     
    359415                    $newp->critid = $cid;
    360416                    $newp->name = $key;
    361                     $newp->value = $value;
     417                    $newp->value = $params[$key];
    362418                    $DB->insert_record('badge_criteria_param', $newp);
    363419                }
     
    366422            $cid = $DB->insert_record('badge_criteria', $fordb, true);
    367423            if ($cid) {
    368                 foreach ($params as $key => $value) {
     424                foreach ($requiredkeys as $key) {
    369425                    $newp = new stdClass();
    370426                    $newp->critid = $cid;
    371427                    $newp->name = $key;
    372                     $newp->value = $value;
     428                    $newp->value = $params[$key];
    373429                    $DB->insert_record('badge_criteria_param', $newp, false, true);
    374430                }
    375431            }
    376          }
    377          $t->allow_commit();
     432        }
     433        $t->allow_commit();
    378434    }
    379435
     
    388444        $fordb->method = $this->method;
    389445        $fordb->badgeid = $newbadgeid;
     446        $fordb->description = $this->description;
     447        $fordb->descriptionformat = $this->descriptionformat;
    390448        if (($newcrit = $DB->insert_record('badge_criteria', $fordb, true)) && isset($this->params)) {
    391449            foreach ($this->params as $k => $param) {
  • moodle/trunk/fuentes/badges/criteria/award_criteria_activity.php

    r136 r1331  
    3838
    3939    private $courseid;
    40     private $coursestartdate;
     40    private $course;
    4141
    4242    public $required_param = 'module';
     
    4747        parent::__construct($record);
    4848
    49         $course = $DB->get_record_sql('SELECT b.courseid, c.startdate
     49        $this->course = $DB->get_record_sql('SELECT c.id, c.enablecompletion, c.cacherev, c.startdate
    5050                        FROM {badge} b INNER JOIN {course} c ON b.courseid = c.id
    5151                        WHERE b.id = :badgeid ', array('badgeid' => $this->badgeid));
    52         $this->courseid = $course->courseid;
    53         $this->coursestartdate = $course->startdate;
     52        $this->courseid = $this->course->id;
    5453    }
    5554
     
    8887                $str = $OUTPUT->error_text(get_string('error:nosuchmod', 'badges'));
    8988            } else {
    90                 $str = html_writer::tag('b', '"' . ucfirst($mod->modname) . ' - ' . $mod->name . '"');
     89                $str = html_writer::tag('b', '"' . get_string('modulename', $mod->modname) . ' - ' . $mod->name . '"');
    9190                if (isset($p['bydate'])) {
    9291                    $str .= get_string('criteria_descr_bydate', 'badges', userdate($p['bydate'], get_string('strftimedate', 'core_langconfig')));
     
    108107     */
    109108    public function get_options(&$mform) {
    110         global $DB;
    111 
    112109        $none = true;
    113110        $existing = array();
    114111        $missing = array();
    115112
    116         $course = $DB->get_record('course', array('id' => $this->courseid));
     113        $course = $this->course;
    117114        $info = new completion_info($course);
    118115        $mods = $info->get_activities();
     
    143140                $param = array('id' => $mod->id,
    144141                        'checked' => $checked,
    145                         'name' => ucfirst($mod->modname) . ' - ' . $mod->name,
     142                        'name' => get_string('modulename', $mod->modname) . ' - ' . $mod->name,
    146143                        'error' => false
    147144                        );
     
    188185    public function review($userid, $filtered = false) {
    189186        $completionstates = array(COMPLETION_COMPLETE, COMPLETION_COMPLETE_PASS);
    190         $course = new stdClass();
    191         $course->id = $this->courseid;
    192 
    193         if ($this->coursestartdate > time()) {
     187
     188        if ($this->course->startdate > time()) {
    194189            return false;
    195190        }
    196191
    197         $info = new completion_info($course);
     192        $info = new completion_info($this->course);
    198193
    199194        $overall = false;
  • moodle/trunk/fuentes/badges/criteria/award_criteria_course.php

    r136 r1331  
    4040
    4141    private $courseid;
    42     private $coursestartdate;
     42    private $course;
    4343
    4444    public $required_param = 'course';
     
    4949        parent::__construct($record);
    5050
    51         $course = $DB->get_record_sql('SELECT b.courseid, c.startdate
     51        $this->course = $DB->get_record_sql('SELECT c.id, c.enablecompletion, c.cacherev, c.startdate
    5252                        FROM {badge} b INNER JOIN {course} c ON b.courseid = c.id
    5353                        WHERE b.id = :badgeid ', array('badgeid' => $this->badgeid));
    54         $this->courseid = $course->courseid;
    55         $this->coursestartdate = $course->startdate;
     54        $this->courseid = $this->course->id;
    5655    }
    5756
     
    7574        }
    7675        echo $OUTPUT->heading($this->get_title() . $OUTPUT->help_icon('criteria_' . $this->criteriatype, 'badges'), 3, 'main help');
     76
     77        if (!empty($this->description)) {
     78            echo $OUTPUT->box(
     79                format_text($this->description, $this->descriptionformat,
     80                        array('context' => context_course::instance($this->courseid))
     81                ),
     82                'criteria-description'
     83            );
     84        }
    7785
    7886        if (!empty($this->params)) {
     
    172180     */
    173181    public function review($userid, $filtered = false) {
    174         $course = new stdClass();
    175         $course->id = $this->courseid;
    176 
    177         if ($this->coursestartdate > time()) {
     182        $course = $this->course;
     183
     184        if ($this->course->startdate > time()) {
    178185            return false;
    179186        }
  • moodle/trunk/fuentes/badges/criteria/award_criteria_courseset.php

    r136 r1331  
    165165                        'id' => $course->id,
    166166                        'checked' => true,
    167                         'name' => ucfirst(format_string($course->fullname, true, array('context' => $coursecontext))),
     167                        'name' => format_string($course->fullname, true, array('context' => $coursecontext)),
    168168                        'error' => false
    169169                );
  • moodle/trunk/fuentes/badges/criteria/award_criteria_overall.php

    r136 r1331  
    4646        if (count($data->criteria) > 2) {
    4747            echo $OUTPUT->box_start();
     48            if (!empty($this->description)) {
     49                $badge = new badge($this->badgeid);
     50                echo $OUTPUT->box(
     51                    format_text($this->description, $this->descriptionformat, array('context' => $badge->get_context())),
     52                    'criteria-description');
     53            }
    4854            echo $OUTPUT->heading($this->get_title(), 2);
    4955
    5056            $agg = $data->get_aggregation_methods();
    5157            if (!$data->is_locked() && !$data->is_active()) {
     58                $editurl = new moodle_url('/badges/criteria_settings.php',
     59                               array('badgeid' => $this->badgeid,
     60                                   'edit' => true,
     61                                   'type' => $this->criteriatype,
     62                                   'crit' => $this->id
     63                               )
     64                        );
     65                $editaction = $OUTPUT->action_icon($editurl, new pix_icon('t/edit', get_string('edit')), null,
     66                              array('class' => 'criteria-action'));
     67                echo $OUTPUT->box($editaction, array('criteria-header'));
     68
    5269                $url = new moodle_url('criteria.php', array('id' => $data->id, 'sesskey' => sesskey()));
    53                 $table = new html_table();
    54                 $table->attributes = array('class' => 'clearfix');
    55                 $table->colclasses = array('', 'activatebadge');
    56                 $table->data[] = array(
    57                         $OUTPUT->single_select($url, 'update', $agg, $data->get_aggregation_method($this->criteriatype), null),
    58                         get_string('overallcrit', 'badges')
    59                         );
    60                 echo html_writer::table($table);
     70                echo $OUTPUT->single_select($url, 'update', $agg, $data->get_aggregation_method($this->criteriatype),
     71                    null, null, array('aria-describedby' => 'overall'));
     72                echo html_writer::span(get_string('overallcrit', 'badges'), '', array('id' => 'overall'));
    6173            } else {
    6274                echo $OUTPUT->box(get_string('criteria_descr_' . $this->criteriatype, 'badges',
     
    156168    public function get_params($cid) {
    157169    }
     170
     171    /**
     172     * Saves overall badge criteria description.
     173     *
     174     * @param array $params Values from the form or any other array.
     175     */
     176    public function save($params = array()) {
     177        global $DB;
     178
     179        // Sort out criteria description.
     180        // If it is coming from the form editor, it is an array of (text, format).
     181        $description = '';
     182        $descriptionformat = FORMAT_HTML;
     183        if (isset($params['description']['text'])) {
     184            $description = $params['description']['text'];
     185            $descriptionformat = $params['description']['format'];
     186        } else if (isset($params['description'])) {
     187            $description = $params['description'];
     188        }
     189
     190        $fordb = new stdClass();
     191        $fordb->criteriatype = $this->criteriatype;
     192        $fordb->badgeid = $this->badgeid;
     193        $fordb->description = $description;
     194        $fordb->descriptionformat = $descriptionformat;
     195        if ($this->id !== 0) {
     196            $fordb->id = $this->id;
     197            $DB->update_record('badge_criteria', $fordb);
     198        } else {
     199            // New record in DB, set aggregation to ALL by default.
     200            $fordb->method = BADGE_CRITERIA_AGGREGATION_ALL;
     201            $DB->insert_record('badge_criteria', $fordb);
     202        }
     203    }
    158204}
  • moodle/trunk/fuentes/badges/criteria/award_criteria_profile.php

    r136 r1331  
    171171
    172172        $join = '';
    173         $where = '';
     173        $whereparts = array();
    174174        $sqlparams = array();
    175175        $rule = ($this->method == BADGE_CRITERIA_AGGREGATION_ANY) ? ' OR ' : ' AND ';
     
    177177        foreach ($this->params as $param) {
    178178            if (is_numeric($param['field'])) {
    179                 $infodata[] = " uid.fieldid = :fieldid{$param['field']} ";
    180                 $sqlparams["fieldid{$param['field']}"] = $param['field'];
    181             } else {
    182                 $userdata[] = $DB->sql_isnotempty('u', "u.{$param['field']}", false, true);
    183             }
    184         }
    185 
    186         // Add user custom field parameters if there are any.
    187         if (!empty($infodata)) {
    188             $extraon = implode($rule, $infodata);
    189             $join = " LEFT JOIN {user_info_data} uid ON uid.userid = u.id AND ({$extraon})";
    190         }
    191 
    192         // Add user table field parameters if there are any.
    193         if (!empty($userdata)) {
    194             $extraon = implode($rule, $userdata);
    195             $where = " AND ({$extraon})";
     179                // This is a custom field.
     180                $idx = count($whereparts) + 1;
     181                $join .= " LEFT JOIN {user_info_data} uid{$idx} ON uid{$idx}.userid = u.id AND uid{$idx}.fieldid = :fieldid{$idx} ";
     182                $sqlparams["fieldid{$idx}"] = $param['field'];
     183                $whereparts[] = "uid{$idx}.id IS NOT NULL";
     184            } else {
     185                // This is a field from {user} table.
     186                $whereparts[] = $DB->sql_isnotempty('u', "u.{$param['field']}", false, true);
     187            }
    196188        }
    197189
    198190        $sqlparams['userid'] = $userid;
    199         $sql = "SELECT u.* FROM {user} u " . $join . " WHERE u.id = :userid " . $where;
     191
     192        if ($whereparts) {
     193            $where = " AND (" . implode($rule, $whereparts) . ")";
     194        } else {
     195            $where = '';
     196        }
     197        $sql = "SELECT 1 FROM {user} u " . $join . " WHERE u.id = :userid $where";
    200198        $overall = $DB->record_exists_sql($sql, $sqlparams);
    201199
     
    213211
    214212        $join = '';
    215         $where = '';
     213        $whereparts = array();
    216214        $params = array();
    217215        $rule = ($this->method == BADGE_CRITERIA_AGGREGATION_ANY) ? ' OR ' : ' AND ';
     
    219217        foreach ($this->params as $param) {
    220218            if (is_numeric($param['field'])) {
    221                 $infodata[] = " uid.fieldid = :fieldid{$param['field']} ";
    222                 $params["fieldid{$param['field']}"] = $param['field'];
    223             } else {
    224                 $userdata[] = $DB->sql_isnotempty('u', "u.{$param['field']}", false, true);
    225             }
    226         }
    227 
    228         // Add user custom fields if there are any.
    229         if (!empty($infodata)) {
    230             $extraon = implode($rule, $infodata);
    231             $join = " LEFT JOIN {user_info_data} uid ON uid.userid = u.id AND ({$extraon})";
    232         }
    233 
    234         // Add user table fields if there are any.
    235         if (!empty($userdata)) {
    236             $extraon = implode($rule, $userdata);
    237             $where = " AND ({$extraon})";
     219                // This is a custom field.
     220                $idx = count($whereparts);
     221                $join .= " LEFT JOIN {user_info_data} uid{$idx} ON uid{$idx}.userid = u.id AND uid{$idx}.fieldid = :fieldid{$idx} ";
     222                $params["fieldid{$idx}"] = $param['field'];
     223                $whereparts[] = "uid{$idx}.id IS NOT NULL";
     224            } else {
     225                $whereparts[] = $DB->sql_isnotempty('u', "u.{$param['field']}", false, true);
     226            }
     227        }
     228
     229        if ($whereparts) {
     230            $where = " AND (" . implode($rule, $whereparts) . ")";
     231        } else {
     232            $where = '';
    238233        }
    239234        return array($join, $where, $params);
  • moodle/trunk/fuentes/badges/criteria_action.php

    r136 r1331  
    6262
    6363if ($delete && has_capability('moodle/badges:configurecriteria', $context)) {
     64    if ($type == BADGE_CRITERIA_TYPE_OVERALL) {
     65        redirect($return, get_string('error:cannotdeletecriterion', 'badges'));
     66    }
    6467    if (!$confirm) {
    6568        $optionsyes = array('confirm' => 1, 'sesskey' => sesskey(), 'badgeid' => $badgeid, 'delete' => true, 'type' => $type);
  • moodle/trunk/fuentes/badges/criteria_form.php

    r136 r1331  
    5656                $mform->addElement('submit', 'cancel', get_string('continue'));
    5757            } else {
     58                $mform->addElement('header', 'description_header', get_string('description'));
     59                $mform->addElement('editor', 'description', '', null, null);
     60                $mform->setType('description', PARAM_RAW);
     61                $mform->setDefault('description', array(
     62                        'text' => $criteria->description,
     63                        'format' => $criteria->descriptionformat
     64                    )
     65                );
     66
    5867                $mform->closeHeaderBefore('buttonar');
    5968                $this->add_action_buttons(true, get_string('save', 'badges'));
     
    7079        $addcourse = $this->_customdata['addcourse'];
    7180
    72         if (!$addcourse) {
     81        if (!$addcourse && isset($this->_customdata['criteria']->required_param)) {
    7382            $required = $this->_customdata['criteria']->required_param;
    7483            $pattern1 = '/^' . $required . '_(\d+)$/';
  • moodle/trunk/fuentes/badges/criteria_settings.php

    r136 r1331  
    6666}
    6767
     68$urlparams = array('badgeid' => $badgeid, 'edit' => $edit, 'type' => $type, 'crit' => $crit);
    6869$PAGE->set_context($context);
    69 $PAGE->set_url('/badges/criteria_settings.php');
     70$PAGE->set_url('/badges/criteria_settings.php', $urlparams);
    7071$PAGE->set_heading($badge->name);
    7172$PAGE->set_title($badge->name);
     
    101102        $criteria_overall->save(array('agg' => BADGE_CRITERIA_AGGREGATION_ALL));
    102103    }
    103     $criteria->save($data);
     104    $criteria->save((array)$data);
    104105    $return->param('msg', $msg);
    105106    redirect($return);
  • moodle/trunk/fuentes/badges/lib/backpacklib.php

    r136 r1331  
    6060        }
    6161
     62        $curl->setHeader(array('Accept: application/json', 'Expect:'));
    6263        $options = array(
    63             'FRESH_CONNECT'  => true,
    64             'RETURNTRANSFER' => true,
    65             'FORBID_REUSE'   => true,
    66             'HEADER'         => 0,
    67             'HTTPHEADER'     => array('Expect:'),
    68             'CONNECTTIMEOUT' => 3,
     64            'FRESH_CONNECT'     => true,
     65            'RETURNTRANSFER'    => true,
     66            'FORBID_REUSE'      => true,
     67            'HEADER'            => 0,
     68            'CONNECTTIMEOUT'    => 3,
     69            // Follow redirects with the same type of request when sent 301, or 302 redirects.
     70            'CURLOPT_POSTREDIR' => 3
    6971        );
    7072
  • moodle/trunk/fuentes/badges/mybackpack.php

    r136 r1331  
    4848$PAGE->set_context($context);
    4949
    50 $title = get_string('mybackpack', 'badges');
     50$title = get_string('backpackdetails', 'badges');
    5151$PAGE->set_title($title);
    52 $PAGE->set_heading($title);
     52$PAGE->set_heading(fullname($USER));
    5353$PAGE->set_pagelayout('mydashboard');
    5454
     
    132132
    133133echo $OUTPUT->header();
     134echo $OUTPUT->heading($title);
    134135$form->display();
    135136echo $OUTPUT->footer();
  • moodle/trunk/fuentes/badges/mybadges.php

    r136 r1331  
    2727require_once(dirname(dirname(__FILE__)) . '/config.php');
    2828require_once($CFG->libdir . '/badgeslib.php');
     29require_once($CFG->libdir . '/filelib.php');
    2930
    3031$page        = optional_param('page', 0, PARAM_INT);
     
    7273    $badge = new badge($download);
    7374    $name = str_replace(' ', '_', $badge->name) . '.png';
    74     ob_start();
    75     $file = badges_bake($hash, $download);
    76     header('Content-Type: image/png');
    77     header('Content-Disposition: attachment; filename="'. $name .'"');
    78     readfile($file);
    79     ob_flush();
     75    $filehash = badges_bake($hash, $download, $USER->id, true);
     76    $fs = get_file_storage();
     77    $file = $fs->get_file_by_hash($filehash);
     78    send_stored_file($file, 0, 0, true, array('filename' => $name));
    8079} else if ($downloadall) {
    8180    require_sesskey();
    82     ob_start();
    8381    badges_download($USER->id);
    84     ob_flush();
    8582}
    8683
     
    9087$PAGE->set_context($context);
    9188
    92 $title = get_string('mybadges', 'badges');
     89$title = get_string('badges', 'badges');
    9390$PAGE->set_title($title);
    94 $PAGE->set_heading($title);
     91$PAGE->set_heading(fullname($USER));
    9592$PAGE->set_pagelayout('mydashboard');
    9693
  • moodle/trunk/fuentes/badges/newbadge.php

    r136 r1331  
    9292    $fordb->messagesubject = get_string('messagesubject', 'badges');
    9393    $fordb->message = get_string('messagebody', 'badges',
    94             html_writer::link($CFG->wwwroot . '/badges/mybadges.php', get_string('mybadges', 'badges')));
     94            html_writer::link($CFG->wwwroot . '/badges/mybadges.php', get_string('managebadges', 'badges')));
    9595    $fordb->attachment = 1;
    9696    $fordb->notification = BADGE_MESSAGE_NEVER;
  • moodle/trunk/fuentes/badges/overview.php

    r136 r1331  
    6262$PAGE->navbar->add($badge->name);
    6363
     64require_capability('moodle/badges:viewbadges', $context);
     65
    6466echo $OUTPUT->header();
    6567echo $OUTPUT->heading(print_badge_image($badge, $context, 'small') . ' ' . $badge->name);
  • moodle/trunk/fuentes/badges/preferences.php

    r136 r1331  
    3131
    3232require_login();
    33 $PAGE->set_context(context_system::instance());
     33$PAGE->set_context(context_user::instance($USER->id));
    3434$PAGE->set_url($url);
    3535$PAGE->set_pagelayout('standard');
     
    4848
    4949if ($mform->is_cancelled()) {
    50     redirect($CFG->wwwroot . '/badges/mybadges.php');
     50    redirect($CFG->wwwroot . '/user/preferences.php');
    5151}
    5252
     
    5656$title = "$strbadges: $strpreferences";
    5757$PAGE->set_title($title);
    58 $PAGE->set_heading($title);
     58$PAGE->set_heading(fullname($USER));
    5959
    6060echo $OUTPUT->header();
  • moodle/trunk/fuentes/badges/renderer.php

    r136 r1331  
    141141        $dl[get_string('name')] = $badge->name;
    142142        $dl[get_string('description', 'badges')] = $badge->description;
    143         $dl[get_string('createdon', 'search')] = $badge->timecreated;
     143        $dl[get_string('createdon', 'search')] = userdate($badge->timecreated);
    144144        $dl[get_string('badgeimage', 'badges')] = print_badge_image($badge, $context, 'large');
    145145        $display .= $this->definition_list($dl);
     
    480480
    481481        // Local badges.
    482         $localhtml = html_writer::start_tag('fieldset', array('id' => 'issued-badge-table', 'class' => 'generalbox'));
     482        $localhtml = html_writer::start_tag('div', array('id' => 'issued-badge-table', 'class' => 'generalbox'));
    483483        $heading = get_string('localbadges', 'badges', format_string($SITE->fullname, true, array('context' => context_system::instance())));
    484         $localhtml .= html_writer::tag('legend', $this->output->heading_with_help($heading, 'localbadgesh', 'badges'));
     484        $localhtml .= $this->output->heading_with_help($heading, 'localbadgesh', 'badges');
    485485        if ($badges->badges) {
    486486            $downloadbutton = $this->output->heading(get_string('badgesearned', 'badges', $badges->totalcount), 4, 'activatebadge');
     
    492492            $localhtml .= $searchform . $this->output->notification(get_string('nobadges', 'badges'));
    493493        }
    494         $localhtml .= html_writer::end_tag('fieldset');
     494        $localhtml .= html_writer::end_tag('div');
    495495
    496496        // External badges.
    497497        $externalhtml = "";
    498498        if (!empty($CFG->badges_allowexternalbackpack)) {
    499             $externalhtml .= html_writer::start_tag('fieldset', array('class' => 'generalbox'));
    500             $externalhtml .= html_writer::tag('legend', $this->output->heading_with_help(get_string('externalbadges', 'badges'), 'externalbadges', 'badges'));
     499            $externalhtml .= html_writer::start_tag('div', array('class' => 'generalbox'));
     500            $externalhtml .= $this->output->heading_with_help(get_string('externalbadges', 'badges'), 'externalbadges', 'badges');
    501501            if (!is_null($backpack)) {
    502502                if ($backpack->totalcollections == 0) {
     
    514514            }
    515515
    516             $externalhtml .= html_writer::end_tag('fieldset');
     516            $externalhtml .= html_writer::end_tag('div');
    517517        }
    518518
     
    705705    }
    706706
    707     // Prints badge criteria.
     707    /**
     708     * Returns information about badge criteria in a list form.
     709     *
     710     * @param badge $badge Badge objects
     711     * @param string $short Indicates whether to print full info about this badge
     712     * @return string $output HTML string to output
     713     */
    708714    public function print_badge_criteria(badge $badge, $short = '') {
    709         $output = "";
    710715        $agg = $badge->get_aggregation_methods();
    711716        if (empty($badge->criteria)) {
    712717            return get_string('nocriteria', 'badges');
    713         } else if (count($badge->criteria) == 2) {
     718        }
     719
     720        $overalldescr = '';
     721        $overall = $badge->criteria[BADGE_CRITERIA_TYPE_OVERALL];
     722        if (!$short && !empty($overall->description)) {
     723            $overalldescr = $this->output->box(
     724                format_text($overall->description, $overall->descriptionformat, array('context' => $badge->get_context())),
     725                'criteria-description'
     726                );
     727        }
     728
     729        // Get the condition string.
     730        if (count($badge->criteria) == 2) {
     731            $condition = '';
    714732            if (!$short) {
    715                 $output .= get_string('criteria_descr', 'badges');
     733                $condition = get_string('criteria_descr', 'badges');
    716734            }
    717735        } else {
    718             $output .= get_string('criteria_descr_' . $short . BADGE_CRITERIA_TYPE_OVERALL, 'badges',
    719                                     core_text::strtoupper($agg[$badge->get_aggregation_method()]));
    720         }
     736            $condition = get_string('criteria_descr_' . $short . BADGE_CRITERIA_TYPE_OVERALL, 'badges',
     737                                      core_text::strtoupper($agg[$badge->get_aggregation_method()]));
     738        }
     739
     740        unset($badge->criteria[BADGE_CRITERIA_TYPE_OVERALL]);
     741
    721742        $items = array();
    722         unset($badge->criteria[BADGE_CRITERIA_TYPE_OVERALL]);
    723         foreach ($badge->criteria as $type => $c) {
     743        // If only one criterion left, make sure its description goe to the top.
     744        if (count($badge->criteria) == 1) {
     745            $c = reset($badge->criteria);
     746            if (!$short && !empty($c->description)) {
     747                $overalldescr = $this->output->box(
     748                    format_text($c->description, $c->descriptionformat, array('context' => $badge->get_context())),
     749                    'criteria-description'
     750                    );
     751            }
    724752            if (count($c->params) == 1) {
    725                 $items[] = get_string('criteria_descr_single_' . $short . $type , 'badges') . $c->get_details($short);
    726             } else {
    727                 $items[] = get_string('criteria_descr_' . $short . $type , 'badges',
    728                         core_text::strtoupper($agg[$badge->get_aggregation_method($type)])) . $c->get_details($short);
    729             }
    730         }
    731         $output .= html_writer::alist($items, array(), 'ul');
    732         return $output;
     753                $items[] = get_string('criteria_descr_single_' . $short . $c->criteriatype , 'badges') .
     754                           $c->get_details($short);
     755            } else {
     756                $items[] = get_string('criteria_descr_' . $short . $c->criteriatype, 'badges',
     757                        core_text::strtoupper($agg[$badge->get_aggregation_method($c->criteriatype)])) .
     758                        $c->get_details($short);
     759            }
     760        } else {
     761            foreach ($badge->criteria as $type => $c) {
     762                $criteriadescr = '';
     763                if (!$short && !empty($c->description)) {
     764                    $criteriadescr = $this->output->box(
     765                        format_text($c->description, $c->descriptionformat, array('context' => $badge->get_context())),
     766                        'criteria-description'
     767                        );
     768                }
     769                if (count($c->params) == 1) {
     770                    $items[] = get_string('criteria_descr_single_' . $short . $type , 'badges') .
     771                               $c->get_details($short) . $criteriadescr;
     772                } else {
     773                    $items[] = get_string('criteria_descr_' . $short . $type , 'badges',
     774                            core_text::strtoupper($agg[$badge->get_aggregation_method($type)])) .
     775                            $c->get_details($short) .
     776                            $criteriadescr;
     777                }
     778            }
     779        }
     780
     781        return $overalldescr . $condition . html_writer::alist($items, array(), 'ul');;
    733782    }
    734783
    735784    // Prints criteria actions for badge editing.
    736785    public function print_criteria_actions(badge $badge) {
    737         $table = new html_table();
    738         $table->attributes = array('class' => 'boxaligncenter', 'id' => 'badgeactions');
    739         $table->colclasses = array('activatebadge');
    740 
    741         $actions = array();
     786        $output = '';
    742787        if (!$badge->is_active() && !$badge->is_locked()) {
    743788            $accepted = $badge->get_accepted_criteria();
     
    750795                    }
    751796                }
    752                 $actions[] = get_string('addbadgecriteria', 'badges');
    753                 $actions[] = $this->output->single_select(new moodle_url('/badges/criteria_settings.php',
    754                         array('badgeid' => $badge->id, 'add' => true)), 'type', $select);
    755             } else {
    756                 $actions[] = $this->output->box(get_string('nothingtoadd', 'badges'), 'clearfix');
    757             }
    758         }
    759 
    760         $table->data[] = $actions;
    761         return html_writer::table($table);
     797                $output .= $this->output->single_select(
     798                    new moodle_url('/badges/criteria_settings.php', array('badgeid' => $badge->id, 'add' => true)),
     799                    'type',
     800                    $select,
     801                    '',
     802                    array('' => 'choosedots'),
     803                    null,
     804                    array('label' => get_string('addbadgecriteria', 'badges'))
     805                );
     806            } else {
     807                $output .= $this->output->box(get_string('nothingtoadd', 'badges'), 'clearfix');
     808            }
     809        }
     810
     811        return $output;
    762812    }
    763813
  • moodle/trunk/fuentes/badges/tests/badgeslib_test.php

    r136 r1331  
    2929global $CFG;
    3030require_once($CFG->libdir . '/badgeslib.php');
     31require_once($CFG->dirroot . '/badges/lib.php');
    3132
    3233class core_badges_badgeslib_testcase extends advanced_testcase {
     
    4142        global $DB, $CFG;
    4243        $this->resetAfterTest(true);
    43 
    44         unset_config('noemailever');
    4544
    4645        $CFG->enablecompletion = true;
     
    155154    }
    156155
     156    public function test_add_badge_criteria_description() {
     157        $criteriaoverall = award_criteria::build(array('criteriatype' => BADGE_CRITERIA_TYPE_OVERALL, 'badgeid' => $this->badgeid));
     158        $criteriaoverall->save(array(
     159                'agg' => BADGE_CRITERIA_AGGREGATION_ALL,
     160                'description' => 'Overall description',
     161                'descriptionformat' => FORMAT_HTML
     162        ));
     163
     164        $criteriaprofile = award_criteria::build(array('criteriatype' => BADGE_CRITERIA_TYPE_PROFILE, 'badgeid' => $this->badgeid));
     165        $params = array(
     166                'agg' => BADGE_CRITERIA_AGGREGATION_ALL,
     167                'field_address' => 'address',
     168                'description' => 'Description',
     169                'descriptionformat' => FORMAT_HTML
     170        );
     171        $criteriaprofile->save($params);
     172
     173        $badge = new badge($this->badgeid);
     174        $this->assertEquals('Overall description', $badge->criteria[BADGE_CRITERIA_TYPE_OVERALL]->description);
     175        $this->assertEquals('Description', $badge->criteria[BADGE_CRITERIA_TYPE_PROFILE]->description);
     176    }
     177
    157178    public function test_delete_badge_criteria() {
    158179        $criteria_overall = award_criteria::build(array('criteriatype' => BADGE_CRITERIA_TYPE_OVERALL, 'badgeid' => $this->badgeid));
     
    179200
    180201        $this->assertCount(2, $badge->get_awards());
     202    }
     203
     204    /**
     205     * Test the {@link badges_get_user_badges()} function in lib/badgeslib.php
     206     */
     207    public function test_badges_get_user_badges() {
     208        global $DB;
     209
     210        // Messaging is not compatible with transactions.
     211        $this->preventResetByRollback();
     212
     213        $badges = array();
     214        $user1 = $this->getDataGenerator()->create_user();
     215        $user2 = $this->getDataGenerator()->create_user();
     216
     217        // Record the current time, we need to be precise about a couple of things.
     218        $now = time();
     219        // Create 11 badges with which to test.
     220        for ($i = 1; $i <= 11; $i++) {
     221            // Mock up a badge.
     222            $badge = new stdClass();
     223            $badge->id = null;
     224            $badge->name = "Test badge $i";
     225            $badge->description = "Testing badges $i";
     226            $badge->timecreated = $now - 12;
     227            $badge->timemodified = $now - 12;
     228            $badge->usercreated = $user1->id;
     229            $badge->usermodified = $user1->id;
     230            $badge->issuername = "Test issuer";
     231            $badge->issuerurl = "http://issuer-url.domain.co.nz";
     232            $badge->issuercontact = "issuer@example.com";
     233            $badge->expiredate = null;
     234            $badge->expireperiod = null;
     235            $badge->type = BADGE_TYPE_SITE;
     236            $badge->courseid = null;
     237            $badge->messagesubject = "Test message subject for badge $i";
     238            $badge->message = "Test message body for badge $i";
     239            $badge->attachment = 1;
     240            $badge->notification = 0;
     241            $badge->status = BADGE_STATUS_INACTIVE;
     242
     243            $badgeid = $DB->insert_record('badge', $badge, true);
     244            $badges[$badgeid] = new badge($badgeid);
     245            $badges[$badgeid]->issue($user2->id, true);
     246            // Check it all actually worked.
     247            $this->assertCount(1, $badges[$badgeid]->get_awards());
     248
     249            // Hack the database to adjust the time each badge was issued.
     250            // The alternative to this is sleep which is a no-no in unit tests.
     251            $DB->set_field('badge_issued', 'dateissued', $now - 11 + $i, array('userid' => $user2->id, 'badgeid' => $badgeid));
     252        }
     253
     254        // Make sure the first user has no badges.
     255        $result = badges_get_user_badges($user1->id);
     256        $this->assertInternalType('array', $result);
     257        $this->assertCount(0, $result);
     258
     259        // Check that the second user has the expected 11 badges.
     260        $result = badges_get_user_badges($user2->id);
     261        $this->assertCount(11, $result);
     262
     263        // Test pagination.
     264        // Ordering is by time issued desc, so things will come out with the last awarded badge first.
     265        $result = badges_get_user_badges($user2->id, 0, 0, 4);
     266        $this->assertCount(4, $result);
     267        $lastbadgeissued = reset($result);
     268        $this->assertSame('Test badge 11', $lastbadgeissued->name);
     269        // Page 2. Expecting 4 results again.
     270        $result = badges_get_user_badges($user2->id, 0, 1, 4);
     271        $this->assertCount(4, $result);
     272        $lastbadgeissued = reset($result);
     273        $this->assertSame('Test badge 7', $lastbadgeissued->name);
     274        // Page 3. Expecting just three results here.
     275        $result = badges_get_user_badges($user2->id, 0, 2, 4);
     276        $this->assertCount(3, $result);
     277        $lastbadgeissued = reset($result);
     278        $this->assertSame('Test badge 3', $lastbadgeissued->name);
     279        // Page 4.... there is no page 4.
     280        $result = badges_get_user_badges($user2->id, 0, 3, 4);
     281        $this->assertCount(0, $result);
     282
     283        // Test search.
     284        $result = badges_get_user_badges($user2->id, 0, 0, 0, 'badge 1');
     285        $this->assertCount(3, $result);
     286        $lastbadgeissued = reset($result);
     287        $this->assertSame('Test badge 11', $lastbadgeissued->name);
     288        // The term Totara doesn't appear anywhere in the badges.
     289        $result = badges_get_user_badges($user2->id, 0, 0, 0, 'Totara');
     290        $this->assertCount(0, $result);
    181291    }
    182292
     
    236346        $criteria_overall->save(array('agg' => BADGE_CRITERIA_AGGREGATION_ANY, 'module_'.$this->module->cmid => $this->module->cmid));
    237347
     348        // Assert the badge will not be issued to the user as is.
     349        $badge = new badge($this->coursebadge);
     350        $badge->review_all_criteria();
     351        $this->assertFalse($badge->is_issued($this->user->id));
     352
    238353        // Set completion for forum activity.
    239354        $c = new completion_info($this->course);
     
    271386        $ccompletion = new completion_completion(array('course' => $this->course->id, 'userid' => $this->user->id));
    272387
     388        // Assert the badge will not be issued to the user as is.
     389        $badge = new badge($this->coursebadge);
     390        $badge->review_all_criteria();
     391        $this->assertFalse($badge->is_issued($this->user->id));
     392
    273393        // Mark course as complete.
    274394        $sink = $this->redirectEmails();
     
    286406     */
    287407    public function test_badges_observer_profile_criteria_review() {
     408        global $CFG, $DB;
     409        require_once($CFG->dirroot.'/user/profile/lib.php');
     410
     411        // Add a custom field of textarea type.
     412        $customprofileid = $DB->insert_record('user_info_field', array(
     413            'shortname' => 'newfield', 'name' => 'Description of new field', 'categoryid' => 1,
     414            'datatype' => 'textarea'));
     415
    288416        $this->preventResetByRollback(); // Messaging is not compatible with transactions.
    289417        $badge = new badge($this->coursebadge);
    290         $this->assertFalse($badge->is_issued($this->user->id));
    291418
    292419        $criteria_overall = award_criteria::build(array('criteriatype' => BADGE_CRITERIA_TYPE_OVERALL, 'badgeid' => $badge->id));
    293420        $criteria_overall->save(array('agg' => BADGE_CRITERIA_AGGREGATION_ANY));
    294421        $criteria_overall1 = award_criteria::build(array('criteriatype' => BADGE_CRITERIA_TYPE_PROFILE, 'badgeid' => $badge->id));
    295         $criteria_overall1->save(array('agg' => BADGE_CRITERIA_AGGREGATION_ALL, 'field_address' => 'address', 'field_aim' => 'aim'));
    296 
     422        $criteria_overall1->save(array('agg' => BADGE_CRITERIA_AGGREGATION_ALL, 'field_address' => 'address', 'field_aim' => 'aim',
     423            'field_' . $customprofileid => $customprofileid));
     424
     425        // Assert the badge will not be issued to the user as is.
     426        $badge = new badge($this->coursebadge);
     427        $badge->review_all_criteria();
     428        $this->assertFalse($badge->is_issued($this->user->id));
     429
     430        // Set the required fields and make sure the badge got issued.
    297431        $this->user->address = 'Test address';
    298432        $this->user->aim = '999999999';
    299433        $sink = $this->redirectEmails();
     434        profile_save_data((object)array('id' => $this->user->id, 'profile_field_newfield' => 'X'));
    300435        user_update_user($this->user, false);
    301436        $this->assertCount(1, $sink->get_messages());
     
    339474        $this->assertStringMatchesFormat($testassertion->issuer, json_encode($assertion->get_issuer()));
    340475    }
     476
     477    /**
     478     * Tests the core_badges_myprofile_navigation() function.
     479     */
     480    public function test_core_badges_myprofile_navigation() {
     481        // Set up the test.
     482        $tree = new \core_user\output\myprofile\tree();
     483        $this->setAdminUser();
     484        $badge = new badge($this->badgeid);
     485        $badge->issue($this->user->id, true);
     486        $iscurrentuser = true;
     487        $course = null;
     488
     489        // Enable badges.
     490        set_config('enablebadges', true);
     491
     492        // Check the node tree is correct.
     493        core_badges_myprofile_navigation($tree, $this->user, $iscurrentuser, $course);
     494        $reflector = new ReflectionObject($tree);
     495        $nodes = $reflector->getProperty('nodes');
     496        $nodes->setAccessible(true);
     497        $this->assertArrayHasKey('localbadges', $nodes->getValue($tree));
     498    }
     499
     500    /**
     501     * Tests the core_badges_myprofile_navigation() function with badges disabled..
     502     */
     503    public function test_core_badges_myprofile_navigation_badges_disabled() {
     504        // Set up the test.
     505        $tree = new \core_user\output\myprofile\tree();
     506        $this->setAdminUser();
     507        $badge = new badge($this->badgeid);
     508        $badge->issue($this->user->id, true);
     509        $iscurrentuser = false;
     510        $course = null;
     511
     512        // Disable badges.
     513        set_config('enablebadges', false);
     514
     515        // Check the node tree is correct.
     516        core_badges_myprofile_navigation($tree, $this->user, $iscurrentuser, $course);
     517        $reflector = new ReflectionObject($tree);
     518        $nodes = $reflector->getProperty('nodes');
     519        $nodes->setAccessible(true);
     520        $this->assertArrayNotHasKey('localbadges', $nodes->getValue($tree));
     521    }
     522
     523    /**
     524     * Tests the core_badges_myprofile_navigation() function with a course badge.
     525     */
     526    public function test_core_badges_myprofile_navigation_with_course_badge() {
     527        // Set up the test.
     528        $tree = new \core_user\output\myprofile\tree();
     529        $this->setAdminUser();
     530        $badge = new badge($this->coursebadge);
     531        $badge->issue($this->user->id, true);
     532        $iscurrentuser = false;
     533
     534        // Check the node tree is correct.
     535        core_badges_myprofile_navigation($tree, $this->user, $iscurrentuser, $this->course);
     536        $reflector = new ReflectionObject($tree);
     537        $nodes = $reflector->getProperty('nodes');
     538        $nodes->setAccessible(true);
     539        $this->assertArrayHasKey('localbadges', $nodes->getValue($tree));
     540    }
    341541}
  • moodle/trunk/fuentes/badges/tests/behat/add_badge.feature

    r136 r1331  
    1313    Given I navigate to "Badges settings" node in "Site administration > Badges"
    1414    And I set the field "Default badge issuer name" to "Test Badge Site"
    15     And I set the field "Default badge issuer contact details" to "testuser@test-badge-site.com"
     15    And I set the field "Default badge issuer contact details" to "testuser@example.com"
    1616    And I press "Save changes"
    1717    When I follow "Add a new badge"
    18     Then the field "issuercontact" matches value "testuser@test-badge-site.com"
     18    Then the field "issuercontact" matches value "testuser@example.com"
    1919    And the field "issuername" matches value "Test Badge Site"
    2020
     
    3131      | Description | Test badge description |
    3232      | issuername | Test Badge Site |
    33       | issuercontact | testuser@test-badge-site.com |
     33      | issuercontact | testuser@example.com |
    3434    And I upload "badges/tests/behat/badge.png" file to "Image" filemanager
    3535    When I press "Create badge"
  • moodle/trunk/fuentes/badges/tests/behat/award_badge.feature

    r136 r1331  
    1313      | Description | Test badge description |
    1414      | issuername | Test Badge Site |
    15       | issuercontact | testuser@test-badge-site.com |
     15      | issuercontact | testuser@example.com |
    1616    And I upload "badges/tests/behat/badge.png" file to "Image" filemanager
    1717    And I press "Create badge"
    1818    And I set the field "type" to "Profile completion"
     19    And I expand all fieldsets
    1920    And I set the field "First name" to "1"
    2021    And I set the field "Email address" to "1"
    2122    And I set the field "Phone" to "1"
     23    And I set the field "id_description" to "Criterion description"
    2224    When I press "Save"
    2325    Then I should see "Profile completion"
    2426    And I should see "First name"
    2527    And I should see "Email address"
     28    And I should see "Phone"
     29    And I should see "Criterion description"
    2630    And I should not see "Criteria for this badge have not been set up yet."
    2731    And I press "Enable access"
    2832    And I press "Continue"
    29     And I expand "My profile settings" node
     33    And I click on "Admin User" "link"
     34    And I follow "Profile" in the open menu
    3035    And I follow "Edit profile"
    3136    And I expand all fieldsets
    3237    And I set the field "Phone" to "123456789"
    3338    And I press "Update profile"
    34     And I navigate to "My badges" node in "My profile"
     39    And I follow "Profile" in the user menu
    3540    Then I should see "Profile Badge"
    3641    And I should not see "There are no badges available."
     
    4045    Given the following "users" exist:
    4146      | username | firstname | lastname | email |
    42       | teacher | teacher | 1 | teacher1@asd.com |
    43       | student | student | 1 | student1@asd.com |
     47      | teacher | teacher | 1 | teacher1@example.com |
     48      | student | student | 1 | student1@example.com |
    4449    And I log in as "admin"
    4550    And I navigate to "Add a new badge" node in "Site administration > Badges"
     
    5762    And I follow "Recipients (0)"
    5863    And I press "Award badge"
    59     And I set the field "potentialrecipients[]" to "teacher 1 (teacher1@asd.com)"
    60     And I press "Award badge"
    61     And I set the field "potentialrecipients[]" to "student 1 (student1@asd.com)"
     64    And I set the field "potentialrecipients[]" to "teacher 1 (teacher1@example.com)"
     65    And I press "Award badge"
     66    And I set the field "potentialrecipients[]" to "student 1 (student1@example.com)"
    6267    And I press "Award badge"
    6368    When I follow "Site Badge"
     
    6570    And I log out
    6671    And I log in as "student"
    67     And I navigate to "My badges" node in "My profile"
     72    And I follow "Profile" in the user menu
    6873    Then I should see "Site Badge"
    6974
     
    7277    Given the following "users" exist:
    7378      | username | firstname | lastname | email |
    74       | teacher1 | Teacher | 1 | teacher1@asd.com |
    75       | student1 | Student | 1 | student1@asd.com |
    76       | student2 | Student | 2 | student2@asd.com |
     79      | teacher1 | Teacher | 1 | teacher1@example.com |
     80      | student1 | Student | 1 | student1@example.com |
     81      | student2 | Student | 2 | student2@example.com |
    7782    And the following "courses" exist:
    7883      | fullname | shortname | category | groupmode |
     
    100105    And I follow "Recipients (0)"
    101106    And I press "Award badge"
    102     And I set the field "potentialrecipients[]" to "Student 2 (student2@asd.com)"
    103     And I press "Award badge"
    104     And I set the field "potentialrecipients[]" to "Student 1 (student1@asd.com)"
     107    And I set the field "potentialrecipients[]" to "Student 2 (student2@example.com)"
     108    And I press "Award badge"
     109    And I set the field "potentialrecipients[]" to "Student 1 (student1@example.com)"
    105110    When I press "Award badge"
    106111    And I follow "Course Badge"
     
    108113    And I log out
    109114    And I log in as "student1"
    110     And I follow "Course 1"
    111     And I navigate to "My badges" node in "My profile"
    112     Then I should see "Course Badge"
     115    And I follow "Profile" in the user menu
     116    And I follow "Course 1"
     117    And I should see "Course Badge"
    113118
    114119  @javascript
     
    119124    And the following "users" exist:
    120125      | username | firstname | lastname | email |
    121       | teacher1 | Teacher | Frist | teacher1@asd.com |
    122       | student1 | Student | First | student1@asd.com |
     126      | teacher1 | Teacher | Frist | teacher1@example.com |
     127      | student1 | Student | First | student1@example.com |
    123128    And the following "course enrolments" exist:
    124129      | user | course | role |
    125130      | teacher1 | C1 | editingteacher |
    126131      | student1 | C1 | student |
    127     And I log in as "admin"
    128     And I set the following administration settings values:
    129       | Enable completion tracking | 1 |
    130     And I follow "Home"
     132    And the following config values are set as admin:
     133      | enablecompletion | 1 |
     134    And I log in as "teacher1"
    131135    And I follow "Course 1"
    132136    And I follow "Edit settings"
    133137    And I set the following fields to these values:
    134138      | Enable completion tracking | Yes |
    135     And I press "Save changes"
     139    And I press "Save and display"
    136140    And I turn editing mode on
    137141    And I add a "Assignment" to section "1" and I fill the form with:
    138142      | Assignment name | Test assignment name |
    139143      | Description | Submit your online text |
    140     And I log out
    141     And I log in as "teacher1"
    142144    And I follow "Course 1"
    143145    And I navigate to "Add a new badge" node in "Course administration > Badges"
     
    156158    And I log out
    157159    And I log in as "student1"
    158     And I follow "Course 1"
    159     And I navigate to "My badges" node in "My profile"
    160     Then I should see "There are no badges available."
    161     And I follow "Home"
     160    And I follow "Profile" in the user menu
     161    And I follow "Course 1"
     162    Then I should not see "badges"
     163    And I am on homepage
    162164    And I follow "Course 1"
    163165    And I press "Mark as complete: Test assignment name"
    164     And I navigate to "My badges" node in "My profile"
     166    And I follow "Profile" in the user menu
     167    And I follow "Course 1"
    165168    Then I should see "Course Badge"
    166169
     
    172175    And the following "users" exist:
    173176      | username | firstname | lastname | email |
    174       | teacher1 | Teacher | Frist | teacher1@asd.com |
    175       | student1 | Student | First | student1@asd.com |
     177      | teacher1 | Teacher | Frist | teacher1@example.com |
     178      | student1 | Student | First | student1@example.com |
    176179    And the following "course enrolments" exist:
    177180      | user | course | role |
    178181      | teacher1 | C1 | editingteacher |
    179182      | student1 | C1 | student |
    180     And I log in as "admin"
    181     And I set the following administration settings values:
    182       | Enable completion tracking | 1 |
    183     And I follow "Home"
     183    And the following config values are set as admin:
     184      | enablecompletion | 1 |
     185    And I log in as "teacher1"
    184186    And I follow "Course 1"
    185187    And I follow "Edit settings"
    186188    And I set the following fields to these values:
    187189      | Enable completion tracking | Yes |
    188     And I press "Save changes"
     190    And I press "Save and display"
    189191    And I turn editing mode on
    190192    And I add a "Assignment" to section "1" and I fill the form with:
     
    195197    And I set the field "id_overall_aggregation" to "2"
    196198    And I click on "Condition: Activity completion" "link"
    197     And I set the field "Assign - Test assignment name" to "1"
     199    And I set the field "Assignment - Test assignment name" to "1"
    198200    And I press "Save changes"
    199     And I log out
    200     And I log in as "teacher1"
    201201    And I follow "Course 1"
    202202    And I navigate to "Add a new badge" node in "Course administration > Badges"
     
    215215    And I log out
    216216    And I log in as "student1"
    217     And I follow "Course 1"
    218     And I navigate to "My badges" node in "My profile"
    219     Then I should see "There are no badges available."
    220     And I follow "Home"
     217    And I follow "Profile" in the user menu
     218    And I follow "Course 1"
     219    Then I should not see "badges"
     220    And I am on homepage
    221221    And I follow "Course 1"
    222222    And I press "Mark as complete: Test assignment name"
    223223    And I log out
    224     And I log in as "admin"
    225     # We can't wait for cron to happen, so the admin manually triggers it.
    226     And I trigger cron
    227     # The admin needs to trigger cron twice to see the completion status as completed.
    228     # We wait more than 1 minute because of the next cron run scheduled time.
    229     And I wait "61" seconds
    230     And I trigger cron
    231     # Finally the admin goes back to homepage to continue the user story.
    232     And I am on homepage
    233     And I log out
    234     And I log in as "student1"
    235     And I navigate to "My badges" node in "My profile"
     224    # Completion cron won't mark the whole course completed unless the
     225    # individual criteria was marked completed more than a second ago. So
     226    # run it twice, first to mark the criteria and second for the course.
     227    And I run the scheduled task "core\task\completion_regular_task"
     228    And I wait "1" seconds
     229    And I run the scheduled task "core\task\completion_regular_task"
     230    # The student should now see their badge.
     231    And I log in as "student1"
     232    And I follow "Profile" in the user menu
    236233    Then I should see "Course Badge"
  • moodle/trunk/fuentes/badges/view.php

    r136 r1331  
    4949
    5050if ($sorthow != 'ASC' && $sorthow != 'DESC') {
    51     $sorthow = 'ACS';
     51    $sorthow = 'ASC';
    5252}
    5353
     
    6363
    6464if ($type == BADGE_TYPE_SITE) {
    65     $title = get_string('sitebadges', 'badges');
    6665    $PAGE->set_context(context_system::instance());
    6766    $PAGE->set_pagelayout('admin');
    68     $PAGE->set_heading($title);
     67    $PAGE->set_heading($SITE->fullname);
     68    $title = get_string('sitebadges', 'badges');
    6969} else {
    7070    require_login($course);
     
    7373    $PAGE->set_context(context_course::instance($course->id));
    7474    $PAGE->set_pagelayout('incourse');
    75     $PAGE->set_heading($title);
     75    $PAGE->set_heading($coursename);
    7676}
     77
     78require_capability('moodle/badges:viewbadges', $PAGE->context);
    7779
    7880$PAGE->set_title($title);
Note: See TracChangeset for help on using the changeset viewer.