Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- * Contact table AR model
- */
- class Contact extends ContactBase
- {
- /**
- * @static
- * @param string $className
- * @return Contact
- */
- public static function model($className=__CLASS__) {
- return parent::model($className);
- }
- /**
- * Relations
- * @return array
- */
- public function relations() {
- return array_merge(parent::relations(), array(
- 'properties' => array(self::MANY_MANY, 'Property', 'property_relation(entity_id, property_id)',
- 'on' => 'table_name=:tablename',
- 'params' => array(':tablename' => self::tableName())
- ),
- ));
- }
- /**
- * Define the contacts form rules
- * @return array
- */
- public function rules() {
- return array_merge(parent::rules(), array(
- array('propertyIds','safe'),
- ));
- }
- /**
- * Define the attribute labels
- * @return array
- */
- public function attributeLabels() {
- return array_merge(parent::attributeLabels(), array(
- 'propertyIds' => Yii::t('contacts', 'Properties'),
- ));
- }
- public function afterSave() {
- // TODO: implementation needs review
- $formData = Yii::app()->request->getParam('Contact');
- $propertyIds = $formData['propertyIds'];
- if ($propertyIds) {
- foreach ($propertyIds as $propertyId) {
- $rel = new PropertyRelation;
- $rel->property_id = $propertyId;
- $rel->entity_id = $this->id;
- $rel->table_name = $this->tableName();
- $rel->create_date = new CDbExpression('NOW()');
- $rel->create_user_id = Yii::app()->user->id;
- $rel->save();
- }
- }
- // Run parent
- return parent::afterSave();
- }
- }
Add Comment
Please, Sign In to add comment