]> git.mjollnir.org Git - moodle.git/commitdiff
added a feature that automatically adds 2 default blocks for new blog users. (block_m...
authortoyomoyo <toyomoyo>
Thu, 20 Apr 2006 06:35:39 +0000 (06:35 +0000)
committertoyomoyo <toyomoyo>
Thu, 20 Apr 2006 06:35:39 +0000 (06:35 +0000)
blog/header.php
blog/index.php
blog/lib.php

index b0250c792f4fe75f8290bdd51a1e4a7049197d59..6973041bcac4df7e92e45f5733530685df624fb2 100755 (executable)
@@ -12,6 +12,9 @@ $blockaction = optional_param('blockaction','', PARAM_ALPHA);
 $instanceid = optional_param('instanceid', 0, PARAM_INT);
 $blockid = optional_param('blockid',    0, PARAM_INT);
 
+/// If user has never visited this page before, install 2 blocks for him
+blog_check_and_install_blocks();
+
 if (!$site = get_site()) {
     redirect($CFG->wwwroot.'/index.php');
 }
index 271da130a1c908a9501fca40bf1977c12baaecbb..c890565b548d7545f4433c21c257e500030a08ac 100755 (executable)
@@ -132,14 +132,14 @@ switch ($filtertype) {
     break;
 }
 
-//first set the start and end day equal to the day argument passed in from the get vars
+// first set the start and end day equal to the day argument passed in from the get vars
 if ($limit == 'none') {
     $limit = get_user_preferences('blogpagesize',10);
 }
 
 include($CFG->dirroot .'/blog/header.php');
 
-//prints the tabs
+// prints the tabs
 $currenttab = 'blogs';
 $user = $USER;
 if (!$course) {
index a20596c5746bde39b895c5c0b09c05e9e31ebc16..44f38ba3bb259dfd2f011bd064cc688662e48056 100755 (executable)
         $SESSION->blog_editing_enabled = false;
     }
 
+    // checks to see if user has visited blogpages before, if not, install 2 default blocks
+    // (blog_menu and blog_tags)
+    function blog_check_and_install_blocks() {
+        global $USER;
+        if (isloggedin() && !isguest()) {
+            // if this user has not visited this page before
+            if (!get_user_preferences('blogpagesize')) {
+                // find the correct ids for blog_menu and blog_from blocks
+                $menublock = get_record('block','name','blog_menu');
+                $tagsblock = get_record('block','name','blog_tags');
+                // add those 2 into block_instance page
+
+                // add blog_menu block
+                $newblock = new object;
+                $newblock -> blockid = $menublock->id;
+                $newblock -> pageid = $USER->id;
+                $newblock -> pagetype = 'blog-view';
+                $newblock -> position = 'r';
+                $newblock -> weight = 0;
+                $newblock -> visible = 1;
+                insert_record('block_instance', $newblock);
+
+                // add blog_tags menu
+                $newblock -> blockid = $tagsblock->id;
+                $newblock -> weight = 1;
+                insert_record('block_instance', $newblock);
+
+                // finally we set the page size pref
+                set_user_preference('blogpagesize',8);
+            }
+        }
+    }
+
+
     /**
      * Adaptation of isediting in moodlelib.php for blog module
      * @return bool