1 <?php
2
3
4 class Product3DDecorator extends DataObjectDecorator{
5 public function (){
6 return array(
7 'db' => array(
8 ),
9 'has_one' => array(
10 '3DModel' => 'File',
11 ),
12 'has_many' => array(
13 'Materials' => 'Material3D_File',
14 'Textures' => 'Texture3D_File',
15
16
17 )
18 );
19 }
20
21 public function updateCMSFields(FieldSet &$fields) {
22
23 ini_set('display_errors',1);
24 $fields->addFieldToTab('Root.Content.3D', $imgField = new FileIFrameField('3DModel', $this->owner->fieldLabel('3DModel')));
25 if ($folder = $this->owner->getAssociatedFolder()) {
26 $folderPath = substr_replace(str_replace(ASSETS_DIR.'/', '', $folder->Filename), "", -1);
27 $imgField->setFolderName($folderPath);
28 }
29
30
31
32
33
34
35
36 $fileManager = new Mediaweb3DPageFiles_Manager($this->owner, "Materials", "Material3D_File", "Attach", array("Caption" => _t("MediawebPage.Caption", "Caption")), "getCMSFields_forPopup");
37 $fileManager->setUploadFolder($folder);
38 $fields->addFieldToTab('Root.Content.3D', $fileManager);
39
40 $photoManager = new MediawebPageTexture_Manager($this->owner, "Textures", "Texture3D_File", "Photo", array("Caption"=>_t("MediawebPage.Caption","Caption")), "getCMSFields_forPopup");
41 $photoManager->setUploadFolder($folder);
42 $fields->addFieldToTab('Root.Content.3D', $photoManager);
43 }
44 }
45
46 class Mediaweb3DPageFiles_Manager extends FileDataObjectManager {
47 public = "MediawebPage_Popup";
48
49 public function __construct($controller, $name, $sourceClass, $fileFieldName, $fieldList = null, $detailFormFields = null, $sourceFilter = "", $sourceJoin = "",$parentClass='MediawebPage') {
50 parent::__construct($controller, $name, $sourceClass, $fileFieldName, $fieldList, $detailFormFields, $sourceFilter, $sourceSort, $sourceJoin);
51 if (!class_exists("FileDataObjectManager")) {
52 die("<strong>Error</strong>: requires the DataObjectManager module.");
53 }
54 $this->setGridLabelField('Caption');
55 $this->setAddTitle(_t('MediawebPage.Files', 'Files'));
56 $this->setBrowseButtonText(_t('MediawebPage.Upload','Upload'));
57 $this->setParentClass($parentClass);
58
59
60 if (!singleton('File')->canCreate()) {
61 $this->removePermission('upload');
62 }
63 }
64
65 public function EditUploadedForm() {
66 $form = parent::EditUploadedForm();
67 if ($current = $form->Fields()->fieldByName('current')) {
68 $current = $current->dataValue();
69 $dataObject = DataObject::get_by_id($this->sourceClass(), $current);
70 $fileObject = $dataObject->obj($this->fileFieldName);
71 $form->loadDataFrom(array('Caption' => preg_replace('/\.[^.]+$/', '', $fileObject->Title)));
72 }
73 return $form;
74 }
75 }
76
77 class MediawebPageTexture_Manager extends ImageDataObjectManager {
78 public = "MediawebPage_Popup";
79
80 public function __construct($controller, $name, $sourceClass, $fileFieldName, $fieldList = null, $detailFormFields = null, $sourceFilter = "", $sourceJoin = "",$parentClass='MediawebPage') {
81 parent::__construct($controller, $name, $sourceClass, $fileFieldName, $fieldList, $detailFormFields, $sourceFilter, $sourceSort, $sourceJoin);
82 if (!class_exists("ImageDataObjectManager")) {
83 die("<strong>Error</strong>: requires the DataObjectManager module.");
84 }
85
86 $this->setGridLabelField('Caption');
87 $this->setAddTitle(_t('MediawebPage.Photos', 'Photos'));
88 $this->setBrowseButtonText(_t('MediawebPage.Upload','Upload'));
89
90
91 $this->setParentClass($parentClass);
92
93
94 if (!singleton('Image')->canCreate()) {
95 $this->removePermission('upload');
96 }
97 }
98
99 public function EditUploadedForm() {
100 $form = parent::EditUploadedForm();
101 if ($current = $form->Fields()->fieldByName('current')) {
102 $current = $current->dataValue();
103 $dataObject = DataObject::get_by_id($this->sourceClass(), $current);
104 $fileObject = $dataObject->obj($this->fileFieldName);
105 $form->loadDataFrom(array('Caption' => preg_replace('/\.[^.]+$/', '', $fileObject->Title)));
106 }
107 return $form;
108 }
109
110 public function getPreviewFieldFor($fileObject, $size = 150) {
111 if ($fileObject instanceof Image) {
112 $URL = $fileObject->SetHeight($size)->URL;
113 return new LiteralField("icon",
114 "<div class='current-image'>
115 <div id='preview-image'>
116 <img src='$URL' alt='' class='preview' />
117 <div class='ajax-loader'><img src='dataobject_manager/images/ajax-loader.gif' /> Rotating...</div>
118 </div>
119 <div class='rotate-controls'>
120 <a href='".$this->CounterClockwiseLink($fileObject)."' title='Rotate clockwise'><img src='webylon/img/clockwise.gif' /></a> |
121 <a href='".$this->ClockwiseLink($fileObject)."' title='Rotate counter-clockwise'><img src='webylon/img/counterclockwise.gif' /></a>
122 </div>
123 <h3>$fileObject->Filename</h3>
124 </div>"
125 );
126 }
127 }
128
129 public function RotateLink($imgObj, $dir) {
130 return "MediawebPage_Controller/rotateimage/{$imgObj->ID}/{$dir}?flush=1";
131 }
132
133 private function CounterClockwiseLink($fileObject) {
134 return $this->RotateLink($fileObject, "ccw");
135 }
136
137 private function ClockwiseLink($fileObject) {
138 return $this->RotateLink($fileObject, "cw");
139 }
140 }
141
142 class Material3D_File extends DataObject {
143 static $db = array (
144 'Caption' => 'Text',
145 );
146
147 static $has_one = array (
148 'MediawebPage' => 'MediawebPage',
149 'Attach' => 'File'
150 );
151
152 function FileLabel(){
153 return $this->Caption;
154 }
155
156 public function () {
157 $fields = new FieldSet();
158 $fields->push(new TextareaField('Caption',_t('MediawebPage.Caption', 'Caption')));
159 $fields->push(new FileField('Attach',_t('MediawebPage.Attach', 'Attachment')));
160 return $fields;
161 }
162
163 public function onAfterWrite() {
164 parent::onAfterWrite();
165
166 }
167
168 public function onBeforeDelete() {
169 if ($this->MediawebPageID && ($page = DataObject::get_by_id('SiteTree', $this->MediawebPageID))) {
170 if ($this->AttachID && $this->Attach()->ID && $page->AssociatedFolderID == $this->Attach()->ParentID)
171 $this->Attach()->delete();
172 }
173 parent::onBeforeDelete();
174 }
175
176 function ParentObject() {
177 return $this->MediawebPage();
178 }
179 }
180
181 class Texture3D_File extends DataObject {
182 static $db = array (
183 'Caption' => 'Text',
184 );
185
186 static $has_one = array (
187 'MediawebPage' => 'MediawebPage',
188 'Photo' => 'Image'
189 );
190
191 public function () {
192 $fields = new FieldSet();
193 $fields->push(new TextareaField('Caption',_t('MediawebPage.Caption', 'Caption')));
194
195
196 return $fields;
197 }
198
199 public function onBeforeDelete() {
200 if ($this->MediawebPageID && ($page = DataObject::get_by_id('SiteTree', $this->MediawebPageID))) {
201 if ($this->PhotoID && $this->Photo()->ID && $page->AssociatedFolderID == $this->Photo()->ParentID)
202 $this->Photo()->delete();
203 }
204 parent::onBeforeDelete();
205 }
206
207 public function onAfterWrite() {
208 parent::onAfterWrite();
209
210 }
211
212 public function Thumbnail() {
213 $thumbnailSize = $this->SiteConfig()->MediawebpageThumbnailSize;
214 return $this->Photo()->CroppedImage($thumbnailSize,$thumbnailSize);
215 }
216
217 public function Large() {
218 $photo = $this->Photo();
219 $normalSize = $this->SiteConfig()->MediawebpageNormalSize;
220 if ($photo->getOrientation() == Image::ORIENTATION_LANDSCAPE) {
221 return $photo->SetWidth($normalSize);
222 } else {
223 return $photo->SetHeight($normalSize);
224 }
225 }
226
227 function ParentObject() {
228 return $this->MediawebPage();
229 }
230
231 }
[Raise a SilverStripe Framework issue/bug](https://github.com/silverstripe/silverstripe-framework/issues/new)
- [Raise a SilverStripe CMS issue/bug](https://github.com/silverstripe/silverstripe-cms/issues/new)
- Please use the
Silverstripe Forums to ask development related questions.
-