Source for file HarmoniGradeRecord.class.php

Documentation is available at HarmoniGradeRecord.class.php

  1. <?php
  2. require_once(OKI2."/osid/grading/GradeRecord.php");
  3.  
  4. /**
  5. * GradeRecord includes a reference to a gradable object, an Agent Id, a Grade,
  6. * and GradeType.
  7. *
  8. * <p>
  9. * OSID Version: 2.0
  10. * </p>
  11. *
  12. * <p>
  13. * Licensed under the {@link org.osid.SidImplementationLicenseMIT MIT}
  14. * O.K.I&#46; OSID Definition License}.
  15. * </p>
  16. *
  17. * @package org.osid.grading
  18. */
  19. class HarmoniGradeRecord
  20. extends GradeRecord
  21. {
  22. /**
  23. * @variable object $_id the unique id for this GradeRecord.
  24. * @access private
  25. * @variable object $_table the GradeRecord table.
  26. * @access private
  27. ***/
  28. var $_id;
  29. var $_table;
  30. /**
  31. * The constructor.
  32. *
  33. * @param object Id $id
  34. *
  35. * @access public
  36. * @return void
  37. */
  38. function HarmoniGradeRecord($id)
  39. {
  40. $this->_id =$id;
  41. $this->_table = 'gr_record';
  42. }
  43. /**
  44. * Update the value for this Grade.
  45. *
  46. * @param object mixed $gradeValue (original type: java.io.Serializable)
  47. *
  48. * @throws object GradingException An exception with one of the
  49. * following messages defined in org.osid.grading.GradingException
  50. * may be thrown: {@link }
  51. * org.osid.grading.GradingException#OPERATION_FAILED
  52. * OPERATION_FAILED}, {@link }
  53. * org.osid.grading.GradingException#PERMISSION_DENIED
  54. * PERMISSION_DENIED}, {@link }
  55. * org.osid.grading.GradingException#CONFIGURATION_ERROR
  56. * CONFIGURATION_ERROR}, {@link }
  57. * org.osid.grading.GradingException#UNIMPLEMENTED UNIMPLEMENTED}
  58. *
  59. * @access public
  60. */
  61. function updateGradeValue ( $gradeValue ) {
  62. $this->_setField("value",$gradeValue);
  63. $this->_setModifiedDateAndAgent();
  64. }
  65.  
  66. /**
  67. * Get the unique Id for this GradeRecord's GradableObject.
  68. *
  69. * @return object Id
  70. *
  71. * @throws object GradingException An exception with one of the
  72. * following messages defined in org.osid.grading.GradingException
  73. * may be thrown: {@link }
  74. * org.osid.grading.GradingException#OPERATION_FAILED
  75. * OPERATION_FAILED}, {@link }
  76. * org.osid.grading.GradingException#PERMISSION_DENIED
  77. * PERMISSION_DENIED}, {@link }
  78. * org.osid.grading.GradingException#CONFIGURATION_ERROR
  79. * CONFIGURATION_ERROR}, {@link }
  80. * org.osid.grading.GradingException#UNIMPLEMENTED UNIMPLEMENTED}
  81. *
  82. * @access public
  83. */
  84. function getGradableObject () {
  85. $idManager = Services::getService("Id");
  86. $idString = $this->_getField("fk_gr_gradable");
  87. return $idManager->getId($idString);
  88. }
  89.  
  90. /**
  91. * Get the Agent Id associated with this GradeRecord. The Agent in this
  92. * context is not the person who took the test nor, necessarily, the
  93. * person who is grading. It is the person whose "GradeBook" this is, for
  94. * example the CourseSection instructor.
  95. *
  96. * @return object Id
  97. *
  98. * @throws object GradingException An exception with one of the
  99. * following messages defined in org.osid.grading.GradingException
  100. * may be thrown: {@link }
  101. * org.osid.grading.GradingException#OPERATION_FAILED
  102. * OPERATION_FAILED}, {@link }
  103. * org.osid.grading.GradingException#PERMISSION_DENIED
  104. * PERMISSION_DENIED}, {@link }
  105. * org.osid.grading.GradingException#CONFIGURATION_ERROR
  106. * CONFIGURATION_ERROR}, {@link }
  107. * org.osid.grading.GradingException#UNIMPLEMENTED UNIMPLEMENTED}
  108. *
  109. * @access public
  110. */
  111. function getAgentId () {
  112. $idManager = Services::getService("Id");
  113. $idString = $this->_getField("fk_agent_id");
  114. return $idManager->getId($idString); ;
  115. }
  116.  
  117. /**
  118. * Get the value for this Grade.
  119. *
  120. * @return object mixed (original type: java.io.Serializable)
  121. *
  122. * @throws object GradingException An exception with one of the
  123. * following messages defined in org.osid.grading.GradingException
  124. * may be thrown: {@link }
  125. * org.osid.grading.GradingException#OPERATION_FAILED
  126. * OPERATION_FAILED}, {@link }
  127. * org.osid.grading.GradingException#PERMISSION_DENIED
  128. * PERMISSION_DENIED}, {@link }
  129. * org.osid.grading.GradingException#CONFIGURATION_ERROR
  130. * CONFIGURATION_ERROR}, {@link }
  131. * org.osid.grading.GradingException#UNIMPLEMENTED UNIMPLEMENTED}
  132. *
  133. * @access public
  134. */
  135. function getGradeValue () {
  136. $ret = $this->_getField("value");
  137. return $ret;
  138. }
  139.  
  140. /**
  141. * Get the Id of the Agent who modified this GradeRecord.
  142. *
  143. * @return object Id
  144. *
  145. * @throws object GradingException An exception with one of the
  146. * following messages defined in org.osid.grading.GradingException
  147. * may be thrown: {@link }
  148. * org.osid.grading.GradingException#OPERATION_FAILED
  149. * OPERATION_FAILED}, {@link }
  150. * org.osid.grading.GradingException#PERMISSION_DENIED
  151. * PERMISSION_DENIED}, {@link }
  152. * org.osid.grading.GradingException#CONFIGURATION_ERROR
  153. * CONFIGURATION_ERROR}, {@link }
  154. * org.osid.grading.GradingException#UNIMPLEMENTED UNIMPLEMENTED}
  155. *
  156. * @access public
  157. */
  158. function getModifiedBy () {
  159. $agentId =$this->_getField("fk_modified_by_agent");
  160. if(""==$agentId){
  161. return null;
  162. }
  163. $idManager = Services::getService("Id");
  164. return $idManager->getId($agentId);
  165. }
  166.  
  167. /**
  168. * Get the date when this GradeRecord was modified, using the UNIX timestamp.
  169. *
  170. * @return long
  171. *
  172. * @throws object GradingException An exception with one of the
  173. * following messages defined in org.osid.grading.GradingException
  174. * may be thrown: {@link }
  175. * org.osid.grading.GradingException#OPERATION_FAILED
  176. * OPERATION_FAILED}, {@link }
  177. * org.osid.grading.GradingException#PERMISSION_DENIED
  178. * PERMISSION_DENIED}, {@link }
  179. * org.osid.grading.GradingException#CONFIGURATION_ERROR
  180. * CONFIGURATION_ERROR}, {@link }
  181. * org.osid.grading.GradingException#UNIMPLEMENTED UNIMPLEMENTED}
  182. *
  183. * @access public
  184. */
  185. function getModifiedDate () {
  186. return $this->_getField("modified_date");
  187. }
  188.  
  189. /**
  190. * Get the GradeRecordType for this GradeRecord. This is the Type of the
  191. * GradeRecord, which is distinct from the Type of Grade. A GradeRecord
  192. * Type might be advisory, mid-term, final, etc, while a Grade Type might
  193. * be letter, numeric, etc.
  194. *
  195. * @return object Type
  196. *
  197. * @throws object GradingException An exception with one of the
  198. * following messages defined in org.osid.grading.GradingException
  199. * may be thrown: {@link }
  200. * org.osid.grading.GradingException#OPERATION_FAILED
  201. * OPERATION_FAILED}, {@link }
  202. * org.osid.grading.GradingException#PERMISSION_DENIED
  203. * PERMISSION_DENIED}, {@link }
  204. * org.osid.grading.GradingException#CONFIGURATION_ERROR
  205. * CONFIGURATION_ERROR}, {@link }
  206. * org.osid.grading.GradingException#UNIMPLEMENTED UNIMPLEMENTED}
  207. *
  208. * @access public
  209. */
  210. function getGradeRecordType () {
  211. return $this->_getType("record");
  212. }
  213.  
  214. /**
  215. * Get the GradeType associated with the GradableObject and Grade.
  216. *
  217. * @return object Type
  218. *
  219. * @throws object GradingException An exception with one of the
  220. * following messages defined in org.osid.grading.GradingException
  221. * may be thrown: {@link }
  222. * org.osid.grading.GradingException#OPERATION_FAILED
  223. * OPERATION_FAILED}, {@link }
  224. * org.osid.grading.GradingException#PERMISSION_DENIED
  225. * PERMISSION_DENIED}, {@link }
  226. * org.osid.grading.GradingException#CONFIGURATION_ERROR
  227. * CONFIGURATION_ERROR}, {@link }
  228. * org.osid.grading.GradingException#UNIMPLEMENTED UNIMPLEMENTED}
  229. *
  230. * @access public
  231. */
  232. function getGradeType () {
  233. $grManager = Services::getService("Grading");
  234. $id = $this->getGradableObject();
  235. $gradableObject =$grManager->getGradableObject($id);
  236. return $gradableObject->getGradeType();
  237. }
  238.  
  239. /**
  240. * Get all the Property Types for GradeRecord.
  241. *
  242. * @return object TypeIterator
  243. *
  244. * @throws object GradingException An exception with one of the
  245. * following messages defined in org.osid.grading.GradingException
  246. * may be thrown: {@link }
  247. * org.osid.grading.GradingException#OPERATION_FAILED
  248. * OPERATION_FAILED}, {@link }
  249. * org.osid.grading.GradingException#PERMISSION_DENIED
  250. * PERMISSION_DENIED}, {@link }
  251. * org.osid.grading.GradingException#CONFIGURATION_ERROR
  252. * CONFIGURATION_ERROR}, {@link }
  253. * org.osid.grading.GradingException#UNIMPLEMENTED UNIMPLEMENTED}
  254. *
  255. * @access public
  256. */
  257. function getPropertyTypes () {
  258. $type =$this->getGradeRecordType();
  259. $propertiesType = new Type("PropertiesType", $type->getAuthority(), "properties");
  260. $array = array($propertiesType);
  261. $typeIterator = new HarmoniTypeIterator($array);
  262. return $typeIterator;
  263. }
  264.  
  265. /**
  266. * Get the Properties of this Type associated with this GradeRecord.
  267. *
  268. * @param object Type $propertiesType
  269. *
  270. * @return object Properties
  271. *
  272. * @throws object GradingException An exception with one of the
  273. * following messages defined in org.osid.grading.GradingException
  274. * may be thrown: {@link }
  275. * org.osid.grading.GradingException#OPERATION_FAILED
  276. * OPERATION_FAILED}, {@link }
  277. * org.osid.grading.GradingException#PERMISSION_DENIED
  278. * PERMISSION_DENIED}, {@link }
  279. * org.osid.grading.GradingException#CONFIGURATION_ERROR
  280. * CONFIGURATION_ERROR}, {@link }
  281. * org.osid.grading.GradingException#UNIMPLEMENTED UNIMPLEMENTED},
  282. * {@link org.osid.grading.GradingException#NULL_ARGUMENT}
  283. * NULL_ARGUMENT}, {@link }
  284. * org.osid.grading.GradingException#UNKNOWN_TYPE UNKNOWN_TYPE}
  285. *
  286. * @access public
  287. */
  288. function getPropertiesByType ( $propertiesType ) {
  289. $type =$this->getGradeRecordType();
  290. $propType = new Type("PropertiesType", $type->getAuthority(), "properties");
  291. if($propertiesType->isEqualTo($propType)){
  292. return $this->_getProperties();
  293. }
  294. return null;
  295. }
  296.  
  297. /**
  298. * Get the Properties associated with this GradeRecord.
  299. *
  300. * @return object PropertiesIterator
  301. *
  302. * @throws object GradingException An exception with one of the
  303. * following messages defined in org.osid.grading.GradingException
  304. * may be thrown: {@link }
  305. * org.osid.grading.GradingException#OPERATION_FAILED
  306. * OPERATION_FAILED}, {@link }
  307. * org.osid.grading.GradingException#PERMISSION_DENIED
  308. * PERMISSION_DENIED}, {@link }
  309. * org.osid.grading.GradingException#CONFIGURATION_ERROR
  310. * CONFIGURATION_ERROR}, {@link }
  311. * org.osid.grading.GradingException#UNIMPLEMENTED UNIMPLEMENTED}
  312. *
  313. * @access public
  314. */
  315. function getProperties () {
  316. $array = array($this->_getProperties());
  317. $ret = new HarmoniPropertiesIterator($array);
  318. return $ret;//return the iterator
  319. }
  320. /**
  321. * Get a Properties object with the information about this object.
  322. *
  323. * @return object Properties
  324. *
  325. * @access private
  326. */
  327. function _getProperties(){
  328. //get the record
  329. $dbManager = Services::getService("DatabaseManager");
  330. $query = new SelectQuery();
  331. $query->addTable('gr_record');
  332. $query->addColumn("*");
  333. $query->addWhere("id='".addslashes($this->_id->getIdString())."'");
  334. $res=$dbManager->query($query);
  335.  
  336. //make sure we can find that record
  337. if(!$res->hasMoreRows()){
  338. print "<b>Warning!</b> Can't get Properties of GradeRecord with id ".$this->_id." since that id wasn't found in the database.";
  339. return null;
  340. }
  341. $row = $res->getCurrentRow();//grab (hopefully) the only row
  342. //make a type
  343. $type =$this->getGradeRecordType();
  344. $propertiesType = new Type("PropertiesType", $type->getAuthority(), "properties");
  345. //create a custom Properties object
  346. $idManager = Services::getService("Id");
  347. $property = new HarmoniProperties($propertiesType);
  348. $property->addProperty('id', $this->_id);
  349. $property->addProperty('value', $row['value']);
  350. $property->addProperty('gradable_object_id', $idManager->getId($row['fk_gr_gradable']));
  351. $property->addProperty('agent_id', $idManager->getId($row['fk_agent_id']));
  352. $property->addProperty('modified_by_agent_id', $idManager->getId($row['fk_modified_by_agent']));
  353. $property->addProperty('modified_date', $row['modified_date']);
  354. $recordType =$this->getGradeRecordType();
  355. $property->addProperty('type', $recordType);
  356. $res->free();
  357. return $property;
  358. }
  359. function _setModifiedDateAndAgent(){
  360. $this->_setField('modified_date',time()*1000);
  361. //@TODO use the timestamp feature in SQL?
  362. //try to get the creator of this ScheduleItem
  363. $authN = Services::getService("AuthN");
  364. $authNTypesIterator =$authN->getAuthenticationTypes();
  365. if($authNTypesIterator->hasNext()){
  366. $authNType1 =$authNTypesIterator->next();
  367. //hopefully the first one is the right one to choose.
  368. $creatorId =$authN->getUserId($authNType1);
  369. $creatorIdString = $creatorId->getIdString();
  370. }else{
  371. $creatorIdString = "";
  372. }
  373. $this->_setField('fk_modified_by_agent',$creatorIdString);
  374.  
  375. }
  376. function _typeToIndex($typename, $type)
  377. {
  378. $gm=Services::getService("Grading");
  379. return $gm->_typeToIndex($typename, $type);
  380. }
  381. function _getTypes($typename)
  382. {
  383. $gm=Services::getService("Grading");
  384. return $gm->_getTypes($typename);
  385. }
  386. function _getField($key)
  387. {
  388. $gm=Services::getService("Grading");
  389. return $gm->_getField($this->_id,$this->_table,$key);
  390. }
  391. function _getType($typename){
  392. $gm=Services::getService("Grading");
  393. return $gm->_getType($this->_id,$this->_table,$typename);
  394. }
  395. function _setField($key, $value)
  396. {
  397. $gm=Services::getService("Grading");
  398. return $gm->_setField($this->_id,$this->_table,$key, $value);
  399. }
  400. }
  401.  
  402. ?>

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