Harmoni PHP Cross Reference Developer Tools

Source: /core/oki2/coursemanagement/CourseManagementManager.class.php - 1881 lines - 61617 bytes - Summary - Text - Print

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

title

Description

title

Description

title

Description

title

title

Body