PageRenderTime 72ms CodeModel.GetById 50ms app.highlight 6ms RepoModel.GetById 14ms app.codeStats 0ms

/mod/feedback/item/feedback_item_form_class.php

https://bitbucket.org/synergylearning/campusconnect
PHP | 111 lines | 68 code | 21 blank | 22 comment | 4 complexity | e935ab4c6a72f027381c89c28a1f9edf MD5 | raw file
  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
 17require_once($CFG->libdir.'/formslib.php');
 18
 19define('FEEDBACK_ITEM_NAME_TEXTBOX_SIZE', 80);
 20define('FEEDBACK_ITEM_LABEL_TEXTBOX_SIZE', 20);
 21abstract class feedback_item_form extends moodleform {
 22    public function definition() {
 23        $item = $this->_customdata['item']; //the item object
 24
 25        //common is an array like:
 26        //    array('cmid'=>$cm->id,
 27        //         'id'=>isset($item->id) ? $item->id : NULL,
 28        //         'typ'=>$item->typ,
 29        //         'items'=>$feedbackitems,
 30        //         'feedback'=>$feedback->id);
 31        $common = $this->_customdata['common'];
 32
 33        //positionlist is an array with possible positions for the item location
 34        $positionlist = $this->_customdata['positionlist'];
 35
 36        //the current position of the item
 37        $position = $this->_customdata['position'];
 38
 39        $mform =& $this->_form;
 40
 41        if ($common['items']) {
 42            $mform->addElement('select',
 43                                'dependitem',
 44                                get_string('dependitem', 'feedback').'&nbsp;',
 45                                $common['items']
 46                                );
 47            $mform->addHelpButton('dependitem', 'depending', 'feedback');
 48            $mform->addElement('text',
 49                                'dependvalue',
 50                                get_string('dependvalue', 'feedback'),
 51                                array('size'=>FEEDBACK_ITEM_LABEL_TEXTBOX_SIZE, 'maxlength'=>255));
 52        } else {
 53            $mform->addElement('hidden', 'dependitem', 0);
 54            $mform->addElement('hidden', 'dependvalue', '');
 55        }
 56
 57        $mform->setType('dependitem', PARAM_INT);
 58        $mform->setType('dependvalue', PARAM_RAW);
 59
 60        $position_select = $mform->addElement('select',
 61                                            'position',
 62                                            get_string('position', 'feedback').'&nbsp;',
 63                                            $positionlist);
 64        $position_select->setValue($position);
 65
 66        $mform->addElement('hidden', 'cmid', $common['cmid']);
 67        $mform->setType('cmid', PARAM_INT);
 68
 69        $mform->addElement('hidden', 'id', $common['id']);
 70        $mform->setType('id', PARAM_INT);
 71
 72        $mform->addElement('hidden', 'feedback', $common['feedback']);
 73        $mform->setType('feedback', PARAM_INT);
 74
 75        $mform->addElement('hidden', 'template', 0);
 76        $mform->setType('template', PARAM_INT);
 77
 78        $mform->setType('name', PARAM_RAW);
 79        $mform->setType('label', PARAM_ALPHANUM);
 80
 81        $mform->addElement('hidden', 'typ', $this->type);
 82        $mform->setType('typ', PARAM_ALPHA);
 83
 84        $mform->addElement('hidden', 'hasvalue', 0);
 85        $mform->setType('hasvalue', PARAM_INT);
 86
 87        $mform->addElement('hidden', 'options', '');
 88        $mform->setType('options', PARAM_ALPHA);
 89
 90        $buttonarray = array();
 91        if (!empty($item->id)) {
 92            $buttonarray[] = &$mform->createElement('submit',
 93                                                    'update_item',
 94                                                    get_string('update_item', 'feedback'));
 95
 96            $buttonarray[] = &$mform->createElement('submit',
 97                                                    'clone_item',
 98                                                    get_string('save_as_new_item', 'feedback'));
 99        } else {
100            $mform->addElement('hidden', 'clone_item', 0);
101            $mform->setType('clone_item', PARAM_INT);
102            $buttonarray[] = &$mform->createElement('submit',
103                                                    'save_item',
104                                                    get_string('save_item', 'feedback'));
105        }
106        $buttonarray[] = &$mform->createElement('cancel');
107        $mform->addGroup($buttonarray, 'buttonar', '&nbsp;', array(' '), false);
108
109    }
110}
111