sloodlecourseobject.php 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  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 award
  12. *
  13. * @contributer Paul Preibisch - aka Fire Centaur
  14. */
  15. /** SLOODLE course data structure */
  16. global $CFG;
  17. require_once(SLOODLE_DIRROOT.'/view/base/base_view_module.php');
  18. class sloodleCourseObj{
  19. var $cm;
  20. var $courseRec;
  21. var $courseId;
  22. /**
  23. * URL for accessing the current course.
  24. * @var string
  25. * @access private
  26. */
  27. var $courseUrl = '';
  28. /**
  29. * Full name of the current course.
  30. * @var string
  31. * @access private
  32. */
  33. var $courseFullName = '';
  34. /**
  35. * Short name of the current course.
  36. * @var string
  37. * @access private
  38. */
  39. var $courseShortName = '';
  40. var $courseContext=null;
  41. var $sloodleCourseObject;
  42. var $sloodleRec;
  43. var $sloodleId;
  44. var $userList;
  45. var $avatarList;
  46. //constructor
  47. function sloodleCourseObj($id){
  48. if(!$this->cm = get_coursemodule_from_id('sloodle',$id)) error ('Course module ID was incorrect.');
  49. //coursemodule id
  50. $this->courseContext = get_context_instance(CONTEXT_MODULE, $this->cm->id);
  51. // Course object
  52. if (!$this->courseRec = sloodle_get_record('course', 'id', $this->cm->course)) error('Failed to retrieve course.');
  53. //set course object
  54. $this->courseId = $this->cm->course;
  55. $this->courseFullName = $this->courseRec->fullname;
  56. $this->courseShortName = $this->courseRec->shortname;
  57. //set sloodle course object
  58. $this->sloodleCourseObject = new SloodleCourse();
  59. $this->userList = $this->getUserList();
  60. $this->avatarList = $this->getAvatarList($this->userList);
  61. if (!$this->sloodleCourseObject->load($this->courseRec)) error(get_string('failedcourseload', 'sloodle'));
  62. //set course context
  63. $this->courseContext =get_context_instance_by_id((int)$this->cm->instance);
  64. // sloodle_get_records('context','instanceid',(int)$this->cm->instance);
  65. // Fetch the SLOODLE instance itself
  66. if (!$this->sloodleRec = sloodle_get_record('sloodle', 'id', $this->cm->instance)) error('Failed to find SLOODLE module instance');
  67. //set sloodleId (id of module instance)
  68. $this->sloodleId= $this->cm->instance;
  69. }
  70. function get_avatars($userid){
  71. return sloodle_get_records('sloodle_users', 'userid', $userid);
  72. }
  73. function get_avatar($userid){
  74. $recs = sloodle_get_records('sloodle_users', 'userid', $userid);
  75. return $recs;
  76. }
  77. //returns a list of avatars in the class
  78. function getAvatarList($userList){
  79. $avList = array();
  80. if ($userList){
  81. foreach ($userList as $u){
  82. $sloodledata = sloodle_get_records('sloodle_users', 'userid', $u->id);
  83. //only adds users who have a linked avatar
  84. if ($sloodledata){
  85. foreach ($sloodledata as $sd){
  86. $av = new stdClass();
  87. $av->userid = $u->id;
  88. $av->username = $u->username;
  89. $av->avname = $sd->avname;
  90. $av->uuid = $sd->uuid;
  91. $avList[]=$av;
  92. }
  93. }
  94. }
  95. }
  96. return $avList;
  97. }
  98. function getSloodleId(){
  99. return $this->sloodleId;
  100. }
  101. function is_teacher($userid){
  102. $context = get_context_instance(CONTEXT_MODULE, $this->cm->id);
  103. if (has_capability('moodle/course:manageactivities',$context, $userid)) {
  104. return true;
  105. }
  106. else return false;
  107. }
  108. function getUserList(){
  109. global $CFG;
  110. //get all the users from the users table in the moodle database that are members in this class
  111. $sql = "select u.*, ra.roleid from ".$CFG->prefix."role_assignments ra, ".$CFG->prefix."context con, ".$CFG->prefix."course c, ".$CFG->prefix."user u ";
  112. $sql .= " where ra.userid=u.id and ra.contextid=con.id and con.instanceid=c.id and c.id=?";
  113. $fullUserList = sloodle_get_records_sql_params($sql, array($this->cm->course));
  114. return $fullUserList;
  115. }
  116. /**
  117. * setUserList set's the private userList array
  118. * @param $this->userList
  119. * @return null
  120. */
  121. function setUserList($list){
  122. $this->userList = $list;
  123. }
  124. function get_moodleUserProfile($u){
  125. global $CFG;
  126. // Construct URLs to this user's Moodle and SLOODLE profile pages
  127. $url_moodleprofile = $CFG->wwwroot."/user/view.php?id={$u->id}&amp;course={$this->courseId}";
  128. return $url_moodleprofile;
  129. }
  130. function get_sloodleprofile($u){
  131. global $CFG;
  132. $url_sloodleprofile = SLOODLE_WWWROOT."/view.php?_type=user&amp;id={$u->id}&amp;course={$this->courseId}";
  133. return $url_sloodleprofile;
  134. }
  135. // There used to be a function here called get_user_by_uuid.
  136. // It looked obviously broken, and wasn't being used anywhere
  137. // function get_user_by_uuid($avuuid)
  138. }
  139. ?>