/protected/models/TicketMessage.php

https://github.com/keenox/Sardinia · PHP · 117 lines · 62 code · 10 blank · 45 comment · 1 complexity · bc3f7c32606aa17187759a88c4353465 MD5 · raw file

  1. <?php
  2. /**
  3. * This is the model class for table "ticket_message".
  4. *
  5. * The followings are the available columns in table 'ticket_message':
  6. * @property integer $id
  7. * @property integer $ticket_id
  8. * @property integer $user_id
  9. * @property integer $admin_id
  10. * @property string $message
  11. * @property string $created
  12. * @property string $ip
  13. *
  14. * The followings are the available model relations:
  15. * @property Administrator $admin
  16. * @property Ticket $ticket
  17. * @property User $user
  18. */
  19. class TicketMessage extends CActiveRecord
  20. {
  21. /**
  22. * Returns the static model of the specified AR class.
  23. * @return TicketMessage the static model class
  24. */
  25. public static function model($className=__CLASS__)
  26. {
  27. return parent::model($className);
  28. }
  29. /**
  30. * @return string the associated database table name
  31. */
  32. public function tableName()
  33. {
  34. return 'ticket_message';
  35. }
  36. public function save()
  37. {
  38. if ($this->isNewRecord)
  39. $this->message = nl2br(htmlentities($this->message));
  40. return parent::save();
  41. }
  42. /**
  43. * @return array validation rules for model attributes.
  44. */
  45. public function rules()
  46. {
  47. // NOTE: you should only define rules for those attributes that
  48. // will receive user inputs.
  49. return array(
  50. array('ticket_id, message, created, ip', 'required'),
  51. array('ticket_id, user_id, admin_id', 'numerical', 'integerOnly'=>true),
  52. array('message', 'length', 'max'=>500),
  53. array('ip', 'length', 'max'=>16),
  54. // The following rule is used by search().
  55. // Please remove those attributes that should not be searched.
  56. array('id, ticket_id, user_id, admin_id, message, created, ip', 'safe', 'on'=>'search'),
  57. );
  58. }
  59. /**
  60. * @return array relational rules.
  61. */
  62. public function relations()
  63. {
  64. // NOTE: you may need to adjust the relation name and the related
  65. // class name for the relations automatically generated below.
  66. return array(
  67. 'admin' => array(self::BELONGS_TO, 'Administrator', 'admin_id'),
  68. 'ticket' => array(self::BELONGS_TO, 'Ticket', 'ticket_id'),
  69. 'user' => array(self::BELONGS_TO, 'User', 'user_id'),
  70. );
  71. }
  72. /**
  73. * @return array customized attribute labels (name=>label)
  74. */
  75. public function attributeLabels()
  76. {
  77. return array(
  78. 'id' => 'ID',
  79. 'ticket_id' => 'Ticket',
  80. 'user_id' => 'User',
  81. 'admin_id' => 'Admin',
  82. 'message' => 'Message',
  83. 'created' => 'Created',
  84. 'ip' => 'Ip',
  85. );
  86. }
  87. /**
  88. * Retrieves a list of models based on the current search/filter conditions.
  89. * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
  90. */
  91. public function search()
  92. {
  93. // Warning: Please modify the following code to remove attributes that
  94. // should not be searched.
  95. $criteria=new CDbCriteria;
  96. $criteria->compare('id',$this->id);
  97. $criteria->compare('ticket_id',$this->ticket_id);
  98. $criteria->compare('user_id',$this->user_id);
  99. $criteria->compare('admin_id',$this->admin_id);
  100. $criteria->compare('message',$this->message,true);
  101. $criteria->compare('created',$this->created,true);
  102. $criteria->compare('ip',$this->ip,true);
  103. return new CActiveDataProvider($this, array(
  104. 'criteria'=>$criteria,
  105. ));
  106. }
  107. }