Source for file FileUrlPart.class.php

Documentation is available at FileUrlPart.class.php

  1. <?php
  2. /**
  3. * @since 12/5/06
  4. * @package harmoni.osid_v2.repository
  5. *
  6. * @copyright Copyright &copy; 2005, Middlebury College
  7. * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License (GPL)
  8. *
  9. * @version $Id: FileUrlPart.class.php,v 1.3 2007/09/11 17:40:57 adamfranco Exp $
  10. */
  11.  
  12. /**
  13. * A Part for storing the file's URL
  14. *
  15. * @since 12/5/06
  16. * @package harmoni.osid_v2.repository
  17. *
  18. * @copyright Copyright &copy; 2005, Middlebury College
  19. * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License (GPL)
  20. *
  21. * @version $Id: FileUrlPart.class.php,v 1.3 2007/09/11 17:40:57 adamfranco Exp $
  22. */
  23. class FileUrlPart
  24. extends Part
  25. {
  26. var $_recordId;
  27. var $_partStructure;
  28. var $_value;
  29. function FileUrlPart( $partStructure, $recordId, $configuration, $asset ) {
  30. $this->_recordId =$recordId;
  31. $this->_partStructure =$partStructure;
  32. $this->_configuration =$configuration;
  33. $this->_asset =$asset;
  34. // Set our data to NULL, so that we can know if it has not been checked
  35. // for yet. If we search for data, but don't have any, or the data is
  36. // an empty string, it will have value "" instead of NULL
  37. $this->_value = NULL;
  38. }
  39. /**
  40. * Get the unique Id for this Part.
  41. *
  42. * @return object Id
  43. *
  44. * @throws object RepositoryException An exception with one of
  45. * the following messages defined in
  46. * org.osid.repository.RepositoryException may be thrown: {@link }
  47. * org.osid.repository.RepositoryException#OPERATION_FAILED
  48. * OPERATION_FAILED}, {@link }
  49. * org.osid.repository.RepositoryException#PERMISSION_DENIED
  50. * PERMISSION_DENIED}, {@link }
  51. * org.osid.repository.RepositoryException#CONFIGURATION_ERROR
  52. * CONFIGURATION_ERROR}, {@link }
  53. * org.osid.repository.RepositoryException#UNIMPLEMENTED
  54. * UNIMPLEMENTED}
  55. *
  56. * @access public
  57. */
  58. function getId() {
  59. $idManager = Services::getService("Id");
  60. return $idManager->getId($this->_recordId->getIdString()."-FILE_URL");
  61. }
  62. /**
  63. * Create a Part. Records are composed of Parts. Parts can also contain
  64. * other Parts. Each Record is associated with a specific RecordStructure
  65. * and each Part is associated with a specific PartStructure.
  66. *
  67. * @param object Id $partStructureId
  68. * @param object mixed $value (original type: java.io.Serializable)
  69. *
  70. * @return object Part
  71. *
  72. * @throws object RepositoryException An exception with one of
  73. * the following messages defined in
  74. * org.osid.repository.RepositoryException may be thrown: {@link }
  75. * org.osid.repository.RepositoryException#OPERATION_FAILED
  76. * OPERATION_FAILED}, {@link }
  77. * org.osid.repository.RepositoryException#PERMISSION_DENIED
  78. * PERMISSION_DENIED}, {@link }
  79. * org.osid.repository.RepositoryException#CONFIGURATION_ERROR
  80. * CONFIGURATION_ERROR}, {@link }
  81. * org.osid.repository.RepositoryException#UNIMPLEMENTED
  82. * UNIMPLEMENTED}, {@link }
  83. * org.osid.repository.RepositoryException#NULL_ARGUMENT
  84. * NULL_ARGUMENT}, {@link }
  85. * org.osid.repository.RepositoryException#UNKNOWN_ID UNKNOWN_ID}
  86. *
  87. * @access public
  88. */
  89. function createPart($partStructureId, $value) {
  90. throwError(
  91. new Error(RepositoryException::UNIMPLEMENTED(), "HarmoniPart", true));
  92. }
  93.  
  94. /**
  95. * Delete a Part and all its Parts.
  96. *
  97. * @param object Id $partId
  98. *
  99. * @throws object RepositoryException An exception with one of
  100. * the following messages defined in
  101. * org.osid.repository.RepositoryException may be thrown: {@link }
  102. * org.osid.repository.RepositoryException#OPERATION_FAILED
  103. * OPERATION_FAILED}, {@link }
  104. * org.osid.repository.RepositoryException#PERMISSION_DENIED
  105. * PERMISSION_DENIED}, {@link }
  106. * org.osid.repository.RepositoryException#CONFIGURATION_ERROR
  107. * CONFIGURATION_ERROR}, {@link }
  108. * org.osid.repository.RepositoryException#UNIMPLEMENTED
  109. * UNIMPLEMENTED}, {@link }
  110. * org.osid.repository.RepositoryException#NULL_ARGUMENT
  111. * NULL_ARGUMENT}, {@link }
  112. * org.osid.repository.RepositoryException#UNKNOWN_ID UNKNOWN_ID}
  113. *
  114. * @access public
  115. */
  116. function deletePart($partId) {
  117. throwError(
  118. new Error(RepositoryException::UNIMPLEMENTED(), "HarmoniPart", true));
  119. }
  120.  
  121. /**
  122. * Get all the Parts in this Part. Iterators return a set, one at a time.
  123. *
  124. * @return object PartIterator
  125. *
  126. * @throws object RepositoryException An exception with one of
  127. * the following messages defined in
  128. * org.osid.repository.RepositoryException may be thrown: {@link }
  129. * org.osid.repository.RepositoryException#OPERATION_FAILED
  130. * OPERATION_FAILED}, {@link }
  131. * org.osid.repository.RepositoryException#PERMISSION_DENIED
  132. * PERMISSION_DENIED}, {@link }
  133. * org.osid.repository.RepositoryException#CONFIGURATION_ERROR
  134. * CONFIGURATION_ERROR}, {@link }
  135. * org.osid.repository.RepositoryException#UNIMPLEMENTED
  136. * UNIMPLEMENTED}
  137. *
  138. * @access public
  139. */
  140. function getParts() {
  141. throwError(
  142. new Error(RepositoryException::UNIMPLEMENTED(), "HarmoniPart", true));
  143. }
  144. /**
  145. * Get the value for this Part.
  146. *
  147. * @return object mixed (original type: java.io.Serializable)
  148. *
  149. * @throws object RepositoryException An exception with one of
  150. * the following messages defined in
  151. * org.osid.repository.RepositoryException may be thrown: {@link }
  152. * org.osid.repository.RepositoryException#OPERATION_FAILED
  153. * OPERATION_FAILED}, {@link }
  154. * org.osid.repository.RepositoryException#PERMISSION_DENIED
  155. * PERMISSION_DENIED}, {@link }
  156. * org.osid.repository.RepositoryException#CONFIGURATION_ERROR
  157. * CONFIGURATION_ERROR}, {@link }
  158. * org.osid.repository.RepositoryException#UNIMPLEMENTED
  159. * UNIMPLEMENTED}
  160. *
  161. * @access public
  162. */
  163. function getValue() {
  164. // If we don't have the name, load it from the database.
  165. if ($this->_value === NULL) {
  166. $dbHandler = Services::getService("DatabaseManager");
  167. // Get the data from the database,
  168. $query = new SelectQuery;
  169. $query->addTable("dr_file");
  170. $query->addTable("dr_file_url", LEFT_JOIN, "dr_file.id = dr_file_url.fk_file");
  171. $query->addColumn("url");
  172. $query->addWhere("dr_file.id = '".$this->_recordId->getIdString()."'");
  173. $result =$dbHandler->query($query, $this->_configuration->getProperty("database_index"));
  174. // If no name was found, return an empty string.
  175. if ($result->getNumberOfRows() == 0)
  176. $this->_value = "";
  177. else
  178. $this->_value = $result->field("url");
  179. $result->free();
  180. }
  181. return $this->_value;
  182. }
  183. /**
  184. * Update the value for this Part.
  185. *
  186. * @param object mixed $value (original type: java.io.Serializable)
  187. *
  188. * @throws object RepositoryException An exception with one of
  189. * the following messages defined in
  190. * org.osid.repository.RepositoryException may be thrown: {@link }
  191. * org.osid.repository.RepositoryException#OPERATION_FAILED
  192. * OPERATION_FAILED}, {@link }
  193. * org.osid.repository.RepositoryException#PERMISSION_DENIED
  194. * PERMISSION_DENIED}, {@link }
  195. * org.osid.repository.RepositoryException#CONFIGURATION_ERROR
  196. * CONFIGURATION_ERROR}, {@link }
  197. * org.osid.repository.RepositoryException#UNIMPLEMENTED
  198. * UNIMPLEMENTED}, {@link }
  199. * org.osid.repository.RepositoryException#NULL_ARGUMENT
  200. * NULL_ARGUMENT}
  201. *
  202. * @access public
  203. */
  204. function updateValue($value) {
  205. ArgumentValidator::validate($value, StringValidatorRule::getRule());
  206. // Store the name in the object in case its asked for again.
  207. $this->_value = $value;
  208. // then write it to the database.
  209. $dbHandler = Services::getService("DatabaseManager");
  210. // Check to see if the name is in the database
  211. // Check to see if the data is in the database
  212. $query = new SelectQuery;
  213. $query->addTable("dr_file_url");
  214. $query->addColumn("COUNT(*) as count");
  215. $query->addWhere("fk_file = '".$this->_recordId->getIdString()."'");
  216. $result =$dbHandler->query($query, $this->_configuration->getProperty("database_index"));
  217. // If it already exists, use an update query.
  218. if ($result->field("count") > 0) {
  219. $query = new UpdateQuery;
  220. $query->setTable("dr_file_url");
  221. $query->setColumns(array("url"));
  222. $query->setValues(array("'".addslashes($value)."'"));
  223. $query->addWhere("fk_file = '".$this->_recordId->getIdString()."'");
  224. }
  225. // If it doesn't exist, use an insert query.
  226. else {
  227. $query = new InsertQuery;
  228. $query->setTable("dr_file_url");
  229. $query->setColumns(array("fk_file","url"));
  230. $query->setValues(array("'".$this->_recordId->getIdString()."'",
  231. "'".addslashes($value)."'"));
  232. }
  233. $result->free();
  234. // run the query
  235. $dbHandler->query($query, $this->_configuration->getProperty("database_index"));
  236. $this->_asset->updateModificationDate();
  237. }
  238. /**
  239. * Get the PartStructure associated with this Part.
  240. *
  241. * @return object PartStructure
  242. *
  243. * @throws object RepositoryException An exception with one of
  244. * the following messages defined in
  245. * org.osid.repository.RepositoryException may be thrown: {@link }
  246. * org.osid.repository.RepositoryException#OPERATION_FAILED
  247. * OPERATION_FAILED}, {@link }
  248. * org.osid.repository.RepositoryException#PERMISSION_DENIED
  249. * PERMISSION_DENIED}, {@link }
  250. * org.osid.repository.RepositoryException#CONFIGURATION_ERROR
  251. * CONFIGURATION_ERROR}, {@link }
  252. * org.osid.repository.RepositoryException#UNIMPLEMENTED
  253. * UNIMPLEMENTED}
  254. *
  255. * @access public
  256. */
  257. function getPartStructure() {
  258. return $this->_partStructure;
  259. }
  260. /**
  261. * Allow the file record to update the fetch from its own queries
  262. *
  263. * @param string $value
  264. * @return void
  265. * @access private
  266. * @since 11/17/05
  267. */
  268. function _updateValue ( $value ) {
  269. $this->_value = $value;
  270. }
  271. }
  272.  
  273. ?>

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