コード例 #1
0
 /**
  * Defines the form used to add calendar subscriptions.
  */
 public function definition()
 {
     $mform = $this->_form;
     $courseid = optional_param('course', 0, PARAM_INT);
     $mform->addElement('header', 'addsubscriptionform', get_string('importcalendarheading', 'calendar'));
     // Name.
     $mform->addElement('text', 'name', get_string('subscriptionname', 'calendar'), array('maxsize' => '255', 'size' => '40'));
     $mform->addRule('name', get_string('required'), 'required');
     $mform->setType('name', PARAM_TEXT);
     // Import from (url | importfile).
     $mform->addElement('html', get_string('importfrominstructions', 'calendar'));
     $choices = array(CALENDAR_IMPORT_FROM_FILE => get_string('importfromfile', 'calendar'), CALENDAR_IMPORT_FROM_URL => get_string('importfromurl', 'calendar'));
     $mform->addElement('select', 'importfrom', get_string('importcalendarfrom', 'calendar'), $choices);
     $mform->setDefault('importfrom', CALENDAR_IMPORT_FROM_URL);
     // URL.
     $mform->addElement('text', 'url', get_string('importfromurl', 'calendar'), array('maxsize' => '255', 'size' => '50'));
     // Cannot set as PARAM_URL since we need to allow webcal:// protocol.
     $mform->setType('url', PARAM_RAW);
     $mform->setForceLtr('url');
     // Poll interval
     $choices = calendar_get_pollinterval_choices();
     $mform->addElement('select', 'pollinterval', get_string('pollinterval', 'calendar'), $choices);
     $mform->setDefault('pollinterval', 604800);
     $mform->addHelpButton('pollinterval', 'pollinterval', 'calendar');
     $mform->setType('pollinterval', PARAM_INT);
     // Import file
     $mform->addElement('filepicker', 'importfile', get_string('importfromfile', 'calendar'), null, array('accepted_types' => '.ics'));
     // Disable appropriate elements depending on import from value.
     $mform->disabledIf('pollinterval', 'importfrom', 'eq', CALENDAR_IMPORT_FROM_FILE);
     $mform->disabledIf('url', 'importfrom', 'eq', CALENDAR_IMPORT_FROM_FILE);
     $mform->disabledIf('importfile', 'importfrom', 'eq', CALENDAR_IMPORT_FROM_URL);
     // Eventtype: 0 = user, 1 = global, anything else = course ID.
     list($choices, $groups) = calendar_get_eventtype_choices($courseid);
     $mform->addElement('select', 'eventtype', get_string('eventkind', 'calendar'), $choices);
     $mform->addRule('eventtype', get_string('required'), 'required');
     $mform->setType('eventtype', PARAM_ALPHA);
     if (!empty($groups) and is_array($groups)) {
         $groupoptions = array();
         foreach ($groups as $group) {
             $groupoptions[$group->id] = $group->name;
         }
         $mform->addElement('select', 'groupid', get_string('typegroup', 'calendar'), $groupoptions);
         $mform->setType('groupid', PARAM_INT);
         $mform->disabledIf('groupid', 'eventtype', 'noteq', 'group');
     }
     $mform->addElement('hidden', 'course');
     $mform->setType('course', PARAM_INT);
     $mform->addElement('submit', 'add', get_string('add'));
 }
コード例 #2
0
ファイル: renderer.php プロジェクト: abhilash1994/moodle
 /**
  * Creates a form to perform actions on a given subscription.
  *
  * @param stdClass $subscription
  * @param int $courseid
  * @return string
  */
 protected function subscription_action_form($subscription, $courseid)
 {
     // Assemble form for the subscription row.
     $html = html_writer::start_tag('form', array('action' => new moodle_url('/calendar/managesubscriptions.php'), 'method' => 'post'));
     if (empty($subscription->url)) {
         // Don't update an iCal file, which has no URL.
         $html .= html_writer::empty_tag('input', array('type' => 'hidden', 'name' => 'pollinterval', 'value' => '0'));
     } else {
         // Assemble pollinterval control.
         $html .= html_writer::start_tag('div', array('style' => 'float:left;'));
         $html .= html_writer::start_tag('select', array('name' => 'pollinterval'));
         foreach (calendar_get_pollinterval_choices() as $k => $v) {
             $attributes = array();
             if ($k == $subscription->pollinterval) {
                 $attributes['selected'] = 'selected';
             }
             $attributes['value'] = $k;
             $html .= html_writer::tag('option', $v, $attributes);
         }
         $html .= html_writer::end_tag('select');
         $html .= html_writer::end_tag('div');
     }
     $html .= html_writer::start_tag('div', array('style' => 'float:right;'));
     $html .= html_writer::empty_tag('input', array('type' => 'hidden', 'name' => 'sesskey', 'value' => sesskey()));
     $html .= html_writer::empty_tag('input', array('type' => 'hidden', 'name' => 'course', 'value' => $courseid));
     $html .= html_writer::empty_tag('input', array('type' => 'hidden', 'name' => 'id', 'value' => $subscription->id));
     if (!empty($subscription->url)) {
         $html .= html_writer::tag('button', get_string('update'), array('type' => 'submit', 'name' => 'action', 'value' => CALENDAR_SUBSCRIPTION_UPDATE));
     }
     $html .= html_writer::tag('button', get_string('remove'), array('type' => 'submit', 'name' => 'action', 'value' => CALENDAR_SUBSCRIPTION_REMOVE));
     $html .= html_writer::end_tag('div');
     $html .= html_writer::end_tag('form');
     return $html;
 }