Source for file course_search.act.php

Documentation is available at course_search.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: course_search.act.php,v 1.14 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. require_once(POLYPHONY."/main/modules/agents/edit_agent_details.act.php");
  15.  
  16. require_once(HARMONI."oki2/agent/AgentSearches/ClassTokenSearch.class.php");
  17.  
  18.  
  19. class course_searchAction
  20. extends MainWindowAction
  21. {
  22. /**
  23. * Check Authorizations
  24. *
  25. * @return boolean
  26. * @access public
  27. * @since 4/26/05
  28. */
  29. function isAuthorizedToExecute () {
  30. // Check for authorization
  31. $authZManager = Services::getService("AuthZ");
  32. $idManager = Services::getService("IdManager");
  33. if ($authZManager->isUserAuthorized(
  34. $idManager->getId("edu.middlebury.authorization.view"),
  35. $idManager->getId("edu.middlebury.coursemanagement")))
  36. {
  37. return TRUE;
  38. } else {
  39.  
  40. return FALSE;
  41. }
  42. }
  43.  
  44. /**
  45. * Return the heading text for this action, or an empty string.
  46. *
  47. * @return string
  48. * @access public
  49. * @since 4/26/05
  50. */
  51. function getHeadingText () {
  52. return dgettext("polyphony", "Search for Courses");
  53. }
  54.  
  55. /**
  56. * Build the content for this action
  57. *
  58. * @return void
  59. * @access public
  60. * @since 4/26/05
  61. */
  62. function buildContent () {
  63. $cm = Services::getService("CourseManagement");
  64.  
  65. $defaultTextDomain = textdomain("polyphony");
  66.  
  67. $actionRows =$this->getActionRows();
  68. $pageRows = new Container(new YLayout(), OTHER, 1);
  69. $harmoni = Harmoni::instance();
  70.  
  71. $searchNumber = RequestContext::value('search_number');
  72.  
  73. if(is_null($searchNumber)){
  74. $searchNumber = "";
  75. }
  76.  
  77. ob_start();
  78.  
  79.  
  80.  
  81. /***************************************************************************************************
  82. * The following performs a wild-card search through LDAP and sucks the courses into the database. *
  83. ***************************************************************************************************/
  84.  
  85. $self = $harmoni->request->quickURL();
  86. print ("<h2>Search for course offerings by the following criteria:</h2>")."";
  87. print "\n\t<form action='$self' method='post'>
  88. \n\t<div>";
  89.  
  90. print "<table>";
  91.  
  92.  
  93. print "\n\t<tr><td>Number: </td><td><input type='text' name='search_number' value='".$searchNumber."'/></td></tr>";
  94.  
  95.  
  96. print "\n\t<tr><td>Term: </td><td><select name='search_term'>";
  97. print "\n\t<option value=''";
  98. print "selected='selected'";
  99. print ">Choose a term</option>";
  100.  
  101.  
  102. //@TODO this sorting is probably pretty slow--it's multiple queries per term.
  103. $numOfImproperOfferingTerms=-1;
  104. $terms =$cm->getTerms();
  105. while($terms->hasNextTerm()){
  106. $term =$terms->nextTerm();
  107. $schedule =$term->getSchedule();
  108. if($schedule->hasNextScheduleItem()){
  109. $item1 =$schedule->nextScheduleItem();
  110. $terms2[$item1->getStart()] = $term;
  111. }else{
  112. $terms2[$numOfImproperOfferingTerms] =$term;
  113. $numOfImproperOfferingTerms--;
  114. }
  115.  
  116. }
  117.  
  118.  
  119. krsort($terms2);
  120. foreach($terms2 as $term){
  121. $id =$term->getId();
  122. print "\n\t<option value='".$id->getIdString()."'";
  123. /*if($searchTerm==$id->getIdString()){
  124. print "selected='selected'";
  125. }*/
  126. print ">".$term->getDisplayName()."</option>";
  127. }
  128. print "\n\t</select></td></tr>";
  129.  
  130. print "\n</table>";
  131.  
  132.  
  133. print "\n\t<p><input type='submit' value='"._("Search!")."'/></p>";
  134. print "\n\t</div></form>";
  135.  
  136. //$actionRows =$this->getActionRows();
  137. $actionRows->add(new Block(ob_get_contents(),2),"100%", null, CENTER, TOP);
  138. ob_end_clean();
  139.  
  140. $searchTerm = RequestContext::value('search_term');
  141. if(is_null($searchTerm)){
  142. $searchTerm="";
  143. }
  144.  
  145. /*
  146.  
  147. if ($search_criteria = $harmoni->request->get('search_criteria')) {
  148. //$typeParts = explode("::", @html_entity_decode($search_type, ENT_COMPAT, 'UTF-8'));
  149.  
  150.  
  151.  
  152. $searchType = new HarmoniType("Agent & Group Search", "edu.middlebury.harmoni", "TokenSearch");
  153. //$searchType = new HarmoniType("Agent & Group Search", "edu.middlebury.harmoni", "WildcardSearch");
  154. $string= "*".$search_criteria."*";
  155. $agents =$agentManager->getAgentsBySearch($string, $searchType);
  156. print "search: " . $search_criteria;
  157.  
  158.  
  159.  
  160. while ($agents->hasNext()) {
  161. $agent =$agents->next();
  162. $id =$agent->getId();
  163.  
  164.  
  165.  
  166.  
  167. $harmoni->history->markReturnURL("polyphony/agents/edit_agent_details");
  168.  
  169. print "\n<p align='center'><a href='".$harmoni->request->quickURL("agents","edit_agent_details", array("agentId"=>$id->getIdString()))."'>";
  170. print "\n".$agent->getDisplayName()."</a>";
  171. print "\n - <a href=\"Javascript:alert('"._("Id:").'\n\t'.addslashes($id->getIdString())."')\">Id</a></p>";
  172. }
  173. print "\n</div>";
  174.  
  175. $actionRows->add(new Block(ob_get_contents(), STANDARD_BLOCK), "100%", null, LEFT, CENTER);
  176. ob_end_clean();
  177.  
  178.  
  179. }
  180.  
  181. */
  182.  
  183.  
  184.  
  185. if ($searchNumber != "" || $searchTerm != "")
  186. {
  187.  
  188.  
  189. ob_start();
  190.  
  191. $pageRows->add(new Heading("Canonical course search results", STANDARD_BLOCK), "100%", null, LEFT, CENTER);
  192. ob_start();
  193.  
  194. print "<p><h2>Search Results</h2></p>";
  195.  
  196.  
  197.  
  198. $searchType = new ClassTokenSearch();
  199.  
  200. $string = "*".$searchNumber."*";
  201. $DNs =$searchType->getClassDNsBySearch($string);
  202. print "search: " . $searchNumber;
  203.  
  204. /*
  205.  
  206. $dbHandler = Services::getService("DBHandler");
  207. $query= new SelectQuery;
  208. $query->addTable('cm_offer');
  209. $query->addColumn('id');
  210.  
  211. if($searchNumber!=null){
  212.  
  213. $query->addWhere("number like '%".addslashes($searchNumber)."%'");
  214. }
  215. if($searchTerm!=null){
  216.  
  217. $query->addWhere("fk_cm_term='".addslashes($searchTerm)."'");
  218. }
  219.  
  220.  
  221. $res =$dbHandler->query($query);*/
  222.  
  223.  
  224. $sections=array();
  225. $cm = Services::getService("CourseManagement");
  226. $im = Services::getService("Id");
  227.  
  228.  
  229.  
  230.  
  231.  
  232. foreach($DNs as $idString) {
  233.  
  234.  
  235.  
  236. if(substr($idString,strlen($idString)-42,42)!=",OU=Classes,OU=Groups,DC=middlebury,DC=edu"){
  237. continue;
  238. }
  239.  
  240.  
  241.  
  242.  
  243. $len = 0;
  244. while($idString[$len+3]!=","&&$len<strlen($idString)){
  245. $len++;
  246. }
  247. $name = substr($idString,3,$len);
  248.  
  249.  
  250. /*
  251. if(!$term somthings $searchTerm){
  252. //continue
  253. }
  254. */
  255.  
  256. //filter out semesters
  257.  
  258.  
  259. if(substr($name,strlen($name)-4,1)!="-"){
  260. continue;
  261. }
  262.  
  263. //filter out gym--actually, that's not fair, is it?
  264. //if(substr($name,0,4)=="phed"){
  265. //
  266. // continue;
  267. //}
  268.  
  269. $sections[]= suck_by_agentAction::_figureOut($name,$agentId = null);
  270.  
  271.  
  272.  
  273. }
  274.  
  275. $offerings = array();
  276.  
  277. $termId = null;
  278. if($searchTerm != ""){
  279. //$term = substr($name, strlen($name)-3,3);
  280. $idManager = Services::getService("Id");
  281. // $term =$cm->getTerm($idManager->getId($searchTerm));
  282. // $termId =$term->getId();
  283. $termId =$idManager->getId($searchTerm);
  284. }
  285. foreach($sections as $section){
  286.  
  287. $offering =$section->getCourseOffering();
  288. $term2 =$offering->getTerm();
  289. $term2Id =$term2->getId();
  290. if(!is_null($termId)&&!$termId->isEqual($term2Id)){
  291. continue;
  292. }
  293. $offeringId =$offering->getId();
  294. $offerings[$offeringId->getIdString()] =$offering;
  295.  
  296. }
  297. /*
  298.  
  299. foreach($DNs as $DN){
  300.  
  301.  
  302.  
  303.  
  304.  
  305. $id =$im->getId($row['id']);
  306. $array[] =$cm->getCourseOffering($id);
  307. }*/
  308.  
  309. $iter = new HarmoniCourseOfferingIterator($offerings);
  310. edit_agent_detailsAction::printCourseOfferings($iter);
  311.  
  312.  
  313.  
  314. $actionRows->add(new Block(ob_get_contents(),2),"100%", null, CENTER, TOP);
  315. ob_end_clean();
  316.  
  317.  
  318. }
  319. }
  320. }
  321.  
  322. /*Once we can connect to BannerWeb sometime in the future, it would be ideal to change this so that it sucks the
  323. courses out of BannerWeb instead of LDAP. The question would be whether the wild card search can be done on
  324. BannerWeb with the addition of asterisks before and after the search query, as we have been able to do on LDAP.
  325. The term search does not quite work. My speculation is that somehow the terms that are sucked by LDAP cannot be
  326. searched directly on our own database.
  327. */

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