Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
Complex classes like UploadField often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use UploadField, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 28 | class UploadField extends FileField { |
||
| 29 | |||
| 30 | /** |
||
| 31 | * @var array |
||
| 32 | */ |
||
| 33 | private static $allowed_actions = array( |
||
|
|
|||
| 34 | 'upload', |
||
| 35 | 'attach', |
||
| 36 | 'handleItem', |
||
| 37 | 'handleSelect', |
||
| 38 | 'fileexists' |
||
| 39 | ); |
||
| 40 | |||
| 41 | /** |
||
| 42 | * @var array |
||
| 43 | */ |
||
| 44 | private static $url_handlers = array( |
||
| 45 | 'item/$ID' => 'handleItem', |
||
| 46 | 'select' => 'handleSelect', |
||
| 47 | '$Action!' => '$Action', |
||
| 48 | ); |
||
| 49 | |||
| 50 | /** |
||
| 51 | * Template to use for the file button widget |
||
| 52 | * |
||
| 53 | * @var string |
||
| 54 | */ |
||
| 55 | protected $templateFileButtons = 'UploadField_FileButtons'; |
||
| 56 | |||
| 57 | /** |
||
| 58 | * Template to use for the edit form |
||
| 59 | * |
||
| 60 | * @var string |
||
| 61 | */ |
||
| 62 | protected $templateFileEdit = 'UploadField_FileEdit'; |
||
| 63 | |||
| 64 | /** |
||
| 65 | * Parent data record. Will be infered from parent form or controller if blank. |
||
| 66 | * |
||
| 67 | * @var DataObject |
||
| 68 | */ |
||
| 69 | protected $record; |
||
| 70 | |||
| 71 | /** |
||
| 72 | * Items loaded into this field. May be a RelationList, or any other SS_List |
||
| 73 | * |
||
| 74 | * @var SS_List |
||
| 75 | */ |
||
| 76 | protected $items; |
||
| 77 | |||
| 78 | /** |
||
| 79 | * Config for this field used in the front-end javascript |
||
| 80 | * (will be merged into the config of the javascript file upload plugin). |
||
| 81 | * See framework/_config/uploadfield.yml for configuration defaults and documentation. |
||
| 82 | * |
||
| 83 | * @var array |
||
| 84 | */ |
||
| 85 | protected $ufConfig = array( |
||
| 86 | /** |
||
| 87 | * Automatically upload the file once selected |
||
| 88 | * |
||
| 89 | * @var boolean |
||
| 90 | */ |
||
| 91 | 'autoUpload' => true, |
||
| 92 | /** |
||
| 93 | * Restriction on number of files that may be set for this field. Set to null to allow |
||
| 94 | * unlimited. If record has a has_one and allowedMaxFileNumber is null, it will be set to 1. |
||
| 95 | * The resulting value will be set to maxNumberOfFiles |
||
| 96 | * |
||
| 97 | * @var integer |
||
| 98 | */ |
||
| 99 | 'allowedMaxFileNumber' => null, |
||
| 100 | /** |
||
| 101 | * Can the user upload new files, or just select from existing files. |
||
| 102 | * String values are interpreted as permission codes. |
||
| 103 | * |
||
| 104 | * @var boolean|string |
||
| 105 | */ |
||
| 106 | 'canUpload' => true, |
||
| 107 | /** |
||
| 108 | * Can the user attach files from the assets archive on the site? |
||
| 109 | * String values are interpreted as permission codes. |
||
| 110 | * |
||
| 111 | * @var boolean|string |
||
| 112 | */ |
||
| 113 | 'canAttachExisting' => "CMS_ACCESS_AssetAdmin", |
||
| 114 | /** |
||
| 115 | * Shows the target folder for new uploads in the field UI. |
||
| 116 | * Disable to keep the internal filesystem structure hidden from users. |
||
| 117 | * |
||
| 118 | * @var boolean|string |
||
| 119 | */ |
||
| 120 | 'canPreviewFolder' => true, |
||
| 121 | /** |
||
| 122 | * Indicate a change event to the containing form if an upload |
||
| 123 | * or file edit/delete was performed. |
||
| 124 | * |
||
| 125 | * @var boolean |
||
| 126 | */ |
||
| 127 | 'changeDetection' => true, |
||
| 128 | /** |
||
| 129 | * Maximum width of the preview thumbnail |
||
| 130 | * |
||
| 131 | * @var integer |
||
| 132 | */ |
||
| 133 | 'previewMaxWidth' => 80, |
||
| 134 | /** |
||
| 135 | * Maximum height of the preview thumbnail |
||
| 136 | * |
||
| 137 | * @var integer |
||
| 138 | */ |
||
| 139 | 'previewMaxHeight' => 60, |
||
| 140 | /** |
||
| 141 | * javascript template used to display uploading files |
||
| 142 | * |
||
| 143 | * @see javascript/UploadField_uploadtemplate.js |
||
| 144 | * @var string |
||
| 145 | */ |
||
| 146 | 'uploadTemplateName' => 'ss-uploadfield-uploadtemplate', |
||
| 147 | /** |
||
| 148 | * javascript template used to display already uploaded files |
||
| 149 | * |
||
| 150 | * @see javascript/UploadField_downloadtemplate.js |
||
| 151 | * @var string |
||
| 152 | */ |
||
| 153 | 'downloadTemplateName' => 'ss-uploadfield-downloadtemplate', |
||
| 154 | /** |
||
| 155 | * Show a warning when overwriting a file. |
||
| 156 | * This requires Upload->replaceFile config to be set to true, otherwise |
||
| 157 | * files will be renamed instead of overwritten |
||
| 158 | * |
||
| 159 | * @see Upload |
||
| 160 | * @var boolean |
||
| 161 | */ |
||
| 162 | 'overwriteWarning' => true |
||
| 163 | ); |
||
| 164 | |||
| 165 | /** |
||
| 166 | * @var String Folder to display in "Select files" list. |
||
| 167 | * Defaults to listing all files regardless of folder. |
||
| 168 | * The folder path should be relative to the webroot. |
||
| 169 | * See {@link FileField->folderName} to set the upload target instead. |
||
| 170 | * @example admin/folder/subfolder |
||
| 171 | */ |
||
| 172 | protected $displayFolderName; |
||
| 173 | |||
| 174 | /** |
||
| 175 | * FieldList $fields or string $name (of a method on File to provide a fields) for the EditForm |
||
| 176 | * @example 'getCMSFields' |
||
| 177 | * |
||
| 178 | * @var FieldList|string |
||
| 179 | */ |
||
| 180 | protected $fileEditFields = null; |
||
| 181 | |||
| 182 | /** |
||
| 183 | * FieldList $actions or string $name (of a method on File to provide a actions) for the EditForm |
||
| 184 | * @example 'getCMSActions' |
||
| 185 | * |
||
| 186 | * @var FieldList|string |
||
| 187 | */ |
||
| 188 | protected $fileEditActions = null; |
||
| 189 | |||
| 190 | /** |
||
| 191 | * Validator (eg RequiredFields) or string $name (of a method on File to provide a Validator) for the EditForm |
||
| 192 | * @example 'getCMSValidator' |
||
| 193 | * |
||
| 194 | * @var RequiredFields|string |
||
| 195 | */ |
||
| 196 | protected $fileEditValidator = null; |
||
| 197 | |||
| 198 | /** |
||
| 199 | * Construct a new UploadField instance |
||
| 200 | * |
||
| 201 | * @param string $name The internal field name, passed to forms. |
||
| 202 | * @param string $title The field label. |
||
| 203 | * @param SS_List $items If no items are defined, the field will try to auto-detect an existing relation on |
||
| 204 | * @link $record}, with the same name as the field name. |
||
| 205 | * @param Form $form Reference to the container form |
||
| 206 | */ |
||
| 207 | public function __construct($name, $title = null, SS_List $items = null) { |
||
| 229 | |||
| 230 | /** |
||
| 231 | * Set name of template used for Buttons on each file (replace, edit, remove, delete) (without path or extension) |
||
| 232 | * |
||
| 233 | * @param string |
||
| 234 | */ |
||
| 235 | public function setTemplateFileButtons($template) { |
||
| 239 | |||
| 240 | /** |
||
| 241 | * @return string |
||
| 242 | */ |
||
| 243 | public function getTemplateFileButtons() { |
||
| 246 | |||
| 247 | /** |
||
| 248 | * Set name of template used for the edit (inline & popup) of a file file (without path or extension) |
||
| 249 | * |
||
| 250 | * @param string |
||
| 251 | */ |
||
| 252 | public function setTemplateFileEdit($template) { |
||
| 256 | |||
| 257 | /** |
||
| 258 | * @return string |
||
| 259 | */ |
||
| 260 | public function getTemplateFileEdit() { |
||
| 263 | |||
| 264 | /** |
||
| 265 | * Determine if the target folder for new uploads in is visible the field UI. |
||
| 266 | * |
||
| 267 | * @return boolean |
||
| 268 | */ |
||
| 269 | public function canPreviewFolder() { |
||
| 274 | |||
| 275 | /** |
||
| 276 | * Determine if the target folder for new uploads in is visible the field UI. |
||
| 277 | * Disable to keep the internal filesystem structure hidden from users. |
||
| 278 | * |
||
| 279 | * @param boolean|string $canPreviewFolder Either a boolean flag, or a |
||
| 280 | * required permission code |
||
| 281 | * @return UploadField Self reference |
||
| 282 | */ |
||
| 283 | public function setCanPreviewFolder($canPreviewFolder) { |
||
| 286 | |||
| 287 | /** |
||
| 288 | * Determine if the field should show a warning when overwriting a file. |
||
| 289 | * This requires Upload->replaceFile config to be set to true, otherwise |
||
| 290 | * files will be renamed instead of overwritten (although the warning will |
||
| 291 | * still be displayed) |
||
| 292 | * |
||
| 293 | * @return boolean |
||
| 294 | */ |
||
| 295 | public function getOverwriteWarning() { |
||
| 298 | |||
| 299 | /** |
||
| 300 | * Determine if the field should show a warning when overwriting a file. |
||
| 301 | * This requires Upload->replaceFile config to be set to true, otherwise |
||
| 302 | * files will be renamed instead of overwritten (although the warning will |
||
| 303 | * still be displayed) |
||
| 304 | * |
||
| 305 | * @param boolean $overwriteWarning |
||
| 306 | * @return UploadField Self reference |
||
| 307 | */ |
||
| 308 | public function setOverwriteWarning($overwriteWarning) { |
||
| 311 | |||
| 312 | /** |
||
| 313 | * @param String |
||
| 314 | */ |
||
| 315 | public function setDisplayFolderName($name) { |
||
| 319 | |||
| 320 | /** |
||
| 321 | * @return String |
||
| 322 | */ |
||
| 323 | public function getDisplayFolderName() { |
||
| 326 | |||
| 327 | /** |
||
| 328 | * Force a record to be used as "Parent" for uploaded Files (eg a Page with a has_one to File) |
||
| 329 | * @param DataObject $record |
||
| 330 | */ |
||
| 331 | public function setRecord($record) { |
||
| 335 | /** |
||
| 336 | * Get the record to use as "Parent" for uploaded Files (eg a Page with a has_one to File) If none is set, it will |
||
| 337 | * use Form->getRecord() or Form->Controller()->data() |
||
| 338 | * |
||
| 339 | * @return DataObject |
||
| 340 | */ |
||
| 341 | public function getRecord() { |
||
| 355 | |||
| 356 | /** |
||
| 357 | * Loads the related record values into this field. UploadField can be uploaded |
||
| 358 | * in one of three ways: |
||
| 359 | * |
||
| 360 | * - By passing in a list of file IDs in the $value parameter (an array with a single |
||
| 361 | * key 'Files', with the value being the actual array of IDs). |
||
| 362 | * - By passing in an explicit list of File objects in the $record parameter, and |
||
| 363 | * leaving $value blank. |
||
| 364 | * - By passing in a dataobject in the $record parameter, from which file objects |
||
| 365 | * will be extracting using the field name as the relation field. |
||
| 366 | * |
||
| 367 | * Each of these methods will update both the items (list of File objects) and the |
||
| 368 | * field value (list of file ID values). |
||
| 369 | * |
||
| 370 | * @param array $value Array of submitted form data, if submitting from a form |
||
| 371 | * @param array|DataObject|SS_List $record Full source record, either as a DataObject, |
||
| 372 | * SS_List of items, or an array of submitted form data |
||
| 373 | * @return UploadField Self reference |
||
| 374 | */ |
||
| 375 | public function setValue($value, $record = null) { |
||
| 441 | |||
| 442 | /** |
||
| 443 | * Sets the items assigned to this field as an SS_List of File objects. |
||
| 444 | * Calling setItems will also update the value of this field, as well as |
||
| 445 | * updating the internal list of File items. |
||
| 446 | * |
||
| 447 | * @param SS_List $items |
||
| 448 | * @return UploadField self reference |
||
| 449 | */ |
||
| 450 | public function setItems(SS_List $items) { |
||
| 453 | |||
| 454 | /** |
||
| 455 | * Retrieves the current list of files |
||
| 456 | * |
||
| 457 | * @return SS_List |
||
| 458 | */ |
||
| 459 | public function getItems() { |
||
| 462 | |||
| 463 | /** |
||
| 464 | * Retrieves a customised list of all File records to ensure they are |
||
| 465 | * properly viewable when rendered in the field template. |
||
| 466 | * |
||
| 467 | * @return SS_List[ViewableData_Customised] |
||
| 468 | */ |
||
| 469 | public function getCustomisedItems() { |
||
| 476 | |||
| 477 | /** |
||
| 478 | * Retrieves the list of selected file IDs |
||
| 479 | * |
||
| 480 | * @return array |
||
| 481 | */ |
||
| 482 | public function getItemIDs() { |
||
| 486 | |||
| 487 | public function Value() { |
||
| 491 | |||
| 492 | public function saveInto(DataObjectInterface $record) { |
||
| 511 | |||
| 512 | /** |
||
| 513 | * Customises a file with additional details suitable for rendering in the |
||
| 514 | * UploadField.ss template |
||
| 515 | * |
||
| 516 | * @param File $file |
||
| 517 | * @return ViewableData_Customised |
||
| 518 | */ |
||
| 519 | protected function customiseFile(File $file) { |
||
| 531 | |||
| 532 | /** |
||
| 533 | * Assign a front-end config variable for the upload field |
||
| 534 | * |
||
| 535 | * @see https://github.com/blueimp/jQuery-File-Upload/wiki/Options for the list of front end options available |
||
| 536 | * |
||
| 537 | * @param string $key |
||
| 538 | * @param mixed $val |
||
| 539 | * @return UploadField self reference |
||
| 540 | */ |
||
| 541 | public function setConfig($key, $val) { |
||
| 545 | |||
| 546 | /** |
||
| 547 | * Gets a front-end config variable for the upload field |
||
| 548 | * |
||
| 549 | * @see https://github.com/blueimp/jQuery-File-Upload/wiki/Options for the list of front end options available |
||
| 550 | * |
||
| 551 | * @param string $key |
||
| 552 | * @return mixed |
||
| 553 | */ |
||
| 554 | public function getConfig($key) { |
||
| 558 | |||
| 559 | /** |
||
| 560 | * Determine if the field should automatically upload the file. |
||
| 561 | * |
||
| 562 | * @return boolean |
||
| 563 | */ |
||
| 564 | public function getAutoUpload() { |
||
| 567 | |||
| 568 | /** |
||
| 569 | * Determine if the field should automatically upload the file |
||
| 570 | * |
||
| 571 | * @param boolean $autoUpload |
||
| 572 | * @return UploadField Self reference |
||
| 573 | */ |
||
| 574 | public function setAutoUpload($autoUpload) { |
||
| 577 | |||
| 578 | /** |
||
| 579 | * Determine maximum number of files allowed to be attached |
||
| 580 | * Defaults to 1 for has_one and null (unlimited) for |
||
| 581 | * many_many and has_many relations. |
||
| 582 | * |
||
| 583 | * @return integer|null Maximum limit, or null for no limit |
||
| 584 | */ |
||
| 585 | public function getAllowedMaxFileNumber() { |
||
| 602 | |||
| 603 | /** |
||
| 604 | * Determine maximum number of files allowed to be attached. |
||
| 605 | * |
||
| 606 | * @param integer|null $allowedMaxFileNumber Maximum limit. 0 or null will be treated as unlimited |
||
| 607 | * @return UploadField Self reference |
||
| 608 | */ |
||
| 609 | public function setAllowedMaxFileNumber($allowedMaxFileNumber) { |
||
| 612 | |||
| 613 | /** |
||
| 614 | * Determine if the user has permission to upload. |
||
| 615 | * |
||
| 616 | * @return boolean |
||
| 617 | */ |
||
| 618 | public function canUpload() { |
||
| 623 | |||
| 624 | /** |
||
| 625 | * Specify whether the user can upload files. |
||
| 626 | * String values will be treated as required permission codes |
||
| 627 | * |
||
| 628 | * @param boolean|string $canUpload Either a boolean flag, or a required |
||
| 629 | * permission code |
||
| 630 | * @return UploadField Self reference |
||
| 631 | */ |
||
| 632 | public function setCanUpload($canUpload) { |
||
| 635 | |||
| 636 | /** |
||
| 637 | * Determine if the user has permission to attach existing files |
||
| 638 | * By default returns true if the user has the CMS_ACCESS_AssetAdmin permission |
||
| 639 | * |
||
| 640 | * @return boolean |
||
| 641 | */ |
||
| 642 | public function canAttachExisting() { |
||
| 647 | |||
| 648 | /** |
||
| 649 | * Returns true if the field is neither readonly nor disabled |
||
| 650 | * |
||
| 651 | * @return boolean |
||
| 652 | */ |
||
| 653 | public function isActive() { |
||
| 656 | |||
| 657 | /** |
||
| 658 | * Specify whether the user can attach existing files |
||
| 659 | * String values will be treated as required permission codes |
||
| 660 | * |
||
| 661 | * @param boolean|string $canAttachExisting Either a boolean flag, or a |
||
| 662 | * required permission code |
||
| 663 | * @return UploadField Self reference |
||
| 664 | */ |
||
| 665 | public function setCanAttachExisting($canAttachExisting) { |
||
| 668 | |||
| 669 | /** |
||
| 670 | * Gets thumbnail width. Defaults to 80 |
||
| 671 | * |
||
| 672 | * @return integer |
||
| 673 | */ |
||
| 674 | public function getPreviewMaxWidth() { |
||
| 677 | |||
| 678 | /** |
||
| 679 | * @see UploadField::getPreviewMaxWidth() |
||
| 680 | * |
||
| 681 | * @param integer $previewMaxWidth |
||
| 682 | * @return UploadField Self reference |
||
| 683 | */ |
||
| 684 | public function setPreviewMaxWidth($previewMaxWidth) { |
||
| 687 | |||
| 688 | /** |
||
| 689 | * Gets thumbnail height. Defaults to 60 |
||
| 690 | * |
||
| 691 | * @return integer |
||
| 692 | */ |
||
| 693 | public function getPreviewMaxHeight() { |
||
| 696 | |||
| 697 | /** |
||
| 698 | * @see UploadField::getPreviewMaxHeight() |
||
| 699 | * |
||
| 700 | * @param integer $previewMaxHeight |
||
| 701 | * @return UploadField Self reference |
||
| 702 | */ |
||
| 703 | public function setPreviewMaxHeight($previewMaxHeight) { |
||
| 706 | |||
| 707 | /** |
||
| 708 | * javascript template used to display uploading files |
||
| 709 | * Defaults to 'ss-uploadfield-uploadtemplate' |
||
| 710 | * |
||
| 711 | * @see javascript/UploadField_uploadtemplate.js |
||
| 712 | * @var string |
||
| 713 | */ |
||
| 714 | public function getUploadTemplateName() { |
||
| 717 | |||
| 718 | /** |
||
| 719 | * @see UploadField::getUploadTemplateName() |
||
| 720 | * |
||
| 721 | * @param string $uploadTemplateName |
||
| 722 | * @return UploadField Self reference |
||
| 723 | */ |
||
| 724 | public function setUploadTemplateName($uploadTemplateName) { |
||
| 727 | |||
| 728 | /** |
||
| 729 | * javascript template used to display already uploaded files |
||
| 730 | * Defaults to 'ss-downloadfield-downloadtemplate' |
||
| 731 | * |
||
| 732 | * @see javascript/DownloadField_downloadtemplate.js |
||
| 733 | * @var string |
||
| 734 | */ |
||
| 735 | public function getDownloadTemplateName() { |
||
| 738 | |||
| 739 | /** |
||
| 740 | * @see Uploadfield::getDownloadTemplateName() |
||
| 741 | * |
||
| 742 | * @param string $downloadTemplateName |
||
| 743 | * @return Uploadfield Self reference |
||
| 744 | */ |
||
| 745 | public function setDownloadTemplateName($downloadTemplateName) { |
||
| 748 | |||
| 749 | /** |
||
| 750 | * FieldList $fields for the EditForm |
||
| 751 | * @example 'getCMSFields' |
||
| 752 | * |
||
| 753 | * @param File $file File context to generate fields for |
||
| 754 | * @return FieldList List of form fields |
||
| 755 | */ |
||
| 756 | public function getFileEditFields(File $file) { |
||
| 778 | |||
| 779 | /** |
||
| 780 | * FieldList $fields or string $name (of a method on File to provide a fields) for the EditForm |
||
| 781 | * @example 'getCMSFields' |
||
| 782 | * |
||
| 783 | * @param FieldList|string |
||
| 784 | * @return Uploadfield Self reference |
||
| 785 | */ |
||
| 786 | public function setFileEditFields($fileEditFields) { |
||
| 790 | |||
| 791 | /** |
||
| 792 | * FieldList $actions or string $name (of a method on File to provide a actions) for the EditForm |
||
| 793 | * @example 'getCMSActions' |
||
| 794 | * |
||
| 795 | * @param File $file File context to generate form actions for |
||
| 796 | * @return FieldList Field list containing FormAction |
||
| 797 | */ |
||
| 798 | public function getFileEditActions(File $file) { |
||
| 817 | |||
| 818 | /** |
||
| 819 | * FieldList $actions or string $name (of a method on File to provide a actions) for the EditForm |
||
| 820 | * @example 'getCMSActions' |
||
| 821 | * |
||
| 822 | * @param FieldList|string |
||
| 823 | * @return Uploadfield Self reference |
||
| 824 | */ |
||
| 825 | public function setFileEditActions($fileEditActions) { |
||
| 829 | |||
| 830 | /** |
||
| 831 | * Determines the validator to use for the edit form |
||
| 832 | * @example 'getCMSValidator' |
||
| 833 | * |
||
| 834 | * @param File $file File context to generate validator from |
||
| 835 | * @return Validator Validator object |
||
| 836 | */ |
||
| 837 | public function getFileEditValidator(File $file) { |
||
| 851 | |||
| 852 | /** |
||
| 853 | * Validator (eg RequiredFields) or string $name (of a method on File to provide a Validator) for the EditForm |
||
| 854 | * @example 'getCMSValidator' |
||
| 855 | * |
||
| 856 | * @param Validator|string |
||
| 857 | * @return Uploadfield Self reference |
||
| 858 | */ |
||
| 859 | public function setFileEditValidator($fileEditValidator) { |
||
| 863 | |||
| 864 | /** |
||
| 865 | * @param File $file |
||
| 866 | * @return string |
||
| 867 | */ |
||
| 868 | protected function getThumbnailURLForFile(File $file) { |
||
| 886 | |||
| 887 | public function getAttributes() { |
||
| 893 | |||
| 894 | public function extraClass() { |
||
| 899 | |||
| 900 | public function Field($properties = array()) { |
||
| 983 | |||
| 984 | /** |
||
| 985 | * Validation method for this field, called when the entire form is validated |
||
| 986 | * |
||
| 987 | * @param Validator $validator |
||
| 988 | * @return boolean |
||
| 989 | */ |
||
| 990 | public function validate($validator) { |
||
| 1036 | |||
| 1037 | /** |
||
| 1038 | * @param SS_HTTPRequest $request |
||
| 1039 | * @return UploadField_ItemHandler |
||
| 1040 | */ |
||
| 1041 | public function handleItem(SS_HTTPRequest $request) { |
||
| 1044 | |||
| 1045 | /** |
||
| 1046 | * @param int $itemID |
||
| 1047 | * @return UploadField_ItemHandler |
||
| 1048 | */ |
||
| 1049 | public function getItemHandler($itemID) { |
||
| 1052 | |||
| 1053 | /** |
||
| 1054 | * @param SS_HTTPRequest $request |
||
| 1055 | * @return UploadField_ItemHandler |
||
| 1056 | */ |
||
| 1057 | public function handleSelect(SS_HTTPRequest $request) { |
||
| 1061 | |||
| 1062 | /** |
||
| 1063 | * Given an array of post variables, extract all temporary file data into an array |
||
| 1064 | * |
||
| 1065 | * @param array $postVars Array of posted form data |
||
| 1066 | * @return array List of temporary file data |
||
| 1067 | */ |
||
| 1068 | protected function extractUploadedFileData($postVars) { |
||
| 1093 | |||
| 1094 | /** |
||
| 1095 | * Loads the temporary file data into a File object |
||
| 1096 | * |
||
| 1097 | * @param array $tmpFile Temporary file data |
||
| 1098 | * @param string $error Error message |
||
| 1099 | * @return File File object, or null if error |
||
| 1100 | */ |
||
| 1101 | protected function saveTemporaryFile($tmpFile, &$error = null) { |
||
| 1142 | |||
| 1143 | /** |
||
| 1144 | * Safely encodes the File object with all standard fields required |
||
| 1145 | * by the front end |
||
| 1146 | * |
||
| 1147 | * @param File $file |
||
| 1148 | * @return array Array encoded list of file attributes |
||
| 1149 | */ |
||
| 1150 | protected function encodeFileAttributes(File $file) { |
||
| 1166 | |||
| 1167 | /** |
||
| 1168 | * Action to handle upload of a single file |
||
| 1169 | * |
||
| 1170 | * @param SS_HTTPRequest $request |
||
| 1171 | * @return SS_HTTPResponse |
||
| 1172 | * @return SS_HTTPResponse |
||
| 1173 | */ |
||
| 1174 | public function upload(SS_HTTPRequest $request) { |
||
| 1208 | |||
| 1209 | /** |
||
| 1210 | * Retrieves details for files that this field wishes to attache to the |
||
| 1211 | * client-side form |
||
| 1212 | * |
||
| 1213 | * @param SS_HTTPRequest $request |
||
| 1214 | * @return SS_HTTPResponse |
||
| 1215 | */ |
||
| 1216 | public function attach(SS_HTTPRequest $request) { |
||
| 1230 | |||
| 1231 | /** |
||
| 1232 | * Check if file exists, both checking filtered filename and exact filename |
||
| 1233 | * |
||
| 1234 | * @param string $originalFile Filename |
||
| 1235 | * @return bool |
||
| 1236 | */ |
||
| 1237 | protected function checkFileExists($originalFile) { |
||
| 1254 | |||
| 1255 | /** |
||
| 1256 | * Determines if a specified file exists |
||
| 1257 | * |
||
| 1258 | * @param SS_HTTPRequest $request |
||
| 1259 | */ |
||
| 1260 | public function fileexists(SS_HTTPRequest $request) { |
||
| 1279 | |||
| 1280 | public function performReadonlyTransformation() { |
||
| 1286 | |||
| 1287 | /** |
||
| 1288 | * Gets the foreign class that needs to be created, or 'File' as default if there |
||
| 1289 | * is no relationship, or it cannot be determined. |
||
| 1290 | * |
||
| 1291 | * @param $default Default value to return if no value could be calculated |
||
| 1292 | * @return string Foreign class name. |
||
| 1293 | */ |
||
| 1294 | public function getRelationAutosetClass($default = 'File') { |
||
| 1309 | |||
| 1310 | } |
||
| 1311 | |||
| 1622 |