Guest User

Untitled

a guest
Oct 16th, 2018
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.64 KB | None | 0 0
  1. <?php
  2. /**
  3. * Contact table AR model
  4. */
  5. class Contact extends ContactBase
  6. {
  7. /**
  8. * @static
  9. * @param string $className
  10. * @return Contact
  11. */
  12. public static function model($className=__CLASS__) {
  13. return parent::model($className);
  14. }
  15.  
  16. /**
  17. * Relations
  18. * @return array
  19. */
  20. public function relations() {
  21. return array_merge(parent::relations(), array(
  22. 'properties' => array(self::MANY_MANY, 'Property', 'property_relation(entity_id, property_id)',
  23. 'on' => 'table_name=:tablename',
  24. 'params' => array(':tablename' => self::tableName())
  25. ),
  26. ));
  27. }
  28.  
  29. /**
  30. * Define the contacts form rules
  31. * @return array
  32. */
  33. public function rules() {
  34. return array_merge(parent::rules(), array(
  35. array('propertyIds','safe'),
  36. ));
  37. }
  38.  
  39. /**
  40. * Define the attribute labels
  41. * @return array
  42. */
  43. public function attributeLabels() {
  44. return array_merge(parent::attributeLabels(), array(
  45. 'propertyIds' => Yii::t('contacts', 'Properties'),
  46. ));
  47. }
  48.  
  49. public function afterSave() {
  50. // TODO: implementation needs review
  51. $formData = Yii::app()->request->getParam('Contact');
  52. $propertyIds = $formData['propertyIds'];
  53.  
  54. if ($propertyIds) {
  55. foreach ($propertyIds as $propertyId) {
  56. $rel = new PropertyRelation;
  57. $rel->property_id = $propertyId;
  58. $rel->entity_id = $this->id;
  59. $rel->table_name = $this->tableName();
  60. $rel->create_date = new CDbExpression('NOW()');
  61. $rel->create_user_id = Yii::app()->user->id;
  62. $rel->save();
  63. }
  64. }
  65.  
  66. // Run parent
  67. return parent::afterSave();
  68. }
  69. }
Add Comment
Please, Sign In to add comment