public function definition() { global $CFG; $mform = $this->_form; // Don't forget the underscore! if (isset($this->_customdata['record']) && is_object($this->_customdata['record'])) { $data = $this->_customdata['record']; } //resourceItem: ID (readonly, hidden) $mform->addElement('hidden', 'id'); $mform->setType('id', PARAM_INT); $categories = $this->get_categories(); foreach ($categories as $k => $v) { $checkbox[$k] = $mform->createElement('checkbox', $k, null, $v); } $categories = $mform->addGroup($checkbox, 'categories', get_string('category'), '<br/>'); //TODO: this doesnt work $mform->addGroupRule('categories', 'You must select at least one category.', 'required', null, 1); //resourceItem: Title $mform->addElement('text', 'title', get_string('title', 'local_courseblog'), array('style' => 'width: 100%')); // Add elements to your form $mform->setType('title', PARAM_TEXT); //Set type of element $mform->addRule('title', get_string('missingtitle'), 'required', null, 'client'); $mform->addRule('title', get_string('maximumchars', '', 255), 'maxlength', 255, 'client'); $mform->addElement('text', 'author', get_string('author', 'local_courseblog'), array('style' => 'width: 100%')); // Add elements to your form $mform->setType('author', PARAM_TEXT); //Set type of element $mform->addRule('author', get_string('maximumchars', '', 128), 'maxlength', 128, 'client'); $mform->addElement('text', 'author_url', get_string('author_url', 'local_courseblog'), array('style' => 'width: 100%')); // Add elements to your form $mform->setType('author_url', PARAM_URL); //Set type of element $mform->addRule('author_url', get_string('maximumchars', '', 1024), 'maxlength', 1024, 'client'); //Date $mform->addElement('date_selector', 'post_date', get_string('post_date', 'local_courseblog')); $mform->addRule('post_date', get_string('missingdate'), 'required', null, 'server'); //Excerpt $mform->addElement('textarea', 'entry_excerpt', get_string("excerpt", 'local_courseblog'), 'wrap="virtual" rows="20" cols="50"'); $mform->addElement('text', 'short_excerpt', get_string('short_excerpt', 'local_courseblog'), array('style' => 'width: 100%')); // Add elements to your form $mform->setType('short_excerpt', PARAM_TEXT); //Set type of element $mform->addRule('short_excerpt', get_string('maximumchars', '', 100), 'maxlength', 100, 'client'); //Entry $entry_text = $mform->addElement('editor', 'entry_text', get_string('entry_body', 'local_courseblog')); $mform->setType('entry_text', PARAM_RAW); $mform->addRule('entry_text', get_string('missingfield'), 'required', null, 'client'); if (isset($data)) { $curr = local_courseblog_get_single_entry($data->id); foreach ($curr['categories'] as $c) { $data->categories[$c] = true; } $this->set_data($data); $entry_text->setValue(array('text' => $data->entry_text)); } $this->add_action_buttons(); }
/// Build page $returnurl = $CFG->wwwroot . '/local/courseblog/view.php'; $PAGE->set_url($returnurl); $PAGE->set_context($systemcontext); //page layout $PAGE->set_pagelayout('standard'); $data = new stdClass(); $data->url = new moodle_url($returnurl); $data->wwwroot = $CFG->wwwroot; $data->blog_title = get_config('local_courseblog')->title; $PAGE->navbar->add(get_config('local_courseblog')->title, new moodle_url('/local/courseblog/view.php'), global_navigation::TYPE_CUSTOM); $category = optional_param('category', false, PARAM_INT); $post_id = optional_param('post', false, PARAM_INT); $categories = local_courseblog_get_categories("id"); if ($post_id != false) { $post = local_courseblog_get_single_entry($post_id); if ($category != false) { $PAGE->navbar->add($categories[$category]['category'], new moodle_url('/local/courseblog/view.php', array('category' => $category)), global_navigation::TYPE_CUSTOM); } $PAGE->navbar->add($post['title'], new moodle_url('/local/courseblog/view.php', array('post' => $post_id)), global_navigation::TYPE_CUSTOM); $data->id = $post_id; $data->title = $post['title']; $data->content = $post['entry_text']; $data->date = date("F j, Y", $post['post_date']); if (strlen($post['author']) > 0) { $data->author = $post['author']; if (strlen($post['author_url']) > 0) { $data->author_url = $post['author_url']; } } $j = 0;