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 * Abstract class for a form element representing something about a grade_grade.
19 *
20 * @package   gradereport_singleview
21 * @copyright 2014 Moodle Pty Ltd (http://moodle.com)
22 * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
23 */
24
25namespace gradereport_singleview\local\ui;
26
27defined('MOODLE_INTERNAL') || die;
28
29/**
30 * Abstract class for a form element representing something about a grade_grade.
31 *
32 * @package   gradereport_singleview
33 * @copyright 2014 Moodle Pty Ltd (http://moodle.com)
34 * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
35 */
36abstract class grade_attribute_format extends attribute_format implements unique_name {
37
38    /** @var string $name The first part of the name attribute of the form input */
39    public $name;
40
41    /** @var string $label The label of the input */
42    public $label;
43
44    /** @var grade_grade $grade The grade_grade of the input */
45    public $grade;
46
47    /**
48     * Constructor
49     *
50     * @param grade_grade $grade The grade_grade we are editing.
51     */
52    public function __construct($grade = 0) {
53        $this->grade = $grade;
54    }
55
56    /**
57     * Get a unique name for this form input
58     *
59     * @return string The form input name attribute.
60     */
61    public function get_name() {
62        return "{$this->name}_{$this->grade->itemid}_{$this->grade->userid}";
63    }
64
65    /**
66     * Should be overridden by the child class to save the value returned in this input.
67     *
68     * @param string $value The value from the form.
69     * @return string Any error message
70     */
71    public abstract function set($value);
72}
73