File tree Expand file tree Collapse file tree 8 files changed +75
-0
lines changed Expand file tree Collapse file tree 8 files changed +75
-0
lines changed Original file line number Diff line number Diff line change 1+ <?php
2+
3+ use yii \db \Migration ;
4+
5+ class m211116_101347_add_timestamp_cols extends Migration
6+ {
7+ public function up ()
8+ {
9+ $ this ->addColumn ('{{%twig}} ' , 'created_at ' , $ this ->dateTime ()->null ());
10+ $ this ->addColumn ('{{%twig}} ' , 'updated_at ' , $ this ->dateTime ()->null ());
11+ $ this ->addColumn ('{{%less}} ' , 'created_at ' , $ this ->dateTime ()->null ());
12+ $ this ->addColumn ('{{%less}} ' , 'updated_at ' , $ this ->dateTime ()->null ());
13+ $ this ->addColumn ('{{%html}} ' , 'created_at ' , $ this ->dateTime ()->null ());
14+ $ this ->addColumn ('{{%html}} ' , 'updated_at ' , $ this ->dateTime ()->null ());
15+ }
16+
17+ public function down ()
18+ {
19+ echo "m211116_101347_add_timestamp_cols cannot be reverted. \n" ;
20+ return false ;
21+ }
22+ }
Original file line number Diff line number Diff line change 1010namespace dmstr \modules \prototype \models ;
1111
1212
13+ use bedezign \yii2 \audit \AuditTrailBehavior ;
1314use Yii ;
15+ use yii \behaviors \TimestampBehavior ;
1416use yii \db \ActiveQuery ;
1517use yii \db \ActiveRecord ;
18+ use yii \db \Expression ;
1619
1720/**
1821 * @package dmstr\modules\prototype\models
1922 * @author Elias Luhr <[email protected] > 2023 */
2124class BaseModel extends ActiveRecord
2225{
26+
27+ /**
28+ * Column attribute 'created_at'
29+ */
30+ const ATTR_CREATED_AT = 'created_at ' ;
31+
32+ /**
33+ * Column attribute 'updated_at'
34+ */
35+ const ATTR_UPDATED_AT = 'updated_at ' ;
36+
37+ /**
38+ * @inheritdoc
39+ *
40+ * Use yii\behaviors\TimestampBehavior for created_at and updated_at attribute
41+ *
42+ * @return array
43+ */
44+ public function behaviors ()
45+ {
46+
47+ $ behaviors = parent ::behaviors ();
48+
49+ $ behaviors ['timestamp ' ] = [
50+ 'class ' => TimestampBehavior::class,
51+ 'createdAtAttribute ' => static ::ATTR_CREATED_AT ,
52+ 'updatedAtAttribute ' => static ::ATTR_UPDATED_AT ,
53+ 'value ' => new Expression ('NOW() ' ),
54+ ];
55+ return $ behaviors ;
56+ }
57+
2358 /**
2459 * @inheritdoc
2560 */
Original file line number Diff line number Diff line change 11<?php
22
3+ use dmstr \modules \prototype \models \BaseModel ;
34use rmrevin \yii \fontawesome \FA ;
45use yii \bootstrap \ButtonDropdown ;
56use yii \grid \GridView ;
103104 'contentOptions ' => ['nowrap ' => 'nowrap ' ],
104105 ],
105106 'key ' ,
107+ BaseModel::ATTR_UPDATED_AT ,
108+ BaseModel::ATTR_CREATED_AT ,
106109 ],
107110 ]
108111 ); ?>
Original file line number Diff line number Diff line change 11<?php
22
33use dmstr \bootstrap \Tabs ;
4+ use dmstr \modules \prototype \models \BaseModel ;
45use rmrevin \yii \fontawesome \FA ;
56use yii \helpers \Html ;
67use yii \widgets \DetailView ;
7980 'id ' ,
8081 'key ' ,
8182 'value:html ' ,
83+ BaseModel::ATTR_UPDATED_AT ,
84+ BaseModel::ATTR_CREATED_AT ,
8285 ],
8386 ]
8487 ); ?>
Original file line number Diff line number Diff line change 11<?php
22
3+ use dmstr \modules \prototype \models \BaseModel ;
34use rmrevin \yii \fontawesome \FA ;
45use yii \bootstrap \ButtonDropdown ;
56use yii \grid \GridView ;
103104 'contentOptions ' => ['nowrap ' => 'nowrap ' ],
104105 ],
105106 'key ' ,
107+ BaseModel::ATTR_UPDATED_AT ,
108+ BaseModel::ATTR_CREATED_AT ,
106109 ],
107110 ]
108111 ); ?>
Original file line number Diff line number Diff line change 11<?php
22
33use dmstr \bootstrap \Tabs ;
4+ use dmstr \modules \prototype \models \BaseModel ;
45use rmrevin \yii \fontawesome \FA ;
56use yii \helpers \Html ;
67use yii \widgets \DetailView ;
8384 'format ' => 'html ' ,
8485 'value ' => '<pre> ' . Html::encode ($ model ->value ) . '</pre> '
8586 ],
87+ BaseModel::ATTR_UPDATED_AT ,
88+ BaseModel::ATTR_CREATED_AT ,
8689 ],
8790 ]
8891 ); ?>
Original file line number Diff line number Diff line change 11<?php
22
3+ use dmstr \modules \prototype \models \BaseModel ;
34use rmrevin \yii \fontawesome \FA ;
45use yii \grid \GridView ;
56use yii \helpers \Html ;
7273 'contentOptions ' => ['nowrap ' => 'nowrap ' ],
7374 ],
7475 'key ' ,
76+ BaseModel::ATTR_UPDATED_AT ,
77+ BaseModel::ATTR_CREATED_AT ,
7578 ],
7679 ]); ?>
7780 </div>
Original file line number Diff line number Diff line change 11<?php
22
33use dmstr \bootstrap \Tabs ;
4+ use dmstr \modules \prototype \models \BaseModel ;
45use rmrevin \yii \fontawesome \FA ;
56use yii \helpers \Html ;
67use yii \widgets \DetailView ;
7576 'format ' => 'raw ' ,
7677 'value ' => "<pre> " . htmlspecialchars ($ model ->value ) . "</pre> " ,
7778 ],
79+ BaseModel::ATTR_UPDATED_AT ,
80+ BaseModel::ATTR_CREATED_AT ,
7881 ],
7982 ]); ?>
8083
You can’t perform that action at this time.
0 commit comments