]> git.mjollnir.org Git - moodle.git/commitdiff
MDL-19676 Put association section in advanced items for edit form, corrected bug...
authornicolasconnault <nicolasconnault>
Wed, 16 Sep 2009 10:05:34 +0000 (10:05 +0000)
committernicolasconnault <nicolasconnault>
Wed, 16 Sep 2009 10:05:34 +0000 (10:05 +0000)
blog/edit.php
blog/edit_form.php
blog/external_form.php
blog/index.php
blog/lib.php
blog/locallib.php
lang/en_utf8/blog.php

index a00a967cb27a04f10eebe659488c01ef04c6cd82..d519c72c645bc8c6d28e8218d216572471fcc39c 100755 (executable)
@@ -140,21 +140,24 @@ if (!empty($existing)) {
 $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':
@@ -222,7 +225,7 @@ switch ($action) {
 $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);
 
index 279366e590c8cae96cc281585f121c0a761ff516..e0c80d61e0bbca60dbaf2ce4a3630ac84f2a62b8 100644 (file)
@@ -25,18 +25,14 @@ class blog_edit_form extends moodleform {
 
         $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');
@@ -47,7 +43,7 @@ class blog_edit_form extends moodleform {
 
         $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();
@@ -71,7 +67,7 @@ class blog_edit_form extends moodleform {
 
         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 {
@@ -103,14 +99,15 @@ class blog_edit_form extends moodleform {
                 }
             }
             $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', '');
@@ -130,7 +127,7 @@ class blog_edit_form extends moodleform {
         $mform->setType('courseid', PARAM_INT);
         $mform->setDefault('courseid', 0);
 
-        $this->set_data($existing);
+        // $this->set_data($existing);
     }
 
     function validation($data, $files) {
index 9aee49981c30f262f2ec1727cb4576234df29c82..34a80683ae6085ea82bebefdbe4a6fc1d8923ff6 100644 (file)
  */
 
 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');
@@ -41,10 +51,6 @@ class blog_edit_external_form extends moodleform {
         $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'));
index 55f019c3a108857774ca5cbd466418149565c2af..1f5365b478d06c8a7b29110cb9690d8f072234d1 100755 (executable)
@@ -11,6 +11,7 @@ require_once($CFG->dirroot .'/blog/lib.php');
 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);
@@ -23,6 +24,8 @@ $groupid      = optional_param('groupid', null, PARAM_INT);
 $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)) {
index b8439880270e5ecf981545b08dad203cc5d6e9dd..302fcbf1ad807332520871b1228c28a07cb4a843 100755 (executable)
@@ -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);
@@ -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));
@@ -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);
index 08f84f05a4e6c7db5ef26b941d06a3e438aaccf7..19cc15471df5f6ef71a2549a6fc6aa68c1abfee5 100644 (file)
@@ -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;
             }
         }
@@ -95,12 +95,18 @@ class blog_entry {
      */
     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>';
@@ -342,13 +348,15 @@ class blog_entry {
      * @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();
         }
@@ -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)) {
@@ -1065,6 +1074,7 @@ class blog_filter_user extends blog_filter {
                 $this->params[]     = $course_context->id;
             }
         }
+
     }
 }
 
index ab06c2dc6362d88e5adacf33bc2cf50188b7eefd..fa2cb19db502b9fe628e8e4dfebc8655d3448739 100755 (executable)
@@ -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';
@@ -60,6 +61,7 @@ $string['groupblogentries'] = 'Blog entries associated with $a->coursename by gr
 $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';
@@ -85,6 +87,7 @@ $string['publishtogroupassocparam'] = 'Your group members in $a';
 $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';