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

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