Kaynağa Gözat

Creación del Repositorio

Damian Zhaoying 2 yıl önce
işleme
eb4d1e1ca3

+ 12 - 0
README.txt

@@ -0,0 +1,12 @@
+SLOODLE Backpack Menu Block
+
+This is an optional menu block is available showing how much of various currencies students have. It is only useful if you are using a SLOODLE activity which is awarding points.
+
+It requires the main SLOODLE module:
+https://github.com/sloodle/moodle-mod_sloodle
+
+It should be installed under the blocks/ directory of your Moodle site.
+
+See http://www.sloodle.org for more information, and post any questions or comments in the forums there.
+
+Edmund Edgar, 2012-05-19

+ 141 - 0
block_sloodle_backpack.php

@@ -0,0 +1,141 @@
+<?php
+
+/**
+* Defines the Sloodle menu block class.
+* 
+* @package sloodle
+* @contributor Paul Preibisch
+* @contributor Edmund Edgar
+*/
+
+/** Include the current Sloodle configuration, if possible. */
+@include_once($CFG->dirroot .'/mod/sloodle/sl_config.php');
+if (defined('SLOODLE_LIBROOT')) {
+    /** Inlcude the current general Sloodle functionality. */
+    require_once(SLOODLE_LIBROOT.'/general.php');
+    /** Include the Sloodle course functionality. */
+    require_once(SLOODLE_LIBROOT.'/course.php');
+}
+
+
+/** Define the Sloodle Menu Block version. */
+define('BACKPACKS_VERSION', 1.0);
+
+/**
+* Defines the block class.
+* @package sloodle
+*/
+class block_sloodle_backpack extends block_base {
+
+    /**
+    * Perform block initialisation.
+    * @return void
+    */
+    function init() {
+        global $CFG;
+        
+        $this->title = get_string('blockname', 'block_sloodle_backpack');
+        $this->content_type = BLOCK_TYPE_TEXT;
+        $this->version = 2011070900;
+    }
+    
+    /**
+    * Indicates whether or not this module has a global configuration page.
+    * @return bool True if there is a global configuration page, or false otherwise.
+    */
+    function has_config() {
+        return false;
+    }
+    
+    /**
+    * Indicates whether or not to hide the header of this block.
+    * @return bool True to hide the header, or false to show it.
+    */
+    function hide_header() {
+        return false;
+    }
+
+    /**
+    * Defines *and* returns the content of this block.
+    * @return object
+    */
+    function get_content() {
+        global $CFG, $COURSE, $USER;
+        
+        // Construct the content
+        $this->content = new stdClass;
+        $this->content->text = '';
+        $this->content->footer = '';
+        
+        
+        
+        // If the user is not logged in or if they are using guest access, then we can't show anything
+        if (!isloggedin() || isguestuser()) {
+            return $this->content;
+        }
+        
+        // Get the context instance for this course
+        $course_context = get_context_instance(CONTEXT_COURSE, $COURSE->id);
+        
+       
+        // Get the Sloodle course data
+        $sloodle_course = new SloodleCourse();
+        if (!$sloodle_course->load((int)$COURSE->id)) {
+            $this->content->text = get_string('failedloadcourse', 'block_sloodle_backpack');
+            return $this->content;
+        }
+        
+        
+        // Attempt to find a Sloodle user for the Moodle user
+        $dbquery = "    SELECT * FROM {$CFG->prefix}sloodle_users
+                        WHERE userid = ? AND NOT (avname = '' AND uuid = '')
+                    ";
+        $dbresult = sloodle_get_records_sql_params($dbquery,array($USER->id));
+        $sl_avatar_name = "";
+        if (!is_array($dbresult) || count($dbresult) == 0) $userresult = FALSE;
+        else if (count($dbresult) > 1) $userresult = "Multiple avatars associated with your Moodle account.";
+        else {
+            $userresult = TRUE;
+            reset($dbresult);
+            $cur = current($dbresult);
+            $sl_avatar_name = $cur->avname;
+        }
+        
+        if ($userresult === TRUE) {
+            // Success
+            // Make sure there was a name
+            if (empty($sl_avatar_name)) $sl_avatar_name = '('.get_string('backpacks:nameunknown', 'sloodle').')';
+            
+            
+            
+        } else if (!is_string($userresult)) {
+            // No avatar linked yet
+            $this->content->text .= '<center><span style="font-style:italic;">('.get_string('backpacks:noavatar', 'sloodle').')</span></center>';
+        }
+        
+        //retreive all currencies and user info
+        $this->content->text .= '<div>';
+        $sql = "select p.currencyid as currencyid, sum(p.amount) as balance, c.name, c.imageurl as imageurl from {$CFG->prefix}sloodle_award_points p inner join {$CFG->prefix}sloodle_currency_types c on p.currencyid=c.id  inner join {$CFG->prefix}sloodle_award_rounds r on p.roundid=r.id  where p.userid=? AND r.courseid=?  group by p.currencyid ORDER BY c.displayorder DESC";
+        $items = sloodle_get_records_sql_params($sql, array($USER->id, $COURSE->id));
+        foreach ($items as $item){
+            $this->content->text .= "<div>";
+            if ($item->imageurl===null)  {
+                $this->content->text .= "<img src=\"".SLOODLE_WWWROOT."/lib/media/blank16.png\"  width=\"16\" height=\"16\" >";
+            }else {
+                $this->content->text .= "<img src=\"{$item->imageurl}\" width=\"16\" height=\"16\" >";    
+            }
+            $this->content->text .= "&nbsp{$item->name}";
+            $this->content->text .= '<span style="float:right">';
+            $this->content->text .= "{$item->balance}";
+            $this->content->text .= '</span>';
+            $this->content->text .= "</div>";
+            
+        }
+        
+        $this->content->text .= '</div>';
+          $this->content->text .= "<br>";
+        return $this->content;
+    }
+}
+
+?>

+ 14 - 0
config_global.html

@@ -0,0 +1,14 @@
+<?php
+    //require_once($CFG->dirroot .'/blocks/sloodle_menu/block_backpacks.php');
+?>
+
+<!-- The form tags are provided by Moodle. Just create the invidivual input elements. -->
+
+<table cellpadding="9" cellspacing="0">
+
+<tr>
+ <td>
+  <h2><?php echo get_string('sloodlemenuversion', 'block_sloodle_backpacks').': '.(string)BACKPACKS_VERSION; ?></h2>
+ </td>
+</tr>
+</table>

BIN
img/coin.png


+ 30 - 0
lang/en/block_sloodle_backpack.php

@@ -0,0 +1,30 @@
+<?php
+// This is the English language file for the Sloodle menu block.
+// It is included automatically by the Moodle framework.
+// Retrieve strings using the Moodle get_string or print_string functions.
+
+$string['pluginname'] = 'SLOODLE Backpack';
+
+$string['blockname'] = 'Sloodle Backpack';
+$string['blocknameplural'] = 'Sloodle Backpacks';
+
+$string['failedloadcourse'] = 'Failed to load SLOODLE course data';
+
+$string['hide'] = 'Hide';
+$string['show'] = 'Show';
+
+$string['nameunknown'] = 'name unknown';
+$string['noavatar'] = 'no avatar';
+
+$string['sloodle'] = 'SLOODLE';
+$string['sloodlenotinstalled'] = 'You need to install the SLOODLE activity module in order to use this block.';
+
+$string['backpack:view'] = 'Backpacks'; 
+$string['backpack:avname'] = 'Avatar'; 
+$string['backpack:currency'] = 'Currency'; 
+$string['backpack:type'] = 'Type'; 
+$string['backpack:time'] = 'Time'; 
+$string['backpack:username'] = 'User name';
+$string['backpack:nocurrency'] = 'No Currency Transactions Exist';
+
+?>

+ 30 - 0
lang/en_utf8/block_sloodle_backpack.php

@@ -0,0 +1,30 @@
+<?php
+// This is the English language file for the Sloodle menu block.
+// It is included automatically by the Moodle framework.
+// Retrieve strings using the Moodle get_string or print_string functions.
+
+$string['pluginname'] = 'SLOODLE Backpack';
+
+$string['blockname'] = 'Sloodle Backpack';
+$string['blocknameplural'] = 'Sloodle Backpacks';
+
+$string['failedloadcourse'] = 'Failed to load SLOODLE course data';
+
+$string['hide'] = 'Hide';
+$string['show'] = 'Show';
+
+$string['nameunknown'] = 'name unknown';
+$string['noavatar'] = 'no avatar';
+
+$string['sloodle'] = 'SLOODLE';
+$string['sloodlenotinstalled'] = 'You need to install the SLOODLE activity module in order to use this block.';
+
+$string['backpack:view'] = 'Backpacks'; 
+$string['backpack:avname'] = 'Avatar'; 
+$string['backpack:currency'] = 'Currency'; 
+$string['backpack:type'] = 'Type'; 
+$string['backpack:time'] = 'Time'; 
+$string['backpack:username'] = 'User name';
+$string['backpack:nocurrency'] = 'No Currency Transactions Exist';
+
+?>

+ 10 - 0
version.php

@@ -0,0 +1,10 @@
+<?php
+$plugin->version  = 2011072301;
+$plugin->requires = 2007021500;  // Requires Moodle 1.8
+
+// For Moodle 2, we have to pretend we don't work on Moodle 1.9 or Moodle gets upset.
+global $CFG;
+if ($CFG->version > 2010060800) {
+    $plugin->requires = 2010000000;  // Requires Moodle 2.0
+}
+?>