Source for file edit_section_roster.act.php

Documentation is available at edit_section_roster.act.php

  1. <?php
  2.  
  3. /**
  4. * This action is the central page for viewing and modifying course section information.
  5. *
  6. * @package polyphony.coursemanagement
  7. *
  8. *
  9. * @since 7/28/06
  10. *
  11. * @copyright Copyright &copy; 2006, Middlebury College
  12. * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License (GPL)
  13. *
  14. * @version $Id: edit_section_roster.act.php,v 1.4 2007/09/19 14:04:54 adamfranco Exp $
  15. */
  16.  
  17. require_once(POLYPHONY."/main/library/AbstractActions/MainWindowAction.class.php");
  18. require_once(HARMONI."GUIManager/Components/Blank.class.php");
  19.  
  20. class edit_section_rosterAction
  21. extends MainWindowAction
  22. {
  23. /**
  24. * Check Authorizations
  25. *
  26. * @return boolean
  27. * @access public
  28. * @since 4/26/05
  29. */
  30. function isAuthorizedToExecute () {
  31. // Check for authorization
  32. $authZManager = Services::getService("AuthZ");
  33. $idManager = Services::getService("IdManager");
  34. $harmoni = Harmoni::instance();
  35.  
  36. $harmoni->request->startNamespace("polyphony-agents");
  37. $sectionIdString = $harmoni->request->get("courseId");
  38.  
  39. $harmoni->request->endNamespace();
  40.  
  41. if ($authZManager->isUserAuthorized(
  42. $idManager->getId("edu.middlebury.authorization.modify"),
  43. $idManager->getId($sectionIdString)))
  44. {
  45. return TRUE;
  46. } else
  47. return FALSE;
  48. }
  49.  
  50. /**
  51. * Return the heading text for this action, or an empty string.
  52. *
  53. * @return string
  54. * @access public
  55. * @since 4/26/05
  56. */
  57. function getHeadingText () {
  58. $harmoni = Harmoni::instance();
  59. $harmoni->request->startNamespace("polyphony-agents");
  60. $harmoni->request->passthrough("courseId");
  61. $sectionIdString = $harmoni->request->get("courseId");
  62. $idManager = Services::getService("Id");
  63. $sectionId =$idManager->getId($sectionIdString);
  64. $cm = Services::getService("CourseManagement");
  65. $section =$cm->getCourseSection($sectionId);
  66. return dgettext("polyphony", $section->getDisplayName());
  67. }
  68.  
  69. /**
  70. * Build the content for this action
  71. *
  72. * @return void
  73. * @access public
  74. * @since 4/26/05
  75. */
  76. function buildContent () {
  77. $defaultTextDomain = textdomain("polyphony");
  78. $idManager = Services::getService("Id");
  79. $harmoni = Harmoni::instance();
  80.  
  81. $harmoni->request->startNamespace("polyphony-agents");
  82. $harmoni->request->passthrough("courseId");
  83. $sectionIdString = $harmoni->request->get("courseId");
  84. $sectionId =$idManager->getId($sectionIdString);
  85. $cm = Services::getService("CourseManagement");
  86. $section =$cm->getCourseSection($sectionId);
  87.  
  88. // Process any changes
  89. if (RequestContext::value("agentIdToAdd") && RequestContext::value("status"))
  90. $this->addStudent($section, RequestContext::value("agentIdToAdd"),
  91. RequestContext::value("status"));
  92. if (RequestContext::value("agentIdToRemove"))
  93. $this->removeStudent($section, RequestContext::value("agentIdToRemove"));
  94. // Print out our search and memebers
  95. $actionRows =$this->getActionRows();
  96. $sectionName = $section->getDisplayName();
  97. $actionRows->add(new Heading(_("Edit roster for $sectionName."), 2), "100%", null, LEFT, CENTER);
  98. $actionRows->add($this->getAddForm($section), "100%", null, LEFT, CENTER);
  99. $actionRows->add($this->getMembers($section), "100%", null, LEFT, CENTER);
  100. $harmoni->request->forget("courseId");
  101. $harmoni->request->endNamespace();
  102.  
  103. textdomain($defaultTextDomain);
  104. }
  105.  
  106. /***************************FUNCTIONS***************************************/
  107.  
  108.  
  109. /*******************************************************
  110. * the wild card search form to add students
  111. *********************************************************/
  112.  
  113. /**
  114. * Creates and prints the wild card agent search form to add students to the course section.
  115. *
  116. * @param object section
  117. * @return void
  118. * @access public
  119. * @since 8/24/05
  120. */
  121. function getAddForm($section) {
  122. $harmoni = Harmoni::instance();
  123. $cmm = Services::getService("CourseManagement");
  124. $idManager = Services::getService("Id");
  125. $am = Services::GetService("AgentManager");
  126.  
  127. $offering =$section->getCourseOffering();
  128. $offeringId = $offering->getId();
  129. $courseIdString = $offeringId->getIdString();
  130. ob_start();
  131. $link1 = $harmoni->request->quickURL("coursemanagement", "edit_offering_details",
  132. array("courseId"=>$courseIdString));
  133. print "<p><a href='$link1'>Return to course offering details.</a></p>";
  134. print _("<p>Please enter a student's name to search and add.</p>")."";
  135. // Search header
  136. $self = $harmoni->request->quickURL("coursemanagement", "edit_section_roster",
  137. array("search_criteria", "search_type"));
  138. $lastCriteria = $harmoni->request->get("search_criteria");
  139. $search_criteria_name = RequestContext::name("search_criteria");
  140. if (is_null($search_criteria_name))
  141. $search_criteria_name = "";
  142. print "<form action='$self' method='post'>
  143. <div>
  144. <input type='text' name='$search_criteria_name' value='$lastCriteria' />";
  145. print "\n\t<input type='submit' value='"._("Search")."' />";
  146. print "\n\t<a href='".$harmoni->request->quickURL()."'>";
  147. print "<input type='button' value='"._("Clear")."' /></a>";
  148. print "\n</div>\n</form>\n";
  149. // Agent search results
  150. if ($search_criteria = $harmoni->request->get('search_criteria')) {
  151. $searchType = new HarmoniType("Agent & Group Search", "edu.middlebury.harmoni", "TokenSearch");
  152. $string = "*".$search_criteria."*";
  153. $agents =$am->getAgentsBySearch($string, $searchType);
  154. $displayName = $section->getDisplayName();
  155. print "\n<hr/><p><h3>Search results</h3></p>";
  156. print "Click on a student's name to add for the course, <strong>$displayName</strong>.";
  157. while ($agents->hasNext()) {
  158. $agent =$agents->next();
  159. $id =$agent->getId();
  160. $harmoni->history->markReturnURL("polyphony/coursemanagement/edit_section_details");
  161. $last_status_name = $harmoni->request->get("status");
  162. $status = RequestContext::name("status");
  163. if (is_null($status))
  164. $status = "";
  165. $idString = $id->getIdString();
  166. $self = $harmoni->request->quickURL("coursemanagement", "edit_section_roster",
  167. array("agentIdToAdd"=>$idString, "status"=>$status,
  168. "search_criteria"=>RequestContext::value("search_criteria")));
  169. print "<p>";
  170. print "<form action='$self' method='post'>";
  171. print "\n<u>".$agent->getDisplayName()."</u>";
  172. /* Search the record to see if student is already enrolled. */
  173. $studentPresent = 0; // To check later whether student is enrolled or not
  174. $roster =$section->getRoster();
  175. while ($roster->hasNextEnrollmentRecord()) {
  176. $record = $roster->nextEnrollmentRecord();
  177. $studentId =$record->getStudent();
  178.  
  179. if ($id->isEqual($studentId))
  180. $studentPresent = 1; // Set to student already being enrolled
  181. }
  182. if ($studentPresent == 0) {
  183. print "<select name='".$status."' value='".$last_status_name."'>";
  184. print "<option value='Student' selected='selected'>Student</option>";
  185. print "<option value='Auditing'>Auditing</option>";
  186. print "</select>";
  187. print "\n\t<input type='submit' value='"._("Add")."' />";
  188. }
  189. print "</form></p>";
  190. }
  191. }
  192. $output = new Block(ob_get_clean(), STANDARD_BLOCK);
  193. return $output;
  194. }
  195. /**
  196. * Prints the list of existing members for the section and a form to remove.
  197. *
  198. * @param string section
  199. * @return void
  200. * @access public
  201. * @since 8/24/05
  202. */
  203. function getMembers($section) {
  204. $harmoni = Harmoni::instance();
  205. $cmm = Services::getService("CourseManagement");
  206. $idManager = Services::getService("Id");
  207. $am = Services::GetService("AgentManager");
  208. ob_start();
  209. print "\n<h4>Members</h4>";
  210. $roster =$section->getRoster();
  211. if (!$roster->hasNextEnrollmentRecord()) {
  212. print "<p>No students are enrolled in this class.</p>";
  213. } else {
  214. while ($roster->hasNextEnrollmentRecord()) {
  215. $er =$roster->nextEnrollmentRecord();
  216. $agent =$am->getAgent($er->getStudent());
  217. $agentName = $agent->getDisplayName();
  218. $id =$agent->getId();
  219. $idString = $id->getIdString();
  220. $self = $harmoni->request->quickURL("coursemanagement", "edit_section_roster",
  221. array("agentIdToRemove"=>$idString,
  222. "search_criteria"=>RequestContext::value("search_criteria")));
  223. print "<form action='$self' method='post'>";
  224. print "\n<a href='".$harmoni->request->quickURL("agents", "edit_agent_details",
  225. array("agentId"=>$id->getIdString()))."'>";
  226. print "\n".$agent->getDisplayName()."</a>";
  227. $statusType =$er->getStatus();
  228. $status = $statusType->getKeyword();
  229. print "&nbsp;&nbsp;&nbsp;$status&nbsp;&nbsp;&nbsp;";
  230.  
  231. print "\n\t<input type='submit' value='"._("Remove")."' />";
  232. print "\n</form>\n";
  233. }
  234. }
  235. $output = new Block(ob_get_clean(), STANDARD_BLOCK);
  236. return $output;
  237. }
  238. /**
  239. * Process any changes in the add form to add a student.
  240. *
  241. * @param object section
  242. * @param string agentIdString
  243. * @param string status
  244. * @return void
  245. * @access public
  246. * @since 8/29/05
  247. */
  248. function addStudent($section, $agentIdString, $status) {
  249. $actionRows =$this->getActionRows();
  250. $pageRows = new Container(new YLayout(), OTHER, 1);
  251. $harmoni = Harmoni::instance();
  252. $cmm = Services::getService("CourseManagement");
  253. $idManager = Services::getService("Id");
  254. $am = Services::GetService("AgentManager");
  255. $agentId =$idManager->getId($agentIdString);
  256. $agent =$am->getAgent($agentId);
  257. $everyoneId =$idManager->getId("edu.middlebury.agents.everyone");
  258. $usersId =$idManager->getId("edu.middlebury.agents.users");
  259. /* Search the record to see if student is already enrolled. */
  260. $studentPresent = 0; // To check later whether student is enrolled or not
  261. $roster =$section->getRoster();
  262. while ($roster->hasNextEnrollmentRecord()) {
  263. $record = $roster->nextEnrollmentRecord();
  264. $studentId =$record->getStudent();
  265.  
  266. if ($agentId->isEqual($studentId))
  267. $studentPresent = 1; // Set to student already being enrolled
  268. }
  269. if ($studentPresent == 0) {
  270. $enrollmentStatusType = new Type("EnrollmentStatusType", "edu.middlebury", $status);
  271. $section->addStudent($agentId, $enrollmentStatusType);
  272. }
  273. }
  274. /**
  275. * Process any changes in the form to remove a section.
  276. *
  277. * @param object section
  278. * @param string agentIdString
  279. * @return void
  280. * @access public
  281. * @since 8/29/05
  282. */
  283. function removeStudent($section, $agentIdString) {
  284. $harmoni = Harmoni::instance();
  285. $harmoni->request->startNamespace("polyphony-agents");
  286. $harmoni->request->passthrough("agentId");
  287. $idManager = Services::getService("Id");
  288. $am = Services::GetService("AgentManager");
  289. $agentId =$idManager->getId($agentIdString);
  290. $section->removeStudent($agentId);
  291. }
  292. }

Documentation generated on Wed, 19 Sep 2007 10:23:00 -0400 by phpDocumentor 1.3.0RC3