Source for file HarmoniGradingManager.class.php

Documentation is available at HarmoniGradingManager.class.php

  1. <?php
  2. require_once(OKI2."/osid/grading/GradingManager.php");
  3.  
  4.  
  5. require_once(HARMONI."oki2/grading/HarmoniGradableObject.class.php");
  6. require_once(HARMONI."oki2/grading/HarmoniGradeRecord.class.php");
  7. require_once(HARMONI."oki2/grading/HarmoniGradableObjectIterator.class.php");
  8. require_once(HARMONI."oki2/grading/HarmoniGradeRecordIterator.class.php");
  9.  
  10.  
  11.  
  12. /**
  13. * <p>
  14. * GradingManager handles creating and deleting:
  15. *
  16. * <ul>
  17. * <li>
  18. * GradableObject,
  19. * </li>
  20. * <li>
  21. * GradeRecord
  22. * </li>
  23. * </ul>
  24. *
  25. * and getting:
  26. *
  27. * <ul>
  28. * <li>
  29. * GradableObject,
  30. * </li>
  31. * <li>
  32. * GradeRecords,
  33. * </li>
  34. * <li>
  35. * various implementation Types.
  36. * </li>
  37. * </ul>
  38. * </p>
  39. *
  40. * <p>
  41. * All implementations of OsidManager (manager) provide methods for accessing
  42. * and manipulating the various objects defined in the OSID package. A manager
  43. * defines an implementation of an OSID. All other OSID objects come either
  44. * directly or indirectly from the manager. New instances of the OSID objects
  45. * are created either directly or indirectly by the manager. Because the OSID
  46. * objects are defined using interfaces, create methods must be used instead
  47. * of the new operator to create instances of the OSID objects. Create methods
  48. * are used both to instantiate and persist OSID objects. Using the
  49. * OsidManager class to define an OSID's implementation allows the application
  50. * to change OSID implementations by changing the OsidManager package name
  51. * used to load an implementation. Applications developed using managers
  52. * permit OSID implementation substitution without changing the application
  53. * source code. As with all managers, use the OsidLoader to load an
  54. * implementation of this interface.
  55. * </p>
  56. *
  57. * <p></p>
  58. *
  59. * <p>
  60. * OSID Version: 2.0
  61. * </p>
  62. *
  63. * <p>
  64. * Licensed under the {@link org.osid.SidImplementationLicenseMIT MIT}
  65. * O.K.I&#46; OSID Definition License}.
  66. * </p>
  67. *
  68. * @package org.osid.grading
  69. */
  70. class HarmoniGradingManager
  71. extends GradingManager
  72. {
  73. /**
  74. * @variable object OsidContext $_osidContext the OSID context.
  75. * @access private
  76. ***/
  77. var $_osidContext;
  78.  
  79.  
  80.  
  81.  
  82.  
  83. /**
  84. * @param ref object $drId A {@link HarmoniId} referencing our DR.
  85. */
  86. function HarmoniCourseManagementManager () {
  87.  
  88.  
  89. }
  90.  
  91.  
  92.  
  93. /**
  94. * Assign the configuration of this Manager. There are no valid configuration options for
  95. * this manager.
  96. *
  97. *
  98. * @param object Properties $configuration (original type: java.util.Properties)
  99. *
  100. * @throws object OsidException An exception with one of the following
  101. * messages defined in org.osid.OsidException: {@link }
  102. * org.osid.OsidException#OPERATION_FAILED OPERATION_FAILED},
  103. * {@link org.osid.OsidException#PERMISSION_DENIED}
  104. * PERMISSION_DENIED}, {@link }
  105. * org.osid.OsidException#CONFIGURATION_ERROR
  106. * CONFIGURATION_ERROR}, {@link }
  107. * org.osid.OsidException#UNIMPLEMENTED UNIMPLEMENTED}, {@link }
  108. * org.osid.OsidException#NULL_ARGUMENT NULL_ARGUMENT}
  109. *
  110. * @access public
  111. */
  112. function assignConfiguration ( $configuration ) {
  113. }
  114.  
  115. /**
  116. * Return context of this OsidManager.
  117. *
  118. * @return object OsidContext
  119. *
  120. * @throws object OsidException
  121. *
  122. * @access public
  123. */
  124. function getOsidContext () {
  125. return $this->_osidContext;
  126. }
  127.  
  128. /**
  129. * Assign the context of this OsidManager.
  130. *
  131. * @param object OsidContext $context
  132. *
  133. * @throws object OsidException An exception with one of the following
  134. * messages defined in org.osid.OsidException: {@link }
  135. * org.osid.OsidException#NULL_ARGUMENT NULL_ARGUMENT}
  136. *
  137. * @access public
  138. */
  139. function assignOsidContext ( $context ) {
  140. $this->_osidContext =$context;
  141. }
  142. /**
  143. * Create a new GradableObject which includes all the elements for grading
  144. * something for a CourseSection. The type of grade and other grade
  145. * characteristics are also specified.
  146. *
  147. * @param string $displayName
  148. * @param string $description
  149. * @param object Id $courseSectionId
  150. * @param object Id $externalReferenceId
  151. * @param object Type $gradeType
  152. * @param object Type $scoringDefinition
  153. * @param object Type $gradeScale
  154. * @param int $gradeWeight
  155. *
  156. * @return object GradableObject
  157. *
  158. * @throws object GradingException An exception with one of the
  159. * following messages defined in org.osid.grading.GradingException
  160. * may be thrown: {@link }
  161. * org.osid.grading.GradingException#OPERATION_FAILED
  162. * OPERATION_FAILED}, {@link }
  163. * org.osid.grading.GradingException#PERMISSION_DENIED
  164. * PERMISSION_DENIED}, {@link }
  165. * org.osid.grading.GradingException#CONFIGURATION_ERROR
  166. * CONFIGURATION_ERROR}, {@link }
  167. * org.osid.grading.GradingException#UNIMPLEMENTED UNIMPLEMENTED},
  168. * {@link org.osid.grading.GradingException#NULL_ARGUMENT}
  169. * NULL_ARGUMENT}, {@link }
  170. * org.osid.grading.GradingException#UNKNOWN_TYPE UNKNOWN_TYPE}
  171. *
  172. * @access public
  173. */
  174. function createGradableObject ( $displayName, $description, $courseSectionId, $externalReferenceId, $gradeType, $scoringDefinition, $gradeScale, $gradeWeight ) {
  175. //make id
  176. $idManager = Services::getService("IdManager");
  177. $id=$idManager->createId();
  178.  
  179. //prepare insert query
  180. $dbManager= Services::getService("DatabaseManager");
  181. $query= new InsertQuery;
  182. $query->setTable('gr_gradable');
  183.  
  184. //ready values
  185. $query->setColumns(array('id','fk_gr_scoring_type','fk_gr_grade_type','fk_gr_gradescale_type','description','name','fk_reference_id','fk_cm_section','weight'));
  186. $values[]="'".addslashes($id->getIdString())."'";
  187. $values[]="'".$this->_typeToIndex('scoring',$scoringDefinition)."'";
  188. $values[]="'".$this->_typeToIndex('grade',$gradeType)."'";
  189. $values[]="'".$this->_typeToIndex('gradescale',$gradeScale)."'";
  190. $values[]="'".addslashes($description)."'";
  191. $values[]="'".addslashes($displayName)."'";
  192. $values[]="'".addslashes($externalReferenceId->getIdString())."'";
  193. $values[]="'".addslashes($courseSectionId->getIdString())."'";
  194. $values[]="'".addslashes($gradeWeight)."'";
  195. $query->addRowOfValues($values);
  196.  
  197.  
  198. //query
  199. $dbManager->query($query);
  200.  
  201. //make object and update
  202. $ret = new HarmoniGradableObject($id);
  203. $ret->_setModifiedDateAndAgent();
  204. return $ret;
  205. }
  206.  
  207. /**
  208. * Delete a GradableObject.
  209. *
  210. * @param object Id $gradableObjectId
  211. *
  212. * @throws object GradingException An exception with one of the
  213. * following messages defined in org.osid.grading.GradingException
  214. * may be thrown: {@link }
  215. * org.osid.grading.GradingException#OPERATION_FAILED
  216. * OPERATION_FAILED}, {@link }
  217. * org.osid.grading.GradingException#PERMISSION_DENIED
  218. * PERMISSION_DENIED}, {@link }
  219. * org.osid.grading.GradingException#CONFIGURATION_ERROR
  220. * CONFIGURATION_ERROR}, {@link }
  221. * org.osid.grading.GradingException#UNIMPLEMENTED UNIMPLEMENTED},
  222. * {@link org.osid.grading.GradingException#NULL_ARGUMENT}
  223. * NULL_ARGUMENT}, {@link }
  224. * org.osid.grading.GradingException#UNKNOWN_ID UNKNOWN_ID}
  225. *
  226. * @access public
  227. */
  228. function deleteGradableObject ( $gradableObjectId ) {
  229.  
  230. $dbManager = Services::getService("DatabaseManager");
  231. //first delete the GradeRecords
  232. $query= new DeleteQuery;
  233. $query->setTable('gr_record');
  234. $where = "fk_gr_gradable='".addslashes($gradableObjectId->getIdString())."'";
  235. $query->addWhere($where);
  236. $dbManager->query($query);
  237. //next delete the GradableObject
  238. $query= new DeleteQuery;
  239. $query->setTable('gr_gradable');
  240. $query->addWhere("id=".addslashes($gradableObjectId->getIdString()));
  241. $dbManager->query($query);
  242. }
  243.  
  244. /**
  245. * Get a GradableObject by unique Id.
  246. *
  247. * @param object Id $gradableObjectId
  248. *
  249. * @return object GradableObject
  250. *
  251. * @throws object GradingException An exception with one of the
  252. * following messages defined in org.osid.grading.GradingException
  253. * may be thrown: {@link }
  254. * org.osid.grading.GradingException#OPERATION_FAILED
  255. * OPERATION_FAILED}, {@link }
  256. * org.osid.grading.GradingException#PERMISSION_DENIED
  257. * PERMISSION_DENIED}, {@link }
  258. * org.osid.grading.GradingException#CONFIGURATION_ERROR
  259. * CONFIGURATION_ERROR}, {@link }
  260. * org.osid.grading.GradingException#UNIMPLEMENTED UNIMPLEMENTED},
  261. * {@link org.osid.grading.GradingException#NULL_ARGUMENT}
  262. * NULL_ARGUMENT}, {@link }
  263. * org.osid.grading.GradingException#UNKNOWN_ID UNKNOWN_ID}
  264. *
  265. * @access public
  266. */
  267. function getGradableObject ( $gradableObjectId ) {
  268. $ret = new HarmoniGradableObject($gradableObjectId);
  269. return $ret;
  270. }
  271.  
  272. /**
  273. * Get all the GradableObjects, optionally including only those for a
  274. * specific CourseSection or External Reference to what is being graded.
  275. * If any parameter is null, what is returned is not filtered by that
  276. * parameter.
  277. *
  278. * @param object Id $courseSectionId
  279. * @param object Id $externalReferenceId
  280. *
  281. * @return object GradableObjectIterator
  282. *
  283. * @throws object GradingException An exception with one of the
  284. * following messages defined in org.osid.grading.GradingException
  285. * may be thrown: {@link }
  286. * org.osid.grading.GradingException#OPERATION_FAILED
  287. * OPERATION_FAILED}, {@link }
  288. * org.osid.grading.GradingException#PERMISSION_DENIED
  289. * PERMISSION_DENIED}, {@link }
  290. * org.osid.grading.GradingException#CONFIGURATION_ERROR
  291. * CONFIGURATION_ERROR}, {@link }
  292. * org.osid.grading.GradingException#UNIMPLEMENTED UNIMPLEMENTED},
  293. * {@link org.osid.grading.GradingException#NULL_ARGUMENT}
  294. * NULL_ARGUMENT}, {@link }
  295. * org.osid.grading.GradingException#UNKNOWN_ID UNKNOWN_ID}
  296. *
  297. * @access public
  298. */
  299. function getGradableObjects ( $courseSectionId, $externalReferenceId ) {
  300. //set up query
  301. $dbManager = Services::getService("DatabaseManager");
  302. $query= new SelectQuery;
  303. $query->addTable('gr_gradable');
  304. $query->addColumn('id');
  305. //add appropriate wheres
  306. if(!is_null($courseSectionId)){
  307. $query->addWhere("fk_cm_section = '".addslashes($courseSectionId->getIdString())."'");
  308. }
  309. if(!is_null($externalReferenceId)){
  310. $query->addWhere("fk_reference_id = '".addslashes($externalReferenceId->getIdString())."'");
  311. }
  312. $res =$dbManager->query($query);
  313.  
  314. //get results in array
  315. $array = array();
  316. $idManager= Services::getService("IdManager");
  317. while($res->hasMoreRows()){
  318. $row = $res->getCurrentRow();
  319. $res->advanceRow();
  320. $id =$idManager->getId($row['id']);
  321. $array[] = new HarmoniGradableObject($id);
  322.  
  323. }
  324. //convert and return
  325. $ret = new HarmoniGradableObjectIterator($array);
  326. return $ret;
  327. }
  328.  
  329. /**
  330. * Create a new GradeRecord for an Agent and with a Grade and
  331. * GradeRecordType. The GradeRecordType is they Type of GradeRecord not
  332. * the Type of Grade contained in it. GradeRecord Types might indicate a
  333. * mid-term, partial, or final grade while GradeTypes might be letter,
  334. * numeric, etc. The Agent in this context is not the person who took the
  335. * test nor, necessarily, the person who is grading. It is the person
  336. * whose "GradeBook" this is, for example the CourseSection instructor.
  337. *
  338. * @param object Id $gradableObjectId
  339. * @param object Id $agentId
  340. * @param object mixed $gradeValue (original type: java.io.Serializable)
  341. * @param object Type $GradeRecordType
  342. *
  343. * @return object GradeRecord
  344. *
  345. * @throws object GradingException An exception with one of the
  346. * following messages defined in org.osid.grading.GradingException
  347. * may be thrown: {@link }
  348. * org.osid.grading.GradingException#OPERATION_FAILED
  349. * OPERATION_FAILED}, {@link }
  350. * org.osid.grading.GradingException#PERMISSION_DENIED
  351. * PERMISSION_DENIED}, {@link }
  352. * org.osid.grading.GradingException#CONFIGURATION_ERROR
  353. * CONFIGURATION_ERROR}, {@link }
  354. * org.osid.grading.GradingException#UNIMPLEMENTED UNIMPLEMENTED},
  355. * {@link org.osid.grading.GradingException#NULL_ARGUMENT}
  356. * NULL_ARGUMENT}, {@link }
  357. * org.osid.grading.GradingException#UNKNOWN_ID UNKNOWN_ID},
  358. * {@link org.osid.grading.GradingException#UNKNOWN_TYPE}
  359. * UNKNOWN_TYPE}
  360. *
  361. * @access public
  362. */
  363. function createGradeRecord ( $gradableObjectId, $agentId, $gradeValue, $GradeRecordType ) {
  364. //make id
  365. $idManager = Services::getService("IdManager");
  366. $id=$idManager->createId();
  367.  
  368. //prepare insert query
  369. $dbManager= Services::getService("DatabaseManager");
  370. $query= new InsertQuery;
  371. $query->setTable('gr_record');
  372.  
  373. //ready values
  374. $query->setColumns(array('id','value','fk_gr_gradable','fk_agent_id','fk_gr_record_type'));
  375. $values[]="'".addslashes($id->getIdString())."'";
  376. $values[]="'".addslashes($gradeValue)."'";
  377. $values[]="'".addslashes($gradableObjectId->getIdString())."'";
  378. $values[]="'".addslashes($agentId->getIdString())."'";
  379. $values[]="'".$this->_typeToIndex('record',$GradeRecordType)."'";
  380. $query->addRowOfValues($values);
  381.  
  382.  
  383. //query
  384. $dbManager->query($query);
  385.  
  386. //make object and update
  387. $ret = new HarmoniGradeRecord($id);
  388. $ret->_setModifiedDateAndAgent();
  389. return $ret;
  390. }
  391.  
  392. /**
  393. * Delete a GradeRecord. The first two parameters are required, but the
  394. * third may be left null to dignify any Type
  395. *
  396. * @param object Id $gradableObjectId
  397. * @param object Id $agentId
  398. * @param object Type $GradeRecordType
  399. *
  400. * @throws object GradingException An exception with one of the
  401. * following messages defined in org.osid.grading.GradingException
  402. * may be thrown: {@link }
  403. * org.osid.grading.GradingException#OPERATION_FAILED
  404. * OPERATION_FAILED}, {@link }
  405. * org.osid.grading.GradingException#PERMISSION_DENIED
  406. * PERMISSION_DENIED}, {@link }
  407. * org.osid.grading.GradingException#CONFIGURATION_ERROR
  408. * CONFIGURATION_ERROR}, {@link }
  409. * org.osid.grading.GradingException#UNIMPLEMENTED UNIMPLEMENTED},
  410. * {@link org.osid.grading.GradingException#NULL_ARGUMENT}
  411. * NULL_ARGUMENT}, {@link }
  412. * org.osid.grading.GradingException#UNKNOWN_ID UNKNOWN_ID}
  413. *
  414. * @access public
  415. */
  416. function deleteGradeRecord ( $gradableObjectId, $agentId, $GradeRecordType = null) {
  417. $dbManager = Services::getService("DatabaseManager");
  418. $query= new DeleteQuery;
  419. $query->setTable('gr_record');
  420. $query->addWhere("fk_gr_gradable='".addslashes($gradableObjectId->getIdString())."'");
  421. $query->addWhere("fk_agent_id='".addslashes($agentId->getIdString())."'");
  422. if(!is_null($GradeRecordType)){
  423. $query->addWhere("fk_gr_record_type='".addslashes($this->_typeToIndex('record',$GradeRecordType))."'");
  424. }
  425. $dbManager->query($query);
  426. }
  427.  
  428. /**
  429. * Get all the GradeRecords, optionally including only those for a specific
  430. * CourseSection, GradableObject, External Reference to what is being
  431. * graded, GradeRecordType, or Agent. If any parameter is null, what is
  432. * returned is not filtered by that parameter. For example,
  433. * getGradeRecords(xyzCourseSectionId,null,null,null,null) returns all
  434. * GradeRecords for the xyzCourseSection; and
  435. * getGradeRecords(xyzCourseSectionId,null,null,myAgent,quizGradeRecordType)
  436. * returns all GradeRecords for quizzes taken by myAgent in the
  437. * xyzCourseSection.
  438. *
  439. * @param object Id $courseSectionId
  440. * @param object Id $externalReferenceId
  441. * @param object Id $gradableObjectId
  442. * @param object Id $agentId
  443. * @param object Type $GradeRecordType
  444. *
  445. * @return object GradeRecordIterator
  446. *
  447. * @throws object GradingException An exception with one of the
  448. * following messages defined in org.osid.grading.GradingException
  449. * may be thrown: {@link }
  450. * org.osid.grading.GradingException#OPERATION_FAILED
  451. * OPERATION_FAILED}, {@link }
  452. * org.osid.grading.GradingException#PERMISSION_DENIED
  453. * PERMISSION_DENIED}, {@link }
  454. * org.osid.grading.GradingException#CONFIGURATION_ERROR
  455. * CONFIGURATION_ERROR}, {@link }
  456. * org.osid.grading.GradingException#UNIMPLEMENTED UNIMPLEMENTED},
  457. * {@link org.osid.grading.GradingException#NULL_ARGUMENT}
  458. * NULL_ARGUMENT}, {@link }
  459. * org.osid.grading.GradingException#UNKNOWN_ID UNKNOWN_ID},
  460. * {@link org.osid.grading.GradingException#UNKNOWN_TYPE}
  461. * UNKNOWN_TYPE}
  462. *
  463. * @access public
  464. */
  465. function getGradeRecords ( $courseSectionId, $externalReferenceId, $gradableObjectId, $agentId, $GradeRecordType ) {
  466. //set up query
  467. $dbManager = Services::getService("DatabaseManager");
  468. $query= new SelectQuery;
  469. $query->addTable('gr_record');
  470. //inner join?
  471. if(!is_null($externalReferenceId) || !is_null($courseSectionId)){
  472. $query->addTable('gr_gradable',INNER_JOIN,"gr_gradable.id=gr_record.fk_gr_gradable");
  473. }
  474. $query->addColumn('id','id','gr_record');
  475. //add appropriate wheres
  476. if(!is_null($courseSectionId)){
  477. $query->addWhere("gr_gradable.fk_cm_section = '".addslashes($courseSectionId->getIdString())."'");
  478. }
  479. if(!is_null($externalReferenceId)){
  480. $query->addWhere("gr_gradable.fk_reference_id = '".addslashes($externalReferenceId->getIdString())."'");
  481. }
  482. if(!is_null($gradableObjectId)){
  483. $query->addWhere("gr_record.fk_gr_gradable = '".addslashes($gradableObjectId->getIdString())."'");
  484. }
  485. if(!is_null($agentId)){
  486. $query->addWhere("gr_record.fk_agent_id='".addslashes($agentId->getIdString())."'");
  487. }
  488. if(!is_null($GradeRecordType)){
  489. $query->addWhere("gr_record.fk_gr_record_type='".addslashes($this->_typeToIndex('record',$GradeRecordType))."'");
  490. }
  491. $res =$dbManager->query($query);
  492.  
  493. //get results in array
  494. $array = array();
  495. $idManager= Services::getService("IdManager");
  496. while($res->hasMoreRows()){
  497.  
  498. $row = $res->getCurrentRow();
  499. $res->advanceRow();
  500. $id =$idManager->getId($row['id']);
  501. $array[] = new HarmoniGradeRecord($id);
  502.  
  503. }
  504. //convert and return
  505. $ret = new HarmoniGradeRecordIterator($array);
  506. return $ret;
  507. }
  508.  
  509. /**
  510. * Get all GradeRecordTypes.
  511. *
  512. * @return object TypeIterator
  513. *
  514. * @throws object GradingException An exception with one of the
  515. * following messages defined in org.osid.grading.GradingException
  516. * may be thrown: {@link }
  517. * org.osid.grading.GradingException#OPERATION_FAILED
  518. * OPERATION_FAILED}, {@link }
  519. * org.osid.grading.GradingException#PERMISSION_DENIED
  520. * PERMISSION_DENIED}, {@link }
  521. * org.osid.grading.GradingException#CONFIGURATION_ERROR
  522. * CONFIGURATION_ERROR}, {@link }
  523. * org.osid.grading.GradingException#UNIMPLEMENTED UNIMPLEMENTED}
  524. *
  525. * @access public
  526. */
  527. function getGradeRecordTypes () {
  528. return $this->_getTypes("record");
  529. }
  530.  
  531. /**
  532. * Get all GradeTypes.
  533. *
  534. * @return object TypeIterator
  535. *
  536. * @throws object GradingException An exception with one of the
  537. * following messages defined in org.osid.grading.GradingException
  538. * may be thrown: {@link }
  539. * org.osid.grading.GradingException#OPERATION_FAILED
  540. * OPERATION_FAILED}, {@link }
  541. * org.osid.grading.GradingException#PERMISSION_DENIED
  542. * PERMISSION_DENIED}, {@link }
  543. * org.osid.grading.GradingException#CONFIGURATION_ERROR
  544. * CONFIGURATION_ERROR}, {@link }
  545. * org.osid.grading.GradingException#UNIMPLEMENTED UNIMPLEMENTED}
  546. *
  547. * @access public
  548. */
  549. function getGradeTypes () {
  550. return $this->_getTypes("grade");
  551. }
  552.  
  553. /**
  554. * Get all ScoringDefinitions.
  555. *
  556. * @return object TypeIterator
  557. *
  558. * @throws object GradingException An exception with one of the
  559. * following messages defined in org.osid.grading.GradingException
  560. * may be thrown: {@link }
  561. * org.osid.grading.GradingException#OPERATION_FAILED
  562. * OPERATION_FAILED}, {@link }
  563. * org.osid.grading.GradingException#PERMISSION_DENIED
  564. * PERMISSION_DENIED}, {@link }
  565. * org.osid.grading.GradingException#CONFIGURATION_ERROR
  566. * CONFIGURATION_ERROR}, {@link }
  567. * org.osid.grading.GradingException#UNIMPLEMENTED UNIMPLEMENTED}
  568. *
  569. * @access public
  570. */
  571. function getScoringDefinitions () {
  572. return $this->_getTypes("scoring");
  573. }
  574.  
  575. /**
  576. * Get all GradeScales.
  577. *
  578. * @return object TypeIterator
  579. *
  580. * @throws object GradingException An exception with one of the
  581. * following messages defined in org.osid.grading.GradingException
  582. * may be thrown: {@link }
  583. * org.osid.grading.GradingException#OPERATION_FAILED
  584. * OPERATION_FAILED}, {@link }
  585. * org.osid.grading.GradingException#PERMISSION_DENIED
  586. * PERMISSION_DENIED}, {@link }
  587. * org.osid.grading.GradingException#CONFIGURATION_ERROR
  588. * CONFIGURATION_ERROR}, {@link }
  589. * org.osid.grading.GradingException#UNIMPLEMENTED UNIMPLEMENTED}
  590. *
  591. * @access public
  592. */
  593. function getGradeScales () {
  594. return $this->_getTypes("gradescale");
  595. }
  596.  
  597. /**
  598. * Get all the Types from the table specified
  599. *
  600. * @param string $typename the type of Types to get
  601. *
  602. * @return object HarmoniTypeIterator
  603. *
  604. * @access private
  605. */
  606. function _getTypes($typename){
  607. //query
  608. $dbHandler = Services::getService("DBHandler");
  609. $query= new SelectQuery;
  610. $query->addTable('gr_'.$typename."_type");
  611. $query->addColumn('domain');
  612. $query->addColumn('authority');
  613. $query->addColumn('keyword');
  614. $query->addColumn('description');
  615. $res=$dbHandler->query($query);
  616. //iterate through results and add to an array
  617. $array=array();
  618. while($res->hasMoreRows()){
  619. $row = $res->getCurrentRow();
  620. $res->advanceRow();
  621. if(is_null($row['description'])){
  622. $the_type = new Type($row['domain'],$row['authority'],$row['keyword']);
  623. }else{
  624. $the_type = new Type($row['domain'],$row['authority'],$row['keyword'],$row['description']);
  625. }
  626. $array[] = $the_type;
  627. }
  628. //convert to an iterator
  629. $ret = new HarmoniTypeIterator($array);
  630. return $ret;
  631. }
  632.  
  633. /**
  634. * For object in table $table with id $id, get the Type with type $typename
  635. *
  636. * @param object Id $id the Id of the object in question
  637. * @param string $table the table our object resides in
  638. * @param string $typename the type of Type to get
  639. *
  640. * @return object Type
  641. *
  642. * @access private
  643. */
  644. function _getType($id, $table, $typename){
  645. //the appropriate table names and fields must be given names according to the pattern indicated below
  646.  
  647. //get the index for the type
  648. $index = $this->_getField($id,$table,"fk_gr_".$typename."_type");
  649.  
  650. return $this->_indexToType($index,$typename);
  651.  
  652. }
  653. /**
  654. * For get the Type with type $typename with id $index
  655. *
  656. * @param string $index the index of the type
  657. * @param string $typename the type of Type to get
  658. *
  659. * @return object Type
  660. *
  661. * @access private
  662. */
  663. function _indexToType($index, $typename){
  664. //the appropriate table names and fields must be given names according to the pattern indicated below
  665.  
  666. //query
  667. $dbHandler = Services::getService("DBHandler");
  668. $query= new SelectQuery;
  669. $query->addTable('gr_'.$typename."_type");
  670. $query->addWhere("id=".$index);
  671. $query->addColumn('domain');
  672. $query->addColumn('authority');
  673. $query->addColumn('keyword');
  674. $query->addColumn('description');
  675. $res=$dbHandler->query($query);
  676.  
  677.  
  678. if(!$res->hasMoreRows()){
  679. throwError(new Error("No Type has Id '".$index."' in table 'gr_".$typename."_type'","CourseManagement", true));
  680. }
  681.  
  682. //There should be exactly one result. Convert it to a type and return it
  683. //remember that the description is optional
  684. $row = $res->getCurrentRow();
  685. if(is_null($row['description'])){
  686. $the_type = new Type($row['domain'],$row['authority'],$row['keyword']);
  687. }else{
  688. $the_type = new Type($row['domain'],$row['authority'],$row['keyword'],$row['description']);
  689. }
  690. return $the_type;
  691.  
  692. }
  693.  
  694. /**
  695. * Find the index for our Type of type $type in its table. If it is not there,
  696. * put it into the table and return the index.
  697. *
  698. * @param string $typename the type of Type that is passed in.
  699. * @param object Type $type the Type itself
  700. *
  701. * @return object Type
  702. *
  703. * @access private
  704. */
  705. function _typeToIndex($typename, $type){
  706. //the appropriate table names and fields must be given names according to the pattern indicated below
  707.  
  708. //validate the Type
  709. ArgumentValidator::validate($type, ExtendsValidatorRule::getRule("Type"), true);
  710. //query to see if it exists
  711. $dbHandler = Services::getService("DBHandler");
  712. $query= new SelectQuery;
  713. $query->addTable('gr_'.$typename."_type");
  714. $query->addWhere("domain='".$type->getDomain()."'");
  715. $query->addWhere("authority='".$type->getAuthority()."'");
  716. $query->addWhere("keyword='".$type->getKeyword()."'");
  717. $query->addColumn('id');
  718. $res=$dbHandler->query($query);
  719.  
  720.  
  721. if($res->getNumberOfRows()==0){
  722. //if not query to create it
  723. $query= new InsertQuery;
  724. $query->setTable('gr_'.$typename.'_type');
  725. $values[]="'".addslashes($type->getDomain())."'";
  726. $values[]="'".addslashes($type->getAuthority())."'";
  727. $values[]="'".addslashes($type->getKeyword())."'";
  728. if(is_null($type->getDescription())){
  729. $query->setColumns(array('domain','authority','keyword'));
  730. }else{
  731. $query->setColumns(array('domain','authority','keyword','description'));
  732. $values[]="'".addslashes($type->getDescription())."'";
  733. }
  734.  
  735. $query->addRowOfValues($values);
  736. $query->setAutoIncrementColumn('id', 'gr_'.$typename.'_type_id_sequence');
  737.  
  738.  
  739. $result =$dbHandler->query($query);
  740.  
  741. return $result->getLastAutoIncrementValue();
  742. }elseif($res->getNumberOfRows()==1){
  743. //if it does exist, create it
  744. $row = $res->getCurrentRow();
  745. $the_index = $row['id'];
  746. return $the_index;
  747.  
  748. }else{
  749. //print a warning if there is more than one such type. Should never happen.
  750. 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";
  751.  
  752.  
  753. //return either one anyway.
  754. $row = $res->getCurrentRow();
  755. $the_index = $row['id'];
  756. return $the_index;
  757.  
  758. }
  759.  
  760. }
  761.  
  762. /**
  763. * Given the object in table $table with id $id, change the field with name $key to $value
  764. *
  765. * @param object Id $id The Id of the object in question
  766. * @param string $table The table that our object resides in
  767. * @param string $key The name of the field
  768. * @param mixed $value The value to pass in
  769. *
  770. *
  771. * @access private
  772. */
  773. function _setField($id, $table, $key, $value)
  774. {
  775. //just an update query
  776. $dbHandler = Services::getService("DBHandler");
  777. $query= new UpdateQuery;
  778. $query->setTable($table);
  779. $query->addWhere("id='".addslashes($id->getIdString())."'");
  780. $query->setColumns(array(addslashes($key)));
  781. $query->setValues(array("'".addslashes($value)."'"));
  782. $dbHandler->query($query);
  783.  
  784.  
  785. }
  786.  
  787. /**
  788. * Given the object in table $table with id $id, get the field with name $key
  789. *
  790. * @param object Id $id The Id of the object in question
  791. * @param string $table The table that our object resides in
  792. * @param string $key The name of the field
  793. *
  794. * @return string
  795. *
  796. * @access private
  797. */
  798. function _getField($id, $table, $key)
  799. {
  800. //just a select query
  801. $dbHandler = Services::getService("DBHandler");
  802. $query= new SelectQuery;
  803. $query->addTable($table);
  804. $query->addWhere("id='".addslashes($id->getIdString())."'");
  805. $query->addColumn(addslashes($key));
  806. $res=$dbHandler->query($query);
  807. $row = $res->getCurrentRow();
  808. $ret=$row[$key];
  809. return $ret;
  810. }
  811. }
  812.  
  813. ?>

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