function authors()
 {
     App::import('Helper', 'Slug');
     $slug = new SlugHelper();
     $authorName = $slug->deslug($this->params['pass'][0]);
     $this->set(array('blogs' => $this->Blog->find('all', array('conditions' => array('Blog.status' => 'active', 'Blog.author' => $authorName), 'order' => array('Blog.stamp' => 'DESC'))), 'author' => $authorName));
 }
Example #2
0
 public static function boot()
 {
     parent::boot();
     static::saving(function ($post) {
         $changed = $post->isDirty() ? $post->getDirty() : array();
         if (!array_key_exists('title', $changed)) {
             return;
         }
         $slugHelper = new SlugHelper($post->id);
         $post->slug = $slugHelper->sluggify($post->title);
     });
 }
    protected function beforeSave() {
        if(parent::beforeSave()) {

            // Create slug
            if(!$this->url){
                Yii::import('ext.SlugHelper.SlugHelper');
                $this->url = SlugHelper::run($this->title, 'yandex');
            }

            $unique = $this->url;

            $suffix = 1;

            while ($this->checkUniqueUrl($unique) > 0){
                $unique = $this->url.$suffix;
                $suffix++;
            }
            $this->url =  $unique;
            
            if($this->isNewRecord) {
                $this->status_id = self::STATUS_ACTIVE;
            } 
            $this->updated_date = date('Y-m-d H:i:s');
            return true;
        } else
            return false;
    } 
Example #4
0
 public function beforeSave()
 {
     if (empty($this->url)) {
         // Create slug
         Yii::import('ext.SlugHelper.SlugHelper');
         $this->url = SlugHelper::run(preg_replace('/\\s{2,}/', ' ', $this->name));
     }
     // Check if url available
     if ($this->isNewRecord) {
         $test = StoreProduct::model()->withUrl($this->url)->count();
         $this->created = date('Y-m-d H:i:s');
     } else {
         $test = StoreProduct::model()->withUrl($this->url)->count('t.id!=:id', array(':id' => $this->id));
     }
     // Create unique url
     if ($test > 0) {
         $this->url .= '-' . date('YmdHis');
     }
     return parent::beforeSave();
 }
Example #5
0
	public function beforeSave()
	{
		if(parent::beforeSave()) {

			$reurl = false;
			if($this->isNewRecord) {
				$this->_newRec = true;
				$this->author = (Yii::app()->user)?Yii::app()->user->id:null;
			} else {
				$this->_curr = self::findByPk($this->id,array('select'=>'status_org'));
               if($this->_curr) {
                	if($this->title != $this->_curr->title)
                        $reurl = true;
	        	} 

			}

			// Create slug
			Yii::import('ext.SlugHelper.SlugHelper');
	        if(!$this->url  || $reurl){
	          //  $this->url = SlugHelper::run(preg_replace('/\s{2,}/', ' ', $this->synonim));
	            $this->url = SlugHelper::run($this->title, 'yandex');
	        } else {
	        	$this->url = SlugHelper::run($this->url, 'yandex');
	        }

	        $this->description = trim(MHelper::String()->purifyFromScript($this->description));

	        $this->updated_date = date('Y-m-d H:i:s');
	        
    		return true;
        } else
            return false;
	}
Example #6
0
 /**
  * @return bool
  */
 public function beforeSave()
 {
     if (!$this->created && $this->isNewRecord) {
         $this->created = date('Y-m-d H:i:s');
     }
     if (!$this->updated) {
         $this->updated = date('Y-m-d H:i:s');
     }
     if (!Yii::app()->user->isGuest) {
         $this->user_id = Yii::app()->user->id;
     }
     if (empty($this->url)) {
         // Create slug
         Yii::import('ext.SlugHelper.SlugHelper');
         $this->url = SlugHelper::run($this->title);
     }
     // Check if url available
     if ($this->isNewRecord) {
         $test = Page::model()->withUrl($this->url)->count();
     } else {
         $test = Page::model()->withUrl($this->url)->count('id!=:id', array(':id' => $this->id));
     }
     if ($test > 0) {
         $this->url .= '-' . date('YmdHis');
     }
     return parent::beforeSave();
 }
Example #7
0
 public function beforeSave()
 {
     if (parent::beforeSave()) {
         // Create slug
         Yii::import('ext.SlugHelper.SlugHelper');
         if (!$this->url) {
             //  $this->url = SlugHelper::run(preg_replace('/\s{2,}/', ' ', $this->synonim));
             $this->url = SlugHelper::run($this->title, 'yandex');
         } else {
             $this->url = SlugHelper::run($this->url, 'yandex');
         }
         $this->updated_date = date('Y-m-d H:i:s');
         return true;
     } else {
         return false;
     }
 }
Example #8
0
 public function beforeSave()
 {
     if (parent::beforeSave()) {
         $reurl = false;
         if ($this->isNewRecord) {
             $this->_newRec = true;
             $this->author = Yii::app()->user ? Yii::app()->user->id : null;
         } else {
             $this->_curr = self::findByPk($this->id);
             if ($this->_curr) {
                 if ($this->title != $this->_curr->title) {
                     $reurl = true;
                 }
             }
         }
         // Create slug
         Yii::import('ext.SlugHelper.SlugHelper');
         if (!$this->url || $reurl) {
             //  $this->url = SlugHelper::run(preg_replace('/\s{2,}/', ' ', $this->synonim));
             $this->url = SlugHelper::run($this->title, 'yandex');
         } else {
             $this->url = SlugHelper::run($this->url, 'yandex');
         }
         $unique = $this->url;
         $addsuffix = 0;
         while ($this->checkUniqueUrl($unique) > 0) {
             $unique = $this->url . $suffix . '-' . $addsuffix;
             $addsuffix++;
         }
         $this->url = $unique;
         $this->description = trim(MHelper::String()->purifyFromScript($this->description));
         $this->updated_date = date('Y-m-d H:i:s');
         return true;
     } else {
         return false;
     }
 }
Example #9
0
 public function beforeSave()
 {
     if (parent::beforeSave()) {
         // Create slug
         Yii::import('ext.SlugHelper.SlugHelper');
         if (!$this->url) {
             //  $this->url = SlugHelper::run(preg_replace('/\s{2,}/', ' ', $this->synonim));
             $this->url = SlugHelper::run($this->title, 'yandex');
         } else {
             $this->url = SlugHelper::run($this->url, 'yandex');
         }
         $dt_fin = $this->date;
         if ($time = CDateTimeParser::parse($dt_fin, 'dd.MM.yyyy hh:mm')) {
             $this->date = date('Y-m-d H:i:s', $time);
         }
         $this->updated_date = date('Y-m-d H:i:s');
         return true;
     } else {
         return false;
     }
 }
Example #10
0
	protected function beforeSave() 
    {
        if(parent::beforeSave()) 
        {
        	// Create slug
            if(!$this->url)
            {
                Yii::import('ext.SlugHelper.SlugHelper');
                $this->url = SlugHelper::run($this->district_name, 'yandex');
            }
        	return true;

        } else
            return false;
    }
Example #11
0
 public function beforeSave()
 {
     if (!$this->created && $this->isNewRecord) {
         $this->created = date('Y-m-d H:i:s');
     }
     if (!$this->updated) {
         $this->updated = date('Y-m-d H:i:s');
     }
     if (empty($this->url)) {
         Yii::import('ext.SlugHelper.SlugHelper');
         $this->url = SlugHelper::run($this->name);
     }
     // Check if url available
     if ($this->isNewRecord) {
         $test = PageCategory::model()->withUrl($this->url)->count('parent_id=:parent_id', array(':parent_id' => $this->parent_id));
     } else {
         $test = PageCategory::model()->withUrl($this->url)->count('id!=:id AND parent_id=:parent_id', array(':id' => $this->id, ':parent_id' => $this->parent_id));
     }
     if ($test > 0) {
         $this->url .= '-' . date('YmdHis');
     }
     return parent::beforeSave();
 }
Example #12
0
 protected function beforeSave()
 {
     if (parent::beforeSave()) {
         $rename = false;
         if ($this->isNewRecord) {
             $this->status_id = self::STATUS_ACTIVE;
         } else {
             $curr = self::findByPk($this->id, array('select' => 'title'));
             if ($curr) {
                 if ($curr->title != $this->title) {
                     $rename = true;
                 }
             }
         }
         // Create slug
         Yii::import('ext.SlugHelper.SlugHelper');
         if (!$this->url || $rename) {
             $this->url = SlugHelper::run($this->title, 'yandex');
         } else {
             $this->url = SlugHelper::run($this->url, 'yandex');
         }
         $unique = $this->url;
         $suffix = 1;
         while ($this->checkUniqueUrl($unique) > 0) {
             $unique = $this->url . $suffix;
             $suffix++;
         }
         $this->url = $unique;
         return true;
     } else {
         return false;
     }
 }
Example #13
0
	public function beforeSave()
	{
		if(parent::beforeSave()) {
			$ydata = false;
			$reurl = false;

			if($this->isNewRecord) {
				$this->ip_address = Yii::app()->request->userHostAddress;
				$ydata = true;
				$this->_newRec = true;
				$this->author = (!Yii::app()->user->isGuest)?Yii::app()->user->id:null;
			} else {
				$this->_curr = self::findByPk($this->id,array('select'=>'city_id,status,address,lat,lng'));
               if($this->_curr) {
                	if($this->title != $this->_curr->title)
                        $reurl = true;
	        	} 
				if($this->city_id != $this->_curr->city_id || $this->address != $this->_curr->address || !$this->lat || !$this->lng){
		                $ydata = true;
		        }
			}

			if($ydata == true){

			if(!empty($this->address)){

				$address = $this->address;

				$params = array(
				    'geocode' => $address, // адрес
				    'format'  => 'json',                          // формат ответа
				    'results' => 1,                               // количество выводимых результатов
				  //  'key'     => '...',                           // ваш api key
				);
				$response = json_decode(@file_get_contents('http://geocode-maps.yandex.ru/1.x/?' . http_build_query($params, '', '&')));

				$result = ''; 
				if ($response && isset($response->response) && $response->response->GeoObjectCollection->metaDataProperty->GeocoderResponseMetaData->found > 0)
				{
				    $result = $response->response->GeoObjectCollection->featureMember[0]->GeoObject->Point->pos;
				    if($result){
				    	$exp_str1 = explode(" ", $result);
						$this->lat = $exp_str1[1];
						$this->lng = $exp_str1[0]; 
					
					   // $this->yanData();
				    }
				}

			}
			}
			// Create slug
			Yii::import('ext.SlugHelper.SlugHelper');
	        if(!$this->url  || $reurl){
	           $this->url = SlugHelper::run($this->title, 'yandex');
	        } else {
	        	$this->url = SlugHelper::run($this->url, 'yandex');
	        }

	        $this->updated_date = date('Y-m-d H:i:s');

    		return true;
        } else
            return false;
	}
Example #14
0
	public function beforeSave()
	{
		if(parent::beforeSave()) {
			// Create slug
			Yii::import('ext.SlugHelper.SlugHelper');
	        if(!$this->name){
	           $this->name = SlugHelper::run($this->title, 'yandex');
	        } else {
	           $this->name = SlugHelper::run($this->name, 'yandex');
	        }
	        $unique = $this->name;

            $suffix = 1;
            while ($this->checkUniqueUrl($unique) > 0){
                $unique = $this->name.$suffix;
                $suffix++;
            }
            $this->name =  $unique;

          	return true;

		} else
            return false;

	}
Example #15
0
 /**
  * Import product properties
  */
 public function importProperties()
 {
     foreach ($this->xml->{"Классификатор"}->{"Свойства"}->{"Свойство"} as $attribute) {
         $model = C1ExternalFinder::getObject(C1ExternalFinder::OBJECT_TYPE_ATTRIBUTE, $attribute->{"Ид"});
         if ($attribute->{"ЭтоФильтр"} == 'false') {
             $useInFilter = false;
         } else {
             $useInFilter = true;
         }
         if (!$model) {
             // Create new attribute
             $model = new StoreAttribute();
             $model->name = SlugHelper::run($attribute->{"Наименование"});
             $model->name = str_replace('-', '_', $model->name);
             $model->title = $attribute->{"Наименование"};
             $model->type = StoreAttribute::TYPE_DROPDOWN;
             $model->use_in_filter = $useInFilter;
             $model->display_on_front = true;
             if ($model->save()) {
                 // Add to type
                 $typeAttribute = new StoreTypeAttribute();
                 $typeAttribute->type_id = self::DEFAULT_TYPE;
                 $typeAttribute->attribute_id = $model->id;
                 $typeAttribute->save();
                 $this->createExternalId(C1ExternalFinder::OBJECT_TYPE_ATTRIBUTE, $model->id, $attribute->{"Ид"});
             }
         }
         // Update attributes
         $model->name = SlugHelper::run($attribute->{"Наименование"});
         $model->use_in_filter = $useInFilter;
         $model->save();
     }
 }
Example #16
0
    protected function beforeSave() 
    {
        if(parent::beforeSave()) 
        {

        	if($this->title)
        	{
				if($this->addcoordinates == true)
				{
					$address = '';
					if($this->region)
					{
						$address .= $this->regionid->title.', ';
					}
					$address .= $this->title;
					$params = array(
					    'geocode' => $address, // адрес
					    'format'  => 'json',                          // формат ответа
					    'results' => 1,                               // количество выводимых результатов
					   // 'kind'=>'locality'
					);
					$response = json_decode(@file_get_contents('http://geocode-maps.yandex.ru/1.x/?' . http_build_query($params, '', '&')));

					$result = ''; 
					if ($response && isset($response->response) && $response->response->GeoObjectCollection->metaDataProperty->GeocoderResponseMetaData->found > 0)
					{
					    $result = $response->response->GeoObjectCollection->featureMember[0]->GeoObject->Point->pos;
					    if($result){
					    	$exp_str1 = explode(" ", $result);
							$this->lat = $exp_str1[1];
							$this->lng = $exp_str1[0]; 
							
						    $this->yanData();
					    }
					}
					
				}
			}
            // Create slug
            if(!$this->url)
            {
                Yii::import('ext.SlugHelper.SlugHelper');
                $this->url = SlugHelper::run($this->title, 'yandex');
            }

            $unique = $this->url;

	        $suffix = '';
	        if($this->region)
	        {
	        	$suffix .= SlugHelper::run('-'.$this->region, 'yandex');
	        } 

	        $addsuffix = 0;
	        while ($this->checkUniqueUrl($unique) > 0)
	        {
	            if($addsuffix == 0)
	            {
	            	$unique = $this->url.$suffix; // добавляется регион
	            } else {
	            	$unique = $this->url.$suffix.'-'.$addsuffix; // если региона нет - цифра
	            }
	            $addsuffix++;
	        }
	        $this->url =  $unique;

            return true;
        } else
            return false;
    }
Example #17
0
 public function beforeSave()
 {
     if (empty($this->url)) {
         // Create slug
         Yii::import('ext.SlugHelper.SlugHelper');
         $this->url = SlugHelper::run($this->name);
     }
     // Check if url available
     if ($this->isNewRecord) {
         $test = StoreCategory::model()->withUrl($this->url)->count();
     } else {
         $test = StoreCategory::model()->withUrl($this->url)->count('id!=:id', array(':id' => $this->id));
     }
     // Create unique url
     if ($test > 0) {
         $this->url .= '-' . date('YmdHis');
     }
     $this->rebuildFullPath();
     return parent::beforeSave();
 }
Example #18
0
 /**
  * @return bool
  */
 public function beforeSave()
 {
     if (empty($this->url)) {
         // Create slug
         Yii::import('ext.SlugHelper.SlugHelper');
         $this->url = SlugHelper::run($this->title);
     }
     // Check if url available
     if ($this->isNewRecord) {
         $test = Event::model()->withUrl($this->url)->count();
     } else {
         $test = Event::model()->withUrl($this->url)->count('id!=:id', array(':id' => $this->id));
     }
     if ($test > 0) {
         $this->url .= '-' . date('YmdHis');
     }
     return parent::beforeSave();
 }
Example #19
0
    protected function beforeSave() {
        if(parent::beforeSave()) {

            // Create slug
            if(!$this->url){
                Yii::import('ext.SlugHelper.SlugHelper');
                $this->url = SlugHelper::run($this->title, 'yandex');
            }

            $unique = $this->url;

            $suffix = 1;

            while ($this->checkUniqueUrl($unique) > 0){
                $unique = $this->url.$suffix;
                $suffix++;
            }
            $this->url =  $unique;


            return true;
        } else
            return false;
    }