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));
 }
Beispiel #2
0
 /**
  * Parse url
  *
  * @param $manager
  * @param $request
  * @param $pathInfo
  * @param $rawPathInfo
  *
  * @return bool|string
  */
 public function parseUrl($manager, $request, $pathInfo, $rawPathInfo)
 {
     if (preg_match('%^(/?([\\w\\-.]+))+$%', $pathInfo, $matches)) {
         $pages = preg_split("/\\//", $pathInfo);
         $element_arr = explode('.', end($pages));
         $element = $element_arr[0];
         if ($page = CatalogCategory::model()->find(array('condition' => 'link=:link', 'params' => array(':link' => $element)))) {
             return '/services/default/category/link/' . $element;
         } else {
             if ($service = CatalogService::model()->find(array('condition' => 'link=:link', 'params' => array(':link' => $element)))) {
                 return '/services/default/service/id/' . $service->id;
             } else {
                 return false;
             }
         }
     }
     return false;
 }
Beispiel #3
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;
     }
 }
Beispiel #4
0
 /**
  * Returns the data model based on the primary key given in the GET variable
  * If the data model is not found, an HTTP exception will be raised
  *
  * @param $id the ID of the model to be loaded
  *
  * @return mixed
  * @throws CHttpException
  */
 public function loadModel($id)
 {
     $model = CatalogService::model()->findByPk($id);
     if ($model === null) {
         throw new CHttpException(404, 'The requested page does not exist.');
     }
     return $model;
 }