Example #1
0
 public function run()
 {
     $limit = CatalogConfig::model()->findByPk(1, array('select' => 'widget_count'));
     $limit = $limit->widget_count;
     $criteria = new CDbCriteria();
     $criteria->limit = $limit;
     $criteria->order = 'id ASC';
     $services = CatalogService::model()->findAll($criteria);
     $this->render('main_page_services', array('services' => $services));
 }
Example #2
0
 /**
  * Output config
  */
 public function actionIndex()
 {
     $model = CatalogConfig::model()->findByPk(1);
     if (isset($_POST['CatalogConfig'])) {
         $model->attributes = $_POST['CatalogConfig'];
         if ($model->save()) {
             Yii::app()->user->setFlash('success', "Изменения успешно сохранены!");
         }
     }
     $this->render('index', array('model' => $model));
 }
Example #3
0
 /**
  * List categories
  *
  * @param string $link
  *
  * @throws CHttpException
  */
 public function actionCategory($link)
 {
     $category = $this->loadCategoryModel($link);
     $this->breadcrumbs = CatalogCategory::getBreadcrumbs($category->id, false);
     $this->breadcrumbs[] = $category->short_title;
     $this->metaInfoGenerate($category->short_title, $category->keywords, $this->catalog_config->description);
     if ($this->catalog_config->layout) {
         $this->layout = $this->catalog_config->layout;
     }
     $dataProvider = new CActiveDataProvider('CatalogService', array('criteria' => array('order' => 'sort_order ASC', 'condition' => 'id_category =' . $category->id), 'pagination' => array('pageSize' => CatalogConfig::model()->findByPk(1)->service_perpage)));
     $this->render('view', array('category' => $category, 'dataProvider' => $dataProvider));
 }
Example #4
0
 protected function beforeSave()
 {
     $catalog_config = CatalogConfig::model()->findByPk($this->id);
     $old_image = $catalog_config->watermark_image;
     if (parent::beforeSave()) {
         if ($image = CUploadedFile::getInstance($this, 'watermark_image')) {
             $name = md5(time() . $image) . '.' . $image->getExtensionName();
             $this->watermark_image = $name;
             $image->saveAs($this->productImagesFolder . '/watermark/' . $name);
             //Удаляем старую картинку
             @unlink($this->productImagesFolder . '/watermark/' . $old_image);
         } else {
             $this->watermark_image = $old_image;
         }
         return true;
     } else {
         return false;
     }
 }
 public function __construct($id, $module = null)
 {
     parent::__construct($id, $module);
     // загружаем конфигурацию каталога
     $this->catalog_config = CatalogConfig::model()->findByPk(1);
 }
Example #6
0
 public static function getBreadcrumbs($id, $product = false)
 {
     $data = array();
     if ($id != 0) {
         $parents = CatalogCategory::model()->findByPk($id);
         $title = CatalogConfig::model()->findByPk(1)->title;
         if ($product == true) {
             $data[$parents->title] = array('/catalog' . CatalogCategory::getCategoryRouteFast($parents));
         }
         while ($parents = CatalogCategory::getParent($parents->parent_id)) {
             //echo $parents->title;
             $data[$parents->title] = array('/catalog' . CatalogCategory::getCategoryRouteFast($parents));
         }
         $data[$title] = array('/catalog');
     }
     //echo 'rtr'.var_dump($data);
     return array_reverse($data);
 }
Example #7
0
 /**
  * Construct
  *
  * @param integer $id
  * @param null $module
  */
 public function __construct($id, $module = null)
 {
     parent::__construct($id, $module);
     $this->catalog_config = CatalogConfig::model()->findByPk(1);
 }
 function actSaveConfig()
 {
     global $ST, $post;
     $config = new CatalogConfig();
     $config->save($post->get());
     echo printJSON(array('msg' => 'Сохранено'));
     exit;
 }
Example #9
0
 protected function beforeSave()
 {
     if (parent::beforeSave()) {
         // Читаем конфигурацию каталога
         $catalog_config = CatalogConfig::model()->findByPk(1);
         //Перед записью загружаем картинки
         // Если это не новая запись - Берем старую модель для удаления старой картинки
         if (!$this->isNewRecord) {
             $old_model = CatalogProduct::model()->findByPk($this->id);
             $old_image = $old_model->photo;
         } else {
             $old_image = '';
             // тут же записываем дату создания
             $this->date_added = time();
         }
         $this->article = trim($this->article);
         if ($photo = CUploadedFile::getInstance($this, 'photo') or $photo = CUploadedFile::getInstance(new ResponseForm(), 'photo')) {
             $name = md5(time() . $photo) . '.' . $photo->getExtensionName();
             $this->photo = $name;
             $photo->saveAs($this->folder . '/' . $name);
             if (isset($catalog_config->watermark_image) && !$catalog_config->no_watermark) {
                 Yii::app()->ih->load($this->folder . '/' . $this->photo)->watermark($this->folder . '/watermark/' . $catalog_config->watermark_image, $catalog_config->watermark_x, $catalog_config->watermark_y)->save();
             }
             Yii::app()->ih->load($this->folder . '/' . $this->photo)->adaptiveThumb($catalog_config->p_image_middle_w, $catalog_config->p_image_middle_h)->save($this->folder . '/medium/' . $this->photo, false, 100)->reload()->adaptiveThumb($catalog_config->p_image_small_w, $catalog_config->p_image_small_h)->save($this->folder . '/small/' . $this->photo, false, 100);
             if ($old_image) {
                 //Удаляем старые картинки
                 @unlink($this->folder . '/' . $old_image);
                 @unlink($this->folder . '/medium/' . $old_image);
                 @unlink($this->folder . '/small/' . $old_image);
             }
         } else {
             if (!$this->photo) {
                 $this->photo = $old_image;
             }
         }
         $productImages = new CatalogImage();
         if ($productImagesUpload = CUploadedFile::getInstances($productImages, 'image')) {
             foreach ($productImagesUpload as $file) {
                 $productImages = new CatalogImage();
                 $productImagesName = md5(time() . $file->name) . '.' . $file->getExtensionName();
                 $productImages->image = $productImagesName;
                 $file->saveAs($this->folder . '/moreimages/' . $productImagesName);
                 $this->images[] = $productImages;
                 if (isset($catalog_config->watermark_image) && !$catalog_config->no_watermark) {
                     Yii::app()->ih->load($this->folder . '/moreimages/' . $productImagesName)->watermark($this->folder . '/watermark/' . $catalog_config->watermark_image, $catalog_config->watermark_x, $catalog_config->watermark_y)->save();
                 }
                 Yii::app()->ih->load($this->folder . '/moreimages/' . $productImagesName)->adaptiveThumb($catalog_config->p_image_small_w, $catalog_config->p_image_small_h)->save($this->folder . '/moreimages/small/' . $productImagesName, false, 100)->reload()->adaptiveThumb($catalog_config->p_image_middle_w, $catalog_config->p_image_middle_h)->save($this->folder . '/moreimages/medium/' . $productImagesName, false, 100);
             }
         }
         return true;
     } else {
         return false;
     }
 }
Example #10
0
 /**
  * Get breadcrumbs
  *
  * @param integer $id
  * @param bool $service
  *
  * @return array
  */
 public static function getBreadcrumbs($id, $service = true)
 {
     $catalogConfig = CatalogConfig::model()->findByPk(1);
     $data = array();
     if ($id != 0) {
         $parents = CatalogCategory::model()->findByPk($id);
         if ($service == true) {
             $data[$parents->short_title] = array('/services' . CatalogCategory::getCategoryRoute($parents->link));
         }
     }
     $data[$catalogConfig->title] = array('/services');
     return array_reverse($data);
 }
Example #11
0
 /**
  * Before save
  *
  * @return bool
  */
 protected function beforeSave()
 {
     if (parent::beforeSave()) {
         $catalogConfig = CatalogConfig::model()->findByPk(1);
         if (!$this->isNewRecord) {
             $old_model = CatalogService::model()->findByPk($this->id);
             $old_image = $old_model->photo;
         } else {
             $old_image = '';
         }
         if ($photo = CUploadedFile::getInstance($this, 'photo')) {
             $name = md5(time() . $photo) . '.' . $photo->getExtensionName();
             $this->photo = $name;
             $photo->saveAs($this->folder . '/' . $name);
             if ($catalogConfig->watermark_image && !$catalogConfig->no_watermark) {
                 Yii::app()->ih->load($this->folder . '/' . $this->photo)->watermark($this->folder . '/watermark/' . $catalogConfig->watermark_image, $catalogConfig->watermark_x, $catalogConfig->watermark_y)->save();
             }
             switch ($catalogConfig->resize_mode) {
                 case 2:
                     Yii::app()->ih->load($this->folder . '/' . $this->photo)->resizeCanvas($catalogConfig->s_image_middle_w, $catalogConfig->s_image_middle_h)->save($this->folder . '/medium/' . $this->photo)->reload()->resizeCanvas($catalogConfig->s_image_small_w, $catalogConfig->s_image_small_h)->save($this->folder . '/small/' . $this->photo);
                     break;
                 default:
                     Yii::app()->ih->load($this->folder . '/' . $this->photo)->resize($catalogConfig->s_image_middle_w, $catalogConfig->s_image_middle_h)->save($this->folder . '/medium/' . $this->photo)->reload()->resize($catalogConfig->s_image_small_w, $catalogConfig->s_image_small_h)->save($this->folder . '/small/' . $this->photo);
                     break;
             }
             if ($old_image) {
                 @unlink($this->folder . '/' . $old_image);
                 @unlink($this->folder . '/medium/' . $old_image);
                 @unlink($this->folder . '/small/' . $old_image);
             }
         } else {
             $this->photo = $old_image;
         }
         $serviceImages = new CatalogImage();
         if ($serviceImagesUpload = CUploadedFile::getInstances($serviceImages, 'image')) {
             foreach ($serviceImagesUpload as $file) {
                 $serviceImages = new CatalogImage();
                 $serviceImagesName = md5(time() . $file->name) . '.' . $file->getExtensionName();
                 $serviceImages->image = $serviceImagesName;
                 $file->saveAs($this->folder . '/moreimages/' . $serviceImagesName);
                 $this->images[] = $serviceImages;
                 if ($catalogConfig->watermark_image && !$catalogConfig->no_watermark) {
                     Yii::app()->ih->load($this->folder . '/moreimages/' . $serviceImagesName)->watermark($this->folder . '/watermark/' . $catalogConfig->watermark_image, $catalogConfig->watermark_x, $catalogConfig->watermark_y)->save();
                 }
                 switch ($catalogConfig->resize_mode) {
                     case 2:
                         Yii::app()->ih->load($this->folder . '/moreimages/' . $serviceImagesName)->resizeCanvas($catalogConfig->s_image_small_w, $catalogConfig->s_image_small_h)->save($this->folder . '/moreimages/small/' . $serviceImagesName)->reload()->resizeCanvas($catalogConfig->s_image_middle_w, $catalogConfig->s_image_middle_h)->save($this->folder . '/moreimages/medium/' . $serviceImagesName);
                         break;
                     default:
                         Yii::app()->ih->load($this->folder . '/moreimages/' . $serviceImagesName)->resize($catalogConfig->s_image_small_w, $catalogConfig->s_image_small_h)->save($this->folder . '/moreimages/small/' . $serviceImagesName)->reload()->resize($catalogConfig->s_image_middle_w, $catalogConfig->s_image_middle_h)->save($this->folder . '/moreimages/medium/' . $serviceImagesName);
                         break;
                 }
             }
         }
         return true;
     } else {
         return false;
     }
 }