Source for file suck_by_agent.act.php

Documentation is available at suck_by_agent.act.php

  1. <?php
  2.  
  3. /**
  4. * @package polyphony.coursemanagement
  5. *
  6. * @copyright Copyright &copy; 2006, Middlebury College
  7. * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License (GPL)
  8. *
  9. * @version $Id: suck_by_agent.act.php,v 1.7 2007/09/19 14:04:54 adamfranco Exp $
  10. */
  11.  
  12. require_once(POLYPHONY."/main/library/AbstractActions/MainWindowAction.class.php");
  13. require_once(HARMONI."GUIManager/Components/Blank.class.php");
  14.  
  15.  
  16. class suck_by_agentAction
  17. extends MainWindowAction
  18. {
  19. /**
  20. * Check Authorizations
  21. *
  22. * @return boolean
  23. * @access public
  24. * @since 4/26/05
  25. */
  26. function isAuthorizedToExecute () {
  27. // Check for authorization
  28. $authZManager = Services::getService("AuthZ");
  29. $idManager = Services::getService("IdManager");
  30. if ($authZManager->isUserAuthorized(
  31. $idManager->getId("edu.middlebury.authorization.view"),
  32. $idManager->getId("edu.middlebury.coursemanagement")))
  33. {
  34. return TRUE;
  35. } else {
  36. return FALSE;
  37. }
  38. }
  39. /**
  40. * Return the heading text for this action, or an empty string.
  41. *
  42. * @return string
  43. * @access public
  44. * @since 4/26/05
  45. */
  46. function getHeadingText () {
  47. return dgettext("polyphony", "Browse Agents and Groups");
  48. }
  49. /**
  50. * Build the content for this action
  51. *
  52. * @return void
  53. * @access public
  54. * @since 4/26/05
  55. */
  56. function buildContent () {
  57. $defaultTextDomain = textdomain("polyphony");
  58. $actionRows =$this->getActionRows();
  59. $pageRows = new Container(new YLayout(), OTHER, 1);
  60. $harmoni = Harmoni::instance();
  61. $harmoni->request->startNamespace("polyphony-agents");
  62.  
  63. $agentManager = Services::getService("Agent");
  64. $idManager = Services::getService("Id");
  65. $cm = Services::getService("CourseManagement");
  66. $everyoneId =$idManager->getId("edu.middlebury.agents.everyone");
  67. $usersId =$idManager->getId("edu.middlebury.agents.users");
  68. /*********************************************************
  69. * the agent search form
  70. *********************************************************/
  71. // Users header
  72. $actionRows->add(new Heading(_("Users"), 2), "100%", null, LEFT, CENTER);
  73. ob_start();
  74. $self = $harmoni->request->quickURL();
  75. $lastCriteria = $harmoni->request->get("search_criteria");
  76. $search_criteria_name = RequestContext::name("search_criteria");
  77. $search_type_name = RequestContext::name("search_type");
  78. print _("Search For Users").": ";
  79. print <<<END
  80. <form action='$self' method='post'>
  81. <div>
  82. <input type='text' name='$search_criteria_name' value='$lastCriteria' />
  83. <select name='$search_type_name'>
  84. END;
  85. $searchTypes =$agentManager->getAgentSearchTypes();
  86. while ($searchTypes->hasNext()) {
  87. $type =$searchTypes->next();
  88. $typeString = htmlspecialchars($type->getDomain()
  89. ."::".$type->getAuthority()
  90. ."::".$type->getKeyword());
  91. print "\n\t\t<option value='$typeString'";
  92. if ($harmoni->request->get("search_type") == $typeString)
  93. print " selected='selected'";
  94. print ">".$type->getKeyword()."</option>";
  95. }
  96. print "\n\t</select>";
  97. print "\n\t<input type='submit' value='"._("Search")."' />";
  98. print "\n\t<a href='".$harmoni->request->quickURL()."'>";
  99. print "<input type='button' value='"._("Clear")."' /></a>";
  100. print "\n</div>\n</form>";
  101. $actionRows->add(new Block(ob_get_contents(), STANDARD_BLOCK), "100%", null, LEFT, CENTER);
  102. ob_end_clean();
  103. /*********************************************************
  104. * The dropdown menu
  105. *********************************************************/
  106. //$pageRows->add(new Heading(_("Agents to Choose".$term->getDisplayName().""), 2), "100%", null, LEFT, CENTER);
  107. if (($search_criteria = $harmoni->request->get('search_criteria')) && ($search_type = $harmoni->request->get('search_type'))) {
  108. ob_start();
  109. $typeParts = explode("::", @html_entity_decode($search_type, ENT_COMPAT, 'UTF-8'));
  110. $searchType = new HarmoniType($typeParts[0], $typeParts[1], $typeParts[2]);
  111. $agents =$agentManager->getAgentsBySearch($search_criteria, $searchType);
  112. print "search: " . $search_criteria;
  113. $self = $harmoni->request->quickURL();
  114. $lastCriteria = $harmoni->request->get("agent_id");
  115. $agent_name = RequestContext::name("agent_id");
  116. print <<<END
  117. <form action='$self' method='post'>
  118. <div>
  119. <p align='center'>
  120. <select name='$agent_name'>
  121. END;
  122. $searchTypes =$agentManager->getAgentSearchTypes();
  123. while ($agents->hasNext()) {
  124. $agent =$agents->next();
  125. $id =$agent->getId();
  126. $idString = $id->getIdString();
  127. print "\n\t\t<option value='".$idString."'";
  128. if ($harmoni->request->get("agent_id") == $idString)
  129. print " selected='selected'";
  130. print ">".$agent->getDisplayName()."</option>";
  131. }
  132. print "\n\t</select>";
  133. print "\n\t<input type='submit' value='"._("Suck Agent's info")."' />";
  134. print "\n</p></div>\n</form>";
  135. print "\n <p align='center'>Sucking may take a few minutes</p>";
  136. $actionRows->add(new Block(ob_get_contents(), STANDARD_BLOCK), "100%", null, LEFT, CENTER);
  137. ob_end_clean();
  138. }
  139. if ($agentIdString = $harmoni->request->get('agent_id')) {
  140. ob_start();
  141. $id =$idManager->getId($agentIdString);
  142. $agent =$agentManager->getAgent($id);
  143. $this->refreshAgentDetails($agent);
  144. $actionRows->add(new Block(ob_get_contents(), STANDARD_BLOCK), "100%", null, LEFT, CENTER);
  145. ob_end_clean();
  146. }
  147. }
  148. function refreshAgentDetails($agent){
  149. $agentManager = Services::getService("Agent");
  150. $idManager = Services::getService("Id");
  151. //$classId =$idManager->getId("OU=Classes,OU=Groups,DC=middlebury,DC=edu ");
  152. //$classes =$agentManager->getGroup($classId);
  153. $agentId =$agent->getId();
  154. $agentIdString = $agentId->getIdString();
  155. //display agent info
  156. print "<h3>Classes for User: ".$agent->getDisplayName()."</h3>";
  157. $agentManager = Services::getService("Agent");
  158. $groups =$agentManager->getGroupsBySearch($agentId,
  159. new Type( "Agent & Group Search",
  160. "edu.middlebury.harmoni",
  161. "AncestorGroups"));
  162. while ($groups->hasNext()) {
  163. $group =$groups->next();
  164. $groupId =$group->getId();
  165. $idString = $groupId->getIdString();
  166. //print "\n\t<p> ".substr($idString,strlen($idString)-42,42)."</p>";
  167. if(substr($idString,strlen($idString)-42,42)!=",OU=Classes,OU=Groups,DC=middlebury,DC=edu"){
  168. continue;
  169. }
  170. //filter out semesters
  171. $name = $group->getDisplayName();
  172. if(substr($name,strlen($name)-4,1)!="-"){
  173. continue;
  174. }
  175. //filter out gym--actually, that's not fair, is it?
  176. //if(substr($name,0,4)=="phed"){
  177. //
  178. // continue;
  179. //}
  180. //print "\n\t<br> ".$group->getDisplayName()." ";
  181. suck_by_agentAction::_figureOut($group->getDisplayName(),$agentId);
  182. //print "</br>";
  183. //print "\n\t<p> ".."</p>";
  184. //print "\n\t<p> ".$group->getDisplayName()." aka ".$groupId->getIdString()."</p>";
  185. }
  186. return;
  187. }
  188. /**
  189. *Given a string, figure out if ets a term from the three letter name, creating it if necesary
  190. **/
  191.  
  192. function _figureOut($ldapName,$agentId){
  193. $term = suck_by_agentAction::_getTerm(substr($ldapName,strlen($ldapName)-3,3));
  194. $can = suck_by_agentAction::_getCanonicalCourse($ldapName);
  195. $offer = suck_by_agentAction::_getCourseOffering($can, $term,$ldapName);
  196. $section = suck_by_agentAction::_getCourseSection($offer,$ldapName);
  197. if($agentId==null){
  198. return $section;
  199. }
  200. $dbManager = Services::getService("DatabaseManager");
  201. $query= new SelectQuery;
  202. $query->addTable('cm_enroll');
  203. $query->addWhere("fk_cm_section='".addslashes($section->_id->getIdString())."'");
  204. $query->addWhere("fk_student_id='".addslashes($agentId->getIdString())."'");
  205. //I don't need Id, but I need to select something for the query to work
  206. $query->addColumn('id');//@TODO select count instead
  207. $res=$dbManager->query($query);
  208. if($res->getNumberOfRows()==0){
  209. $section->addStudent($agentId, $p = new Type("EnrollmentStatusType","edu.middlebury","LDAP"));
  210. }
  211. return $section;
  212. }
  213. /**
  214. *Gets a term from the three letter name, creating it if necesary
  215. **/
  216.  
  217. function _getTerm($termName ){
  218. $cm = Services::getService("CourseManagement");
  219. if($termName[0]=="s"){
  220. $season = "Spring";
  221. } else if($termName[0]=="f"){
  222. $season = "Fall";
  223. } else if($termName[0]=="w"){
  224. $season = "Winter";
  225. } else if($termName[0]=="l"){
  226. $season = "Summer";
  227. }
  228. $year = '20'.substr($termName,1,2);
  229. $name = $season." ".$year;
  230. $dbHandler = Services::getService("DBHandler");
  231. $query= new SelectQuery;
  232. $query->addTable('cm_term');
  233. $query->addWhere("name='".addslashes($name)."'");
  234. $query->addColumn('id');
  235. $res=$dbHandler->query($query);
  236.  
  237.  
  238.  
  239. if($res->getNumberOfRows()==0){
  240. $termType = new Type("TermType","edu.middlebury",$season);
  241. $term =$cm->createTerm($termType,$arr=array());
  242. $term->updateDisplayName($name);
  243. return $term;
  244. }else{
  245. $row = $res->getCurrentRow();
  246. $idManager = Services::getService("Id");
  247. $id =$idManager->getId($row['id']);
  248. $term =$cm->getTerm($id);
  249. return $term;
  250.  
  251. }
  252. }
  253. function _getCanonicalCourse($courseString ){
  254. $cm = Services::getService("CourseManagement");
  255. //$num = substr($courseString,4,4);
  256. $number = substr($courseString,0,strlen($courseString)-5);
  257. $dbHandler = Services::getService("DBHandler");
  258. $query= new SelectQuery;
  259. $query->addTable('cm_can');
  260. $query->addWhere("number='".addslashes($number)."'");
  261. $query->addColumn('id');
  262. $res=$dbHandler->query($query);
  263.  
  264.  
  265.  
  266. if($res->getNumberOfRows()==0){
  267. //$termType = new Type("Coursemanagement","edu.middlebury",$season);
  268. //$index = $cm->_typeToIndex('term',$termType);
  269. $dept = substr($courseString,0,strlen($courseString)-9);
  270. $type = new Type("CanonicalCourseType","edu.middlebury",$dept);
  271. $stattype = new Type("CanonicalCourseStatusType","edu.middlebury","LDAP");
  272. $can =$cm->createCanonicalCourse($number,$number,"",$type,$stattype,1);
  273. //print "<font size=3 color='red'>#</font>\n";
  274. return $can;
  275. //$canId =$can->getId();
  276.  
  277. //return $canId->getIdString();
  278. }else{
  279. $row = $res->getCurrentRow();
  280. //$the_index = $row['id'];
  281. $idManager = Services::getService("Id");
  282. $id =$idManager->getId($row['id']);
  283. $can =$cm->getCanonicalCourse($id);
  284. // print "<font size=3>#</font>\n";
  285. return $can;
  286.  
  287. }
  288. }
  289. function _getCourseOffering($can,$term,$courseString ){
  290. //$num = substr($courseString,4,4);
  291. $number = substr($courseString,0,strlen($courseString)-5);
  292. $termId =$term->getId();
  293. $dbHandler = Services::getService("DBHandler");
  294. $query= new SelectQuery;
  295. $query->addTable('cm_offer');
  296. $query->addWhere("number='".addslashes($number)."'");
  297. $query->addWhere("fk_cm_term='".addslashes($termId->getIdString())."'");
  298. $query->addColumn('id');
  299. $res=$dbHandler->query($query);
  300.  
  301. if($res->getNumberOfRows()==0){
  302. $deftype1 = new Type("CourseOfferingType","edu.middlebury","LDAP");
  303. $deftype2 = new Type("CourseOfferingStatusType","edu.middlebury","LDAP");
  304. $deftype3 = new Type("GradeType","edu.middlebury","LDAP");
  305. $offer =$can->createCourseOffering($number,$number,"",$termId,$deftype1,$deftype2,$deftype3);
  306. // print "<font size=3 color='red'>#</font>\n";
  307. return $offer;
  308. }else{
  309. //print " ";
  310. $row = $res->getCurrentRow();
  311. $cm = Services::getService("CourseManagement");
  312. $idManager = Services::getService("Id");
  313. $id =$idManager->getId($row['id']);
  314. $offer =$cm->getCourseOffering($id);
  315. //print "<font size=3>#</font>\n";
  316. return $offer;
  317.  
  318. }
  319. }
  320. function _getCourseSection($offer,$ldapName){
  321. $sections =$offer->getCourseSections();
  322. $number = substr($ldapName,0,strlen($ldapName)-4);
  323. while($sections->hasNextCourseSection()){
  324. $section =$sections->nextCourseSection();
  325. if($section->getNumber()==$number){
  326. $cm = Services::getService("CourseManagement");
  327. //print "<font size=3>#</font>\n";
  328. return $section;
  329. }
  330. }
  331. $deftype = new Type("CourseSectionStatusType","edu.middlebury","LDAP");
  332. if(strcasecmp($number[strlen($number)-1],'T')<0){
  333. $stattype = new Type("CourseSectionType","edu.middlebury","Main");
  334. }else{
  335. $stattype = new Type("CourseSectionType","edu.middlebury","Auxiliary");
  336. }
  337. $section =$offer->createCourseSection($number,$number,"",$deftype,$stattype,$loc = "");
  338. //print "<font size=3 color='red'>#</font>\n";
  339. return $section;
  340. }
  341. /**
  342. * copied stright from edit_agent_detailsAction in the agent module
  343. **/
  344.  
  345. function _getUsableProperties($agent){
  346. $propertiesArray=array();
  347. $propertiesIterator =$agent->getProperties();
  348. $i=0;
  349. while($propertiesIterator->hasNext()){
  350. $property =$propertiesIterator->next();
  351. $type=$property->getType();
  352. $typeString = $type->getDomain()."::".$type->getAuthority()."::".$type->getKeyword();
  353. $keys =$property->getKeys();
  354. while($keys->hasNext()){
  355. $key=$keys->next();
  356. $propertiesArray[$key]['value'] = $property->getProperty($key);
  357. $propertiesArray[$key]['type'] = $typeString;
  358. }
  359. }
  360. return $propertiesArray;
  361. }
  362. }

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