<?php
/**
* This is the model class for table "{{user_notifications}}".
*/
class UserNotification extends CActiveRecord {
const SUCCESS = 'success';
const DANGER = 'danger';
const WARNING = 'warning';
const INFO = 'info';
/**
* @return string the associated database table name
*/
public function tableName() {
return '{{user_notifications}}';
}
/**
* @return array validation rules for model attributes.
*/
public function rules() {
return array(
array('user_id, text, type', 'required'),
array('user_id', 'length', 'max' => 10),
array('new', 'boolean'),
array('type', 'in', 'range' => array_keys($this->possibleTypes)),
);
}
/**
* @return array relational rules.
*/
public function relations() {
return array(
'user' => array(self::BELONGS_TO, 'User', 'user_id'),
);
}
/**
* Returns the static model of the specified AR class.
* Please note that you should have this exact method in all your CActiveRecord descendants!
* @param string $className active record class name.
* @return Notification the static model class
*/
public static function model($className=__CLASS__) {
return parent::model($className);
}
/**
* Returns possible types
*/
public function getPossibleTypes() {
return array(
self::SUCCESS => Yii::t('Users', 'Success'),
self::DANGER => Yii::t('Users', 'Danger'),
self::WARNING => Yii::t('Users', 'Warning'),
self::INFO => Yii::t('Users', 'Info'),
);
}
/**
* Unmarks as new
*/
public function unmarkNew() {
$this->new = "0";
return $this->save();
}
/**
* Default named scope
*/
public function defaultScope() {
return array(
'order' => 'created_at DESC',
);
}
}