Ejemplo n.º 1
0
 /**
  * After find callback
  *  
  * @params array $results
  */
 public function afterFind($results, $primary = false)
 {
     parent::afterFind($results, $primary);
     if (!empty($results[0]['Gallery'])) {
         // handle hasMany results
         $i = 0;
         foreach ($results as $result) {
             $results[$i] = Set::merge(array('GallerySettings' => $this->gallerySettings($result)), $result);
             $i++;
         }
     }
     if (!empty($results['id'])) {
         $results = Set::merge(array('GallerySettings' => $this->gallerySettings($results)), $results);
     }
     return $results;
 }
Ejemplo n.º 2
0
 /**
  * Delete method
  * 
  * Delete both the record and the file on the server
  * 
  * @access public
  * @param string
  * @return bool
  */
 public function delete($id = null, $cascade = true)
 {
     $this->id = $id;
     if (!$this->exists()) {
         throw new Exception(__('Invalid file'));
     }
     $image = $this->read(null, $id);
     $fileName = $image['GalleryImage']['filename'];
     $file = $this->rootPath . ZuhaSet::webrootSubPath($image['GalleryImage']['dir']) . $fileName;
     if (parent::delete($id)) {
         if (file_exists($file) && is_file($file)) {
             unlink($file);
             // delete the largest file
         }
         $small = str_replace($fileName, 'thumb' . DS . 'small' . DS . $fileName, $file);
         if (file_exists($small) && is_file($small)) {
             unlink($small);
             // delete the small thumb
         }
         $medium = str_replace($fileName, 'thumb' . DS . 'medium' . DS . $fileName, $file);
         if (file_exists($medium) && is_file($medium)) {
             unlink($medium);
             // delete the medium thumb
         }
         $large = str_replace($fileName, 'thumb' . DS . 'large' . DS . $fileName, $file);
         if (file_exists($large) && is_file($large)) {
             unlink($large);
             // delete the medium thumb
         }
         return true;
     } else {
         throw new Exception(__('Delete failed'));
     }
 }