Skip to content

Commit

Permalink
MDL-19676 Put association section in advanced items for edit form, co…
Browse files Browse the repository at this point in the history
…rrected bug in group listing, enabled commenting
  • Loading branch information
nicolasconnault committed Sep 16, 2009
1 parent ac06c0a commit b73d1ca
Show file tree
Hide file tree
Showing 7 changed files with 58 additions and 35 deletions.
17 changes: 10 additions & 7 deletions blog/edit.php
Original file line number Diff line number Diff line change
Expand Up @@ -140,21 +140,24 @@
$textfieldoptions = array('trusttext'=>true, 'subdirs'=>true);
$blogeditform = new blog_edit_form(null, compact('existing', 'sitecontext', 'textfieldoptions', 'id'));
$draftitemid = file_get_submitted_draft_itemid('attachments');
file_prepare_draft_area($draftitemid, $PAGE->context, 'blog_attachment', empty($id)?null:$id);
file_prepare_draft_area($draftitemid, $PAGE->context->id, 'blog_attachment', empty($id)?null:$id);

$draftid_editor = file_get_submitted_draft_itemid('summary');
$currenttext = file_prepare_draft_area($draftid_editor, $PAGE->context, 'blog_post', empty($id) ? null : $id, array('subdirs'=>true), @$existing->summary);
$editordraftid = file_get_submitted_draft_itemid('summary');
$currenttext = file_prepare_draft_area($editordraftid, $PAGE->context->id, 'blog_post', empty($id) ? null : $id, array('subdirs'=>true), @$existing->summary);

$data = array('id'=>$id, 'summary'=>array('text'=>$currenttext, 'format'=>FORMAT_HTML, 'itemid' => $editordraftid));
$blogeditform->set_data($data); // set defaults

if ($blogeditform->is_cancelled()){
redirect($returnurl);
} else if ($fromform = $blogeditform->get_data()){
$fromform = file_postupdate_standard_editor($fromform, 'summary', $textfieldoptions, $PAGE->get_context());

//save stuff in db
switch ($action) {
case 'add':
$blog_entry = new blog_entry($fromform, $blogeditform);
$blog_entry->add();
$blogentry = new blog_entry($fromform, $blogeditform);
$blogentry->summary = file_save_draft_area_files($fromform->summary['itemid'], $PAGE->context->id, 'blog_post', $blogentry->id, array('subdirs'=>true), $fromform->summary['text']);
$blogentry->add();
break;

case 'edit':
Expand Down Expand Up @@ -222,7 +225,7 @@
$entry->modid = $modid;
$entry->courseid = $courseid;
$entry->attachments = $draftitemid;
$entry->summary = array('text' => @$existing->summary, 'format' => empty($existing->summaryformat) ? FORMAT_HTML : $existing->summaryformat, 'itemid' => $draftid_editor);
$entry->summary = array('text' => @$existing->summary, 'format' => empty($existing->summaryformat) ? FORMAT_HTML : $existing->summaryformat, 'itemid' => $editordraftid);
$entry->summaryformat = (empty($existing->summaryformat)) ? FORMAT_HTML : $existing->summaryformat;
$PAGE->requires->data_for_js('blog_edit_existing', $entry);

Expand Down
17 changes: 7 additions & 10 deletions blog/edit_form.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,14 @@ function definition() {

$mform =& $this->_form;

$existing = $this->_customdata['existing'];
$entryid = $this->_customdata['id'];
$summaryoptions = $this->_customdata['textfieldoptions'];

$entryid = $this->_customdata['id'];
$existing = $this->_customdata['existing'];
$sitecontext = $this->_customdata['sitecontext'];

$mform->addElement('header', 'general', get_string('general', 'form'));

$mform->addElement('text', 'subject', get_string('entrytitle', 'blog'), 'size="60"');
$textfieldoptions = array('trusttext'=>true, 'subdirs'=>true);
$mform->addElement('editor', 'summary', get_string('entrybody', 'blog'), null, $summaryoptions);
$mform->addElement('editor', 'summary', get_string('entrybody', 'blog'), null, array('trusttext'=>true, 'subdirs'=>true, 'maxfiles' => -1));

$mform->setType('subject', PARAM_TEXT);
$mform->addRule('subject', get_string('emptytitle', 'blog'), 'required', null, 'client');
Expand All @@ -47,7 +43,7 @@ function definition() {

$mform->addElement('format', 'summaryformat', get_string('format'));

$mform->addElement('filemanager', 'attachments', get_string('attachment', 'forum'));
$mform->addElement('filemanager', 'attachment', get_string('attachment', 'forum'));

//disable publishstate options that are not allowed
$publishstates = array();
Expand All @@ -71,7 +67,7 @@ function definition() {

if (!empty($CFG->useblogassociations)) {
$mform->addElement('header', 'assochdr', get_string('associations', 'blog'));

$mform->addElement('static', 'assocdescription', '', get_string('assocdescription', 'blog'));
if (has_capability('moodle/site:doanything', get_context_instance(CONTEXT_USER, $USER->id))) {
$courses = get_courses('all', 'visible DESC, fullname ASC');
} else {
Expand Down Expand Up @@ -103,14 +99,15 @@ function definition() {
}
}
$mform->addElement('select', 'courseassoc', get_string('course'), $coursenames, 'onchange="addCourseAssociations()"');
$mform->setAdvanced('courseassoc');
$selectassoc = &$mform->addElement('select', 'modassoc', get_string('managemodules'), $allmodnames);
$mform->setAdvanced('modassoc');
$selectassoc->setMultiple(true);
$PAGE->requires->data_for_js('blog_edit_form_modnames', $this->modnames);

}

$this->add_action_buttons();

$mform->addElement('hidden', 'action');
$mform->setType('action', PARAM_ACTION);
$mform->setDefault('action', '');
Expand All @@ -130,7 +127,7 @@ function definition() {
$mform->setType('courseid', PARAM_INT);
$mform->setDefault('courseid', 0);

$this->set_data($existing);
// $this->set_data($existing);
}

function validation($data, $files) {
Expand Down
16 changes: 11 additions & 5 deletions blog/external_form.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,23 @@
*/

require_once($CFG->libdir.'/formslib.php');

// TODO remove "Blogging is disabled" text from blog_menu when editing not on
// DONE put Associations in Advanced items
// TODO add descriptive text to Associations fieldset
// TODO forceopen on preferences page
// TODO Add Blog link under course navigation tree
// DONE add string for invalidgroupid
// DONE Restrict groupid entries to entries associated with the course
class blog_edit_external_form extends moodleform {
public function definition() {
global $CFG;

$mform =& $this->_form;

$mform->addElement('text', 'url', get_string('url'));
$mform->addRule('url', get_string('emptyurl', 'blog'), 'required', null, 'client');
$mform->setHelpButton('url', array('url', get_string('url', 'blog'), 'blog'));

$mform->addElement('text', 'name', get_string('name'));
// No need to require the name, it gets prefilled with the external blog's site name if empty
// $mform->addRule('name', get_string('emptyname', 'blog'), 'required', null, 'client');
Expand All @@ -41,10 +51,6 @@ public function definition() {
$mform->addElement('textarea', 'description', get_string('description'), array('cols' => 50, 'rows' => 7));
$mform->setHelpButton('description', array('description', get_string('description', 'blog'), 'blog'));

$mform->addElement('text', 'url', get_string('url'));
$mform->addRule('url', get_string('emptyurl', 'blog'), 'required', null, 'client');
$mform->setHelpButton('url', array('url', get_string('url', 'blog'), 'blog'));

if (!empty($CFG->usetags)) {
$mform->addElement('text', 'tags', get_string('tags'));
$mform->setHelpButton('tags', array('tags', get_string('tags', 'blog'), 'blog'));
Expand Down
3 changes: 3 additions & 0 deletions blog/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
require_once($CFG->dirroot .'/blog/locallib.php');
require_once($CFG->dirroot .'/course/lib.php');
require_once($CFG->dirroot .'/tag/lib.php');
require_once($CFG->libdir .'/commentlib.php');

$id = optional_param('id', null, PARAM_INT);
$start = optional_param('formstart', 0, PARAM_INT);
Expand All @@ -23,6 +24,8 @@
$courseid = optional_param('courseid', null, PARAM_INT); // needed for user tabs and course tracking
$search = optional_param('search', null, PARAM_RAW);

comment::js();

$url_params = compact('id', 'start', 'tag', 'userid', 'tagid', 'modid', 'entryid', 'groupid', 'courseid', 'search');
foreach ($url_params as $var => $val) {
if (empty($val)) {
Expand Down
5 changes: 3 additions & 2 deletions blog/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -423,7 +423,7 @@ function blog_get_headers() {
$cm->context = get_context_instance(CONTEXT_MODULE, $modid);
$PAGE->set_cm($cm, $course);
}

// Case 0: No entry, mod, course or user params: all site entries to be shown (filtered by search and tag/tagid)
if (empty($entryid) && empty($modid) && empty($courseid) && empty($userid)) {
$PAGE->navbar->add($strblogentries, $blog_url);
Expand All @@ -433,6 +433,7 @@ function blog_get_headers() {
}

// Case 1: only entryid is requested, ignore all other filters. courseid is used to give more contextual information
// TODO Blog entries link has entryid instead of userid
if (!empty($entryid)) {
$sql = 'SELECT u.* FROM {user} u, {post} p WHERE p.id = ? AND p.userid = u.id';
$user = $DB->get_record_sql($sql, array($entryid));
Expand Down Expand Up @@ -603,7 +604,7 @@ function blog_extend_settings_navigation($settingsnav) {
$blogkey = $settingsnav->add(get_string('blogadministration', 'blog'));
$blog = $settingsnav->get($blogkey);
$blog->forceopen = true;

$blog->add(get_string('preferences', 'blog'), new moodle_url('preferences.php'), navigation_node::TYPE_SETTING);
if ($CFG->useexternalblogs && $CFG->maxexternalblogsperuser > 0) {
$blog->add(get_string('externalblogs', 'blog'), new moodle_url('external.php'), navigation_node::TYPE_SETTING);
Expand Down
32 changes: 21 additions & 11 deletions blog/locallib.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,18 +68,18 @@ class blog_entry {
/**
* Constructor. If given an id, will fetch the corresponding record from the DB.
*
* @param mixed $id_or_params A blog entry id if INT, or data for a new entry if array
* @param mixed $idorparams A blog entry id if INT, or data for a new entry if array
*/
public function __construct($id_or_params=null, $form=null) {
global $DB;
public function __construct($idorparams=null, $form=null) {
global $DB, $PAGE;

if (!empty($id_or_params) && !is_array($id_or_params) && !is_object($id_or_params)) {
$object = $DB->get_record('post', array('id' => $id_or_params));
if (!empty($idorparams) && !is_array($idorparams) && !is_object($idorparams)) {
$object = $DB->get_record('post', array('id' => $idorparams));
foreach ($object as $var => $val) {
$this->$var = $val;
}
} else if (!empty($id_or_params) && (is_array($id_or_params) || is_object($id_or_params))) {
foreach ($id_or_params as $var => $val) {
} else if (!empty($idorparams) && (is_array($idorparams) || is_object($idorparams))) {
foreach ($idorparams as $var => $val) {
$this->$var = $val;
}
}
Expand All @@ -95,12 +95,18 @@ public function __construct($id_or_params=null, $form=null) {
*/
public function print_html($return=false) {

global $USER, $CFG, $COURSE, $DB, $OUTPUT;
global $USER, $CFG, $COURSE, $DB, $OUTPUT, $PAGE;


// Comments
$user = $DB->get_record('user', array('id'=>$this->userid));
// Comments
$cmt = new stdClass();
$cmt->contextid = get_context_instance(CONTEXT_USER, $user->id)->id;
$cmt->area = 'format_blog';
$cmt->itemid = $this->id;
$options->comments = $cmt;

$template['body'] = format_text($this->summary, $this->format);
$template['body'] = format_text($this->summary, $this->format, $options);
$template['title'] = '<a id="b'. s($this->id) .'" />';
//enclose the title in nolink tags so that moodle formatting doesn't autolink the text
$template['title'] .= '<span class="nolink">'. format_string($this->subject) .'</span>';
Expand Down Expand Up @@ -342,13 +348,15 @@ public function add() {
* @return void
*/
public function edit($params=array(), $form=null) {
global $CFG, $USER, $DB;
global $CFG, $USER, $DB, $PAGE;

$this->form = $form;
foreach ($params as $var => $val) {
$this->$var = $val;
}

$this->summary = file_save_draft_area_files($params->summary['itemid'], $PAGE->context->id, 'blog_post', $this->id, array('subdirs'=>true), $params->summary['text']);

if (!empty($CFG->useblogassociations)) {
$this->add_associations();
}
Expand Down Expand Up @@ -1032,6 +1040,7 @@ class blog_filter_user extends blog_filter {
* @param int $id
*/
public function __construct($id=null, $type='user') {
global $CFG, $DB;
$this->available_types = array('user' => get_string('user'), 'group' => get_string('group'));

if (empty($id)) {
Expand Down Expand Up @@ -1065,6 +1074,7 @@ public function __construct($id=null, $type='user') {
$this->params[] = $course_context->id;
}
}

}
}

Expand Down
3 changes: 3 additions & 0 deletions lang/en_utf8/blog.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

$string['addnewentry'] = 'Add a new entry';
$string['addnewexternalblog'] = 'New external blog...';
$string['assocdescription'] = 'If you are writing about a course and/or activity modules, select them here.';
$string['associations'] = 'Associations';
$string['associationunviewable'] = 'This entry cannot be viewed by others until a course is associated with it or the \'Publish To\' field is changed';
$string['backupblogshelp'] = 'If enabled then blogs will be included in SITE automated backups';
Expand Down Expand Up @@ -60,6 +61,7 @@
$string['groupblogs'] = 'Users can only see blogs for people who share a group';
$string['incorrectblogfilter'] = 'Incorrect blog filter type specified';
$string['intro'] = 'This RSS feed was automatically generated from one or more blogs.';
$string['invalidgroupid'] = 'Invalid group ID';
$string['invalidurl'] = 'This URL is unreachable';
$string['linktooriginalentry'] = 'Link to original blog entry';
$string['maxexternalblogsperuser'] = 'Maximum number of external blogs per user';
Expand All @@ -85,6 +87,7 @@
$string['publishtonoone'] = 'Yourself (draft)';
$string['publishtosite'] = 'Anyone on this site';
$string['publishtoworld'] = 'Anyone in the world';
$string['readfirst'] = 'Read this first';
$string['settingsupdatederror'] = 'An error has occurred, blog preference setting could not be updated';
$string['searchterm'] = 'Search: $a';
$string['siteblog'] = 'Site blog: $a';
Expand Down

0 comments on commit b73d1ca

Please sign in to comment.