[ Index ]

PHP Cross Reference of moodle-2.8

title

Body

[close]

/badges/criteria/ -> award_criteria_overall.php (source)

   1  <?php
   2  // This file is part of Moodle - http://moodle.org/
   3  //
   4  // Moodle is free software: you can redistribute it and/or modify
   5  // it under the terms of the GNU General Public License as published by
   6  // the Free Software Foundation, either version 3 of the License, or
   7  // (at your option) any later version.
   8  //
   9  // Moodle is distributed in the hope that it will be useful,
  10  // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12  // GNU General Public License for more details.
  13  //
  14  // You should have received a copy of the GNU General Public License
  15  // along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
  16  
  17  /**
  18   * This file contains the overall badge award criteria type
  19   *
  20   * @package    core
  21   * @subpackage badges
  22   * @copyright  2012 onwards Totara Learning Solutions Ltd {@link http://www.totaralms.com/}
  23   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  24   * @author     Yuliya Bozhko <[email protected]>
  25   */
  26  
  27  defined('MOODLE_INTERNAL') || die();
  28  
  29  /**
  30   * Overall badge award criteria
  31   *
  32   */
  33  class award_criteria_overall extends award_criteria {
  34  
  35      /* @var int Criteria [BADGE_CRITERIA_TYPE_OVERALL] */
  36      public $criteriatype = BADGE_CRITERIA_TYPE_OVERALL;
  37  
  38      /**
  39       * Add appropriate form elements to the criteria form
  40       *
  41       * @param stdClass $data details of overall criterion
  42       */
  43      public function config_form_criteria($data) {
  44          global $OUTPUT;
  45          $prefix = 'criteria-' . $this->id;
  46          if (count($data->criteria) > 2) {
  47              echo $OUTPUT->box_start();
  48              echo $OUTPUT->heading($this->get_title(), 2);
  49  
  50              $agg = $data->get_aggregation_methods();
  51              if (!$data->is_locked() && !$data->is_active()) {
  52                  $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);
  61              } else {
  62                  echo $OUTPUT->box(get_string('criteria_descr_' . $this->criteriatype, 'badges',
  63                          core_text::strtoupper($agg[$data->get_aggregation_method()])), 'clearfix');
  64              }
  65              echo $OUTPUT->box_end();
  66          }
  67      }
  68  
  69      /**
  70       * Add appropriate parameter elements to the criteria form
  71       *
  72       */
  73      public function config_options(&$mform, $param) {
  74      }
  75  
  76      /**
  77       * Get criteria details for displaying to users
  78       *
  79       * @return string
  80       */
  81      public function get_details($short = '') {
  82      }
  83  
  84      /**
  85       * Review this criteria and decide if it has been completed
  86       * Overall criteria review should be called only from other criteria handlers.
  87       *
  88       * @param int $userid User whose criteria completion needs to be reviewed.
  89       * @param bool $filtered An additional parameter indicating that user list
  90       *        has been reduced and some expensive checks can be skipped.
  91       *
  92       * @return bool Whether criteria is complete
  93       */
  94      public function review($userid, $filtered = false) {
  95          global $DB;
  96  
  97          $sql = "SELECT bc.*, bcm.critid, bcm.userid, bcm.datemet
  98                  FROM {badge_criteria} bc
  99                  LEFT JOIN {badge_criteria_met} bcm
 100                      ON bc.id = bcm.critid AND bcm.userid = :userid
 101                  WHERE bc.badgeid = :badgeid
 102                      AND bc.criteriatype != :criteriatype ";
 103  
 104          $params = array(
 105                      'userid' => $userid,
 106                      'badgeid' => $this->badgeid,
 107                      'criteriatype' => BADGE_CRITERIA_TYPE_OVERALL
 108                  );
 109  
 110          $criteria = $DB->get_records_sql($sql, $params);
 111          $overall = false;
 112          foreach ($criteria as $crit) {
 113              if ($this->method == BADGE_CRITERIA_AGGREGATION_ALL) {
 114                  if ($crit->datemet === null) {
 115                      return false;
 116                  } else {
 117                      $overall = true;
 118                      continue;
 119                  }
 120              } else {
 121                  if ($crit->datemet === null) {
 122                      $overall = false;
 123                      continue;
 124                  } else {
 125                      return true;
 126                  }
 127              }
 128          }
 129  
 130          return $overall;
 131      }
 132  
 133      /**
 134       * Returns array with sql code and parameters returning all ids
 135       * of users who meet this particular criterion.
 136       *
 137       * @return array list($join, $where, $params)
 138       */
 139      public function get_completed_criteria_sql() {
 140          return array('', '', array());
 141      }
 142  
 143      /**
 144       * Add appropriate criteria elements to the form
 145       *
 146       */
 147      public function get_options(&$mform) {
 148      }
 149  
 150      /**
 151       * Return criteria parameters
 152       *
 153       * @param int $critid Criterion ID
 154       * @return array
 155       */
 156      public function get_params($cid) {
 157      }
 158  }


Generated: Fri Nov 28 20:29:05 2014 Cross-referenced by PHPXref 0.7.1