Source for file RemoteFileRecord.class.php

Documentation is available at RemoteFileRecord.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: RemoteFileRecord.class.php,v 1.3 2007/09/11 17:40:57 adamfranco Exp $
  10. */
  11.  
  12. require_once(dirname(__FILE__)."/Fields/FileUrlPart.class.php");
  13. require_once(dirname(__FILE__)."/Fields/RemoteFileSizePart.class.php");
  14.  
  15. /**
  16. * Remote fileRecords are just like FileRecords, but they reference file-data that
  17. * lies at a remote web-accessible location.
  18. *
  19. * Each Asset has one of the AssetType supported by the Repository. There are
  20. * also zero or more RecordStructures required by the Repository for each
  21. * AssetType. RecordStructures provide structural information. The values for
  22. * a given Asset's RecordStructure are stored in a Record. RecordStructures
  23. * can contain sub-elements which are referred to as PartStructures. The
  24. * structure defined in the RecordStructure and its PartStructures is used in
  25. * for any Records for the Asset. Records have Parts which parallel
  26. * PartStructures.
  27. *
  28. * <p>
  29. * OSID Version: 2.0
  30. * </p>
  31. *
  32. * @since 12/5/06
  33. * @package harmoni.osid_v2.repository
  34. *
  35. * @copyright Copyright &copy; 2005, Middlebury College
  36. * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License (GPL)
  37. *
  38. * @version $Id: RemoteFileRecord.class.php,v 1.3 2007/09/11 17:40:57 adamfranco Exp $
  39. */
  40. class RemoteFileRecord
  41. extends FileRecord
  42. {
  43. /**
  44. * Constructor
  45. *
  46. * @param <##>
  47. * @return object
  48. * @access public
  49. * @since 12/5/06
  50. */
  51. function RemoteFileRecord ( $recordStructure, $id, $configuration, $asset ) {
  52. $this->FileRecord($recordStructure, $id, $configuration, $asset);
  53. unset($this->_parts['FILE_DATA'], $this->_parts['FILE_SIZE']);
  54. $idManager = Services::getService("Id");
  55. $this->_parts['FILE_URL'] = new FileUrlPart(
  56. $recordStructure->getPartStructure($idManager->getId('FILE_URL')),
  57. $this->_id,
  58. $this->_configuration,
  59. $this->_asset);
  60. $this->_parts['FILE_SIZE'] = new RemoteFileSizePart(
  61. $recordStructure->getPartStructure($idManager->getId('FILE_SIZE')),
  62. $this->_id,
  63. $this->_configuration,
  64. $this->_asset);
  65. }
  66. /**
  67. * Add a fileDataPart
  68. *
  69. * @param $recordStructure
  70. * @return void
  71. * @access public
  72. * @since 12/6/06
  73. */
  74. function addFileDataPart ($recordStructure) {
  75. }
  76. /**
  77. * Delete a Part and all its Parts.
  78. *
  79. * @param object Id $partId
  80. *
  81. * @throws object RepositoryException An exception with one of
  82. * the following messages defined in
  83. * org.osid.repository.RepositoryException may be thrown: {@link }
  84. * org.osid.repository.RepositoryException#OPERATION_FAILED
  85. * OPERATION_FAILED}, {@link }
  86. * org.osid.repository.RepositoryException#PERMISSION_DENIED
  87. * PERMISSION_DENIED}, {@link }
  88. * org.osid.repository.RepositoryException#CONFIGURATION_ERROR
  89. * CONFIGURATION_ERROR}, {@link }
  90. * org.osid.repository.RepositoryException#UNIMPLEMENTED
  91. * UNIMPLEMENTED}, {@link }
  92. * org.osid.repository.RepositoryException#NULL_ARGUMENT
  93. * NULL_ARGUMENT}, {@link }
  94. * org.osid.repository.RepositoryException#UNKNOWN_ID UNKNOWN_ID}
  95. *
  96. * @access public
  97. */
  98. function deletePart($partId) {
  99. $string = $partId->getIdString();
  100. if (ereg("(.*)-(".implode("|", array_keys($this->_parts)).")",$string,$r)) {
  101. $recordId = $r[1];
  102. $field = $r[2];
  103. if ($this->_isLastPart($field)) {
  104. $dbHandler = Services::getService("DatabaseManager");
  105. // Delete the data
  106. $query = new DeleteQuery();
  107. $query->setTable("dr_file_url");
  108. $query->setWhere("fk_file = '".$this->_id->getIdString()."'");
  109. $dbHandler->query($query, $this->_configuration->getProperty("database_index"));
  110. // Delete the thumbnail
  111. $query = new DeleteQuery();
  112. $query->setTable("dr_thumbnail");
  113. $query->setWhere("fk_file = '".$this->_id->getIdString()."'");
  114. $dbHandler->query($query, $this->_configuration->getProperty("database_index"));
  115. // delete the file row.
  116. $query = new DeleteQuery();
  117. $query->setTable("dr_file");
  118. $query->setWhere("id = '".$this->_id->getIdString()."'");
  119. $dbHandler->query($query, $this->_configuration->getProperty("database_index"));
  120. } else {
  121. $this->_parts[$field]->updateValue("NULL");
  122. }
  123. } else {
  124. throwError(new Error(RepositoryException::UNKNOWN_ID().": $string", "FileRecord", true));
  125. }
  126. $this->_asset->updateModificationDate();
  127. }
  128. /**
  129. * Return TRUE if the Part of the passed Id is the last one, and the whole schebang should be deleted.
  130. *
  131. * WARNING: NOT IN OSID - Use at your own risk
  132. *
  133. * @param string $idString
  134. * @return boolean
  135. * @access private
  136. * @since 10/25/04
  137. */
  138. function _isLastPart ($idString) {
  139. if (!isset($this->_toDelete))
  140. $this->_toDelete = array();
  141. $dbHandler = Services::getService("DatabaseManager");
  142. // Check to see if the data is in the database
  143. $query = new SelectQuery;
  144. $query->addTable("dr_file");
  145. $query->addTable("dr_file_url", LEFT_JOIN, "dr_file.id = dr_file_url.fk_file");
  146. $query->addTable("dr_thumbnail", LEFT_JOIN, "dr_file.id = dr_thumbnail.fk_file");
  147. $query->addTable("dr_mime_type", LEFT_JOIN, "dr_file.fk_mime_type = file_mime_type.id", "file_mime_type");
  148. $query->addTable("dr_mime_type", LEFT_JOIN, "dr_thumbnail.fk_mime_type = thumbnail_mime_type.id", "thumbnail_mime_type");
  149. $query->addColumn("filename", "FILE_NAME");
  150. $query->addColumn("size", "FILE_SIZE");
  151. $query->addColumn("file_mime_type.type", "MIME_TYPE");
  152. $query->addColumn("dr_file_url.url", "FILE_URL");
  153. $query->addColumn("thumbnail_mime_type.type", "THUMBNAIL_MIME_TYPE");
  154. $query->addColumn("dr_thumbnail.data", "THUMBNAIL_DATA");
  155. $query->addWhere("dr_file.id = '".$this->_id->getIdString()."'");
  156. $result =$dbHandler->query($query, $this->_configuration->getProperty("database_index"));
  157. if (!$result->getNumberOfRows()) {
  158. $result->free();
  159. return TRUE;
  160. }
  161. $fields = array('FILE_NAME', 'FILE_SIZE', 'MIME_TYPE', 'FILE_URL', 'THUMBNAIL_MIME_TYPE', 'THUMBNAIL_DATA');
  162. $countValues = 0;
  163. foreach ($fields as $field) {
  164. if ($result->field($field) && !in_array($field, $this->_toDelete))
  165. $countValues++;
  166. }
  167. $result->free();
  168. $this->_toDelete[] = $idString;
  169. if ($countValues <= 1)
  170. return TRUE;
  171. else
  172. return FALSE;
  173. }
  174. /**
  175. * Do a single query to load all of the small-valued parts for the record;
  176. * that is, everything but the file and thumb data.
  177. *
  178. * @return void
  179. * @access private
  180. * @since 11/17/05
  181. */
  182. function _loadParts () {
  183. if ($this->_partsLoaded)
  184. return;
  185. $dbHandler = Services::getService("DBHandler");
  186. $query = new SelectQuery;
  187. $query->addTable("dr_file");
  188. $query->addTable("dr_file_url", LEFT_JOIN, "dr_file.id = dr_file_url.fk_file");
  189. $query->addTable("dr_thumbnail", LEFT_JOIN, "dr_file.id = dr_thumbnail.fk_file");
  190. $query->addTable("dr_mime_type", LEFT_JOIN, "dr_file.fk_mime_type = file_mime_type.id", "file_mime_type");
  191. $query->addTable("dr_mime_type", LEFT_JOIN, "dr_thumbnail.fk_mime_type = thumbnail_mime_type.id", "thumbnail_mime_type");
  192. $query->addColumn("filename");
  193. $query->addColumn("size");
  194. $query->addColumn("dr_file.width", "file_width");
  195. $query->addColumn("dr_file.height", "file_height");
  196. $query->addColumn("dr_file_url.url", "url");
  197. $query->addColumn("file_mime_type.type", "file_type");
  198. $query->addColumn("thumbnail_mime_type.type", "thumbnail_type");
  199. $query->addColumn("dr_thumbnail.width", "thumb_width");
  200. $query->addColumn("dr_thumbnail.height", "thumb_height");
  201. $query->addWhere("dr_file.id = '".$this->_id->getIdString()."'");
  202. $result =$dbHandler->query($query, $this->_configuration->getProperty("database_index"));
  203. if ($result->getNumberOfRows()) {
  204. $this->_parts['FILE_NAME']->_updateValue($result->field('filename'));
  205. $this->_parts['FILE_URL']->_updateValue($result->field('url'));
  206. $this->_parts['FILE_SIZE']->_updateValue($result->field('size'));
  207. $this->_parts['MIME_TYPE']->_updateValue($result->field('file_type'));
  208. $this->_parts['DIMENSIONS']->_updateValue(array($result->field('file_width'), $result->field('file_height')));
  209. $this->_parts['THUMBNAIL_MIME_TYPE']->_updateValue($result->field('thumbnail_type'));
  210. $this->_parts['THUMBNAIL_DIMENSIONS']->_updateValue(array($result->field('thumb_width'), $result->field('thumb_height')));
  211. }
  212. $this->_partsLoaded = true;
  213. }
  214. }
  215.  
  216. ?>

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