/** * @param File $file * * @return array */ public function getObjectFromData(File $file) { $object = array('id' => $file->ID, 'created' => $file->Created, 'lastUpdated' => $file->LastEdited, 'owner' => null, 'parent' => null, 'title' => $file->Title, 'exists' => $file->exists(), 'type' => $file instanceof Folder ? 'folder' : $file->FileType, 'category' => $file instanceof Folder ? 'folder' : $file->appCategory(), 'name' => $file->Name, 'filename' => $file->Filename, 'extension' => $file->Extension, 'size' => $file->AbsoluteSize, 'url' => $file->AbsoluteURL, 'published' => $file->isPublished(), 'modified' => $file->isModifiedOnDraft(), 'draft' => $file->isOnDraftOnly(), 'canEdit' => $file->canEdit(), 'canDelete' => $file->canArchive()); /** @var Member $owner */ $owner = $file->Owner(); if ($owner) { $object['owner'] = array('id' => $owner->ID, 'title' => trim($owner->FirstName . ' ' . $owner->Surname)); } /** @var Folder $parent */ $parent = $file->Parent(); if ($parent) { $object['parent'] = array('id' => $parent->ID, 'title' => $parent->Title, 'filename' => $parent->Filename); } /** @var File $file */ if ($file->getIsImage()) { // Small thumbnail $smallWidth = UploadField::config()->get('thumbnail_width'); $smallHeight = UploadField::config()->get('thumbnail_height'); $smallThumbnail = $file->FitMax($smallWidth, $smallHeight); if ($smallThumbnail && $smallThumbnail->exists()) { $object['smallThumbnail'] = $smallThumbnail->getAbsoluteURL(); } // Large thumbnail $width = $this->config()->get('thumbnail_width'); $height = $this->config()->get('thumbnail_height'); $thumbnail = $file->FitMax($width, $height); if ($thumbnail && $thumbnail->exists()) { $object['thumbnail'] = $thumbnail->getAbsoluteURL(); } $object['dimensions']['width'] = $file->Width; $object['dimensions']['height'] = $file->Height; } else { $object['thumbnail'] = $file->PreviewLink(); } return $object; }