Source for file CourseManagementManager.class.php

Documentation is available at CourseManagementManager.class.php

  1. <?php
  2.  
  3. /**
  4. * @package harmoni.osid_v2.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: CourseManagementManager.class.php,v 1.51 2007/09/13 16:04:18 adamfranco Exp $
  10. */
  11.  
  12. require_once(OKI2."/osid/coursemanagement/CourseManagementManager.php");
  13.  
  14. require_once(HARMONI."oki2/coursemanagement/CanonicalCourse.class.php");
  15. require_once(HARMONI."oki2/coursemanagement/CanonicalCourseIterator.class.php");
  16. require_once(HARMONI."oki2/coursemanagement/CourseGradeRecord.class.php");
  17. require_once(HARMONI."oki2/coursemanagement/CourseGradeRecordIterator.class.php");
  18. require_once(HARMONI."oki2/coursemanagement/CourseGroup.class.php");
  19. require_once(HARMONI."oki2/coursemanagement/CourseGroupIterator.class.php");
  20. require_once(HARMONI."oki2/coursemanagement/CourseOffering.class.php");
  21. require_once(HARMONI."oki2/coursemanagement/CourseOfferingIterator.class.php");
  22. require_once(HARMONI."oki2/coursemanagement/CourseSection.class.php");
  23. require_once(HARMONI."oki2/coursemanagement/CourseSectionIterator.class.php");
  24. require_once(HARMONI."oki2/coursemanagement/EnrollmentRecord.class.php");
  25. require_once(HARMONI."oki2/coursemanagement/EnrollmentRecordIterator.class.php");
  26. require_once(HARMONI."oki2/coursemanagement/Term.class.php");
  27. require_once(HARMONI."oki2/coursemanagement/TermIterator.class.php");
  28.  
  29. /**
  30. * <p>
  31. * CourseManagementManager handles creating and deleting
  32. *
  33. * <ul>
  34. * <li>
  35. * CanonicalCourse,
  36. * </li>
  37. * <li>
  38. * CourseGradeRecord,
  39. * </li>
  40. * <li>
  41. * CourseGroup,
  42. * </li>
  43. * <li>
  44. * Term;
  45. * </li>
  46. * </ul>
  47. *
  48. * and gets:
  49. *
  50. * <ul>
  51. * <li>
  52. * CanonicalCourse,
  53. * </li>
  54. * <li>
  55. * CourseGradeRecord,
  56. * </li>
  57. * <li>
  58. * CourseGroup,
  59. * </li>
  60. * <li>
  61. * CourseOffering,
  62. * </li>
  63. * <li>
  64. * CourseSection,
  65. * </li>
  66. * <li>
  67. * Term,
  68. * </li>
  69. * <li>
  70. * various implementation Types.
  71. * </li>
  72. * </ul>
  73. * </p>
  74. *
  75. * <p>
  76. * All implementations of OsidManager (manager) provide methods for accessing
  77. * and manipulating the various objects defined in the OSID package. A manager
  78. * defines an implementation of an OSID. All other OSID objects come either
  79. * directly or indirectly from the manager. New instances of the OSID objects
  80. * are created either directly or indirectly by the manager. Because the OSID
  81. * objects are defined using interfaces, create methods must be used instead
  82. * of the new operator to create instances of the OSID objects. Create methods
  83. * are used both to instantiate and persist OSID objects. Using the
  84. * OsidManager class to define an OSID's implementation allows the application
  85. * to change OSID implementations by changing the OsidManager package name
  86. * used to load an implementation. Applications developed using managers
  87. * permit OSID implementation substitution without changing the application
  88. * source code. As with all managers, use the OsidLoader to load an
  89. * implementation of this interface.
  90. * </p>
  91. *
  92. * <p></p>
  93. *
  94. * <p>
  95. * OSID Version: 2.0
  96. * </p>
  97. *
  98. * @package harmoni.osid_v2.coursemanagement
  99. *
  100. * @copyright Copyright &copy; 2005, Middlebury College
  101. * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License (GPL)
  102. *
  103. * @version $Id: CourseManagementManager.class.php,v 1.51 2007/09/13 16:04:18 adamfranco Exp $
  104. */
  105. class HarmoniCourseManagementManager
  106. extends CourseManagementManager
  107. {
  108.  
  109. /**
  110. * @variable object OsidContext $_osidContext the OSID context.
  111. * @access private
  112. * @variable object Properties $_configuration the configuration for the CourseManagementManager.
  113. * @access private
  114. * @variable object Hierarchy $_hierarchy the hierarchy
  115. * @access private
  116. * @variable object Id $_courseManagementRootId the root id of the CourseManagement part of the hierarchy
  117. * @access private
  118. * @variable object Id $_canonicalCoursesId the parent of all top level CanonicalCourses
  119. * @access private
  120. * @variable object Id $_courseGroupsId the parent of all top level CourseGroups
  121. * @access private
  122. ***/
  123. var $_osidContext;
  124. var $_configuration;
  125. var $_hierarchy;
  126. var $_courseManagementRootId;
  127. var $_canonicalCoursesId;
  128. var $_courseGroupsId;
  129.  
  130.  
  131.  
  132. function HarmoniCourseManagementManager () {
  133.  
  134.  
  135. }
  136.  
  137.  
  138.  
  139. /**
  140. * Assign the configuration of this Manager. Valid configuration options are as
  141. * follows:
  142. * hierarchy_id string
  143. * root_id string
  144. * course_management_id string
  145. * canonical_courses_id string
  146. * course_groups_id string
  147. *
  148. * @param object Properties $configuration (original type: java.util.Properties)
  149. *
  150. * @throws object OsidException An exception with one of the following
  151. * messages defined in org.osid.OsidException: {@link }
  152. * org.osid.OsidException#OPERATION_FAILED OPERATION_FAILED},
  153. * {@link org.osid.OsidException#PERMISSION_DENIED}
  154. * PERMISSION_DENIED}, {@link }
  155. * org.osid.OsidException#CONFIGURATION_ERROR
  156. * CONFIGURATION_ERROR}, {@link }
  157. * org.osid.OsidException#UNIMPLEMENTED UNIMPLEMENTED}, {@link }
  158. * org.osid.OsidException#NULL_ARGUMENT NULL_ARGUMENT}
  159. *
  160. * @access public
  161. */
  162. function assignConfiguration ( $configuration ) {
  163. $this->_configuration =$configuration;
  164.  
  165. $hierarchyId =$configuration->getProperty('hierarchy_id');
  166. $courseManagementId =$configuration->getProperty('course_management_id');
  167. $terms =$configuration->getProperty('terms_to_add');
  168. $makeTerms =$configuration->getProperty('whether_to_add_terms');
  169. $authority =$configuration->getProperty('authority');
  170.  
  171. // ** parameter validation
  172. ArgumentValidator::validate($hierarchyId, StringValidatorRule::getRule(), true);
  173. ArgumentValidator::validate($courseManagementId, StringValidatorRule::getRule(), true);
  174. ArgumentValidator::validate($makeTerms, BooleanValidatorRule::getRule(), true);
  175. ArgumentValidator::validate($authority, StringValidatorRule::getRule(), true);
  176. // ** end of parameter validation
  177.  
  178.  
  179.  
  180. //convert to ids
  181. $idManager = Services::getService("Id");
  182.  
  183. $hierarchyId =$idManager->getId($hierarchyId);
  184. $canonicalCoursesId =$idManager->getId($courseManagementId.".canonicalcourses");
  185. $courseGroupsId =$idManager->getId($courseManagementId.".coursegroups");
  186. $courseManagementId =$idManager->getId($courseManagementId);
  187.  
  188.  
  189. $hierarchyManager = Services::getService("Hierarchy");
  190. $this->_hierarchy =$hierarchyManager->getHierarchy($hierarchyId);
  191. $this->_courseManagementRootId =$courseManagementId;
  192. $this->_canonicalCoursesId =$canonicalCoursesId;
  193. $this->_courseGroupsId =$courseGroupsId;
  194.  
  195.  
  196. //terms
  197. if($makeTerms){
  198.  
  199. if (!isset($_SESSION['terms_have_been_taken_care_of'])) {
  200.  
  201. /*********************************************************
  202. * Check for existing data in the database
  203. *********************************************************/
  204. $dbManager = Services::getService("DatabaseManager");
  205. $query = new SelectQuery();
  206. $query->addTable('cm_term');
  207. $query->addColumn('id');
  208. $res=$dbManager->query($query);
  209.  
  210. //create terms only if the term table is empty
  211. if(!$res->hasMoreRows()){
  212. $sm = Services::getService("Scheduling");
  213. foreach($terms as $array){
  214.  
  215. $name = $array['name'];
  216.  
  217. $start = $array['start']->asUnixTimeStamp()*1000;
  218. $end = $array['end']->asUnixTimeStamp()*1000-1;
  219.  
  220. $type = new Type("ScheduleItemStatusType",$authority,"Autogenerated Term");
  221. $schedule[0] =$sm->createScheduleItem($name." range","The start and end of the ".$name." Term",
  222. $type,$start,$end,null);
  223. $term =$this->createTerm($array['type'],$schedule);
  224. $term->updateDisplayName($name);
  225.  
  226. }
  227. $_SESSION['table_setup_complete'] = TRUE;
  228. }
  229. }
  230. }
  231. }
  232.  
  233. /**
  234. * Return context of this OsidManager.
  235. *
  236. * @return object OsidContext
  237. *
  238. * @throws object OsidException
  239. *
  240. * @access public
  241. */
  242. function getOsidContext () {
  243. return $this->_osidContext;
  244. }
  245.  
  246. /**
  247. * Assign the context of this OsidManager.
  248. *
  249. * @param object OsidContext $context
  250. *
  251. * @throws object OsidException An exception with one of the following
  252. * messages defined in org.osid.OsidException: {@link }
  253. * org.osid.OsidException#NULL_ARGUMENT NULL_ARGUMENT}
  254. *
  255. * @access public
  256. */
  257. function assignOsidContext ( $context ) {
  258. $this->_osidContext =$context;
  259. }
  260.  
  261.  
  262. /**
  263. * Create a new CanonicalCourse. The display name defaults to the title, but this can be changed later.
  264. *
  265. * @param string $title
  266. * @param string $number
  267. * @param string $description
  268. * @param object Type $courseType
  269. * @param object Type $courseStatusType
  270. * @param float $credits
  271. *
  272. * @return object CanonicalCourse
  273. *
  274. * @throws object CourseManagementException An exception
  275. * with one of the following messages defined in
  276. * org.osid.coursemanagement.CourseManagementException may be
  277. * thrown: {@link }
  278. * org.osid.coursemanagement.CourseManagementException#OPERATION_FAILED
  279. * OPERATION_FAILED}, {@link }
  280. * org.osid.coursemanagement.CourseManagementException#PERMISSION_DENIED
  281. * PERMISSION_DENIED}, {@link }
  282. * org.osid.coursemanagement.CourseManagementException#CONFIGURATION_ERROR
  283. * CONFIGURATION_ERROR}, {@link }
  284. * org.osid.coursemanagement.CourseManagementException#UNIMPLEMENTED
  285. * UNIMPLEMENTED}, {@link }
  286. * org.osid.coursemanagement.CourseManagementException#NULL_ARGUMENT
  287. * NULL_ARGUMENT}, {@link }
  288. * org.osid.coursemanagement.CourseManagementException#UNKNOWN_TYPE
  289. * UNKNOWN_TYPE}
  290. *
  291. * @access public
  292. */
  293. function createCanonicalCourse ( $title, $number, $description, $courseType, $courseStatusType, $credits ) {
  294. //make id
  295. $idManager = Services::getService("IdManager");
  296. $id=$idManager->createId();
  297.  
  298. //make node
  299. $type = new Type("CourseManagement","edu.middlebury", "CanonicalCourse");
  300. $node =$this->_hierarchy->createNode($id,$this->_canonicalCoursesId,$type,$title,$description);
  301.  
  302. //prepare insert query
  303. $dbManager= Services::getService("DatabaseManager");
  304. $query= new InsertQuery;
  305. $query->setTable('cm_can');
  306.  
  307. //ready values
  308. $query->setColumns(array('id','number','credits','equivalent','fk_cm_can_type','title','fk_cm_can_stat_type'));
  309. $values[]="'".addslashes($id->getIdString())."'";
  310. $values[]="'".addslashes($number)."'";
  311. $values[]="'".addslashes($credits)."'";
  312. $values[]="'".addslashes($id->getIdString())."'";
  313. $values[]="'".$this->_typeToIndex('can',$courseType)."'";
  314. $values[]="'".addslashes($title)."'";
  315. $values[]="'".$this->_typeToIndex('can_stat',$courseStatusType)."'";
  316. $query->addRowOfValues($values);
  317.  
  318.  
  319. //query
  320. $dbManager->query($query);
  321.  
  322. //make object
  323. $ret = new HarmoniCanonicalCourse($id, $node);
  324. return $ret;
  325.  
  326. }
  327.  
  328. /**
  329. * Delete a CanonicalCourse.
  330. *
  331. * @param object Id $canonicalCourseId
  332. *
  333. * @throws object CourseManagementException An exception
  334. * with one of the following messages defined in
  335. * org.osid.coursemanagement.CourseManagementException may be
  336. * thrown: {@link }
  337. * org.osid.coursemanagement.CourseManagementException#OPERATION_FAILED
  338. * OPERATION_FAILED}, {@link }
  339. * org.osid.coursemanagement.CourseManagementException#PERMISSION_DENIED
  340. * PERMISSION_DENIED}, {@link }
  341. * org.osid.coursemanagement.CourseManagementException#CONFIGURATION_ERROR
  342. * CONFIGURATION_ERROR}, {@link }
  343. * org.osid.coursemanagement.CourseManagementException#UNIMPLEMENTED
  344. * UNIMPLEMENTED}, {@link }
  345. * org.osid.coursemanagement.CourseManagementException#NULL_ARGUMENT
  346. * NULL_ARGUMENT}, {@link }
  347. * org.osid.coursemanagement.CourseManagementException#UNKNOWN_ID
  348. * UNKNOWN_ID}
  349. *
  350. * @access public
  351. */
  352. function deleteCanonicalCourse ( $canonicalCourseId ) {
  353.  
  354. ArgumentValidator::validate($canonicalCourseId, ExtendsValidatorRule::getRule("Id"), true);
  355.  
  356. $node =$this->_hierarchy->getNode($canonicalCourseId);
  357. $iterator =$node->getChildren();
  358. if($iterator->hasNextNode()){
  359. print "<b>Warning!</b> Can't delete CanonicalCourses without deleting the CourseOfferings and the CanonicalCourse children first.";
  360. return;
  361. }
  362. $this->_hierarchy->deleteNode($canonicalCourseId);
  363.  
  364.  
  365. $dbManager = Services::getService("DatabaseManager");
  366. $query= new DeleteQuery;
  367. $query->setTable('cm_can');
  368. $query->addWhere("id=".addslashes($canonicalCourseId->getIdString()));
  369. $dbManager->query($query);
  370. }
  371.  
  372. /**
  373. * Get all CanonicalCourses.
  374. *
  375. * @return object CanonicalCourseIterator
  376. *
  377. * @throws object CourseManagementException An exception
  378. * with one of the following messages defined in
  379. * org.osid.coursemanagement.CourseManagementException may be
  380. * thrown: {@link }
  381. * org.osid.coursemanagement.CourseManagementException#OPERATION_FAILED
  382. * OPERATION_FAILED}, {@link }
  383. * org.osid.coursemanagement.CourseManagementException#PERMISSION_DENIED
  384. * PERMISSION_DENIED}, {@link }
  385. * org.osid.coursemanagement.CourseManagementException#CONFIGURATION_ERROR
  386. * CONFIGURATION_ERROR}, {@link }
  387. * org.osid.coursemanagement.CourseManagementException#UNIMPLEMENTED
  388. * UNIMPLEMENTED}
  389. *
  390. * @access public
  391. */
  392. function getCanonicalCourses () {
  393.  
  394.  
  395. $dbManager = Services::getService("DatabaseManager");
  396. $idManager = Services::getService("Id");
  397. $query= new SelectQuery;
  398.  
  399.  
  400. $query->addTable('cm_can');
  401. $query->addColumn('id');
  402. $res=$dbManager->query($query);
  403.  
  404. $canonicalCourseArray = array();
  405.  
  406. while($res->hasMoreRows()){
  407.  
  408. $row = $res->getCurrentRow();
  409. $res->advanceRow();
  410. $canonicalIdString = $row['id'];
  411. $canonicalId =$idManager->getId($canonicalIdString);
  412. $canonicalCourseArray[] = $this->getCanonicalCourse($canonicalId);
  413.  
  414. }
  415. $ret = new HarmoniCanonicalCourseIterator($canonicalCourseArray);
  416. return $ret;
  417.  
  418. }
  419.  
  420. /**
  421. * Get a CanonicalCourse by Id.
  422. *
  423. * @param object Id $canonicalCourseId
  424. *
  425. * @return object CanonicalCourse
  426. *
  427. * @throws object CourseManagementException An exception
  428. * with one of the following messages defined in
  429. * org.osid.coursemanagement.CourseManagementException may be
  430. * thrown: {@link }
  431. * org.osid.coursemanagement.CourseManagementException#OPERATION_FAILED
  432. * OPERATION_FAILED}, {@link }
  433. * org.osid.coursemanagement.CourseManagementException#PERMISSION_DENIED
  434. * PERMISSION_DENIED}, {@link }
  435. * org.osid.coursemanagement.CourseManagementException#CONFIGURATION_ERROR
  436. * CONFIGURATION_ERROR}, {@link }
  437. * org.osid.coursemanagement.CourseManagementException#UNIMPLEMENTED
  438. * UNIMPLEMENTED}, {@link }
  439. * org.osid.coursemanagement.CourseManagementException#NULL_ARGUMENT
  440. * NULL_ARGUMENT}, {@link }
  441. * org.osid.coursemanagement.CourseManagementException#UNKNOWN_ID
  442. * UNKNOWN_ID}
  443. *
  444. * @access public
  445. */
  446. function getCanonicalCourse ( $canonicalCourseId ) {
  447. $node =$this->_hierarchy->getNode($canonicalCourseId);
  448. $ret = new HarmoniCanonicalCourse($canonicalCourseId, $node);
  449. return $ret;
  450.  
  451. }
  452.  
  453. /**
  454. * Get all CanonicalCourses of the specified Type.
  455. *
  456. * @param object Type $courseType
  457. *
  458. * @return object CanonicalCourseIterator
  459. *
  460. * @throws object CourseManagementException An exception
  461. * with one of the following messages defined in
  462. * org.osid.coursemanagement.CourseManagementException may be
  463. * thrown: {@link }
  464. * org.osid.coursemanagement.CourseManagementException#OPERATION_FAILED
  465. * OPERATION_FAILED}, {@link }
  466. * org.osid.coursemanagement.CourseManagementException#PERMISSION_DENIED
  467. * PERMISSION_DENIED}, {@link }
  468. * org.osid.coursemanagement.CourseManagementException#CONFIGURATION_ERROR
  469. * CONFIGURATION_ERROR}, {@link }
  470. * org.osid.coursemanagement.CourseManagementException#UNIMPLEMENTED
  471. * UNIMPLEMENTED}, {@link }
  472. * org.osid.coursemanagement.CourseManagementException#NULL_ARGUMENT
  473. * NULL_ARGUMENT}, {@link }
  474. * org.osid.coursemanagement.CourseManagementException#UNKNOWN_TYPE
  475. * UNKNOWN_TYPE}
  476. *
  477. * @access public
  478. */
  479. function getCanonicalCoursesByType ( $courseType ) {
  480. //get the index for the type
  481. $typeIndex = $this->_typeToIndex('can',$courseType);
  482.  
  483. //get all canonical courses with the appropriate type
  484. $dbManager = Services::getService("DatabaseManager");
  485. $query= new SelectQuery;
  486. $query->addTable('cm_can');
  487. $query->addColumn('id');
  488. $query->addWhere("fk_cm_can_type='".addslashes($typeIndex)."'");
  489. $res=$dbManager->query($query);
  490.  
  491. //convert results to array of Canonical Courses
  492. $canonicalCourseArrayByType = array();
  493. $idManager = Services::getService("IdManager");
  494. while($res->hasMoreRows()){
  495. $row = $res->getCurrentRow();
  496. $res->advanceRow();
  497. $id =$idManager->getId($row['id']);
  498. $canonicalCourseArrayByType[] =$this->getCanonicalCourse($id);
  499. }
  500.  
  501. //convert to an iterator
  502. $ret = new HarmoniCanonicalCourseIterator($canonicalCourseArrayByType);
  503. return $ret;
  504. }
  505.  
  506. /**
  507. * Get a CourseOffering by unique Id.
  508. *
  509. * @param object Id $courseOfferingId
  510. *
  511. * @return object CourseOffering
  512. *
  513. * @throws object CourseManagementException An exception
  514. * with one of the following messages defined in
  515. * org.osid.coursemanagement.CourseManagementException may be
  516. * thrown: {@link }
  517. * org.osid.coursemanagement.CourseManagementException#OPERATION_FAILED
  518. * OPERATION_FAILED}, {@link }
  519. * org.osid.coursemanagement.CourseManagementException#PERMISSION_DENIED
  520. * PERMISSION_DENIED}, {@link }
  521. * org.osid.coursemanagement.CourseManagementException#CONFIGURATION_ERROR
  522. * CONFIGURATION_ERROR}, {@link }
  523. * org.osid.coursemanagement.CourseManagementException#UNIMPLEMENTED
  524. * UNIMPLEMENTED}, {@link }
  525. * org.osid.coursemanagement.CourseManagementException#NULL_ARGUMENT
  526. * NULL_ARGUMENT}, {@link }
  527. * org.osid.coursemanagement.CourseManagementException#UNKNOWN_ID
  528. * UNKNOWN_ID}
  529. *
  530. * @access public
  531. */
  532. function getCourseOffering ( $courseOfferingId ) {
  533.  
  534.  
  535. $node =$this->_hierarchy->getNode($courseOfferingId);
  536. $ret = new HarmoniCourseOffering($courseOfferingId, $node);
  537. return $ret;
  538.  
  539.  
  540.  
  541.  
  542.  
  543. }
  544.  
  545. /**
  546. * Get a CourseSection by unique Id.
  547. *
  548. * @param object Id $courseSectionId
  549. *
  550. * @return object CourseSection
  551. *
  552. * @throws object CourseManagementException An exception
  553. * with one of the following messages defined in
  554. * org.osid.coursemanagement.CourseManagementException may be
  555. * thrown: {@link }
  556. * org.osid.coursemanagement.CourseManagementException#OPERATION_FAILED
  557. * OPERATION_FAILED}, {@link }
  558. * org.osid.coursemanagement.CourseManagementException#PERMISSION_DENIED
  559. * PERMISSION_DENIED}, {@link }
  560. * org.osid.coursemanagement.CourseManagementException#CONFIGURATION_ERROR
  561. * CONFIGURATION_ERROR}, {@link }
  562. * org.osid.coursemanagement.CourseManagementException#UNIMPLEMENTED
  563. * UNIMPLEMENTED}, {@link }
  564. * org.osid.coursemanagement.CourseManagementException#NULL_ARGUMENT
  565. * NULL_ARGUMENT}, {@link }
  566. * org.osid.coursemanagement.CourseManagementException#UNKNOWN_ID
  567. * UNKNOWN_ID}
  568. *
  569. * @access public
  570. */
  571. function getCourseSection ( $courseSectionId ) {
  572.  
  573. $node =$this->_hierarchy->getNode($courseSectionId);
  574. $ret = new HarmoniCourseSection($courseSectionId, $node);
  575. return $ret;
  576. }
  577.  
  578. /**
  579. * Get all the Sections in which the specified Agent is enrolled.
  580. *
  581. * @param object Id $agentId
  582. *
  583. * @return object CourseSectionIterator
  584. *
  585. * @throws object CourseManagementException An exception
  586. * with one of the following messages defined in
  587. * org.osid.coursemanagement.CourseManagementException may be
  588. * thrown: {@link }
  589. * org.osid.coursemanagement.CourseManagementException#OPERATION_FAILED
  590. * OPERATION_FAILED}, {@link }
  591. * org.osid.coursemanagement.CourseManagementException#PERMISSION_DENIED
  592. * PERMISSION_DENIED}, {@link }
  593. * org.osid.coursemanagement.CourseManagementException#CONFIGURATION_ERROR
  594. * CONFIGURATION_ERROR}, {@link }
  595. * org.osid.coursemanagement.CourseManagementException#UNIMPLEMENTED
  596. * UNIMPLEMENTED}, {@link }
  597. * org.osid.coursemanagement.CourseManagementException#NULL_ARGUMENT
  598. * NULL_ARGUMENT}, {@link }
  599. * org.osid.coursemanagement.CourseManagementException#UNKNOWN_ID
  600. * UNKNOWN_ID}
  601. *
  602. * @access public
  603. */
  604. function getCourseSections ( $agentId ) {
  605.  
  606.  
  607. $dbManager = Services::getService("DatabaseManager");
  608. $query= new SelectQuery;
  609. $query->addTable('cm_enroll');
  610. $query->addColumn('fk_cm_section');
  611. $query->addWhere("fk_student_id='".addslashes($agentId->getIdString())."'");
  612.  
  613.  
  614. $res=$dbManager->query($query);
  615. $array=array();
  616. $idManager = Services::getService('IdManager');
  617. while($res->hasMoreRows()){
  618. $row = $res->getCurrentRow();
  619. $res->advanceRow();
  620. $id =$idManager->getId($row['fk_cm_section']);
  621. $course =$this->getCourseSection($id);
  622.  
  623. $array[]=$course;
  624. //}
  625. }
  626. $ret = new HarmoniCourseSectionIterator($array);
  627. return $ret;
  628. }
  629.  
  630. /**
  631. * Get all the Offerings in which the specified Agent is enrolled.
  632. *
  633. * @param object Id $agentId
  634. *
  635. * @return object CourseOfferingIterator
  636. *
  637. * @throws object CourseManagementException An exception
  638. * with one of the following messages defined in
  639. * org.osid.coursemanagement.CourseManagementException may be
  640. * thrown: {@link }
  641. * org.osid.coursemanagement.CourseManagementException#OPERATION_FAILED
  642. * OPERATION_FAILED}, {@link }
  643. * org.osid.coursemanagement.CourseManagementException#PERMISSION_DENIED
  644. * PERMISSION_DENIED}, {@link }
  645. * org.osid.coursemanagement.CourseManagementException#CONFIGURATION_ERROR
  646. * CONFIGURATION_ERROR}, {@link }
  647. * org.osid.coursemanagement.CourseManagementException#UNIMPLEMENTED
  648. * UNIMPLEMENTED}, {@link }
  649. * org.osid.coursemanagement.CourseManagementException#NULL_ARGUMENT
  650. * NULL_ARGUMENT}, {@link }
  651. * org.osid.coursemanagement.CourseManagementException#UNKNOWN_ID
  652. * UNKNOWN_ID}
  653. *
  654. * @access public
  655. */
  656. function getCourseOfferings ( $agentId ) {
  657.  
  658.  
  659.  
  660. $dbManager = Services::getService("DatabaseManager");
  661. $query= new SelectQuery;
  662. $query->addTable('cm_enroll');
  663. $query->addColumn('fk_cm_section');
  664. $query->addWhere("fk_student_id='".addslashes($agentId->getIdString())."'");
  665.  
  666.  
  667. $res=$dbManager->query($query);
  668. $array=array();
  669. $idManager = Services::getService('IdManager');
  670. while($res->hasMoreRows()){
  671. $row = $res->getCurrentRow();
  672. $res->advanceRow();
  673. $courseSection =$this->getCourseSection($idManager->getId($row['fk_cm_section']));
  674. $courseOffering =$courseSection->getCourseOffering();
  675. $courseOfferingId =$courseOffering->getId();
  676. $courseOfferingIdString = $courseOfferingId->getIdString();
  677. if(isset($array[$courseOfferingIdString])){
  678. continue;
  679. }
  680. $array[$courseOfferingIdString] =$courseOffering;
  681. }
  682. $ret = new HarmoniCourseOfferingIterator($array);
  683. return $ret;
  684.  
  685.  
  686.  
  687.  
  688. }
  689.  
  690. /**
  691. * Create a new Term with a specific type and Schedule. Schedules are
  692. * defined in the scheduling OSID.
  693. *
  694. *
  695. * @param object Type $termType
  696. * @param object ScheduleItem[] $schedule
  697. * @param optional string $displayname The displayname. WARNING: NOT IN OSID -- USE AT YOUR OWN RISK
  698. *
  699. * @return object Term
  700. *
  701. * @throws object CourseManagementException An exception
  702. * with one of the following messages defined in
  703. * org.osid.coursemanagement.CourseManagementException may be
  704. * thrown: {@link }
  705. * org.osid.coursemanagement.CourseManagementException#OPERATION_FAILED
  706. * OPERATION_FAILED}, {@link }
  707. * org.osid.coursemanagement.CourseManagementException#PERMISSION_DENIED
  708. * PERMISSION_DENIED}, {@link }
  709. * org.osid.coursemanagement.CourseManagementException#CONFIGURATION_ERROR
  710. * CONFIGURATION_ERROR}, {@link }
  711. * org.osid.coursemanagement.CourseManagementException#UNIMPLEMENTED
  712. * UNIMPLEMENTED}, {@link }
  713. * org.osid.coursemanagement.CourseManagementException#NULL_ARGUMENT
  714. * NULL_ARGUMENT}, {@link }
  715. * org.osid.coursemanagement.CourseManagementException#UNKNOWN_TYPE
  716. * UNKNOWN_TYPE}
  717. *
  718. * @access public
  719. */
  720. function createTerm ( $termType, $schedule, $displayname = "" ) {
  721.  
  722. $idManager = Services::getService("IdManager");
  723. $id=$idManager->createId();
  724.  
  725. $dbManager= Services::getService("DatabaseManager");
  726. $query= new InsertQuery;
  727.  
  728. $query->setTable('cm_term');
  729.  
  730. $query->setColumns(array('id','name','fk_cm_term_type'));
  731.  
  732. $values[]="'".addslashes($id->getIdString())."'";
  733. $values[]="'".$displayname."'";
  734. $values[]="'".$this->_typeToIndex('term',$termType)."'";
  735.  
  736.  
  737. $query->addRowOfValues($values);
  738.  
  739. $dbManager->query($query);
  740.  
  741.  
  742. if(count($schedule)>0){
  743. //query to add schedule items
  744. $query= new InsertQuery;
  745. $query->setTable('cm_schedule');
  746. $query->setColumns(array('fk_id','fk_sc_item'));
  747. $idString = "'".addslashes($id->getIdString())."'";
  748.  
  749.  
  750. //iterate through array
  751. foreach($schedule as $scheduleItem){
  752. $values = array();
  753. $values[]= $idString;
  754. $scheduleId =$scheduleItem->getId();
  755. $values[]="'".addslashes($scheduleId->getIdString())."'";
  756. $query->addRowOfValues($values);
  757.  
  758. }
  759. $dbManager->query($query);
  760. }
  761. $ret = new HarmoniTerm($id);
  762. return $ret;
  763. }
  764.  
  765. /**
  766. * Delete a Term by unique Id.
  767. *
  768. * @param object Id $termId
  769. *
  770. * @throws object CourseManagementException An exception
  771. * with one of the following messages defined in
  772. * org.osid.coursemanagement.CourseManagementException may be
  773. * thrown: {@link }
  774. * org.osid.coursemanagement.CourseManagementException#OPERATION_FAILED
  775. * OPERATION_FAILED}, {@link }
  776. * org.osid.coursemanagement.CourseManagementException#PERMISSION_DENIED
  777. * PERMISSION_DENIED}, {@link }
  778. * org.osid.coursemanagement.CourseManagementException#CONFIGURATION_ERROR
  779. * CONFIGURATION_ERROR}, {@link }
  780. * org.osid.coursemanagement.CourseManagementException#UNIMPLEMENTED
  781. * UNIMPLEMENTED}, {@link }
  782. * org.osid.coursemanagement.CourseManagementException#NULL_ARGUMENT
  783. * NULL_ARGUMENT}, {@link }
  784. * org.osid.coursemanagement.CourseManagementException#UNKNOWN_ID
  785. * UNKNOWN_ID}
  786. *
  787. * @access public
  788. */
  789. function deleteTerm ( $termId ) {
  790.  
  791. ArgumentValidator::validate($termId, ExtendsValidatorRule::getRule("Id"), true);
  792.  
  793. $dbManager = Services::getService("DatabaseManager");
  794. $query= new DeleteQuery;
  795. $query->setTable('cm_term');
  796. $query->addWhere("id=".addslashes($termId->getIdString()));
  797. $dbManager->query($query);
  798.  
  799. $query= new DeleteQuery;
  800. $query->setTable('cm_schedule');
  801. $query->addWhere("fk_id=".addslashes($termId->getIdString()));
  802. $dbManager->query($query);
  803.  
  804. }
  805.  
  806. /**
  807. * Get a Term by unique Id.
  808. *
  809. * @param object Id $termId
  810. *
  811. * @return object Term
  812. *
  813. * @throws object CourseManagementException An exception
  814. * with one of the following messages defined in
  815. * org.osid.coursemanagement.CourseManagementException may be
  816. * thrown: {@link }
  817. * org.osid.coursemanagement.CourseManagementException#OPERATION_FAILED
  818. * OPERATION_FAILED}, {@link }
  819. * org.osid.coursemanagement.CourseManagementException#PERMISSION_DENIED
  820. * PERMISSION_DENIED}, {@link }
  821. * org.osid.coursemanagement.CourseManagementException#CONFIGURATION_ERROR
  822. * CONFIGURATION_ERROR}, {@link }
  823. * org.osid.coursemanagement.CourseManagementException#UNIMPLEMENTED
  824. * UNIMPLEMENTED}, {@link }
  825. * org.osid.coursemanagement.CourseManagementException#NULL_ARGUMENT
  826. * NULL_ARGUMENT}, {@link }
  827. * org.osid.coursemanagement.CourseManagementException#UNKNOWN_ID
  828. * UNKNOWN_ID}
  829. *
  830. * @access public
  831. */
  832. function getTerm ( $termId ) {
  833. $ret = new HarmoniTerm($termId);
  834. return $ret;
  835. }
  836.  
  837. /**
  838. * Get all the Terms.
  839. *
  840. * @return object TermIterator
  841. *
  842. * @throws object CourseManagementException An exception
  843. * with one of the following messages defined in
  844. * org.osid.coursemanagement.CourseManagementException may be
  845. * thrown: {@link }
  846. * org.osid.coursemanagement.CourseManagementException#OPERATION_FAILED
  847. * OPERATION_FAILED}, {@link }
  848. * org.osid.coursemanagement.CourseManagementException#PERMISSION_DENIED
  849. * PERMISSION_DENIED}, {@link }
  850. * org.osid.coursemanagement.CourseManagementException#CONFIGURATION_ERROR
  851. * CONFIGURATION_ERROR}, {@link }
  852. * org.osid.coursemanagement.CourseManagementException#UNIMPLEMENTED
  853. * UNIMPLEMENTED}
  854. *
  855. * @access public
  856. */
  857. function getTerms () {
  858.  
  859. $dbManager = Services::getService("DatabaseManager");
  860. $query= new SelectQuery;
  861. $query->addTable('cm_term');
  862. $query->addColumn('id');
  863. $res=$dbManager->query($query);
  864. $array=array();
  865. $idManager = Services::getService('IdManager');
  866. while($res->hasMoreRows()){
  867. $row = $res->getCurrentRow();
  868. $res->advanceRow();
  869. $array[]=$this->getTerm($idManager->getId($row['id']));
  870. }
  871. $ret = new HarmoniTermIterator($array);
  872. return $ret;
  873. }
  874.  
  875. /**
  876. * Get all the Terms that contain this date.
  877. *
  878. * The implementation is probably pretty slow. If I was convinced it was more useful,
  879. * I might make it faster.
  880. *
  881. * @param int $date
  882. *
  883. * @return object TermIterator
  884. *
  885. * @throws object CourseManagementException An exception
  886. * with one of the following messages defined in
  887. * org.osid.coursemanagement.CourseManagementException may be
  888. * thrown: {@link }
  889. * org.osid.coursemanagement.CourseManagementException#OPERATION_FAILED
  890. * OPERATION_FAILED}, {@link }
  891. * org.osid.coursemanagement.CourseManagementException#PERMISSION_DENIED
  892. * PERMISSION_DENIED}, {@link }
  893. * org.osid.coursemanagement.CourseManagementException#CONFIGURATION_ERROR
  894. * CONFIGURATION_ERROR}, {@link }
  895. * org.osid.coursemanagement.CourseManagementException#UNIMPLEMENTED
  896. * UNIMPLEMENTED}
  897. *
  898. * @access public
  899. */
  900. function getTermsByDate ( $date ) {
  901. $terms =$this->getTerms();
  902. $array = array();
  903. //iterate through all terms
  904. while($terms->hasNextTerm()){
  905. $term=$terms->nextTerm();
  906. $scheduleItems =$term->getSchedule();
  907.  
  908. //iterate through all ScheduleItems
  909. while($scheduleItems->hasNextScheduleItem()){
  910. $scheduleItem =$scheduleItems->nextScheduleItem();
  911. $start = $scheduleItem->getStart();
  912. $end = $scheduleItem->getEnd();
  913.  
  914. //if we found a ScheduleItem that overlaps, add it to the array
  915. if($date>=$start && $date<=$end){
  916. $array[] =$term;
  917. break;
  918. }
  919. }
  920.  
  921. }
  922.  
  923. //make iterator
  924. $ret = new HarmoniTermIterator($array);
  925. return $ret;
  926. }
  927.  
  928. /**
  929. * Get all the defined Course Types. These Types are meaningful to the
  930. * implementation and applications and are not specified by the OSID.
  931. *
  932. * @return object TypeIterator
  933. *
  934. * @throws object CourseManagementException An exception
  935. * with one of the following messages defined in
  936. * org.osid.coursemanagement.CourseManagementException may be
  937. * thrown: {@link }
  938. * org.osid.coursemanagement.CourseManagementException#OPERATION_FAILED
  939. * OPERATION_FAILED}, {@link }
  940. * org.osid.coursemanagement.CourseManagementException#PERMISSION_DENIED
  941. * PERMISSION_DENIED}, {@link }
  942. * org.osid.coursemanagement.CourseManagementException#CONFIGURATION_ERROR
  943. * CONFIGURATION_ERROR}, {@link }
  944. * org.osid.coursemanagement.CourseManagementException#UNIMPLEMENTED
  945. * UNIMPLEMENTED}
  946. *
  947. * @access public
  948. */
  949. function getCourseTypes () {
  950.  
  951. return $this->_getTypes('can');
  952.  
  953. }
  954.  
  955. /**
  956. * Get all the defined Canonical Course Status Types. These Types are
  957. * meaningful to the implementation and applications and are not specified
  958. * by the OSID.
  959. *
  960. * @return object TypeIterator
  961. *
  962. * @throws object CourseManagementException An exception
  963. * with one of the following messages defined in
  964. * org.osid.coursemanagement.CourseManagementException may be
  965. * thrown: {@link }
  966. * org.osid.coursemanagement.CourseManagementException#OPERATION_FAILED
  967. * OPERATION_FAILED}, {@link }
  968. * org.osid.coursemanagement.CourseManagementException#PERMISSION_DENIED
  969. * PERMISSION_DENIED}, {@link }
  970. * org.osid.coursemanagement.CourseManagementException#CONFIGURATION_ERROR
  971. * CONFIGURATION_ERROR}, {@link }
  972. * org.osid.coursemanagement.CourseManagementException#UNIMPLEMENTED
  973. * UNIMPLEMENTED}
  974. *
  975. * @access public
  976. */
  977. function getCourseStatusTypes () {
  978.  
  979. return $this->_getTypes('can_stat');
  980. }
  981.  
  982. /**
  983. * Get all the defined Course Offering Status Types. These Types are
  984. * meaningful to the implementation and applications and are not specified
  985. * by the OSID.
  986. *
  987. * @return object TypeIterator
  988. *
  989. * @throws object CourseManagementException An exception
  990. * with one of the following messages defined in
  991. * org.osid.coursemanagement.CourseManagementException may be
  992. * thrown: {@link }
  993. * org.osid.coursemanagement.CourseManagementException#OPERATION_FAILED
  994. * OPERATION_FAILED}, {@link }
  995. * org.osid.coursemanagement.CourseManagementException#PERMISSION_DENIED
  996. * PERMISSION_DENIED}, {@link }
  997. * org.osid.coursemanagement.CourseManagementException#CONFIGURATION_ERROR
  998. * CONFIGURATION_ERROR}, {@link }
  999. * org.osid.coursemanagement.CourseManagementException#UNIMPLEMENTED
  1000. * UNIMPLEMENTED}
  1001. *
  1002. * @access public
  1003. */
  1004. function getOfferingStatusTypes () {
  1005. return $this->_getTypes('offer_stat');
  1006. }
  1007.  
  1008. /**
  1009. * Get all the defined Course Section Status Types. These Types are
  1010. * meaningful to the implementation and applications and are not specified
  1011. * by the OSID.
  1012. *
  1013. * @return object TypeIterator
  1014. *
  1015. * @throws object CourseManagementException An exception
  1016. * with one of the following messages defined in
  1017. * org.osid.coursemanagement.CourseManagementException may be
  1018. * thrown: {@link }
  1019. * org.osid.coursemanagement.CourseManagementException#OPERATION_FAILED
  1020. * OPERATION_FAILED}, {@link }
  1021. * org.osid.coursemanagement.CourseManagementException#PERMISSION_DENIED
  1022. * PERMISSION_DENIED}, {@link }
  1023. * org.osid.coursemanagement.CourseManagementException#CONFIGURATION_ERROR
  1024. * CONFIGURATION_ERROR}, {@link }
  1025. * org.osid.coursemanagement.CourseManagementException#UNIMPLEMENTED
  1026. * UNIMPLEMENTED}
  1027. *
  1028. * @access public
  1029. */
  1030. function getSectionStatusTypes () {
  1031. return $this->_getTypes('section_stat');
  1032. }
  1033.  
  1034. /**
  1035. * Get all the defined Offering Types. These Types are meaningful to the
  1036. * implementation and applications and are not specified by the OSID.
  1037. *
  1038. * @return object TypeIterator
  1039. *
  1040. * @throws object CourseManagementException An exception
  1041. * with one of the following messages defined in
  1042. * org.osid.coursemanagement.CourseManagementException may be
  1043. * thrown: {@link }
  1044. * org.osid.coursemanagement.CourseManagementException#OPERATION_FAILED
  1045. * OPERATION_FAILED}, {@link }
  1046. * org.osid.coursemanagement.CourseManagementException#PERMISSION_DENIED
  1047. * PERMISSION_DENIED}, {@link }
  1048. * org.osid.coursemanagement.CourseManagementException#CONFIGURATION_ERROR
  1049. * CONFIGURATION_ERROR}, {@link }
  1050. * org.osid.coursemanagement.CourseManagementException#UNIMPLEMENTED
  1051. * UNIMPLEMENTED}
  1052. *
  1053. * @access public
  1054. */
  1055. function getOfferingTypes () {
  1056. return $this->_getTypes('offer');
  1057. }
  1058.  
  1059. /**
  1060. * Get all the defined Section Types. These Types are meaningful to the
  1061. * implementation and applications and are not specified by the OSID.
  1062. *
  1063. * @return object TypeIterator
  1064. *
  1065. * @throws object CourseManagementException An exception
  1066. * with one of the following messages defined in
  1067. * org.osid.coursemanagement.CourseManagementException may be
  1068. * thrown: {@link }
  1069. * org.osid.coursemanagement.CourseManagementException#OPERATION_FAILED
  1070. * OPERATION_FAILED}, {@link }
  1071. * org.osid.coursemanagement.CourseManagementException#PERMISSION_DENIED
  1072. * PERMISSION_DENIED}, {@link }
  1073. * org.osid.coursemanagement.CourseManagementException#CONFIGURATION_ERROR
  1074. * CONFIGURATION_ERROR}, {@link }
  1075. * org.osid.coursemanagement.CourseManagementException#UNIMPLEMENTED
  1076. * UNIMPLEMENTED}
  1077. *
  1078. * @access public
  1079. */
  1080. function getSectionTypes () {
  1081. return $this->_getTypes('section');
  1082. }
  1083.  
  1084. /**
  1085. * Get all the defined Enrollment Status Types. These Types are meaningful
  1086. * to the implementation and applications and are not specified by the
  1087. * OSID.
  1088. *
  1089. * @return object TypeIterator
  1090. *
  1091. * @throws object CourseManagementException An exception
  1092. * with one of the following messages defined in
  1093. * org.osid.coursemanagement.CourseManagementException may be
  1094. * thrown: {@link }
  1095. * org.osid.coursemanagement.CourseManagementException#OPERATION_FAILED
  1096. * OPERATION_FAILED}, {@link }
  1097. * org.osid.coursemanagement.CourseManagementException#PERMISSION_DENIED
  1098. * PERMISSION_DENIED}, {@link }
  1099. * org.osid.coursemanagement.CourseManagementException#CONFIGURATION_ERROR
  1100. * CONFIGURATION_ERROR}, {@link }
  1101. * org.osid.coursemanagement.CourseManagementException#UNIMPLEMENTED
  1102. * UNIMPLEMENTED}
  1103. *
  1104. * @access public
  1105. */
  1106. function getEnrollmentStatusTypes () {
  1107. return $this->_getTypes('enroll_stat');
  1108. }
  1109.  
  1110. /**
  1111. * Get all the defined CourseGrade Types. GradeTypes are defined in the
  1112. * grading OSID. These Types are meaningful to the implementation and
  1113. * applications and are not specified by the grading OSID.
  1114. *
  1115. * @return object TypeIterator
  1116. *
  1117. * @throws object CourseManagementException An exception
  1118. * with one of the following messages defined in
  1119. * org.osid.coursemanagement.CourseManagementException may be
  1120. * thrown: {@link }
  1121. * org.osid.coursemanagement.CourseManagementException#OPERATION_FAILED
  1122. * OPERATION_FAILED}, {@link }
  1123. * org.osid.coursemanagement.CourseManagementException#PERMISSION_DENIED
  1124. * PERMISSION_DENIED}, {@link }
  1125. * org.osid.coursemanagement.CourseManagementException#CONFIGURATION_ERROR
  1126. * CONFIGURATION_ERROR}, {@link }
  1127. * org.osid.coursemanagement.CourseManagementException#UNIMPLEMENTED
  1128. * UNIMPLEMENTED}
  1129. *
  1130. * @access public
  1131. */
  1132. function getCourseGradeTypes () {
  1133. $gm = Services::getService("Grading");
  1134. return $gm->_getTypes('grade');
  1135. }
  1136.  
  1137. /**
  1138. * Get all the TermTypes.
  1139. *
  1140. * @return object TypeIterator
  1141. *
  1142. * @throws object CourseManagementException An exception
  1143. * with one of the following messages defined in
  1144. * org.osid.coursemanagement.CourseManagementException may be
  1145. * thrown: {@link }
  1146. * org.osid.coursemanagement.CourseManagementException#OPERATION_FAILED
  1147. * OPERATION_FAILED}, {@link }
  1148. * org.osid.coursemanagement.CourseManagementException#PERMISSION_DENIED
  1149. * PERMISSION_DENIED}, {@link }
  1150. * org.osid.coursemanagement.CourseManagementException#CONFIGURATION_ERROR
  1151. * CONFIGURATION_ERROR}, {@link }
  1152. * org.osid.coursemanagement.CourseManagementException#UNIMPLEMENTED
  1153. * UNIMPLEMENTED}
  1154. *
  1155. * @access public
  1156. */
  1157. function getTermTypes () {
  1158. return $this->_getTypes('term');
  1159. }
  1160.  
  1161. /**
  1162. * Create a CourseGradeRecord for the specified Agent (student),
  1163. * CourseOffering, CourseGradeType, and CourseGrade. Note that the intent
  1164. * is that this is a summative grade.
  1165. *
  1166. * @param object Id $agentId
  1167. * @param object Id $courseOfferingId
  1168. * @param object Type $courseGradeType
  1169. * @param object mixed $courseGrade (original type: java.io.Serializable)
  1170. *
  1171. * @return object CourseGradeRecord
  1172. *
  1173. * @throws object CourseManagementException An exception
  1174. * with one of the following messages defined in
  1175. * org.osid.coursemanagement.CourseManagementException may be
  1176. * thrown: {@link }
  1177. * org.osid.coursemanagement.CourseManagementException#OPERATION_FAILED
  1178. * OPERATION_FAILED}, {@link }
  1179. * org.osid.coursemanagement.CourseManagementException#PERMISSION_DENIED
  1180. * PERMISSION_DENIED}, {@link }
  1181. * org.osid.coursemanagement.CourseManagementException#CONFIGURATION_ERROR
  1182. * CONFIGURATION_ERROR}, {@link }
  1183. * org.osid.coursemanagement.CourseManagementException#UNIMPLEMENTED
  1184. * UNIMPLEMENTED}, {@link }
  1185. * org.osid.coursemanagement.CourseManagementException#NULL_ARGUMENT
  1186. * NULL_ARGUMENT}, {@link }
  1187. * org.osid.coursemanagement.CourseManagementException#UNKNOWN_TYPE
  1188. * UNKNOWN_TYPE}, {@link }
  1189. * org.osid.coursemanagement.CourseManagementException#UNKNOWN_ID
  1190. * UNKNOWN_ID}
  1191. *
  1192. * @access public
  1193. */
  1194. function createCourseGradeRecord ( $agentId, $courseOfferingId, $courseGradeType, $courseGrade ) {
  1195. $idManager = Services::getService("IdManager");
  1196. $dbManager= Services::getService("DatabaseManager");
  1197.  
  1198.  
  1199. $courseOffering =$this->getCourseOffering($courseOfferingId);
  1200. if($courseGradeType!=null && !$courseGradeType->isEqual($courseOffering->getGradeType())){
  1201. throwError(new Error("Cannot create a CourseGradeRecord if the GradeType differs from the CourseOffering","CourseManagementManager",true));
  1202. }
  1203.  
  1204.  
  1205. $query= new InsertQuery;
  1206.  
  1207. $query->setTable('cm_grade_rec');
  1208.  
  1209. $query->setColumns(array('fk_student_id','fk_cm_offer','name','grade'));
  1210.  
  1211. $values[]="'".addslashes($agentId->getIdString())."'";
  1212. $values[]="'".addslashes($courseOfferingId->getIdString())."'";
  1213. $values[]="'CourseGradeRecord'";
  1214. $values[]="'".addslashes($courseGrade)."'";
  1215.  
  1216. $query->addRowOfValues($values);
  1217. $query->setAutoIncrementColumn('id','cm_grade_rec_id_seq');
  1218.  
  1219. $result = $dbManager->query($query);
  1220. $id = $result->getLastAutoIncrementValue();
  1221.  
  1222. $ret = new HarmoniCourseGradeRecord($idManager->getId($id));
  1223. return $ret;
  1224. }
  1225.  
  1226. /**
  1227. * Delete the specified CourseGradeRecord by Id. courseGradeRecordId
  1228. *
  1229. * @param object Id $courseGradeRecordId
  1230. *
  1231. * @throws object CourseManagementException An exception
  1232. * with one of the following messages defined in
  1233. * org.osid.coursemanagement.CourseManagementException may be
  1234. * thrown: {@link }
  1235. * org.osid.coursemanagement.CourseManagementException#OPERATION_FAILED
  1236. * OPERATION_FAILED}, {@link }
  1237. * org.osid.coursemanagement.CourseManagementException#PERMISSION_DENIED
  1238. * PERMISSION_DENIED}, {@link }
  1239. * org.osid.coursemanagement.CourseManagementException#CONFIGURATION_ERROR
  1240. * CONFIGURATION_ERROR}, {@link }
  1241. * org.osid.coursemanagement.CourseManagementException#UNIMPLEMENTED
  1242. * UNIMPLEMENTED}, {@link }
  1243. * org.osid.coursemanagement.CourseManagementException#NULL_ARGUMENT
  1244. * NULL_ARGUMENT}, {@link }
  1245. * org.osid.coursemanagement.CourseManagementException#UNKNOWN_ID
  1246. * UNKNOWN_ID}
  1247. *
  1248. * @access public
  1249. */
  1250. function deleteCourseGradeRecord ( $courseGradeRecordId ) {
  1251.  
  1252. ArgumentValidator::validate($courseGradeRecordId, ExtendsValidatorRule::getRule("Id"), true);
  1253.  
  1254.  
  1255.  
  1256. $dbManager = Services::getService("DatabaseManager");
  1257. $query= new DeleteQuery;
  1258.  
  1259.  
  1260. $query->setTable('cm_grade_rec');
  1261.  
  1262. $query->addWhere("id=".addslashes($courseGradeRecordId->getIdString()));
  1263. $dbManager->query($query);
  1264. }
  1265.  
  1266. /**
  1267. * Get all the CourseGradeRecords, optionally including only those for a
  1268. * specific Student, CourseOffering, or CourseGradeType. Put null if you don't wish to include these.
  1269. *
  1270. * @param object Id $agentId
  1271. * @param object Id $courseOfferingId
  1272. * @param object Type $courseGradeType
  1273. *
  1274. * @return object CourseGradeRecordIterator
  1275. *
  1276. * @throws object CourseManagementException An exception
  1277. * with one of the following messages defined in
  1278. * org.osid.coursemanagement.CourseManagementException may be
  1279. * thrown: {@link }
  1280. * org.osid.coursemanagement.CourseManagementException#OPERATION_FAILED
  1281. * OPERATION_FAILED}, {@link }
  1282. * org.osid.coursemanagement.CourseManagementException#PERMISSION_DENIED
  1283. * PERMISSION_DENIED}, {@link }
  1284. * org.osid.coursemanagement.CourseManagementException#CONFIGURATION_ERROR
  1285. * CONFIGURATION_ERROR}, {@link }
  1286. * org.osid.coursemanagement.CourseManagementException#UNIMPLEMENTED
  1287. * UNIMPLEMENTED}, {@link }
  1288. * org.osid.coursemanagement.CourseManagementException#NULL_ARGUMENT
  1289. * NULL_ARGUMENT}, {@link }
  1290. * org.osid.coursemanagement.CourseManagementException#UNKNOWN_TYPE
  1291. * UNKNOWN_TYPE}, {@link }
  1292. * org.osid.coursemanagement.CourseManagementException#UNKNOWN_ID
  1293. * UNKNOWN_ID}
  1294. *
  1295. * @access public
  1296. */
  1297. function getCourseGradeRecords ( $agentId, $courseOfferingId, $courseGradeType ) {
  1298.  
  1299.  
  1300. $dbManager = Services::getService("DatabaseManager");
  1301. $query= new SelectQuery;
  1302.  
  1303.  
  1304.  
  1305.  
  1306. $query->addTable('cm_grade_rec');
  1307. $query->addColumn('id');
  1308.  
  1309. if(!is_null($courseGradeType)){
  1310. $courseGradeType=$this->_typeToIndex('can',$courseGradeType);
  1311. $query->addWhere("fk_cm_grade_type='".addslashes($courseGradeType)."'");
  1312. }
  1313. if(!is_null($agentId)){
  1314. $query->addWhere("fk_student_id='".addslashes($agentId->getIdString())."'");
  1315. }
  1316. if(!is_null($courseOfferingId)){
  1317.  
  1318. $query->addWhere("fk_cm_offer='".addslashes($courseOfferingId->getIdString())."'");
  1319. }
  1320.  
  1321.  
  1322.  
  1323.  
  1324. $res =$dbManager->query($query);
  1325.  
  1326. $array = array();
  1327. $idManager= Services::getService("IdManager");
  1328.  
  1329. while($res->hasMoreRows()){
  1330.  
  1331. $row = $res->getCurrentRow();
  1332. $res->advanceRow();
  1333. $id =$idManager->getId($row['id']);
  1334. $array[] = new HarmoniCourseGradeRecord($id);
  1335.  
  1336. }
  1337. $ret = new HarmoniCourseGradeRecordIterator($array);
  1338. return $ret;
  1339.  
  1340. }
  1341.  
  1342. /**
  1343. * Create a CourseGroup of a particular CourseGroupType. CourseGroups can
  1344. * be used to model prerequisites, corequisites, majors, minors,
  1345. * sequences, etc.
  1346. *
  1347. * @param object Type $courseGroupType
  1348. *
  1349. * @return object CourseGroup
  1350. *
  1351. * @throws object CourseManagementException An exception
  1352. * with one of the following messages defined in
  1353. * org.osid.coursemanagement.CourseManagementException may be
  1354. * thrown: {@link }
  1355. * org.osid.coursemanagement.CourseManagementException#OPERATION_FAILED
  1356. * OPERATION_FAILED}, {@link }
  1357. * org.osid.coursemanagement.CourseManagementException#PERMISSION_DENIED
  1358. * PERMISSION_DENIED}, {@link }
  1359. * org.osid.coursemanagement.CourseManagementException#CONFIGURATION_ERROR
  1360. * CONFIGURATION_ERROR}, {@link }
  1361. * org.osid.coursemanagement.CourseManagementException#UNIMPLEMENTED
  1362. * UNIMPLEMENTED}, {@link }
  1363. * org.osid.coursemanagement.CourseManagementException#NULL_ARGUMENT
  1364. * NULL_ARGUMENT}, {@link }
  1365. * org.osid.coursemanagement.CourseManagementException#UNKNOWN_TYPE
  1366. * UNKNOWN_TYPE}
  1367. *
  1368. * @access public
  1369. */
  1370. function createCourseGroup ( $courseGroupType ) {
  1371. $idManager = Services::getService("IdManager");
  1372. $id=$idManager->createId();
  1373.  
  1374. $node =$this->_hierarchy->createNode($id,$this->_courseGroupsId,$courseGroupType,"","A group for CanonicalCourses");
  1375.  
  1376.  
  1377.  
  1378. $ret = new HarmoniCourseGroup($node);
  1379. return $ret;
  1380.  
  1381. }
  1382.  
  1383. /**
  1384. * Delete a CourseGroup by unique Id.
  1385. *
  1386. * @param object Id $courseGroupId
  1387. *
  1388. * @throws object CourseManagementException An exception
  1389. * with one of the following messages defined in
  1390. * org.osid.coursemanagement.CourseManagementException may be
  1391. * thrown: {@link }
  1392. * org.osid.coursemanagement.CourseManagementException#OPERATION_FAILED
  1393. * OPERATION_FAILED}, {@link }
  1394. * org.osid.coursemanagement.CourseManagementException#PERMISSION_DENIED
  1395. * PERMISSION_DENIED}, {@link }
  1396. * org.osid.coursemanagement.CourseManagementException#CONFIGURATION_ERROR
  1397. * CONFIGURATION_ERROR}, {@link }
  1398. * org.osid.coursemanagement.CourseManagementException#UNIMPLEMENTED
  1399. * UNIMPLEMENTED}, {@link }
  1400. * org.osid.coursemanagement.CourseManagementException#NULL_ARGUMENT
  1401. * NULL_ARGUMENT}, {@link }
  1402. * org.osid.coursemanagement.CourseManagementException#UNKNOWN_ID
  1403. * UNKNOWN_ID}
  1404. *
  1405. * @access public
  1406. */
  1407. function deleteCourseGroup ( $courseGroupId ) {
  1408.  
  1409. ArgumentValidator::validate($courseGroupId, ExtendsValidatorRule::getRule("Id"), true);
  1410.  
  1411. //we can't delete non-root nodes, so first break all the connections
  1412. $node =$this->_hierarchy->getNode($courseGroupId);
  1413. $nodeIterator = $node->getChildren();
  1414. while($nodeIterator->hasNextNode()){
  1415. $child =$nodeIterator->nextNode();
  1416. $child->removeParent($courseGroupId);
  1417. }
  1418.  
  1419. //now we can delete the node
  1420. $this->_hierarchy->deleteNode($courseGroupId);
  1421. }
  1422.  
  1423. /**
  1424. * Get a CourseGroup by unique Id.
  1425. *
  1426. * @param object Id $courseGroupId
  1427. *
  1428. * @return object CourseGroup
  1429. *
  1430. * @throws object CourseManagementException An exception
  1431. * with one of the following messages defined in
  1432. * org.osid.coursemanagement.CourseManagementException may be
  1433. * thrown: {@link }
  1434. * org.osid.coursemanagement.CourseManagementException#OPERATION_FAILED
  1435. * OPERATION_FAILED}, {@link }
  1436. * org.osid.coursemanagement.CourseManagementException#PERMISSION_DENIED
  1437. * PERMISSION_DENIED}, {@link }
  1438. * org.osid.coursemanagement.CourseManagementException#CONFIGURATION_ERROR
  1439. * CONFIGURATION_ERROR}, {@link }
  1440. * org.osid.coursemanagement.CourseManagementException#UNIMPLEMENTED
  1441. * UNIMPLEMENTED}, {@link }
  1442. * org.osid.coursemanagement.CourseManagementException#NULL_ARGUMENT
  1443. * NULL_ARGUMENT}, {@link }
  1444. * org.osid.coursemanagement.CourseManagementException#UNKNOWN_ID
  1445. * UNKNOWN_ID}
  1446. *
  1447. * @access public
  1448. */
  1449. function getCourseGroup ( $courseGroupId ) {
  1450. $node =$this->_hierarchy->getNode($courseGroupId);
  1451. $ret = new HarmoniCourseGroup($node);
  1452. return $ret;
  1453.  
  1454.  
  1455. }
  1456.  
  1457. /**
  1458. * Get all the CourseGroups of a given CourseGroupType.
  1459. *
  1460. * @param object Type $courseGroupType
  1461. *
  1462. * @return object CourseGroupIterator
  1463. *
  1464. * @throws object CourseManagementException An exception
  1465. * with one of the following messages defined in
  1466. * org.osid.coursemanagement.CourseManagementException may be
  1467. * thrown: {@link }
  1468. * org.osid.coursemanagement.CourseManagementException#OPERATION_FAILED
  1469. * OPERATION_FAILED}, {@link }
  1470. * org.osid.coursemanagement.CourseManagementException#PERMISSION_DENIED
  1471. * PERMISSION_DENIED}, {@link }
  1472. * org.osid.coursemanagement.CourseManagementException#CONFIGURATION_ERROR
  1473. * CONFIGURATION_ERROR}, {@link }
  1474. * org.osid.coursemanagement.CourseManagementException#UNIMPLEMENTED
  1475. * UNIMPLEMENTED}, {@link }
  1476. * org.osid.coursemanagement.CourseManagementException#NULL_ARGUMENT
  1477. * NULL_ARGUMENT}, {@link }
  1478. * org.osid.coursemanagement.CourseManagementException#UNKNOWN_TYPE
  1479. * UNKNOWN_TYPE}
  1480. *
  1481. * @access public
  1482. */
  1483. function getCourseGroupsByType ( $courseGroupType ) {
  1484. $parent =$this->_hierarchy->getNode($this->_courseGroupsId);
  1485. $nodeIterator =$parent->getChildren();
  1486. $arrayOfGroups = array();
  1487. while($nodeIterator->hasNextNode()){
  1488. $node =$nodeIterator->nextNode();
  1489. if($courseGroupType->isEqualTo($node->getType())){
  1490. $arrayOfGroups[] =$this->getCourseGroup($node->getId());
  1491. }
  1492. }
  1493. $ret = new HarmoniCourseGroupIterator($arrayOfGroups);
  1494. return $ret;
  1495. }
  1496.  
  1497. /**
  1498. * Get all the CourseGroups that contain the specified CanoncialCourse.
  1499. *
  1500. * @param object Id $canonicalCourseId
  1501. *
  1502. * @return object CourseGroupIterator
  1503. *
  1504. * @throws object CourseManagementException An exception
  1505. * with one of the following messages defined in
  1506. * org.osid.coursemanagement.CourseManagementException may be
  1507. * thrown: {@link }
  1508. * org.osid.coursemanagement.CourseManagementException#OPERATION_FAILED
  1509. * OPERATION_FAILED}, {@link }
  1510. * org.osid.coursemanagement.CourseManagementException#PERMISSION_DENIED
  1511. * PERMISSION_DENIED}, {@link }
  1512. * org.osid.coursemanagement.CourseManagementException#CONFIGURATION_ERROR
  1513. * CONFIGURATION_ERROR}, {@link }
  1514. * org.osid.coursemanagement.CourseManagementException#UNIMPLEMENTED
  1515. * UNIMPLEMENTED}, {@link }
  1516. * org.osid.coursemanagement.CourseManagementException#NULL_ARGUMENT
  1517. * NULL_ARGUMENT}, {@link }
  1518. * org.osid.coursemanagement.CourseManagementException#UNKNOWN_ID
  1519. * UNKNOWN_ID}
  1520. *
  1521. * @access public
  1522. */
  1523. function getCourseGroups ( $canonicalCourseId ) {
  1524.  
  1525.  
  1526.  
  1527. $childNode =$this->_hierarchy->getNode($canonicalCourseId);
  1528. $nodeIterator =$childNode->getParents();
  1529. $arrayOfGroups = array();
  1530. while($nodeIterator->hasNextNode()){
  1531. $parentNode=$nodeIterator->nextNode();
  1532. $grandparents = $parentNode->getParents();
  1533. if(!$grandparents->hasNextNode()){
  1534. print "<b>Warning!</b> The CanonicalCourse with id ".$canonicalCourseId." is a root node";
  1535. continue;
  1536. }
  1537. $grandparentNode = $grandparents->nextNode();
  1538. if($this->_courseGroupsId->isEqual($grandparentNode->getId())){
  1539. $arrayOfGroups[] =$this->getCourseGroup($parentNode->getId());
  1540. }
  1541. }
  1542. $ret = new HarmoniCourseGroupIterator($arrayOfGroups);
  1543. return $ret;
  1544. }
  1545.  
  1546. /**
  1547. * Get all the CourseGroupTypes supported by this implementation. This can be innefficient if there
  1548. * is a tremendous number of Types and course groups.
  1549. *
  1550. * @return object TypeIterator
  1551. *
  1552. * @throws object CourseManagementException An exception
  1553. * with one of the following messages defined in
  1554. * org.osid.coursemanagement.CourseManagementException may be
  1555. * thrown: {@link }
  1556. * org.osid.coursemanagement.CourseManagementException#OPERATION_FAILED
  1557. * OPERATION_FAILED}, {@link }
  1558. * org.osid.coursemanagement.CourseManagementException#PERMISSION_DENIED
  1559. * PERMISSION_DENIED}, {@link }
  1560. * org.osid.coursemanagement.CourseManagementException#CONFIGURATION_ERROR
  1561. * CONFIGURATION_ERROR}, {@link }
  1562. * org.osid.coursemanagement.CourseManagementException#UNIMPLEMENTED
  1563. * UNIMPLEMENTED}
  1564. *
  1565. * @access public
  1566. */
  1567. function getCourseGroupTypes () {
  1568.  
  1569.  
  1570. $parent =$this->_hierarchy->getNode($this->_courseGroupsId);
  1571. $nodeIterator =$parent->getChildren();
  1572. $arrayOfTypes = array();
  1573. while($nodeIterator->hasNextNode()){
  1574. $node=$nodeIterator->nextNode();
  1575. foreach($arrayOfTypes as $value){
  1576. if($value->isEqual($node->getType())){
  1577. continue 2;
  1578. }
  1579. }
  1580. $arrayOfTypes[] =$node->getType();
  1581. }
  1582. $ret = new HarmoniTypeIterator($arrayOfTypes);
  1583. return $ret;
  1584. }
  1585.  
  1586. /**
  1587. * This method indicates whether this implementation supports
  1588. * CourseManagementManager methods: createCanonicalCourse,
  1589. * createCourseGradeRecord, createCourseGroup, createTerm,
  1590. * deleteCanonicalCourse, deleteCourseGradeRecord, deleteCourseGroup,
  1591. * deleteTerm. CanonicalCourse methods: addEquivalentCourse, addTopic,
  1592. * createCanonicalCourse, createCourseOffering, deleteCourseOffering.
  1593. * CourseGroup methods: addCourse, removeCourse, updateDisplayName.
  1594. * CourseOffering methods: addAsset, addStudent, createCourseSection,
  1595. * deleteCourseSection, removeAsset, removeStudent, updateCourseGradeType,
  1596. * updateDescription, updateDisplayName, updateStatus, updateTitle.
  1597. * CourseSection methods: addAsset, addStudent, changeStudent.
  1598. *
  1599. * @return boolean
  1600. *
  1601. * @throws object CourseManagementException An exception
  1602. * with one of the following messages defined in
  1603. * org.osid.coursemanagement.CourseManagementException may be
  1604. * thrown: {@link }
  1605. * org.osid.coursemanagement.CourseManagementException#OPERATION_FAILED
  1606. * OPERATION_FAILED}, {@link }
  1607. * org.osid.coursemanagement.CourseManagementException#PERMISSION_DENIED
  1608. * PERMISSION_DENIED}, {@link }
  1609. * org.osid.coursemanagement.CourseManagementException#CONFIGURATION_ERROR
  1610. * CONFIGURATION_ERROR}, {@link }
  1611. * org.osid.coursemanagement.CourseManagementException#UNIMPLEMENTED
  1612. * UNIMPLEMENTED}
  1613. *
  1614. * @access public
  1615. */
  1616. function supportsUpdate () {
  1617. return true;
  1618. }
  1619.  
  1620.  
  1621.  
  1622.  
  1623.  
  1624.  
  1625.  
  1626. /**
  1627. * Get all the Types from the table specified
  1628. *
  1629. * @param string $typename the type of Types to get
  1630. *
  1631. * @return object HarmoniTypeIterator
  1632. *
  1633. * @access private
  1634. */
  1635. function _getTypes($typename){
  1636.  
  1637. //query
  1638. $dbHandler = Services::getService("DBHandler");
  1639. $query= new SelectQuery;
  1640. $query->addTable('cm_'.$typename."_type");
  1641. $query->addColumn('domain');
  1642. $query->addColumn('authority');
  1643. $query->addColumn('keyword');
  1644. $query->addColumn('description');
  1645. $res=$dbHandler->query($query);
  1646.  
  1647. //iterate through results and add to an array
  1648. $array=array();
  1649. while($res->hasMoreRows()){
  1650. $row = $res->getCurrentRow();
  1651. $res->advanceRow();
  1652. if(is_null($row['description'])){
  1653. $the_type = new Type($row['domain'],$row['authority'],$row['keyword']);
  1654. }else{
  1655. $the_type = new Type($row['domain'],$row['authority'],$row['keyword'],$row['description']);
  1656. }
  1657. $array[] = $the_type;
  1658. }
  1659.  
  1660. //convert to an iterator
  1661. $ret = new HarmoniTypeIterator($array);
  1662. return $ret;
  1663. }
  1664.  
  1665. /**
  1666. * For object in table $table with id $id, get the Type with type $typename
  1667. *
  1668. * @param object Id $id the Id of the object in question
  1669. * @param string $table the table our object resides in
  1670. * @param string $typename the type of Type to get
  1671. *
  1672. * @return object Type
  1673. *
  1674. * @access private
  1675. */
  1676. function _getType($id, $table, $typename){
  1677. //the appropriate table names and fields must be given names according to the pattern indicated below
  1678.  
  1679. //get the index for the type
  1680. $index = $this->_getField($id,$table,"fk_cm_".$typename."_type");
  1681.  
  1682. return $this->_indexToType($index,$typename);
  1683.  
  1684. }
  1685. /**
  1686. * For get the Type with type $typename with id $index
  1687. *
  1688. * @param string $index the index of the type
  1689. * @param string $typename the type of Type to get
  1690. *
  1691. * @return object Type
  1692. *
  1693. * @access private
  1694. */
  1695. function _indexToType($index, $typename){
  1696. //the appropriate table names and fields must be given names according to the pattern indicated below
  1697.  
  1698. //query
  1699. $dbHandler = Services::getService("DBHandler");
  1700. $query= new SelectQuery;
  1701. $query->addTable('cm_'.$typename."_type");
  1702. $query->addWhere("id=".$index);
  1703. $query->addColumn('domain');
  1704. $query->addColumn('authority');
  1705. $query->addColumn('keyword');
  1706. $query->addColumn('description');
  1707. $res=$dbHandler->query($query);
  1708.  
  1709.  
  1710. if(!$res->hasMoreRows()){
  1711. throwError(new Error("No Type has Id '".$index."' in table 'cm_".$typename."_type'","CourseManagement", true));
  1712. }
  1713.  
  1714. //There should be exactly one result. Convert it to a type and return it
  1715. //remember that the description is optional
  1716. $row = $res->getCurrentRow();
  1717. if(is_null($row['description'])){
  1718. $the_type = new Type($row['domain'],$row['authority'],$row['keyword']);
  1719. }else{
  1720. $the_type = new Type($row['domain'],$row['authority'],$row['keyword'],$row['description']);
  1721. }
  1722. return $the_type;
  1723.  
  1724. }
  1725.  
  1726. /**
  1727. * Find the index for our Type of type $type in its table. If it is not there,
  1728. * put it into the table and return the index.
  1729. *
  1730. * @param string $typename the type of Type that is passed in.
  1731. * @param object Type $type the Type itself
  1732. *
  1733. * @return object Type
  1734. *
  1735. * @access private
  1736. */
  1737. function _typeToIndex($typename, $type){
  1738. //the appropriate table names and fields must be given names according to the pattern indicated below
  1739.  
  1740. //validate the Type
  1741. ArgumentValidator::validate($type, ExtendsValidatorRule::getRule("Type"), true);
  1742.  
  1743. //query to see if it exists
  1744. $dbHandler = Services::getService("DBHandler");
  1745. $query= new SelectQuery;
  1746. $query->addTable('cm_'.$typename."_type");
  1747. $query->addWhere("domain='".$type->getDomain()."'");
  1748. $query->addWhere("authority='".$type->getAuthority()."'");
  1749. $query->addWhere("keyword='".$type->getKeyword()."'");
  1750. $query->addColumn('id');
  1751. $res=$dbHandler->query($query);
  1752.  
  1753.  
  1754.  
  1755. if($res->getNumberOfRows()==0){
  1756. //if not query to create it
  1757. $query= new InsertQuery;
  1758. $query->setTable('cm_'.$typename.'_type');
  1759. $values[]="'".addslashes($type->getDomain())."'";
  1760. $values[]="'".addslashes($type->getAuthority())."'";
  1761. $values[]="'".addslashes($type->getKeyword())."'";
  1762. if(is_null($type->getDescription())){
  1763. $query->setColumns(array('domain','authority','keyword'));
  1764. }else{
  1765. $query->setColumns(array('domain','authority','keyword','description'));
  1766. $values[]="'".addslashes($type->getDescription())."'";
  1767. }
  1768.  
  1769. $query->addRowOfValues($values);
  1770. $query->setAutoIncrementColumn('id','cm_'.$typename.'_type_id_seq');
  1771.  
  1772.  
  1773. $result =$dbHandler->query($query);
  1774.  
  1775. return $result->getLastAutoIncrementValue();
  1776. }elseif($res->getNumberOfRows()==1){
  1777. //if it does exist, create it
  1778. $row = $res->getCurrentRow();
  1779. $the_index = $row['id'];
  1780. return $the_index;
  1781.  
  1782. }else{
  1783. //print a warning if there is more than one such type. Should never happen.
  1784. print "\n<b>Warning!<\b> The Type with domain ".$type->getDomain().", authority ".$type->getAuthority().", and keyword ".$type->getKeyword()." is not unique--there are ".$res->getNumberOfRows()." copies.\n";
  1785.  
  1786.  
  1787. //return either one anyway.
  1788. $row = $res->getCurrentRow();
  1789. $the_index = $row['id'];
  1790. return $the_index;
  1791.  
  1792. }
  1793.  
  1794. }
  1795.  
  1796. /**
  1797. * Given the object in table $table with id $id, change the field with name $key to $value
  1798. *
  1799. * @param object Id $id The Id of the object in question
  1800. * @param string $table The table that our object resides in
  1801. * @param string $key The name of the field
  1802. * @param mixed $value The value to pass in
  1803. *
  1804. *
  1805. * @access private
  1806. */
  1807. function _setField($id, $table, $key, $value)
  1808. {
  1809. //just an update query
  1810. $dbHandler = Services::getService("DBHandler");
  1811. $query= new UpdateQuery;
  1812. $query->setTable($table);
  1813. $query->addWhere("id='".addslashes($id->getIdString())."'");
  1814. $query->setColumns(array(addslashes($key)));
  1815. $query->setValues(array("'".addslashes($value)."'"));
  1816. $dbHandler->query($query);
  1817.  
  1818.  
  1819. }
  1820.  
  1821. /**
  1822. * Given the object in table $table with id $id, get the field with name $key
  1823. *
  1824. * @param object Id $id The Id of the object in question
  1825. * @param string $table The table that our object resides in
  1826. * @param string $key The name of the field
  1827. *
  1828. * @return string
  1829. *
  1830. * @access private
  1831. */
  1832. function _getField($id, $table, $key)
  1833. {
  1834. // Validate the Id
  1835. ArgumentValidator::validate($id, ExtendsValidatorRule::getRule("Id"), true);
  1836.  
  1837. $idString = $id->getIdString();
  1838.  
  1839. //just a select query
  1840. $dbHandler = Services::getService("DBHandler");
  1841. $query= new SelectQuery;
  1842. $query->addTable($table);
  1843. $query->addWhere("id='".addslashes($idString)."'");
  1844. $query->addColumn(addslashes($key));
  1845. $res =$dbHandler->query($query);
  1846.  
  1847. if(!$res->hasMoreRows()){
  1848. throwError(new Error("Cannot get key '".$key."' from non-existant object with id '".$idString."'", "CourseManagement", true));
  1849. }
  1850.  
  1851. $row = $res->getCurrentRow();
  1852. $ret=$row[$key];
  1853. return $ret;
  1854. }
  1855.  
  1856. }
  1857.  
  1858. ?>

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