Source for file sloodlecourseobject.php

Documentation is available at sloodlecourseobject.php

  1. <?php
  2. /**
  3. * sloodlecourseobject provides basic functionality for accessing information about
  4. * the students, including a student list, and avatar list
  5. *
  6. @package sloodle
  7. @copyright Copyright (c) 2008 Sloodle (various contributors)
  8. @license http://www.gnu.org/licenses/gpl-3.0.html GNU GPL v3
  9. @see http://slisweb.sjsu.edu/sl/index.php/Sloodle_Stipend_Giver
  10. @see iBank
  11. *
  12. @contributer Paul Preibisch - aka Fire Centaur
  13. */
  14.  
  15.  /** SLOODLE course data structure */
  16. global $CFG;   
  17. require_once(SLOODLE_DIRROOT.'/view/base/base_view_module.php');   
  18.  
  19.  
  20.   class sloodleCourseObj{
  21.       
  22.       
  23.       var $cm;
  24.       
  25.       var $courseRec;
  26.       
  27.       var $courseId;
  28.       /**
  29.       * URL for accessing the current course.
  30.       * @var string 
  31.       * @access private
  32.       */
  33.       var $courseUrl = '';
  34.       
  35.       /**
  36.       * Full name of the current course.
  37.       * @var string 
  38.        * @access private
  39.       */
  40.       var $courseFullName = '';
  41.   
  42.       /**
  43.       * Short name of the current course.
  44.       * @var string 
  45.       * @access private
  46.       */
  47.       var $courseShortName = '';
  48.       
  49.       var $courseContext=null;
  50.       
  51.       var $sloodleCourseObject;
  52.       
  53.       var $sloodleRec;
  54.       
  55.       var $sloodleId;
  56.       
  57.       var $userList;
  58.       
  59.       var $avatarList;
  60.    
  61.  
  62.            
  63.       //constructor
  64.       function sloodleCourseObj($id){
  65.           
  66.           if(!$this->cm = get_coursemodule_from_id('sloodle',$id)) error ('Course module ID was incorrect.');
  67.           //coursemodule id
  68.           
  69.          $this->courseContext = get_context_instance(CONTEXT_MODULE$this->cm->id);
  70.          
  71.           // Course object
  72.           if (!$this->courseRec = get_record('course''id'$this->cm->course)) error('Failed to retrieve course.');            
  73.           
  74.           //set course object
  75.           $this->courseId = $this->cm->course;
  76.  
  77.           $this->courseFullName = $this->courseRec->fullname;
  78.           $this->courseShortName = $this->courseRec->shortname;
  79.           
  80.          //set sloodle course object          
  81.           $this->sloodleCourseObject = new SloodleCourse();
  82.           
  83.           $this->userList = $this->getUserList();
  84.           $this->avatarList = $this->getAvatarList($this->userList);
  85.           
  86.         if (!$this->sloodleCourseObject->load($this->courseRec)) error(get_string('failedcourseload''sloodle'));
  87.         //set course context
  88.           $this->courseContext = get_record('context','instanceid',(int)$this->cm->instance);   
  89.              
  90.           
  91.         // Fetch the SLOODLE instance itself
  92.         if (!$this->sloodleRec = get_record('sloodle''id'$this->cm->instance)) error('Failed to find SLOODLE module instance');
  93.             
  94.         //set sloodleId  (id of module instance)          
  95.         $this->sloodleId$this->cm->instance;  
  96.  
  97.       
  98.       
  99.       }     
  100.       
  101.       function get_avatars($userid){
  102.          return  get_records('sloodle_users''userid'$userid);   
  103.           
  104.       
  105.       //returns a list of avatars in the class
  106.       function getAvatarList($userList){
  107.          $avList array();
  108.          
  109.          foreach ($userList as $u){             
  110.              $sloodledata get_records('sloodle_users''userid'$u->id);   
  111.              
  112.              if ($sloodledata){
  113.                 foreach ($sloodledata as $sd){
  114.                    $av new stdClass()
  115.                    $av->userid $u->id;
  116.                    $av->username $u->username;
  117.                    $av->avname $sd->avname;
  118.                    $av->uuid $sd->uuid;
  119.                    $avList[]=$av;
  120.                 }
  121.              
  122.              
  123.              }
  124.          }
  125.          return $avList;
  126.       }
  127.       function getSloodleId(){
  128.         return $this->sloodleId;
  129.       }  
  130.       function is_teacher($userid){
  131.            $context get_context_instance(CONTEXT_MODULE$this->cm->id);
  132.           
  133.           if (has_capability('moodle/course:manageactivities',$context$userid)) 
  134.               return true;
  135.           }
  136.           else return false;
  137.           
  138.           
  139.       }
  140.       
  141.       function getUserList(){
  142.             global $CFG;  
  143.             
  144.            //get all the users from the users table in the moodle database   
  145.            $sql "select u.*, ra.roleid from ".$CFG->prefix."role_assignments ra, ".$CFG->prefix."context con, ".$CFG->prefix."course c, ".$CFG->prefix."user u ";
  146.            $sql .= " where ra.userid=u.id and ra.contextid=con.id and con.instanceid=c.id and c.id=".$this->cm->course;
  147.            
  148.            
  149.            $fullUserList get_records_sql($sql);          
  150.            return $fullUserList;                          
  151.       }
  152.   
  153.    
  154.      /**
  155.      * setUserList set's the private userList array
  156.      * @param $this->userList 
  157.      * @return null 
  158.      */   
  159.      
  160.      function setUserList($list){
  161.         $this->userList = $list;
  162.      }
  163.      
  164.      function get_moodleUserProfile($u){
  165.          global $CFG;
  166.         // Construct URLs to this user's Moodle and SLOODLE profile pages
  167.         $url_moodleprofile $CFG->wwwroot."/user/view.php?id={$u->id}&amp;course={$this->courseId}";
  168.         return $url_moodleprofile;
  169.      }
  170.      
  171.      function get_sloodleprofile($u){
  172.          global $CFG;
  173.         $url_sloodleprofile = SLOODLE_WWWROOT."/view.php?_type=user&amp;id={$u->id}&amp;course={$this->courseId}";        
  174.         return $url_sloodleprofile;
  175.      }
  176.   }
  177.         

Documentation generated on Fri, 17 Jul 2009 11:02:28 +0100 by phpDocumentor 1.4.0