Commits

Bogdan Savluk committed b459647

big gallery by all works for model

Comments (0)

Files changed (1)

models/GalleryPhoto.php

 class GalleryPhoto extends CActiveRecord
 {
     /** @var string Extensions for gallery images */
-    public $galleryExt = 'jpg';
+    private static $galleryExt = 'jpg';
     /** @var string directory in web root for galleries */
-    public $galleryDir = 'gallery';
+    private static $galleryDir = 'gallery';
 
     /**
      * Returns the static model of the specified AR class.
 
     public function getPreview()
     {
-        return Yii::app()->request->baseUrl . '/' . $this->galleryDir . '/_' . $this->getFileName('') . '.' . $this->galleryExt;
+        return Yii::app()->request->baseUrl . '/' . self::$galleryDir . '/_' . $this->getFileName('') . '.' . self::$galleryExt;
     }
 
     private function getFileName($version = '')
 
     public function getUrl($version = '')
     {
-        return Yii::app()->request->baseUrl . '/' . $this->galleryDir . '/' . $this->getFileName($version) . '.' . $this->galleryExt;
+        return Yii::app()->request->baseUrl . '/' . self::$galleryDir . '/' . $this->getFileName($version) . '.' . self::$galleryExt;
     }
 
     public function setImage($path)
     {
         //save image in original size
-        Yii::app()->image->load($path)->save($this->galleryDir . '/' . $this->getFileName('') . '.' . $this->galleryExt);
+        Yii::app()->image->load($path)->save(self::$galleryDir . '/' . $this->getFileName('') . '.' . self::$galleryExt);
         //create image preview for gallery manager
-        Yii::app()->image->load($path)->resize(300, null)->save($this->galleryDir . '/_' . $this->getFileName('') . '.' . $this->galleryExt);
+        Yii::app()->image->load($path)->resize(300, null)->save(self::$galleryDir . '/_' . $this->getFileName('') . '.' . self::$galleryExt);
 
         foreach ($this->gallery->versions as $version => $actions) {
             $image = Yii::app()->image->load($path);
             foreach ($actions as $method => $args) {
                 call_user_func_array(array($image, $method), $args);
             }
-            $image->save($this->galleryDir . '/' . $this->getFileName($version) . '.' . $this->galleryExt);
+            $image->save(self::$galleryDir . '/' . $this->getFileName($version) . '.' . self::$galleryExt);
         }
     }
 
     public function delete()
     {
-        $this->removeFile($this->galleryDir . '/' . $this->getFileName('') . '.' . $this->galleryExt);
+        $this->removeFile(self::$galleryDir . '/' . $this->getFileName('') . '.' . self::$galleryExt);
         //create image preview for gallery manager
-        $this->removeFile($this->galleryDir . '/_' . $this->getFileName('') . '.' . $this->galleryExt);
+        $this->removeFile(self::$galleryDir . '/_' . $this->getFileName('') . '.' . self::$galleryExt);
 
         foreach ($this->gallery->versions as $version => $actions) {
-            $this->removeFile($this->galleryDir . '/' . $this->getFileName($version) . '.' . $this->galleryExt);
+            $this->removeFile(self::$galleryDir . '/' . $this->getFileName($version) . '.' . self::$galleryExt);
         }
         return parent::delete();
     }
     public function removeImages()
     {
         foreach ($this->gallery->versions as $version => $actions) {
-            $this->removeFile($this->galleryDir . '/' . $this->getFileName($version) . '.' . $this->galleryExt);
+            $this->removeFile(self::$galleryDir . '/' . $this->getFileName($version) . '.' . self::$galleryExt);
         }
     }
 
     public function updateImages()
     {
         foreach ($this->gallery->versions as $version => $actions) {
-            $this->removeFile($this->galleryDir . '/' . $this->getFileName($version) . '.' . $this->galleryExt);
+            $this->removeFile(self::$galleryDir . '/' . $this->getFileName($version) . '.' . self::$galleryExt);
 
-            $image = Yii::app()->image->load($this->galleryDir . '/' . $this->getFileName('') . '.' . $this->galleryExt);
+            $image = Yii::app()->image->load(self::$galleryDir . '/' . $this->getFileName('') . '.' . self::$galleryExt);
             foreach ($actions as $method => $args) {
                 call_user_func_array(array($image, $method), $args);
             }
-            $image->save($this->galleryDir . '/' . $this->getFileName($version) . '.' . $this->galleryExt);
+            $image->save(self::$galleryDir . '/' . $this->getFileName($version) . '.' . self::$galleryExt);
         }
     }
 
-
+    public static function photoUrl($version, $id){
+         return Yii::app()->request->baseUrl . '/' . self::$galleryDir . '/' . $id.$version . '.' . self::$galleryExt;
+    }
 }
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.