Version: current

     1 <?php
     2
     3 class PhotoAlbumManager extends ImageDataObjectManager {
     4     public $popupClass = "PhotoAlbumManager_Popup";
     5
     6     public function getPreviewFieldFor($fileObject, $size = 150) {
     7         if($fileObject->ID && $fileObject instanceof Image) {
     8             $URL = $fileObject->SetHeight($size)->URL;
     9             return new LiteralField("icon",
    10                 "<div class='current-image'>
    11                     <div id='preview-image'>
    12                         <img src='$URL' alt='' class='preview' />
    13                         <div class='ajax-loader'><img src='dataobject_manager/images/ajax-loader.gif' />". _t('PhotoAlbumManager.ROTATING','Rotating')."...</div>
    14                     </div>
    15                     <div class='rotate-controls'>
    16                         <a href='".$this->CounterClockwiseLink($fileObject)."' title='"._t("PhotoAlbumManager.ROTATECLOCKWISE","Rotate clockwise")."'><img src='webylon/img/clockwise.gif' /></a> |
    17                         <a href='".$this->ClockwiseLink($fileObject)."' title='"._t("PhotoAlbumManager.ROTATECOUNTERCLOCKWISE","Rotate counter-clockwise")."'><img src='webylon/img/counterclockwise.gif' /></a>
    18                     </div>
    19                     <h3>$fileObject->Filename</h3>
    20                 </div>"
    21             );
    22         } else {
    23             return new LiteralField("icon",
    24                 "<div class='current-image'>
    25                     <div id='preview-image'>
    26
    27                     </div>
    28                     <div class='rotate-controls'>
    29
    30                     </div>
    31                     <h3>No Image</h3>
    32                 </div>"
    33             );
    34         }
    35     }
    36
    37     public function EditUploadedForm() {
    38         $form = parent::EditUploadedForm();
    39         if ($current = $form->Fields()->fieldByName('current')) {
    40             $current = $current->dataValue();
    41             $dataObject = DataObject::get_by_id($this->sourceClass(), $current);
    42             $fileObject = $dataObject->obj($this->fileFieldName);
    43             $form->loadDataFrom(array('Caption' => preg_replace('/\.[^.]+$/', '', $fileObject->Title)));
    44         }
    45         return $form;
    46     }
    47
    48     public function RotateLink($imgObj, $dir) {
    49         return "PhotoAlbumManager_Controller/rotateimage/{$imgObj->ID}/{$dir}?flush=1";
    50     }
    51
    52     private function CounterClockwiseLink($fileObject) {
    53         return $this->RotateLink($fileObject, "ccw");
    54     }
    55
    56     private function ClockwiseLink($fileObject) {
    57         return $this->RotateLink($fileObject, "cw");
    58     }
    59 }
    60
    61 class PhotoAlbumManager_Controller extends Controller {
    62     public function rotateimage() {
    63         if($image = DataObject::get_by_id("Image", $this->urlParams['ID'])) {
    64             $url = $this->urlParams['OtherID'] == 'cw' ? $image->RotateClockwise()->URL : $image->RotateCounterClockwise()->URL;
    65             $original_file = $image->Filename;
    66             if(copy(Director::baseFolder().'/'.$url, Director::baseFolder().'/'.$original_file)) {
    67                 $image->flushCache();
    68                 $image->deleteFormattedImages();
    69             }
    70             echo $image->SetHeight(150)->URL . "?t=".time();
    71         }
    72     }
    73 }
    74
    75 class PhotoAlbumManager_Popup extends FileDataObjectManager_Popup {
    76     function __construct($controller, $name, $fields, $validator, $readonly, $dataObject) {
    77             parent::__construct($controller, $name, $fields, $validator, $readonly, $dataObject);
    78             Requirements::javascript('photo_gallery/javascript/imagegallerymanager_popup.js');
    79
    80     }
    81 }
    82
    83

[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. -