123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960 |
- <?php
- namespace app\models\base;
- use app\helpers\Transliterator;
- use yii\db\ActiveRecord;
- use yii\helpers\Url;
- /**
- * @property string $id
- * @property string $comment_pull_id
- * @property string $message
- * @property \app\models\News | null $post
- * @property string $publishedAt
- */
- class Comments extends ActiveRecord
- {
- public static function getDb()
- {
- return \Yii::$app->old_db;
- }
- public static function tableName()
- {
- return "{{%comments}}";
- }
- public function getPull()
- {
- return $this->hasOne(CommentsPull::class,['comment_pull_id'=>'id']);
- }
- public function getOldPost()
- {
- return $this->hasOne(OldNews::class,['comment_pull_id'=>'comment_pull_id']);
- }
- public function getPost()
- {
- return $this->hasOne(News::class,['uid'=>'id'])->via('oldPost');
- }
- public function getPublishedAt(){
- if($this->created_at<date("Y-m-d H:i:s",strtotime("-1 day"))){
- return date("d",strtotime($this->created_at))." ".mb_strtolower(Transliterator::month(date("n",strtotime($this->created_at))));
- } else {
- $diff = ceil((time() - strtotime($this->created_at))/60); //В минутах
- if($diff<=60){
- return Transliterator::plural($diff,['минуту','минуты', 'минут'],true,'только что','минуту')." назад";
- } else {
- $diff = (int)floor($diff/60);
- return Transliterator::plural($diff,['час','часа', 'часов'],true,'только что','час')." назад";
- }
- }
- }
- }
|