Source for file HarmoniGradableObject.class.php

Documentation is available at HarmoniGradableObject.class.php

  1. <?php
  2. require_once(OKI2."/osid/grading/GradableObject.php");
  3.  
  4.  
  5. /**
  6. * GradableObject includes a Name, Description, Id, GradeType, CourseSection
  7. * reference, and External Reference to what is being graded.
  8. *
  9. * <p>
  10. * OSID Version: 2.0
  11. * </p>
  12. *
  13. * <p>
  14. * Licensed under the {@link org.osid.SidImplementationLicenseMIT MIT}
  15. * O.K.I&#46; OSID Definition License}.
  16. * </p>
  17. *
  18. * @package org.osid.grading
  19. */
  20. class HarmoniGradableObject
  21. extends GradableObject
  22. {
  23. /**
  24. * @variable object $_id the unique id for this GradableObject.
  25. * @access private
  26. * @variable object $_table the GradableObject table.
  27. * @access private
  28. ***/
  29. var $_id;
  30. var $_table;
  31. /**
  32. * The constructor.
  33. *
  34. * @param object Id $id
  35. *
  36. * @access public
  37. * @return void
  38. */
  39. function HarmoniGradableObject($id)
  40. {
  41. $this->_id =$id;
  42. $this->_table = 'gr_gradable';
  43. }
  44. /**
  45. * Update the display name for this Assignment.
  46. *
  47. * @param string $displayName
  48. *
  49. * @throws object GradingException An exception with one of the
  50. * following messages defined in org.osid.grading.GradingException
  51. * may be thrown: {@link }
  52. * org.osid.grading.GradingException#OPERATION_FAILED
  53. * OPERATION_FAILED}, {@link }
  54. * org.osid.grading.GradingException#PERMISSION_DENIED
  55. * PERMISSION_DENIED}, {@link }
  56. * org.osid.grading.GradingException#CONFIGURATION_ERROR
  57. * CONFIGURATION_ERROR}, {@link }
  58. * org.osid.grading.GradingException#UNIMPLEMENTED UNIMPLEMENTED}
  59. *
  60. * @access public
  61. */
  62. function updateDisplayName ( $displayName ) {
  63. $this->_setField("name",$displayName);
  64. $this->_setModifiedDateAndAgent();
  65. }
  66.  
  67. /**
  68. * Update the description for this GradableObject.
  69. *
  70. * @param string $description
  71. *
  72. * @throws object GradingException An exception with one of the
  73. * following messages defined in org.osid.grading.GradingException
  74. * may be thrown: {@link }
  75. * org.osid.grading.GradingException#OPERATION_FAILED
  76. * OPERATION_FAILED}, {@link }
  77. * org.osid.grading.GradingException#PERMISSION_DENIED
  78. * PERMISSION_DENIED}, {@link }
  79. * org.osid.grading.GradingException#CONFIGURATION_ERROR
  80. * CONFIGURATION_ERROR}, {@link }
  81. * org.osid.grading.GradingException#UNIMPLEMENTED UNIMPLEMENTED}
  82. *
  83. * @access public
  84. */
  85. function updateDescription ( $description ) {
  86. $this->_setField("description",$description);
  87. $this->_setModifiedDateAndAgent();
  88. }
  89.  
  90. /**
  91. * Get the display name for this GradableObject.
  92. *
  93. * @return string
  94. *
  95. * @throws object GradingException An exception with one of the
  96. * following messages defined in org.osid.grading.GradingException
  97. * may be thrown: {@link }
  98. * org.osid.grading.GradingException#OPERATION_FAILED
  99. * OPERATION_FAILED}, {@link }
  100. * org.osid.grading.GradingException#PERMISSION_DENIED
  101. * PERMISSION_DENIED}, {@link }
  102. * org.osid.grading.GradingException#CONFIGURATION_ERROR
  103. * CONFIGURATION_ERROR}, {@link }
  104. * org.osid.grading.GradingException#UNIMPLEMENTED UNIMPLEMENTED}
  105. *
  106. * @access public
  107. */
  108. function getDisplayName () {
  109. return $this->_getField("name");
  110. }
  111.  
  112. /**
  113. * Get the description for this GradableObject.
  114. *
  115. * @return string
  116. *
  117. * @throws object GradingException An exception with one of the
  118. * following messages defined in org.osid.grading.GradingException
  119. * may be thrown: {@link }
  120. * org.osid.grading.GradingException#OPERATION_FAILED
  121. * OPERATION_FAILED}, {@link }
  122. * org.osid.grading.GradingException#PERMISSION_DENIED
  123. * PERMISSION_DENIED}, {@link }
  124. * org.osid.grading.GradingException#CONFIGURATION_ERROR
  125. * CONFIGURATION_ERROR}, {@link }
  126. * org.osid.grading.GradingException#UNIMPLEMENTED UNIMPLEMENTED}
  127. *
  128. * @access public
  129. */
  130. function getDescription () {
  131. return $this->_getField("description");
  132. }
  133.  
  134. /**
  135. * Get the unique Id for this GradableObject.
  136. *
  137. * @return object Id
  138. *
  139. * @throws object GradingException An exception with one of the
  140. * following messages defined in org.osid.grading.GradingException
  141. * may be thrown: {@link }
  142. * org.osid.grading.GradingException#OPERATION_FAILED
  143. * OPERATION_FAILED}, {@link }
  144. * org.osid.grading.GradingException#PERMISSION_DENIED
  145. * PERMISSION_DENIED}, {@link }
  146. * org.osid.grading.GradingException#CONFIGURATION_ERROR
  147. * CONFIGURATION_ERROR}, {@link }
  148. * org.osid.grading.GradingException#UNIMPLEMENTED UNIMPLEMENTED}
  149. *
  150. * @access public
  151. */
  152. function getId () {
  153. return $this->_id;
  154. }
  155.  
  156. /**
  157. * Get the unique Id with a CourseSection. CourseSections are created and
  158. * managed through the CourseManagement OSID.
  159. *
  160. * @return object Id
  161. *
  162. * @throws object GradingException An exception with one of the
  163. * following messages defined in org.osid.grading.GradingException
  164. * may be thrown: {@link }
  165. * org.osid.grading.GradingException#OPERATION_FAILED
  166. * OPERATION_FAILED}, {@link }
  167. * org.osid.grading.GradingException#PERMISSION_DENIED
  168. * PERMISSION_DENIED}, {@link }
  169. * org.osid.grading.GradingException#CONFIGURATION_ERROR
  170. * CONFIGURATION_ERROR}, {@link }
  171. * org.osid.grading.GradingException#UNIMPLEMENTED UNIMPLEMENTED}
  172. *
  173. * @access public
  174. */
  175. function getCourseSection () {
  176. $idManager = Services::getService("Id");
  177. $idString = $this->_getField("fk_cm_section");
  178. return $idManager->getId($idString);
  179. }
  180.  
  181. /**
  182. * Get the unique Id associated with some object that is being graded such
  183. * as an Assessment.
  184. *
  185. * @return object Id
  186. *
  187. * @throws object GradingException An exception with one of the
  188. * following messages defined in org.osid.grading.GradingException
  189. * may be thrown: {@link }
  190. * org.osid.grading.GradingException#OPERATION_FAILED
  191. * OPERATION_FAILED}, {@link }
  192. * org.osid.grading.GradingException#PERMISSION_DENIED
  193. * PERMISSION_DENIED}, {@link }
  194. * org.osid.grading.GradingException#CONFIGURATION_ERROR
  195. * CONFIGURATION_ERROR}, {@link }
  196. * org.osid.grading.GradingException#UNIMPLEMENTED UNIMPLEMENTED}
  197. *
  198. * @access public
  199. */
  200. function getExternalReference () {
  201. $externalId = $this->_getField("fk_reference_id");
  202. if(is_null($externalId)){
  203. return null;
  204. }
  205. $idManager = Services::getService("Id");
  206. return $idManager->getId($externalId);
  207. }
  208.  
  209. /**
  210. * Get the GradeType associated with the GradableObject and Grade.
  211. *
  212. * @return object Type
  213. *
  214. * @throws object GradingException An exception with one of the
  215. * following messages defined in org.osid.grading.GradingException
  216. * may be thrown: {@link }
  217. * org.osid.grading.GradingException#OPERATION_FAILED
  218. * OPERATION_FAILED}, {@link }
  219. * org.osid.grading.GradingException#PERMISSION_DENIED
  220. * PERMISSION_DENIED}, {@link }
  221. * org.osid.grading.GradingException#CONFIGURATION_ERROR
  222. * CONFIGURATION_ERROR}, {@link }
  223. * org.osid.grading.GradingException#UNIMPLEMENTED UNIMPLEMENTED}
  224. *
  225. * @access public
  226. */
  227. function getGradeType () {
  228. return $this->_getType("grade");
  229. }
  230.  
  231. /**
  232. * Get the ScoringDefinition associated with the GradableObject and Grade.
  233. *
  234. * @return object Type
  235. *
  236. * @throws object GradingException An exception with one of the
  237. * following messages defined in org.osid.grading.GradingException
  238. * may be thrown: {@link }
  239. * org.osid.grading.GradingException#OPERATION_FAILED
  240. * OPERATION_FAILED}, {@link }
  241. * org.osid.grading.GradingException#PERMISSION_DENIED
  242. * PERMISSION_DENIED}, {@link }
  243. * org.osid.grading.GradingException#CONFIGURATION_ERROR
  244. * CONFIGURATION_ERROR}, {@link }
  245. * org.osid.grading.GradingException#UNIMPLEMENTED UNIMPLEMENTED}
  246. *
  247. * @access public
  248. */
  249. function getScoringDefinition () {
  250. return $this->_getType("scoring");
  251. }
  252.  
  253. /**
  254. * Get the GradeScale associated with the GradableObject and Grade.
  255. *
  256. * @return object Type
  257. *
  258. * @throws object GradingException An exception with one of the
  259. * following messages defined in org.osid.grading.GradingException
  260. * may be thrown: {@link }
  261. * org.osid.grading.GradingException#OPERATION_FAILED
  262. * OPERATION_FAILED}, {@link }
  263. * org.osid.grading.GradingException#PERMISSION_DENIED
  264. * PERMISSION_DENIED}, {@link }
  265. * org.osid.grading.GradingException#CONFIGURATION_ERROR
  266. * CONFIGURATION_ERROR}, {@link }
  267. * org.osid.grading.GradingException#UNIMPLEMENTED UNIMPLEMENTED}
  268. *
  269. * @access public
  270. */
  271. function getGradeScale () {
  272. return $this->_getType("gradescale");
  273. }
  274.  
  275. /**
  276. * Get the gradeWeight of this GradableObject.
  277. *
  278. * @return int
  279. *
  280. * @throws object GradingException An exception with one of the
  281. * following messages defined in org.osid.grading.GradingException
  282. * may be thrown: {@link }
  283. * org.osid.grading.GradingException#OPERATION_FAILED
  284. * OPERATION_FAILED}, {@link }
  285. * org.osid.grading.GradingException#PERMISSION_DENIED
  286. * PERMISSION_DENIED}, {@link }
  287. * org.osid.grading.GradingException#CONFIGURATION_ERROR
  288. * CONFIGURATION_ERROR}, {@link }
  289. * org.osid.grading.GradingException#UNIMPLEMENTED UNIMPLEMENTED}
  290. *
  291. * @access public
  292. */
  293. function getGradeWeight () {
  294. return $this->_getField("weight");
  295. }
  296.  
  297. /**
  298. * Get the Properties of this Type associated with this GradableObject.
  299. *
  300. * @param object Type $propertiesType
  301. *
  302. * @return object Properties
  303. *
  304. * @throws object GradingException An exception with one of the
  305. * following messages defined in org.osid.grading.GradingException
  306. * may be thrown: {@link }
  307. * org.osid.grading.GradingException#OPERATION_FAILED
  308. * OPERATION_FAILED}, {@link }
  309. * org.osid.grading.GradingException#PERMISSION_DENIED
  310. * PERMISSION_DENIED}, {@link }
  311. * org.osid.grading.GradingException#CONFIGURATION_ERROR
  312. * CONFIGURATION_ERROR}, {@link }
  313. * org.osid.grading.GradingException#UNIMPLEMENTED UNIMPLEMENTED},
  314. * {@link org.osid.grading.GradingException#NULL_ARGUMENT}
  315. * NULL_ARGUMENT}, {@link }
  316. * org.osid.grading.GradingException#UNKNOWN_TYPE UNKNOWN_TYPE}
  317. *
  318. * @access public
  319. */
  320. function getPropertiesByType ( $propertiesType ) {
  321. $type =$this->getGradeType();
  322. $propType = new Type("PropertiesType", $type->getAuthority(), "properties");
  323. if($propertiesType->isEqualTo($propType)){
  324. return $this->_getProperties();
  325. }
  326. return null;
  327. }
  328.  
  329. /**
  330. * Get the Properties Types supported by this GradableObject.
  331. *
  332. * @return object TypeIterator
  333. *
  334. * @throws object GradingException An exception with one of the
  335. * following messages defined in org.osid.grading.GradingException
  336. * may be thrown: {@link }
  337. * org.osid.grading.GradingException#OPERATION_FAILED
  338. * OPERATION_FAILED}, {@link }
  339. * org.osid.grading.GradingException#PERMISSION_DENIED
  340. * PERMISSION_DENIED}, {@link }
  341. * org.osid.grading.GradingException#CONFIGURATION_ERROR
  342. * CONFIGURATION_ERROR}, {@link }
  343. * org.osid.grading.GradingException#UNIMPLEMENTED UNIMPLEMENTED}
  344. *
  345. * @access public
  346. */
  347. function getPropertyTypes () {
  348. $type =$this->getGradeType();
  349. $propertiesType = new Type("PropertiesType", $type->getAuthority(), "properties");
  350. $array = array($propertiesType);
  351. $typeIterator = new HarmoniTypeIterator($array);
  352. return $typeIterator;
  353. }
  354.  
  355. /**
  356. * Get the Properties associated with this GradableObject.
  357. *
  358. * @return object PropertiesIterator
  359. *
  360. * @throws object GradingException An exception with one of the
  361. * following messages defined in org.osid.grading.GradingException
  362. * may be thrown: {@link }
  363. * org.osid.grading.GradingException#OPERATION_FAILED
  364. * OPERATION_FAILED}, {@link }
  365. * org.osid.grading.GradingException#PERMISSION_DENIED
  366. * PERMISSION_DENIED}, {@link }
  367. * org.osid.grading.GradingException#CONFIGURATION_ERROR
  368. * CONFIGURATION_ERROR}, {@link }
  369. * org.osid.grading.GradingException#UNIMPLEMENTED UNIMPLEMENTED}
  370. *
  371. * @access public
  372. */
  373. function getProperties () {
  374. $array = array($this->_getProperties());
  375. $ret = new HarmoniPropertiesIterator($array);
  376. return $ret;//return the iterator
  377. }
  378.  
  379. /**
  380. * Get the Id of the Agent who modified this GradableObject.
  381. *
  382. * @return object Id
  383. *
  384. * @throws object GradingException An exception with one of the
  385. * following messages defined in org.osid.grading.GradingException
  386. * may be thrown: {@link }
  387. * org.osid.grading.GradingException#OPERATION_FAILED
  388. * OPERATION_FAILED}, {@link }
  389. * org.osid.grading.GradingException#PERMISSION_DENIED
  390. * PERMISSION_DENIED}, {@link }
  391. * org.osid.grading.GradingException#CONFIGURATION_ERROR
  392. * CONFIGURATION_ERROR}, {@link }
  393. * org.osid.grading.GradingException#UNIMPLEMENTED UNIMPLEMENTED}
  394. *
  395. * @access public
  396. */
  397. function getModifiedBy () {
  398. $agentId =$this->_getField("fk_modified_by_agent");
  399. if(""==$agentId){
  400. return null;
  401. }
  402. $idManager = Services::getService("Id");
  403. return $idManager->getId($agentId);
  404. }
  405.  
  406. /**
  407. * Get the date when this GradableObject was modified, using the UNIX timestamp.
  408. *
  409. * @return int
  410. *
  411. * @throws object GradingException An exception with one of the
  412. * following messages defined in org.osid.grading.GradingException
  413. * may be thrown: {@link }
  414. * org.osid.grading.GradingException#OPERATION_FAILED
  415. * OPERATION_FAILED}, {@link }
  416. * org.osid.grading.GradingException#PERMISSION_DENIED
  417. * PERMISSION_DENIED}, {@link }
  418. * org.osid.grading.GradingException#CONFIGURATION_ERROR
  419. * CONFIGURATION_ERROR}, {@link }
  420. * org.osid.grading.GradingException#UNIMPLEMENTED UNIMPLEMENTED}
  421. *
  422. * @access public
  423. */
  424. function getModifiedDate () {
  425. return $this->_getField("modified_date");
  426. }
  427. /**
  428. * Get a Properties object with the information about this object.
  429. *
  430. * @return object Properties
  431. *
  432. * @access private
  433. */
  434. function _getProperties(){
  435. //get the record
  436. $dbManager = Services::getService("DatabaseManager");
  437. $query = new SelectQuery();
  438. $query->addTable('gr_gradable');
  439. $query->addColumn("*");
  440. $query->addWhere("id='".addslashes($this->_id->getIdString())."'");
  441. $res=$dbManager->query($query);
  442.  
  443. //make sure we can find that record
  444. if(!$res->hasMoreRows()){
  445. print "<b>Warning!</b> Can't get Properties of GradableObject with id ".$this->_id." since that id wasn't found in the database.";
  446. return null;
  447. }
  448. $row = $res->getCurrentRow();//grab (hopefully) the only row
  449. //make a type
  450. $type =$this->getGradeType();
  451. $propertiesType = new Type("PropertiesType", $type->getAuthority(), "properties");
  452. //create a custom Properties object
  453. $idManager = Services::getService("Id");
  454. $property = new HarmoniProperties($propertiesType);
  455. $property->addProperty('id', $idManager->getId($row['id']));
  456. $scoringType =$this->getScoringDefinition();
  457. $property->addProperty('scoring_type', $scoringType);
  458. $gradeType =$this->getGradeType();
  459. $property->addProperty('grade_type', $gradeType);
  460. $gradeScale =$this->getGradeScale();
  461. $property->addProperty('grade_scale', $gradeScale);
  462. $property->addProperty('description', $row['description']);
  463. $property->addProperty('display_name', $row['name']);
  464. $property->addProperty('modified_date', $row['modified_date']);
  465. $property->addProperty('modified_by_agent_id', $idManager->getId($row['fk_modified_by_agent']));
  466. $property->addProperty('reference_id', $idManager->getId($row['fk_reference_id']));
  467. $property->addProperty('course_section_id', $idManager->getId($row['fk_cm_section']));
  468. $property->addProperty('weight', $row['weight']);
  469. $res->free();
  470. return $property;
  471. }
  472. function _setModifiedDateAndAgent(){
  473. $this->_setField('modified_date',time()*1000);
  474. //@TODO use the timestamp feature in SQL?
  475. //try to get the creator of this ScheduleItem
  476. $authN = Services::getService("AuthN");
  477. $authNTypesIterator =$authN->getAuthenticationTypes();
  478. if($authNTypesIterator->hasNext()){
  479. $authNType1 =$authNTypesIterator->next();
  480. //hopefully the first one is the right one to choose.
  481. $creatorId =$authN->getUserId($authNType1);
  482. $creatorIdString = $creatorId->getIdString();
  483. }else{
  484. $creatorIdString = "";
  485. }
  486. $this->_setField('fk_modified_by_agent',$creatorIdString);
  487.  
  488. }
  489. function _typeToIndex($typename, $type)
  490. {
  491. $gm=Services::getService("Grading");
  492. return $gm->_typeToIndex($typename, $type);
  493. }
  494. function _getTypes($typename)
  495. {
  496. $gm=Services::getService("Grading");
  497. return $gm->_getTypes($typename);
  498. }
  499. function _getField($key)
  500. {
  501. $gm=Services::getService("Grading");
  502. return $gm->_getField($this->_id,$this->_table,$key);
  503. }
  504. function _getType($typename){
  505. $gm=Services::getService("Grading");
  506. return $gm->_getType($this->_id,$this->_table,$typename);
  507. }
  508. function _setField($key, $value)
  509. {
  510. $gm=Services::getService("Grading");
  511. return $gm->_setField($this->_id,$this->_table,$key, $value);
  512. }
  513. }
  514.  
  515. ?>

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