Source for file ThumbnailDataPart.class.php

Documentation is available at ThumbnailDataPart.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: ThumbnailDataPart.class.php,v 1.12 2007/09/11 17:40:57 adamfranco Exp $
  23. */
  24. class ThumbnailDataPart extends Part
  25. // extends java.io.Serializable
  26.  
  27. {
  28.  
  29. var $_recordId;
  30. var $_partStructure;
  31. var $_data;
  32. function ThumbnailDataPart( $partStructure, $recordId, $configuration, $asset ) {
  33. $this->_recordId =$recordId;
  34. $this->_partStructure =$partStructure;
  35. $this->_configuration = $configuration;
  36. $this->_asset =$asset;
  37. // Set our data to NULL, so that we can know if it has not been checked
  38. // for yet. If we search for data, but don't have any, or the data is
  39. // an empty string, it will have value "" instead of NULL
  40. $this->_data = 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()."-THUMBNAIL_DATA");
  64. }
  65. /**
  66. * Create a Part. Records are composed of Parts. Parts can also contain
  67. * other Parts. Each Record is associated with a specific RecordStructure
  68. * and each Part is associated with a specific PartStructure.
  69. *
  70. * @param object Id $partStructureId
  71. * @param object mixed $value (original type: java.io.Serializable)
  72. *
  73. * @return object Part
  74. *
  75. * @throws object RepositoryException An exception with one of
  76. * the following messages defined in
  77. * org.osid.repository.RepositoryException may be thrown: {@link }
  78. * org.osid.repository.RepositoryException#OPERATION_FAILED
  79. * OPERATION_FAILED}, {@link }
  80. * org.osid.repository.RepositoryException#PERMISSION_DENIED
  81. * PERMISSION_DENIED}, {@link }
  82. * org.osid.repository.RepositoryException#CONFIGURATION_ERROR
  83. * CONFIGURATION_ERROR}, {@link }
  84. * org.osid.repository.RepositoryException#UNIMPLEMENTED
  85. * UNIMPLEMENTED}, {@link }
  86. * org.osid.repository.RepositoryException#NULL_ARGUMENT
  87. * NULL_ARGUMENT}, {@link }
  88. * org.osid.repository.RepositoryException#UNKNOWN_ID UNKNOWN_ID}
  89. *
  90. * @access public
  91. */
  92. function createPart($partStructureId, $value) {
  93. throwError(
  94. new Error(RepositoryException::UNIMPLEMENTED(), "HarmoniPart", true));
  95. }
  96.  
  97. /**
  98. * Delete a Part and all its Parts.
  99. *
  100. * @param object Id $partId
  101. *
  102. * @throws object RepositoryException An exception with one of
  103. * the following messages defined in
  104. * org.osid.repository.RepositoryException may be thrown: {@link }
  105. * org.osid.repository.RepositoryException#OPERATION_FAILED
  106. * OPERATION_FAILED}, {@link }
  107. * org.osid.repository.RepositoryException#PERMISSION_DENIED
  108. * PERMISSION_DENIED}, {@link }
  109. * org.osid.repository.RepositoryException#CONFIGURATION_ERROR
  110. * CONFIGURATION_ERROR}, {@link }
  111. * org.osid.repository.RepositoryException#UNIMPLEMENTED
  112. * UNIMPLEMENTED}, {@link }
  113. * org.osid.repository.RepositoryException#NULL_ARGUMENT
  114. * NULL_ARGUMENT}, {@link }
  115. * org.osid.repository.RepositoryException#UNKNOWN_ID UNKNOWN_ID}
  116. *
  117. * @access public
  118. */
  119. function deletePart($partId) {
  120. throwError(
  121. new Error(RepositoryException::UNIMPLEMENTED(), "HarmoniPart", true));
  122. }
  123.  
  124. /**
  125. * Get all the Parts in this Part. Iterators return a set, one at a time.
  126. *
  127. * @return object PartIterator
  128. *
  129. * @throws object RepositoryException An exception with one of
  130. * the following messages defined in
  131. * org.osid.repository.RepositoryException may be thrown: {@link }
  132. * org.osid.repository.RepositoryException#OPERATION_FAILED
  133. * OPERATION_FAILED}, {@link }
  134. * org.osid.repository.RepositoryException#PERMISSION_DENIED
  135. * PERMISSION_DENIED}, {@link }
  136. * org.osid.repository.RepositoryException#CONFIGURATION_ERROR
  137. * CONFIGURATION_ERROR}, {@link }
  138. * org.osid.repository.RepositoryException#UNIMPLEMENTED
  139. * UNIMPLEMENTED}
  140. *
  141. * @access public
  142. */
  143. function getParts() {
  144. throwError(
  145. new Error(RepositoryException::UNIMPLEMENTED(), "HarmoniPart", true));
  146. }
  147.  
  148. /**
  149. * Get the value for this Part.
  150. *
  151. * @return object mixed (original type: java.io.Serializable)
  152. *
  153. * @throws object RepositoryException An exception with one of
  154. * the following messages defined in
  155. * org.osid.repository.RepositoryException may be thrown: {@link }
  156. * org.osid.repository.RepositoryException#OPERATION_FAILED
  157. * OPERATION_FAILED}, {@link }
  158. * org.osid.repository.RepositoryException#PERMISSION_DENIED
  159. * PERMISSION_DENIED}, {@link }
  160. * org.osid.repository.RepositoryException#CONFIGURATION_ERROR
  161. * CONFIGURATION_ERROR}, {@link }
  162. * org.osid.repository.RepositoryException#UNIMPLEMENTED
  163. * UNIMPLEMENTED}
  164. *
  165. * @access public
  166. */
  167. function getValue() {
  168. // If we don't have the data, load it from the database.
  169. // if ($this->_data === NULL) {
  170. $dbHandler = Services::getService("DatabaseManager");
  171. // Get the data from the database,
  172. $query = new SelectQuery;
  173. $query->addTable("dr_thumbnail");
  174. $query->addColumn("data");
  175. $query->addWhere("fk_file = '".$this->_recordId->getIdString()."'");
  176. $result =$dbHandler->query($query, $this->_configuration->getProperty("database_index"));
  177. // If no data was found, return an empty string.
  178. if ($result->getNumberOfRows() == 0)
  179. $data = "";
  180. //$this->_data = "";
  181. else
  182. $data = base64_decode($result->field("data"));
  183. //$this->_data = base64_decode($result->field("data"));
  184. $result->free();
  185. // }
  186. return $data;// $this->_data;
  187. }
  188.  
  189. /**
  190. * Update the value for this Part.
  191. *
  192. * @param object mixed $value (original type: java.io.Serializable)
  193. *
  194. * @throws object RepositoryException An exception with one of
  195. * the following messages defined in
  196. * org.osid.repository.RepositoryException may be thrown: {@link }
  197. * org.osid.repository.RepositoryException#OPERATION_FAILED
  198. * OPERATION_FAILED}, {@link }
  199. * org.osid.repository.RepositoryException#PERMISSION_DENIED
  200. * PERMISSION_DENIED}, {@link }
  201. * org.osid.repository.RepositoryException#CONFIGURATION_ERROR
  202. * CONFIGURATION_ERROR}, {@link }
  203. * org.osid.repository.RepositoryException#UNIMPLEMENTED
  204. * UNIMPLEMENTED}, {@link }
  205. * org.osid.repository.RepositoryException#NULL_ARGUMENT
  206. * NULL_ARGUMENT}
  207. *
  208. * @access public
  209. */
  210. function updateValue($value) {
  211. // ArgumentValidator::validate($value, StringValidatorRule::getRule());
  212. // Store the data in the object in case its asked for again.
  213. // $this->_data = $value;
  214. // Base64 encode the data to preserve it,
  215. // then write it to the database.
  216. $dbHandler = Services::getService("DatabaseManager");
  217. // Check to see if the data is in the database
  218. $query = new SelectQuery;
  219. $query->addTable("dr_thumbnail");
  220. $query->addColumn("COUNT(*) as count");
  221. $query->addWhere("fk_file = '".$this->_recordId->getIdString()."'");
  222. $result =$dbHandler->query($query, $this->_configuration->getProperty("database_index"));
  223. // If it already exists, use an update query.
  224. if ($result->field("count") > 0) {
  225. $query = new UpdateQuery;
  226. $query->setTable("dr_thumbnail");
  227. $query->setColumns(array("data"));
  228. $query->setValues(array("'".base64_encode($value)."'"));
  229. $query->addWhere("fk_file = '".$this->_recordId->getIdString()."'");
  230. }
  231. // If it doesn't exist, use an insert query.
  232. else {
  233. $query = new InsertQuery;
  234. $query->setTable("dr_thumbnail");
  235. $query->setColumns(array("fk_file","data"));
  236. $query->setValues(array("'".$this->_recordId->getIdString()."'",
  237. "'".base64_encode($value)."'"));
  238. }
  239. $result->free();
  240. // printpre($query);
  241. // printpre(MySQL_SQLGenerator::generateSQLQuery($query));
  242. // run the query
  243. $dbHandler->query($query, $this->_configuration->getProperty("database_index"));
  244. $this->_asset->updateModificationDate();
  245. }
  246.  
  247. /**
  248. * Get the PartStructure associated with this Part.
  249. *
  250. * @return object PartStructure
  251. *
  252. * @throws object RepositoryException An exception with one of
  253. * the following messages defined in
  254. * org.osid.repository.RepositoryException may be thrown: {@link }
  255. * org.osid.repository.RepositoryException#OPERATION_FAILED
  256. * OPERATION_FAILED}, {@link }
  257. * org.osid.repository.RepositoryException#PERMISSION_DENIED
  258. * PERMISSION_DENIED}, {@link }
  259. * org.osid.repository.RepositoryException#CONFIGURATION_ERROR
  260. * CONFIGURATION_ERROR}, {@link }
  261. * org.osid.repository.RepositoryException#UNIMPLEMENTED
  262. * UNIMPLEMENTED}
  263. *
  264. * @access public
  265. */
  266. function getPartStructure() {
  267. return $this->_partStructure;
  268. }
  269. }

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