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); } }
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; }
public function getList4($id, $mpage_id, $maxlevel = 1, $level = 1, $param_list = false) { if ($level > $maxlevel) { return NULL; } /*//$modulelist4 = new ModuleList4(); //$val = $modulelist4->findByAttributes(array('id' => $id, 'mpage_id' => $mpage_id)); //if (is_null($val)) return NULL; $val = (object) array('id'=>$id); //$list4 = $val->getAttributes(); $list4 = array('id'=>$id);*/ $modulelist4 = new ModuleList4(); $val = $modulelist4->findByAttributes(array('id' => $id, 'mpage_id' => $mpage_id)); if (is_null($val)) { return NULL; } $list4 = $val->getAttributes(); if ($param_list !== false) { $params = ModuleList4Params::model()->findAllByAttributes(array('mpage_id' => $mpage_id, 'code' => $param_list)); } else { $params = ModuleList4Params::model()->findAllByAttributes(array('mpage_id' => $mpage_id)); } foreach ($params as $param) { $list4['params'][$param->id] = $param->getAttributes(); $list4['params'][$param->id]['settings'] = unserialize($list4['params'][$param->id]['settings']); switch ($param->data_type_id) { case '1': case '2': case '3': case '4': $values = ModuleList4Values::model()->findAllByAttributes(array('param_id' => $param->id, 'item_id' => $val->id)); $j = 0; foreach ($values as $value) { $list4['params'][$param->id]['values'][$j] = $value->getAttributes(); $list4['params'][$param->id]['values'][$j]['value'] = $value->value; $j++; } break; /* case '3': $values = ModuleList4Values::model()->findAllByAttributes( array( 'param_id' => $param->id, 'item_id' => $val->id, ) ); $j = 0; foreach ($values as $value) { $list4['params'][$param->id]['values'][$j] = $value->getAttributes(); $list4['params'][$param->id]['values'][$j]['value'] = $value->value; $j++; } break; case '4': $values = ModuleList4Values::model()->findAllByAttributes( array( 'param_id' => $param->id, 'item_id' => $val->id, ) ); $j = 0; foreach ($values as $value) { $list4['params'][$param->id]['values'][$j] = $value->getAttributes(); $list4['params'][$param->id]['values'][$j]['value'] = $value->value; $j++; } break; */ /* case '3': $values = ModuleList4Values::model()->findAllByAttributes( array( 'param_id' => $param->id, 'item_id' => $val->id, ) ); $j = 0; foreach ($values as $value) { $list4['params'][$param->id]['values'][$j] = $value->getAttributes(); $list4['params'][$param->id]['values'][$j]['value'] = $value->value; $j++; } break; case '4': $values = ModuleList4Values::model()->findAllByAttributes( array( 'param_id' => $param->id, 'item_id' => $val->id, ) ); $j = 0; foreach ($values as $value) { $list4['params'][$param->id]['values'][$j] = $value->getAttributes(); $list4['params'][$param->id]['values'][$j]['value'] = $value->value; $j++; } break; */ case '5': $values = ModuleList4Values::model()->findAllByAttributes(array('param_id' => $param->id, 'item_id' => $val->id)); $j = 0; foreach ($values as $value) { $list4['params'][$param->id]['values'][$j] = $value->getAttributes(); $list4['params'][$param->id]['values'][$j]['value'] = ModuleList4ParamsValues::model()->findByPk($value->value)->title; $tmp_value = ModuleList4ParamsValues::model()->findByPk($value->value); if ($tmp_value) { $tmp_value_id = $tmp_value->id; $list4['params'][$param->id]['values'][$j]['value_id'] = $tmp_value_id; } // $list4['params'][$param->id]['values'][$j]['value_id'] = ModuleList4ParamsValues::model()-> // findByPk($value->value)->id; $j++; } break; // $values = ModuleList4Values::model()->with('list4paramsvalues')->findAllByAttributes( // array( // 't.param_id' => $param->id, // 't.item_id' => $val->id, // ) // ); // $j = 0; // foreach ($values as $value) { // $list4['params'][$param->id]['values'][$j] = $value->getAttributes(); // $list4['params'][$param->id]['values'][$j]['value'] = $value->list4paramsvalues->title; // $j++; // } break; case '8': $value = ModuleList4Values::model()->findByAttributes(array('param_id' => $param->id, 'item_id' => $val->id)); $photos = array(); // $gId = $list4['params'][$param->id]['value'] = '1234123412';//$value->value; $gId = $value->value; foreach (ModuleGalleryPhotos::model()->with('file')->findAllByAttributes(array('gallery_id' => $gId)) as $item) { $photos[] = $item->file->file_name; } $list4['params'][$param->id]['value'] = $photos; break; case '9': $linked_mpages = array(); foreach (ModuleList4ParamsList4::model()->findAllByAttributes(array('param_id' => $param->id)) as $link) { $linked_mpages[] = $link->mpage_id; } $j = 0; foreach ($linked_mpages as $linked_mpage) { $allowed = array(); foreach ($modulelist4->findAllByAttributes(array('mpage_id' => $linked_mpage)) as $v) { $allowed[] = $v->id; } $linkparams = ModuleList4List4::model()->findAllByAttributes(array('id_1' => $val->id, 'id_2' => $allowed)); foreach ($linkparams as $linkparam) { $list4['params'][$param->id]['values'][$j] = $linkparam->getAttributes(); $list4['params'][$param->id]['values'][$j]['value'] = $this->getList4($linkparam->id_2, $linked_mpage, $maxlevel, $level + 1, $param_list); $j++; } } break; default: break; } } return $list4; }
public function deleteItem($mpage_id, $id, $module) { $result = false; if (!is_null($id) && $this->existsItem($mpage_id, $id)) { $result = true; if (ModuleGalleryPhotos::model()->deleteList($id, $module) && $this->findByPk($id)->delete()) { $result = true; } } return $result; }
public function actionDelete_photo($id = null) { $out = ''; if (ModuleGalleryPhotos::model()->deleteItem($id, $this->module->id)) { $out = '0'; } else { $out = '1'; } echo $out; }