Source for file HarmoniFunction.class.php

Documentation is available at HarmoniFunction.class.php

  1. <?php
  2.  
  3. require_once(OKI2."/osid/authorization/Function.php");
  4.  
  5. /**
  6. * Function is composed of Id, a displayName, a description, a category, and a
  7. * QualifierType. Ids in Authorization are externally defined and their
  8. * uniqueness is enforced by the implementation.
  9. *
  10. * <p>
  11. * OSID Version: 2.0
  12. * </p>
  13. *
  14. * @package harmoni.osid_v2.authorization
  15. *
  16. * @copyright Copyright &copy; 2005, Middlebury College
  17. * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License (GPL)
  18. *
  19. * @version $Id: HarmoniFunction.class.php,v 1.13 2007/09/13 16:04:18 adamfranco Exp $
  20. */
  21. class HarmoniFunction
  22. extends FunctionInterface
  23. {
  24.  
  25. /**
  26. * The Unique ID of this function.
  27. * @var object _id
  28. * @access private
  29. */
  30. var $_id;
  31.  
  32. /**
  33. * The display name of this function.
  34. * @var string _referenceName
  35. * @access private
  36. */
  37. var $_referenceName;
  38.  
  39. /**
  40. * The description of this function.
  41. * @var string _description
  42. * @access private
  43. */
  44. var $_description;
  45.  
  46. /**
  47. * The type of this function.
  48. * @var object _functionType
  49. * @access private
  50. */
  51. var $_functionType;
  52. /**
  53. * The ID of the qualifier hierarchy that is associated with this function.
  54. * @var object _qualifierHierarchyId
  55. * @access private
  56. */
  57. var $_qualifierHierarchyId;
  58.  
  59.  
  60. /**
  61. * The index of the database connection as returned by the DBHandler.
  62. * @var integer _dbIndex
  63. * @access private
  64. */
  65. var $_dbIndex;
  66.  
  67.  
  68. /**
  69. * The constructor.
  70. * @param ref object id - is externally defined functionId - is externally
  71. * defined.
  72. * @param string referenceName - is externally defined referenceName - the
  73. * name to display for this Function
  74. * @param string description - is externally defined description - the
  75. * description of this Function
  76. * @param ref object functionType - is externally defined functionType - the
  77. * Type of this Function
  78. * @param ref object qualifierHierarchyId - is externally defined
  79. * qualifierHierarchyId - the Id of the Qualifier Hierarchy associated
  80. * with this Function
  81. * @param integer dbIndex The index of the database connection as returned
  82. * by the DBHandler.
  83. * @param string authzDB The name of the Authorization database.
  84. * @access public
  85. */
  86. function HarmoniFunction($id, $referenceName, $description, $functionType,
  87. $qualifierHierarchyId, $dbIndex) {
  88. // ** parameter validation
  89. $stringRule = StringValidatorRule::getRule();
  90. ArgumentValidator::validate($referenceName, $stringRule, true);
  91. ArgumentValidator::validate($description, $stringRule, true);
  92. $extendsRule = ExtendsValidatorRule::getRule("Id");
  93. ArgumentValidator::validate($id, $extendsRule, true);
  94. ArgumentValidator::validate($qualifierHierarchyId, $extendsRule, true);
  95. $extendsRule = ExtendsValidatorRule::getRule("Type");
  96. ArgumentValidator::validate($functionType, $extendsRule, true);
  97. $integerRule = IntegerValidatorRule::getRule();
  98. ArgumentValidator::validate($dbIndex, $integerRule, true);
  99. // ** end of parameter validation
  100. $this->_id =$id;
  101. $this->_referenceName = $referenceName;
  102. $this->_description = $description;
  103. $this->_functionType =$functionType;
  104. $this->_qualifierHierarchyId =$qualifierHierarchyId;
  105. $this->_dbIndex = $dbIndex;
  106. }
  107. /**
  108. * Get the unique Id for this Function.
  109. *
  110. * @return object Id
  111. *
  112. * @throws object AuthorizationException An exception with
  113. * one of the following messages defined in
  114. * org.osid.authorization.AuthorizationException may be thrown:
  115. * {@link }
  116. * org.osid.authorization.AuthorizationException#OPERATION_FAILED
  117. * OPERATION_FAILED}, {@link }
  118. * org.osid.authorization.AuthorizationException#PERMISSION_DENIED
  119. * PERMISSION_DENIED}, {@link }
  120. * org.osid.authorization.AuthorizationException#CONFIGURATION_ERROR
  121. * CONFIGURATION_ERROR}, {@link }
  122. * org.osid.authorization.AuthorizationException#UNIMPLEMENTED
  123. * UNIMPLEMENTED}
  124. *
  125. * @access public
  126. */
  127. function getId () {
  128. return $this->_id;
  129. }
  130. /**
  131. * Get the permanent reference name for this Function.
  132. *
  133. * @return string
  134. *
  135. * @throws object AuthorizationException An exception with
  136. * one of the following messages defined in
  137. * org.osid.authorization.AuthorizationException may be thrown:
  138. * {@link }
  139. * org.osid.authorization.AuthorizationException#OPERATION_FAILED
  140. * OPERATION_FAILED}, {@link }
  141. * org.osid.authorization.AuthorizationException#PERMISSION_DENIED
  142. * PERMISSION_DENIED}, {@link }
  143. * org.osid.authorization.AuthorizationException#CONFIGURATION_ERROR
  144. * CONFIGURATION_ERROR}, {@link }
  145. * org.osid.authorization.AuthorizationException#UNIMPLEMENTED
  146. * UNIMPLEMENTED}
  147. *
  148. * @access public
  149. */
  150. function getReferenceName () {
  151. return $this->_referenceName;
  152. }
  153.  
  154. /**
  155. * Get the description for this Function.
  156. *
  157. * @return string
  158. *
  159. * @throws object AuthorizationException An exception with
  160. * one of the following messages defined in
  161. * org.osid.authorization.AuthorizationException may be thrown:
  162. * {@link }
  163. * org.osid.authorization.AuthorizationException#OPERATION_FAILED
  164. * OPERATION_FAILED}, {@link }
  165. * org.osid.authorization.AuthorizationException#PERMISSION_DENIED
  166. * PERMISSION_DENIED}, {@link }
  167. * org.osid.authorization.AuthorizationException#CONFIGURATION_ERROR
  168. * CONFIGURATION_ERROR}, {@link }
  169. * org.osid.authorization.AuthorizationException#UNIMPLEMENTED
  170. * UNIMPLEMENTED}
  171. *
  172. * @access public
  173. */
  174. function getDescription () {
  175. return $this->_description;
  176. }
  177.  
  178. /**
  179. * Get the FunctionType for this Function.
  180. *
  181. * @return object Type
  182. *
  183. * @throws object AuthorizationException An exception with
  184. * one of the following messages defined in
  185. * org.osid.authorization.AuthorizationException may be thrown:
  186. * {@link }
  187. * org.osid.authorization.AuthorizationException#OPERATION_FAILED
  188. * OPERATION_FAILED}, {@link }
  189. * org.osid.authorization.AuthorizationException#PERMISSION_DENIED
  190. * PERMISSION_DENIED}, {@link }
  191. * org.osid.authorization.AuthorizationException#CONFIGURATION_ERROR
  192. * CONFIGURATION_ERROR}, {@link }
  193. * org.osid.authorization.AuthorizationException#UNIMPLEMENTED
  194. * UNIMPLEMENTED}
  195. *
  196. * @access public
  197. */
  198. function getFunctionType () {
  199. return $this->_functionType;
  200. }
  201.  
  202. /**
  203. * Get the QualifierHierarchyId for this Function.
  204. *
  205. * @return object Id
  206. *
  207. * @throws object AuthorizationException An exception with
  208. * one of the following messages defined in
  209. * org.osid.authorization.AuthorizationException may be thrown:
  210. * {@link }
  211. * org.osid.authorization.AuthorizationException#OPERATION_FAILED
  212. * OPERATION_FAILED}, {@link }
  213. * org.osid.authorization.AuthorizationException#PERMISSION_DENIED
  214. * PERMISSION_DENIED}, {@link }
  215. * org.osid.authorization.AuthorizationException#CONFIGURATION_ERROR
  216. * CONFIGURATION_ERROR}, {@link }
  217. * org.osid.authorization.AuthorizationException#UNIMPLEMENTED
  218. * UNIMPLEMENTED}
  219. *
  220. * @access public
  221. */
  222. function getQualifierHierarchyId () {
  223. return $this->_qualifierHierarchyId;
  224. }
  225. /**
  226. * Update the description for this Function.
  227. *
  228. * @param string $description
  229. *
  230. * @throws object AuthorizationException An exception with
  231. * one of the following messages defined in
  232. * org.osid.authorization.AuthorizationException may be thrown:
  233. * {@link }
  234. * org.osid.authorization.AuthorizationException#OPERATION_FAILED
  235. * OPERATION_FAILED}, {@link }
  236. * org.osid.authorization.AuthorizationException#PERMISSION_DENIED
  237. * PERMISSION_DENIED}, {@link }
  238. * org.osid.authorization.AuthorizationException#CONFIGURATION_ERROR
  239. * CONFIGURATION_ERROR}, {@link }
  240. * org.osid.authorization.AuthorizationException#UNIMPLEMENTED
  241. * UNIMPLEMENTED}, {@link }
  242. * org.osid.authorization.AuthorizationException#NULL_ARGUMENT
  243. * NULL_ARGUMENT}
  244. *
  245. * @access public
  246. */
  247. function updateDescription ( $description ) {
  248. // ** parameter validation
  249. $stringRule = StringValidatorRule::getRule();
  250. ArgumentValidator::validate($description, $stringRule, true);
  251. // ** end of parameter validation
  252. if ($this->_description == $description)
  253. return; // nothing to update
  254.  
  255. // update the object
  256. $this->_description = $description;
  257.  
  258. // update the database
  259. $dbHandler = Services::getService("DatabaseManager");
  260. $query = new UpdateQuery();
  261. $query->setTable("az_function");
  262. $id =$this->getId();
  263. $idValue = $id->getIdString();
  264. $where = "function_id = '".addslashes($idValue)."'";
  265. $query->setWhere($where);
  266. $query->setColumns(array("function_description"));
  267. $query->setValues(array("'".addslashes($description)."'"));
  268. $queryResult =$dbHandler->query($query, $this->_dbIndex);
  269. if ($queryResult->getNumberOfRows() == 0)
  270. throwError(new Error(AuthorizationExeption::OPERATION_FAILED(),"AuthorizationFunction",true));
  271. if ($queryResult->getNumberOfRows() > 1)
  272. throwError(new Error(AuthorizationExeption::OPERATION_FAILED() ,"AuthorizationFunction",true));
  273. }
  274. /**
  275. * Update the reference name for this Function.
  276. *
  277. * WARNING: NOT IN OSID
  278. *
  279. * @param string $referenceName
  280. *
  281. * @throws object AuthorizationException An exception with
  282. * one of the following messages defined in
  283. * org.osid.authorization.AuthorizationException may be thrown:
  284. * {@link }
  285. * org.osid.authorization.AuthorizationException#OPERATION_FAILED
  286. * OPERATION_FAILED}, {@link }
  287. * org.osid.authorization.AuthorizationException#PERMISSION_DENIED
  288. * PERMISSION_DENIED}, {@link }
  289. * org.osid.authorization.AuthorizationException#CONFIGURATION_ERROR
  290. * CONFIGURATION_ERROR}, {@link }
  291. * org.osid.authorization.AuthorizationException#UNIMPLEMENTED
  292. * UNIMPLEMENTED}, {@link }
  293. * org.osid.authorization.AuthorizationException#NULL_ARGUMENT
  294. * NULL_ARGUMENT}
  295. *
  296. * @access public
  297. */
  298. function updateReferenceName ( $referenceName ) {
  299. // ** parameter validation
  300. $stringRule = StringValidatorRule::getRule();
  301. ArgumentValidator::validate($referenceName, $stringRule, true);
  302. // ** end of parameter validation
  303.  
  304. if ($this->_referenceName == $referenceName)
  305. return; // nothing to update
  306. // update the object
  307. $this->_referenceName = $referenceName;
  308. // update the database
  309. $dbHandler = Services::getService("DatabaseManager");
  310. $query = new UpdateQuery();
  311. $query->setTable("az_function");
  312. $id =$this->getId();
  313. $idValue = $id->getIdString();
  314. $where = "function_id = '".addslashes($idValue)."'";
  315. $query->setWhere($where);
  316. $query->setColumns(array("function_reference_name"));
  317. $query->setValues(array("'".addslashes($referenceName)."'"));
  318. $queryResult =$dbHandler->query($query, $this->_dbIndex);
  319. if ($queryResult->getNumberOfRows() == 0)
  320. throwError(new Error(AuthorizationExeption::OPERATION_FAILED(),"AuthorizationFunction",true));
  321. if ($queryResult->getNumberOfRows() > 1)
  322. throwError(new Error(AuthorizationExeption::OPERATION_FAILED() ,"AuthorizationFunction",true));
  323. }
  324.  
  325. }
  326.  
  327. ?>

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