Source for file FileNamePart.class.php

Documentation is available at FileNamePart.class.php

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

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