Commits

Bogdan Savluk committed e14fe9b

default values for properties, fixed bugs in changeConfig method

  • Participants
  • Parent commits 004cccc

Comments (0)

Files changed (1)

File GalleryBehavior.php

      */
     public $versions;
     /** @var boolean does images in gallery need names */
-    public $name;
+    public $name=true;
     /** @var boolean does images in gallery need descriptions */
-    public $description;
+    public $description=true;
     /** @var boolean does images in gallery need links */
-    public $link;
+    public $link=false;
 
     private $_gallery;
 
     public function changeConfig()
     {
         /** @var $gallery Gallery */
-        $gallery = Gallery::model()->findByPk($this->getOwner()->{$this->idAttribute});
-        foreach ($gallery->galleryPhotos as $photo) {
-            $photo->removeImages();
+        $gallery = $this->getGallery();
+        if ($gallery === null) return;
+        $changed = false;
+        if ($gallery->name != $this->name) {
+            $changed = true; echo 'name';
         }
+        if ($gallery->description != $this->description) {
+            $changed = true; echo 'description';
+        }
+        if ($gallery->link != $this->link) {
+            $changed = true;  echo 'link';
+        }
+        if ($gallery->versions_data != serialize($this->versions)) {
+            $changed = true; echo 'data';
+        }
+        if ($changed) {
+            foreach ($gallery->galleryPhotos as $photo) {
+                $photo->removeImages();
+            }
 
-        $gallery->name = $this->name;
-        $gallery->description = $this->description;
-        $gallery->link = $this->link;
-        $gallery->versions = $this->versions;
-        $gallery->save();
+            $gallery->name = $this->name;
+            $gallery->description = $this->description;
+            $gallery->link = $this->link;
+            $gallery->versions = $this->versions;
+            $gallery->save();
 
-        foreach ($gallery->galleryPhotos as $photo) {
-            $photo->updateImages();
+            foreach ($gallery->galleryPhotos as $photo) {
+                $photo->updateImages();
+            }
         }
-
         $this->getOwner()->{$this->idAttribute} = $gallery->id;
         $this->getOwner()->saveAttributes($this->getOwner()->getAttributes());
     }