Proyectos de Subversion Moodle

Rev

Rev 1 | Mostrar el archivo completo | | | Autoría | Ultima modificación | Ver Log |

Rev 1 Rev 1441
Línea 12... Línea 12...
12
// GNU General Public License for more details.
12
// GNU General Public License for more details.
13
//
13
//
14
// You should have received a copy of the GNU General Public License
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/>.
15
// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
Línea 16... Línea -...
16
 
-
 
17
/**
-
 
18
 * Contains class \core\output\inplace_editable
-
 
19
 *
-
 
20
 * @package    core
-
 
21
 * @category   output
-
 
22
 * @copyright  2016 Marina Glancy
-
 
23
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
-
 
24
 */
-
 
25
 
16
 
Línea 26... Línea -...
26
namespace core\output;
-
 
27
 
-
 
28
use templatable;
17
namespace core\output;
29
use renderable;
-
 
Línea 30... Línea 18...
30
use lang_string;
18
 
31
use pix_icon;
19
use lang_string;
32
 
20
 
33
/**
21
/**
Línea 50... Línea 38...
50
 * @package    core
38
 * @package    core
51
 * @category   output
39
 * @category   output
52
 * @copyright  2016 Marina Glancy
40
 * @copyright  2016 Marina Glancy
53
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
41
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
54
 */
42
 */
55
class inplace_editable implements templatable, renderable {
43
class inplace_editable implements renderable, templatable {
56
 
-
 
57
    /**
44
    /**
58
     * @var string component responsible for diplsying/updating
45
     * @var string component responsible for diplsying/updating
59
     */
46
     */
60
    protected $component = null;
47
    protected $component = null;
Línea 112... Línea 99...
112
 
99
 
113
    /**
100
    /**
114
     * Constructor.
101
     * Constructor.
115
     *
102
     *
-
 
103
     * @param string $component name of the component or plugin responsible for the updating of the value (must declare callback)
116
     * @param string $component name of the component or plugin responsible for the updating of the value (must declare callback)
104
     * @param string $itemtype type of the item inside the component
117
     * @param string $itemtype type of the item inside the component - each component/plugin may implement multiple inplace-editable elements
105
     *                         Each component/plugin may implement multiple inplace-editable elements.
118
     * @param int $itemid identifier of the item that can be edited in-place
106
     * @param int $itemid identifier of the item that can be edited in-place
119
     * @param bool $editable whether this value is editable (check capabilities and editing mode), if false, only "displayvalue"
107
     * @param bool $editable whether this value is editable (check capabilities and editing mode), if false, only "displayvalue"
120
     *              will be displayed without anything else
108
     *              will be displayed without anything else
121
     * @param string $displayvalue what needs to be displayed to the user, it must be cleaned, with applied filters (call
109
     * @param string $displayvalue what needs to be displayed to the user, it must be cleaned, with applied filters (call
122
     *              {@link format_string()}). It may be wrapped in an html link, contain icons or other decorations
110
     *              {@link format_string()}). It may be wrapped in an html link, contain icons or other decorations
123
     * @param string $value what needs to be edited - usually raw value from the database, it may contain multilang tags
111
     * @param string $value what needs to be edited - usually raw value from the database, it may contain multilang tags
124
     * @param lang_string|string $edithint hint (title) that will be displayed under the edit link
112
     * @param lang_string|string $edithint hint (title) that will be displayed under the edit link
125
     * @param lang_string|string $editlabel label for the input element in the editing mode (for screenreaders)
113
     * @param lang_string|string $editlabel label for the input element in the editing mode (for screenreaders)
126
     * @param pix_icon|null $editicon icon to use to toggle editing
114
     * @param pix_icon|null $editicon icon to use to toggle editing
127
     */
115
     */
-
 
116
    public function __construct(
-
 
117
        $component,
-
 
118
        $itemtype,
-
 
119
        $itemid,
-
 
120
        $editable,
-
 
121
        $displayvalue,
-
 
122
        $value = null,
-
 
123
        $edithint = null,
128
    public function __construct($component, $itemtype, $itemid, $editable,
124
        $editlabel = null,
-
 
125
        ?pix_icon $editicon = null
129
            $displayvalue, $value = null, $edithint = null, $editlabel = null, ?pix_icon $editicon = null) {
126
    ) {
130
        $this->component = $component;
127
        $this->component = $component;
131
        $this->itemtype = $itemtype;
128
        $this->itemtype = $itemtype;
132
        $this->itemid = $itemid;
129
        $this->itemid = $itemid;
133
        $this->editable = $editable;
130
        $this->editable = $editable;
Línea 149... Línea 146...
149
     * @param array $options toggle options as simple, non-associative array; defaults to array(0,1)
146
     * @param array $options toggle options as simple, non-associative array; defaults to array(0,1)
150
     * @return self
147
     * @return self
151
     */
148
     */
152
    public function set_type_toggle($options = null) {
149
    public function set_type_toggle($options = null) {
153
        if ($options === null) {
150
        if ($options === null) {
154
            $options = array(0, 1);
151
            $options = [0, 1];
155
        }
152
        }
156
        $options = array_values($options);
153
        $options = array_values($options);
157
        $idx = array_search($this->value, $options, true);
154
        $idx = array_search($this->value, $options, true);
158
        if ($idx === false) {
155
        if ($idx === false) {
159
            throw new \coding_exception('Specified value must be one of the toggle options');
156
            throw new \coding_exception('Specified value must be one of the toggle options');
Línea 246... Línea 243...
246
     * @param \renderer_base $output typically, the renderer that's calling this function
243
     * @param \renderer_base $output typically, the renderer that's calling this function
247
     * @return array data context for a mustache template
244
     * @return array data context for a mustache template
248
     */
245
     */
249
    public function export_for_template(\renderer_base $output) {
246
    public function export_for_template(\renderer_base $output) {
250
        if (!$this->editable) {
247
        if (!$this->editable) {
251
            return array(
248
            return [
252
                'displayvalue' => (string)$this->displayvalue
249
                'displayvalue' => (string)$this->displayvalue,
253
            );
250
            ];
254
        }
251
        }
Línea 255... Línea 252...
255
 
252
 
256
        if ($this->editicon === null) {
253
        if ($this->editicon === null) {
257
            $this->editicon = new pix_icon('t/editstring', (string) $this->edithint);
254
            $this->editicon = new pix_icon('t/editstring', (string) $this->edithint);
Línea 258... Línea 255...
258
        }
255
        }
259
 
256
 
260
        return array(
257
        return [
261
            'component' => $this->component,
258
            'component' => $this->component,
262
            'itemtype' => $this->itemtype,
259
            'itemtype' => $this->itemtype,
263
            'itemid' => $this->itemid,
260
            'itemid' => $this->itemid,
Línea 267... Línea 264...
267
            'editlabel' => (string)$this->editlabel,
264
            'editlabel' => (string)$this->editlabel,
268
            'editicon' => $this->editicon->export_for_pix(),
265
            'editicon' => $this->editicon->export_for_pix(),
269
            'type' => $this->type,
266
            'type' => $this->type,
270
            'options' => $this->options,
267
            'options' => $this->options,
271
            'linkeverything' => $this->get_linkeverything() ? 1 : 0,
268
            'linkeverything' => $this->get_linkeverything() ? 1 : 0,
272
        );
269
        ];
273
    }
270
    }
Línea 274... Línea 271...
274
 
271
 
275
    /**
272
    /**
276
     * Renders this element
273
     * Renders this element