Created
November 30, 2011 11:18
-
-
Save DrMabuse23/1408733 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
MODEL LOCATIONS lokk at cityName | |
<?php | |
/** | |
* This is the model class for table "fz_locations". | |
* | |
* The followings are the available columns in table 'fz_locations': | |
* @property integer $id | |
* @property integer $public_id | |
* @property string $name | |
* @property string $name_short | |
* @property integer $city_id | |
* @property string $contact | |
* @property string $phone | |
* @property string $e_mail | |
* @property integer $capacity_50_100 | |
* @property integer $capacity_101_150 | |
* @property integer $capacity_151_200 | |
* @property integer $capacity_201_250 | |
* @property integer $capacity_251 | |
* @property string $_cityName | |
* @property string $_thumbnails | |
* | |
* The followings are the available model relations: | |
* @property FzCity $city | |
*/ | |
class Locations extends CActiveRecord | |
{ | |
public $_cityName; | |
public $_thumbnails; | |
public $_inlistButton; | |
/** | |
* Returns the static model of the specified AR class. | |
* @return Locations the static model class | |
*/ | |
public static function model($className=__CLASS__) | |
{ | |
return parent::model($className); | |
} | |
/** | |
* @return string the associated database table name | |
*/ | |
public function tableName() | |
{ | |
return 'fz_locations'; | |
} | |
/** | |
* @return array validation rules for model attributes. | |
*/ | |
public function rules() | |
{ | |
// NOTE: you should only define rules for those attributes that | |
// will receive user inputs. | |
return array( | |
array('public_id, name, name_short, city_id, contact, phone, e_mail', 'required'), | |
array('public_id, city_id, capacity_50_100, capacity_101_150, capacity_151_200, capacity_201_250, capacity_251', 'numerical', 'integerOnly'=>true), | |
array('name, name_short, contact, phone, e_mail', 'length', 'max'=>255), | |
// The following rule is used by search(). | |
// Please remove those attributes that should not be searched. | |
array( | |
'id, | |
public_id, name,cityName, name_short, city_id, | |
contact, phone, e_mail, capacity_50_100, capacity_101_150, capacity_151_200, capacity_201_250, capacity_251', 'safe', 'on'=>'search'), | |
); | |
} | |
/** | |
* @return array relational rules. | |
*/ | |
public function relations() | |
{ | |
// NOTE: you may need to adjust the relation name and the related | |
// class name for the relations automatically generated below. | |
return array( | |
'city' => array(self::HAS_ONE, 'City', 'id'), | |
'locationdistances' => array(self::HAS_MANY, 'LocationsDistances', 'city_id'), | |
); | |
} | |
/** | |
* @return array customized attribute labels (name=>label) | |
*/ | |
public function attributeLabels() | |
{ | |
return array( | |
'id' => 'ID', | |
'public_id' => 'Public', | |
'name' => 'Name', | |
'name_short' => 'Name Short', | |
'city_id' => 'City', | |
'contact' => 'Contact', | |
'phone' => 'Phone', | |
'e_mail' => 'E Mail', | |
'capacity_50_100' => '50 bis 100 Personen:', | |
'capacity_101_150' => '101 bis 150 Personen:', | |
'capacity_151_200' => '151 bis 200 Personen:', | |
'capacity_201_250' => '201 bis 250 Personen:', | |
'capacity_251' => 'Mehr als 251 Personen:', | |
'cityName' => 'Stadt', | |
'thumbnails' => 'Bilder' | |
); | |
} | |
/** | |
* 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->with = array('city'); | |
$criteria->compare('id',$this->id); | |
$criteria->compare('public_id',$this->public_id); | |
$criteria->compare('name',$this->name,true); | |
$criteria->compare('name_short',$this->name_short,true); | |
$criteria->compare('city_id',$this->city_id); | |
$criteria->compare('city.name',$this->_cityName,true); | |
$criteria->compare('contact',$this->contact,true); | |
$criteria->compare('phone',$this->phone,true); | |
$criteria->compare('e_mail',$this->e_mail,true); | |
$criteria->compare('capacity_50_100',$this->capacity_50_100); | |
$criteria->compare('capacity_101_150',$this->capacity_101_150); | |
$criteria->compare('capacity_151_200',$this->capacity_151_200); | |
$criteria->compare('capacity_201_250',$this->capacity_201_250); | |
$criteria->compare('capacity_251',$this->capacity_251); | |
$criteria->order = 'city.name ASC'; | |
return new CActiveDataProvider($this, array( | |
'criteria'=>$criteria, | |
)); | |
} | |
/** | |
* @return string the URL that shows the detail of the post | |
*/ | |
public function getUrl() | |
{ | |
return Yii::app()->createAbsoluteUrl( | |
'/locationdatenbank/locations/show/location', | |
array( | |
'id'=>$this->id, | |
'city' => urlencode($this->cityName), | |
'title'=> urlencode($this->name), | |
) | |
); | |
} | |
/** | |
* Damit nicht die StadtID angezeigt wird erweitern wir das Grid mit dem Stadt Namen | |
* @return null | |
*/ | |
public function getCityName() | |
{ | |
if ($this->_cityName === null && $this->city !== null) | |
{ | |
$this->_cityName = $this->city->name; | |
} | |
return $this->_cityName; | |
} | |
/** | |
* @param $value | |
* @return void | |
*/ | |
public function setCityName($value) | |
{ | |
$this->_cityName = $value; | |
} | |
//not in Use at the moment | |
public function getDistance($city_id,$capacity){ | |
$query = 'SELECT fz_locations.id, | |
fz_locations.public_id, | |
fz_locations.name_short, | |
fz_locations.city_id, | |
fz_distances.distance | |
FROM fz_locations, | |
fz_distances | |
WHERE fz_locations.'. $capacity.'=\'1\' AND | |
fz_distances.city_id_from= '.$city_id.' AND | |
fz_distances.city_id_to = fz_locations.city_id | |
ORDER BY fz_distances.distance, | |
fz_locations.name_short ASC'; | |
$row = Yii::app()->db->createCommand($query)->queryRow(); | |
return $row; | |
// BK_Debug::output_array($row); | |
} | |
} | |
///////////////////////////// | |
VIEW | |
<div class="headbox locations search"> | |
<div class="contentslider"> | |
<div class="contentslider_hangup"> | |
<a href="" title="" ></a> | |
</div> | |
<div class="content"> | |
<?php | |
$columns = array( | |
array( | |
'header'=>CHtml::encode('Name'), | |
'name'=>'name_short', | |
'type' => 'raw', | |
'value'=>'$data->name', | |
), | |
array( | |
'header'=>CHtml::encode('Stadt'), | |
'name'=>'cityName', | |
'value'=>'$data->cityName', | |
), | |
array( | |
'header' => CHtml::encode('Vorschau'), | |
'type' => 'raw', | |
'value' => 'CHtml::image($data->_thumbnails[0],"",array("width" => 120 ,"height" => 120))' | |
), | |
array( | |
'header' => CHtml::encode('Merken'), | |
'type' => 'raw', | |
'value' => '$data->_inlistButton' | |
) | |
); | |
?> | |
<?php echo CHtml::link('zur Suche', array( 'suche' ) ); ?> | |
<?php echo CHtml::link('Anfrage senden', array( 'contact' ) ); ?> | |
<?php | |
$this->widget('zii.widgets.grid.CGridView', array( | |
'id'=>'area-grid', | |
'dataProvider'=>$dataProvider, | |
'ajaxUpdate'=>false, | |
'columns'=>$columns, | |
)); | |
?> | |
</div> | |
</div> | |
<div class="bottom_line"></div> | |
</div> | |
<?php $this->renderPartial('js_file',false,true) ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment