Ejemplo n.º 1
0
 public function makePhotoZip()
 {
     $result = [];
     $current_hash = $this->_calcPhotoZipHash();
     $zip_file_path = UserUrl::photobook(false, $this->id, $this->user_id) . DIRECTORY_SEPARATOR . UserUrl::zipPhotosFile($this->id);
     $url = UserUrl::photobook(true, $this->id, $this->user_id) . '/' . UserUrl::zipPhotosFile($this->id);
     if ($current_hash != $this->photos_zip_hash || !file_exists($zip_file_path)) {
         $path_photos = [];
         foreach ($this->photos as $group_name => $group) {
             foreach ($group['photos'] as $key => $photo_id) {
                 $path_photos[] = UserUrl::photobookPhotos(false, $this->id, $this->user_id) . DIRECTORY_SEPARATOR . UserUrl::imageFile($photo_id, UserUrl::IMAGE_ORIGINAL);
             }
         }
         if (file_exists($zip_file_path)) {
             unlink($zip_file_path);
         }
         if (Utils::create_zip($path_photos, $zip_file_path, true)) {
             $result = ['response' => ['status' => true, 'url' => $url]];
         } else {
             $result = ['error' => ['msg' => Yii::t('app', 'Не удалось сосздать zip архив с фото.')]];
         }
     } else {
         $result = ['response' => ['status' => true, 'url' => $url]];
     }
     $this->photos_zip_hash = $current_hash;
     $this->save();
     return $result;
 }