Example #1
0
 public function productXmlAdd($product)
 {
     $model = new ModuleCatalogProduct();
     $album_id = false;
     foreach ($product as $key => $value) {
         if ($key == 'Ид') {
             $model->xml_id = $value;
         } else {
             if ($key == 'Наименование') {
                 $model->name = $value;
             } else {
                 if ($key == 'БазоваяЕдиница') {
                     $model->unit = $value;
                 } else {
                     if ($key == 'Картинка') {
                         if (!is_array($value)) {
                             $value = array($value);
                         }
                         foreach ($value as $value_img) {
                             $name = explode('\\', $value_img);
                             $src = $_SERVER['DOCUMENT_ROOT'] . '/upload/xml/extract/e' . str_replace('\\', '//', $value_img);
                             $folder = $_SERVER['DOCUMENT_ROOT'] . '/' . Files::model()->getUploadFolder('catalog', true, true);
                             if (count($name) - 1 > 0 && file_exists($src) && $name[count($name) - 1] != 'www.eldorado.ru') {
                                 $thumb = Yii::app()->thumb->create($src);
                                 $iname = explode('.', $name[count($name) - 1]);
                                 //&& copy($src, $folder.'/'.$name[count($name) - 1])
                                 if (empty($album_id)) {
                                     $album_id = ModuleGalleryAlbums::model()->createAlbum('catalog');
                                 }
                                 $thumb->resize(320, 340);
                                 $thumb->save($folder . '/' . $iname[count($iname) - 2] . '_large.' . $iname[count($iname) - 1]);
                                 $files = new Files();
                                 $files->file_name = $iname[count($iname) - 2] . '_large.' . $iname[count($iname) - 1];
                                 $files->temp = 1;
                                 $files->save();
                                 ModuleGalleryPhotos::model()->createPhoto($album_id, $files->id);
                                 $thumb->resize(190, 190);
                                 $thumb->save($folder . '/' . $iname[count($iname) - 2] . '_catalog.' . $iname[count($iname) - 1]);
                                 $files = new Files();
                                 $files->file_name = $iname[count($iname) - 2] . '_catalog.' . $iname[count($iname) - 1];
                                 $files->temp = 1;
                                 $files->save();
                                 ModuleGalleryPhotos::model()->createPhoto($album_id, $files->id);
                                 $thumb->resize(100, 100);
                                 $thumb->save($folder . '/' . $iname[count($iname) - 2] . '_small.' . $iname[count($iname) - 1]);
                                 $files = new Files();
                                 $files->file_name = $iname[count($iname) - 2] . '_small.' . $iname[count($iname) - 1];
                                 $files->temp = 1;
                                 $files->save();
                                 ModuleGalleryPhotos::model()->createPhoto($album_id, $files->id);
                             }
                         }
                     } else {
                         if ($key == 'Группы' && is_array($value)) {
                             $value_group = $this->getProductGroupXmlId($value);
                             $category_id = ModuleCatalogCategory::model()->getCategoryIdByXmlCode($value_group);
                             if (!empty($category_id)) {
                                 $model->category_id = $category_id;
                             }
                         }
                     }
                 }
             }
         }
     }
     if (!empty($album_id)) {
         $model->album_id = $album_id;
     }
     if ($model->save() && isset($product["ХарактеристикиТовара"]["ХарактеристикаТовара"])) {
         $this->addProperties($product["ХарактеристикиТовара"]["ХарактеристикаТовара"], $model->id, $product);
     }
 }
Example #2
0
 public function imageUpload($module_name, $width, $height, $resize, $compare_width, $compare_height, $with_album = false, $album_id = null)
 {
     Yii::import("ext.EAjaxUpload.qqFileUploader");
     $result = false;
     try {
         $uploader = new qqFileUploader(array("jpg", "jpeg", "gif", "png", "bmp"), 8 * 1024 * 1024);
         $upload_folder = $this->getUploadFolder($module_name);
         $result = $uploader->handleUpload($upload_folder);
         if (isset($result["error"]) && strlen($result["error"]) > 0) {
             throw new Exception("Не удаётся загрузить файл.");
         } else {
             $image_path = $upload_folder . $result["filename"];
             $thumb = Yii::app()->thumb->create($image_path);
             if ($resize) {
                 $thumb->resize($width, $height);
                 $thumb->save($image_path);
             } else {
                 list($current_width, $current_height) = getimagesize($image_path);
                 if ($this->resolutionCompare($current_width, $width, $compare_width) || $this->resolutionCompare($current_height, $height, $compare_height)) {
                     $result = array('error' => 'Upload image resolution is incorrect !');
                 }
             }
             if (!isset($result["error"])) {
                 $model = new Files();
                 $model->file_name = $result["filename"];
                 $model->temp = 1;
                 $model->module = $module_name;
                 $model->save();
                 if ($with_album) {
                     if (is_null($album_id)) {
                         $album_id = ModuleGalleryAlbums::model()->createAlbum($module_name);
                         Yii::app()->session->add('album_id', $album_id);
                     }
                     $photo_id = ModuleGalleryPhotos::model()->createPhoto($album_id, $model->id);
                 }
                 $result["image_id"] = $model->id;
                 $result["album_id"] = $album_id;
                 if (isset($photo_id)) {
                     $result["photo_id"] = $photo_id;
                 }
             }
         }
     } catch (Exception $e) {
         $result = array('error' => $result["filename"]);
     }
     return $result;
 }