Code Coverage |
||||||||||
Classes and Traits |
Functions and Methods |
Lines |
||||||||
| Total | |
0.00% |
0 / 1 |
|
0.00% |
0 / 9 |
CRAP | |
0.00% |
0 / 46 |
| Table | |
0.00% |
0 / 1 |
|
0.00% |
0 / 9 |
110.00 | |
0.00% |
0 / 46 |
| tableName | |
0.00% |
0 / 1 |
2.00 | |
0.00% |
0 / 3 |
|||
| behaviors | |
0.00% |
0 / 1 |
2.00 | |
0.00% |
0 / 5 |
|||
| rules | |
0.00% |
0 / 1 |
2.00 | |
0.00% |
0 / 9 |
|||
| attributeLabels | |
0.00% |
0 / 1 |
2.00 | |
0.00% |
0 / 10 |
|||
| beforeSave | |
0.00% |
0 / 1 |
6.00 | |
0.00% |
0 / 7 |
|||
| getOn | |
0.00% |
0 / 1 |
2.00 | |
0.00% |
0 / 3 |
|||
| getOrganizations | |
0.00% |
0 / 1 |
2.00 | |
0.00% |
0 / 3 |
|||
| getMeetings | |
0.00% |
0 / 1 |
2.00 | |
0.00% |
0 / 3 |
|||
| find | |
0.00% |
0 / 1 |
2.00 | |
0.00% |
0 / 3 |
|||
| <?php | |
| namespace common\models; | |
| use Yii; | |
| use yii\behaviors\TimestampBehavior; | |
| /** | |
| * This is the model class for table "{{%table}}". | |
| * | |
| * @property integer $id | |
| * @property integer $on | |
| * @property string $name | |
| * @property integer $is_special | |
| * @property integer $created_at | |
| * @property integer $updated_at | |
| * | |
| * @property Organization[] $organizations | |
| * @property Meeting[] $meetings | |
| */ | |
| class Table extends \yii\db\ActiveRecord | |
| { | |
| /** | |
| * @inheritdoc | |
| */ | |
| public static function tableName() | |
| { | |
| return '{{%table}}'; | |
| } | |
| /** | |
| * @inheritdoc | |
| */ | |
| public function behaviors() | |
| { | |
| return [ | |
| TimestampBehavior::className(), | |
| ]; | |
| } | |
| /** | |
| * @inheritdoc | |
| */ | |
| public function rules() | |
| { | |
| return [ | |
| [['name', 'is_special'], 'required'], | |
| [['on'], 'integer'], | |
| [['name'], 'string', 'max' => 30], | |
| [['on', 'is_special'], 'unique', 'targetAttribute' => ['on', 'is_special']], | |
| [['name'], 'unique'], | |
| ]; | |
| } | |
| /** | |
| * @inheritdoc | |
| */ | |
| public function attributeLabels() | |
| { | |
| return [ | |
| 'id' => Yii::t('app', 'ID'), | |
| 'on' => Yii::t('app', 'Order number'), | |
| 'name' => Yii::t('app', 'Name'), | |
| 'is_special' => Yii::t('app', 'Is special'), | |
| 'created_at' => Yii::t('app', 'Created at'), | |
| 'updated_at' => Yii::t('app', 'Updated at'), | |
| ]; | |
| } | |
| /** | |
| * @inheritdoc | |
| */ | |
| public function beforeSave($insert) | |
| { | |
| if($insert === true){ | |
| $maxOn = Table::find()->where(['is_special' => $this->is_special])->max('[[on]]'); | |
| $this->on = $maxOn +1; | |
| } | |
| return parent::beforeSave($insert); | |
| } | |
| /** | |
| * @inheritdoc | |
| */ | |
| public function getOn() | |
| { | |
| return $this->on; | |
| } | |
| /** | |
| * @return \yii\db\ActiveQuery | |
| */ | |
| public function getOrganizations() | |
| { | |
| return $this->hasMany(Organization::className(), ['id' => 'organization_id'])->viaTable('{{%organization_table}}', ['table_id' => 'id']); | |
| } | |
| /** | |
| * @return \yii\db\ActiveQuery | |
| */ | |
| public function getMeetings() | |
| { | |
| return $this->hasMany(Meeting::className(), ['table_id' => 'id']); | |
| } | |
| /** | |
| * @inheritdoc | |
| * @return TableQuery | |
| */ | |
| public static function find() | |
| { | |
| return new TableQuery(get_called_class()); | |
| } | |
| } |