Exemplo n.º 1
0
 protected function loadModel($id)
 {
     $model = Car::model()->findByPk($id);
     if (empty($model)) {
         throw new CHttpException(404, 'ผิดพลาดการดึงข้อมูลรถ ลองใหม่อีกครั้ง');
     }
     return $model;
 }
Exemplo n.º 2
0
 public function afterDelete()
 {
     # Проверка и очистка связей
     $models = Car::model()->findAll('brand_id=:brand_id', array(':brand_id' => $this->id));
     if (count($models) > 0) {
         foreach ($models as $model) {
             $model->delete();
         }
     }
     $this->deleteImage('logo_delete', $this->logo_sizes);
     return parent::afterDelete();
 }
 public function actionIndex()
 {
     echo "<h1>All cars</h1>";
     $cars = Car::model()->findAll();
     foreach ($cars as $car) {
         // Each car can be of class Car, SportCar or FamilyCar
         echo get_class($car) . ' ' . $car->name . "<br />";
     }
     echo "<h1>Sport cars only</h1>";
     $sportCars = SportCar::model()->findAll();
     foreach ($sportCars as $car) {
         // Each car should be SportCar
         echo get_class($car) . ' ' . $car->name . "<br />";
     }
 }
 public function run()
 {
     Yii::import($this->import);
     $id = Yii::app()->request->getParam('id', 0);
     if ($id <= 0) {
         echo '{}';
     } else {
         $models = Car::model()->findAll(array('condition' => 'brand_id=' . $id, 'order' => 'title'));
         $data = array('');
         foreach ($models as $m) {
             $data[$m->id] = $m->title . ' ' . EString::getYear($m->manufacture_start) . (empty($m->manufacture_end) ? '...' : ' - ' . EString::getYear($m->manufacture_end));
         }
         echo CJavaScript::jsonEncode($data);
     }
 }
Exemplo n.º 5
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 ($modification = Yii::app()->request->getParam('Modification', false)) {
             $a = CHtml::listData(Car::model()->findAll('brand_id=:brand_id', array(':brand_id' => $modification['brandId'])), 'id', 'id');
             if (count($a) > 0) {
                 $criteria->compare('model_id', $a);
             } elseif ($modification['model_id'] > 0) {
                 $criteria->compare('model_id', 0);
             } else {
                 $criteria->compare('model_id', array());
             }
             $this->brandId = $modification['brandId'];
             $a = CHtml::listData(Car::model()->findAll('title like :title', array(':title' => '%' . $modification['modelTitle'] . '%')), 'id', 'id');
             if (count($a) > 0) {
                 $criteria->compare('model_id', $a);
             } elseif ($modification['modelTitle']) {
                 $criteria->compare('model_id', 0);
             } else {
                 $criteria->compare('model_id', array());
             }
             $criteria->compare('model_id', $a);
             $this->modelTitle = $modification['modelTitle'];
         }
     }
     $criteria->compare('title', $this->title, true);
     $criteria->compare('alias', $this->alias, true);
     $criteria->compare('archive', $this->archive);
     $criteria->compare('manufacture_start', $this->manufacture_start, true);
     $criteria->compare('manufacture_end', $this->manufacture_end, true);
     $criteria->compare('description', $this->description, true);
     return new CActiveDataProvider('Modification', array('criteria' => $criteria, 'pagination' => array('pageSize' => Yii::app()->params['linesPerPage'])));
 }
 public static function model($className = __CLASS__)
 {
     return parent::model($className);
 }
 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);
     }
 }
Exemplo n.º 8
0
 public static function car($criteria = array())
 {
     return CHtml::listData(Car::model()->desc()->findAll($criteria), 'car_id', 'license_no');
 }
Exemplo n.º 9
0
<div class='row' id='<?php 
echo $this->id;
?>
'>
	<lable><?php 
echo CHtml::activeLabelEx($model, $name);
?>
</label>
	<div class='input'>
		<div id='<?php 
echo $this->id;
?>
_brand'>
			<label for='brand_id'><?php 
echo Car::model()->getAttributeLabel('brand_id');
?>
</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 
Exemplo n.º 10
0
<?php

class Car
{
    public function __construct()
    {
        echo '12334';
    }
    public static function model()
    {
        static::getModel();
    }
    protected static function getModel()
    {
        echo "This is a car model" . PHP_EOL;
    }
}
Car::model();
class Taxi extends Car
{
    public function __construct()
    {
        parent::__construct();
        echo '12334';
    }
    protected static function getModel()
    {
        echo "This is a Taxi model2" . PHP_EOL;
    }
}
Taxi::model();
Exemplo n.º 11
0
 public function loadModel($id)
 {
     $model = Car::model()->findByPk($id);
     if ($model === null) {
         throw new CHttpException(404, 'The requested page does not exist.');
     }
     return $model;
 }
Exemplo n.º 12
0
<li class="extra">
    <?php 
echo CHtml::image(Yii::app()->params['pathUpload'] . $data->pic, '', array('style' => 'width: 100px;'));
?>
    <p> 
        <strong><?php 
echo '[' . $data->license_no . ']' . $data->brand->name;
?>
</strong>
        <b><a href="#show_detail_<?php 
echo $data->car_id;
?>
" rel='facebox'>Read More</a></b>
    </p>
</li>
<div id="show_detail_<?php 
echo $data->car_id;
?>
" style='display: none;'>
    <?php 
echo CHtml::image(Yii::app()->params['pathUpload'] . $data->pic, '', array('style' => 'width: 600px;'));
$model = Car::model()->findByPk($data->car_id);
$this->widget('zii.widgets.CDetailView', array('data' => $model, 'attributes' => array('license_no', array('name' => 'date_registration', 'value' => Tools::DateTimeToShow($model->create_at, '/', false)), 'brand.name', 'engine_no', 'personnel.name', array('name' => 'create_at', 'value' => Tools::DateTimeToShow($model->create_at, '/', false)))));
?>
</div>

Exemplo n.º 13
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'])));
 }
Exemplo n.º 14
0
 <br/>โทรศัพท์ : <?php 
    echo $driver->tel;
    ?>
<br/>ตำแหน่ง : <?php 
    echo $driver->position->name;
    ?>
" 
                                 width="270px"
                                 >
                        </li>
                        <?php 
}
?>

                    <?php 
$carBuss = Car::model()->car_bus()->findAll();
foreach ($carBuss as $carBus) {
    ?>
                        <li class="item-thumbs span3 car_bus">
                            <!-- Fancybox - Gallery Enabled - Title - Full Image -->
                            <a class="hover-wrap fancybox" data-fancybox-group="gallery" title="<?php 
    echo $carBus->typeCar->name;
    ?>
" href="<?php 
    echo Yii::app()->params['pathUpload'] . $carBus->pic;
    ?>
">
                                <span class="overlay-img"></span>
                                <span class="overlay-img-thumb font-icon-plus"></span>
                            </a>
                            <!-- Thumb Image and Description -->
 /**
  * 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 = Car::model()->findbyPk($_GET['id']);
         }
         if ($this->_model === null) {
             throw new CHttpException(404, 'The requested page does not exist.');
         }
     }
     return $this->_model;
 }