FilePluginFile.php 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. <?php
  2. /**
  3. * Override the ElggFile
  4. *
  5. * @note When extending an ElggEntity, one should always register a unique type/subtype
  6. * combination. We failed to do so here, so get_entity() and friends will always return
  7. * these objects as ElggFile. We leave it this way just for BC.
  8. */
  9. class FilePluginFile extends ElggFile {
  10. protected function initializeAttributes() {
  11. parent::initializeAttributes();
  12. // This should have been a unique subtype (see above)
  13. $this->attributes['subtype'] = "file";
  14. }
  15. public function __construct($guid = null) {
  16. if ($guid && !is_object($guid)) {
  17. // Loading entities via __construct(GUID) is deprecated, so we give it the entity row and the
  18. // attribute loader will finish the job. This is necessary due to not using a custom
  19. // subtype (see above).
  20. $guid = get_entity_as_row($guid);
  21. }
  22. parent::__construct($guid);
  23. }
  24. public function delete() {
  25. $thumbnails = array($this->thumbnail, $this->smallthumb, $this->largethumb);
  26. foreach ($thumbnails as $thumbnail) {
  27. if ($thumbnail) {
  28. $delfile = new ElggFile();
  29. $delfile->owner_guid = $this->owner_guid;
  30. $delfile->setFilename($thumbnail);
  31. $delfile->delete();
  32. }
  33. }
  34. return parent::delete();
  35. }
  36. }