Ejemplo n.º 1
0
 public function afterDelete()
 {
     # Проверка и очистка связей
     $modifications = Modification::model()->findAll('model_id=:model_id', array(':model_id' => $this->id));
     if (count($modifications) > 0) {
         foreach ($modifications as $modification) {
             $modification->delete();
         }
     }
     return parent::afterDelete();
 }
 public function run()
 {
     Yii::import($this->import);
     $id = Yii::app()->request->getParam('id', 0);
     if ($id <= 0) {
         echo '{}';
     } else {
         $data = CHtml::listData(Modification::model()->findAll(array('condition' => 'model_id=' . $id, 'order' => 'title')), 'id', 'title');
         $data[0] = '';
         ksort($data);
         echo CJavaScript::jsonEncode($data);
     }
 }
 protected function saveChar($model)
 {
     if (!($brand = Brand::model()->find('alias=:alias', array(':alias' => $model->brand_alias)))) {
         $brand = new Brand();
     }
     $brand->title = $model->brand;
     $brand->alias = $model->brand_alias;
     $brand->save();
     if (!empty($brand->errors)) {
         d('brand ' . $brand->title);
         d($brand->errors);
     }
     if (!($car = Car::model()->find('alias=:alias', array(':alias' => $model->model_alias)))) {
         $car = new Car();
     }
     $car->brand_id = $brand->id;
     $car->title = $model->model;
     $car->alias = $model->model_alias;
     $car->manufacture_start = $model->modificationManufactureStart . '0101';
     $car->manufacture_end = $model->modificationManufactureEnd ? $model->modificationManufactureEnd . '0101' : null;
     $car->save();
     if (!empty($car->errors)) {
         d('model ' . $car->title);
         d($car->errors);
     }
     if (!($mod = Modification::model()->find('alias=:alias', array(':alias' => $model->mod_alias)))) {
         $mod = new Modification();
     }
     $mod->model_id = $car->id;
     $mod->title = $model->mod;
     $mod->alias = $model->mod_alias;
     $mod->manufacture_start = $model->modificationManufactureStart . '0101';
     $mod->manufacture_end = $model->modificationManufactureEnd ? $model->modificationManufactureEnd . '0101' : null;
     $mod->save();
     if (!empty($mod->errors)) {
         d('mod ' . $mod->title);
         d($mod->errors);
     }
     if (!($char = Characteristic::model()->find('modification_id=:mod_id', array(':mod_id' => $mod->id)))) {
         $char = new Characteristic();
     }
     $char->attributes = $model->char->attributes;
     $char->modification_id = $mod->id;
     $char->save();
     if (!empty($char->errors)) {
         d('char ' . $mod->title);
         d($char->errors);
         d($model->url);
     }
 }
 /**
  * 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.
  */
 public function loadModel()
 {
     if ($this->_model === null) {
         if (isset($_GET['id'])) {
             $this->_model = Modification::model()->findbyPk($_GET['id']);
         }
         if ($this->_model === null) {
             throw new CHttpException(404, 'The requested page does not exist.');
         }
     }
     return $this->_model;
 }
Ejemplo n.º 5
0
</label><br />
			<?php 
echo CHtml::dropDownList(get_class($model) . '[brand_id]', '', array());
?>
			<img src='/images/loader.gif' class='loader' style='display: none;'>
		</div>
		<?php 
if ($options['select'] != 'Brand') {
    ?>
		
		<div id='<?php 
    echo $this->id;
    ?>
_model' style='display: none;'>
			<label for='model_id'><?php 
    echo Modification::model()->getAttributeLabel('model_id');
    ?>
</label><br />
			<?php 
    echo CHtml::dropDownList(get_class($model) . '[model_id]', '', array());
    ?>
			<img src='/images/loader.gif' class='loader' style='display: none;'>
		</div>
		
		<?php 
}
?>

		<?php 
if ($options['select'] != 'Brand' && $options['select'] != 'Car') {
    ?>
 /**
  * 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 integer the ID of the model to be loaded
  */
 public function loadModel($id)
 {
     $model = Modification::model()->findByPk($id);
     if ($model === null) {
         throw new CHttpException(404, 'The requested page does not exist.');
     }
     return $model;
 }
Ejemplo n.º 7
0
 /**
  * Retrieves a list of models based on the current search/filter conditions.
  * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
  */
 public function search()
 {
     // Warning: Please modify the following code to remove attributes that
     // should not be searched.
     $criteria = new CDbCriteria();
     $criteria->compare('id', $this->id);
     if (Yii::app()->request->isAjaxRequest) {
         if ($model = Yii::app()->request->getParam('Characteristic', false)) {
             $a = CHtml::listData(Modification::model()->findAll('title like :title', array(':title' => '%' . $model['modificationTitle'] . '%')), 'id', 'id');
             if (count($a) > 0) {
                 $criteria->compare('modification_id', $a);
             } elseif ($modification['modificationTitle']) {
                 $criteria->compare('modification_id', 0);
             } else {
                 $criteria->compare('modification_id', array());
             }
             $criteria->compare('modification_id', $a);
             $this->modificationTitle = $model['modificationTitle'];
             $a = Car::model()->findAll('title like :title', array(':title' => '%' . $model['modelTitle'] . '%'));
             $tmp = array();
             foreach ($a as $m) {
                 if (count($m->modifications) > 0) {
                     foreach ($m->modifications as $t) {
                         $tmp[$t->id] = $t->id;
                     }
                 }
             }
             $a = $tmp;
             if (count($a) > 0) {
                 $criteria->compare('modification_id', $a);
             } elseif ($modification['modelTitle']) {
                 $criteria->compare('modification_id', 0);
             } else {
                 $criteria->compare('modification_id', array());
             }
             $criteria->compare('modification_id', $a);
             $this->modelTitle = $model['modelTitle'];
             $a = Brand::model()->findAll('title like :title', array(':title' => '%' . $model['brandTitle'] . '%'));
             $tmp = array();
             foreach ($a as $b) {
                 if (count($b->models) > 0) {
                     foreach ($b->models as $m) {
                         if (count($m->modifications) > 0) {
                             foreach ($m->modifications as $t) {
                                 $tmp[$t->id] = $t->id;
                             }
                         }
                     }
                 }
             }
             $a = $tmp;
             if (count($a) > 0) {
                 $criteria->compare('modification_id', $a);
             } elseif ($modification['brandTitle']) {
                 $criteria->compare('modification_id', 0);
             } else {
                 $criteria->compare('modification_id', array());
             }
             $criteria->compare('modification_id', $a);
             $this->brandTitle = $model['brandTitle'];
         }
     }
     $criteria->compare('fuel_capacity', $this->fuel_capacity);
     $criteria->compare('body', $this->body, true);
     $criteria->compare('doors', $this->doors);
     $criteria->compare('seats', $this->seats, true);
     $criteria->compare('weight', $this->weight);
     $criteria->compare('weight_loaded', $this->weight_loaded);
     $criteria->compare('top_speed_at', $this->top_speed_at);
     $criteria->compare('acceleration_at', $this->acceleration_at);
     $criteria->compare('top_speed_mt', $this->top_speed_mt);
     $criteria->compare('acceleration_mt', $this->acceleration_mt);
     $criteria->compare('turn_radius', $this->turn_radius);
     $criteria->compare('trunk_capacity', $this->trunk_capacity, true);
     $criteria->compare('length', $this->length);
     $criteria->compare('width', $this->width);
     $criteria->compare('height', $this->height);
     $criteria->compare('track_front', $this->tyres_front);
     $criteria->compare('track_rear', $this->tyres_front);
     $criteria->compare('track_front', $this->disks_front);
     $criteria->compare('track_rear', $this->disks_front);
     $criteria->compare('wheelbase', $this->wheelbase);
     $criteria->compare('engine_type', $this->engine_type, true);
     $criteria->compare('volume', $this->volume);
     $criteria->compare('displacement', $this->displacement, true);
     $criteria->compare('cylinders', $this->cylinders, true);
     $criteria->compare('valves', $this->valves);
     $criteria->compare('max_power', $this->max_power);
     $criteria->compare('max_power_rpm', $this->max_power_rpm, true);
     $criteria->compare('max_torque', $this->max_torque);
     $criteria->compare('max_torque_rpm', $this->max_torque_rpm, true);
     $criteria->compare('transmission_at', $this->transmission_at, true);
     $criteria->compare('gears_at', $this->gears_at, true);
     $criteria->compare('transmission_mt', $this->transmission_mt, true);
     $criteria->compare('gears_mt', $this->gears_mt, true);
     $criteria->compare('drive', $this->drive, true);
     $criteria->compare('suspension_front', $this->suspension_front, true);
     $criteria->compare('suspension_rear', $this->suspension_rear, true);
     $criteria->compare('tyres_front', $this->tyres_front, true);
     $criteria->compare('tyres_rear', $this->tyres_rear, true);
     $criteria->compare('brakes_front', $this->brakes_front, true);
     $criteria->compare('brakes_rear', $this->brakes_rear, true);
     $criteria->compare('fuel_consumption_urban_at', $this->fuel_consumption_urban_at);
     $criteria->compare('fuel_consumption_country_at', $this->fuel_consumption_country_at);
     $criteria->compare('fuel_consumption_combined_at', $this->fuel_consumption_combined_at);
     $criteria->compare('fuel_consumption_urban_mt', $this->fuel_consumption_urban_mt);
     $criteria->compare('fuel_consumption_country_mt', $this->fuel_consumption_country_mt);
     $criteria->compare('fuel_consumption_combined_mt', $this->fuel_consumption_combined_mt);
     $criteria->compare('fuel_type', $this->fuel_type, true);
     return new CActiveDataProvider('Characteristic', array('criteria' => $criteria, 'pagination' => array('pageSize' => Yii::app()->params['linesPerPage'])));
 }