You can not select more than 25 topics
			Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
		
		
		
		
		
			
		
			
				
					
					
						
							93 lines
						
					
					
						
							2.0 KiB
						
					
					
				
			
		
		
	
	
							93 lines
						
					
					
						
							2.0 KiB
						
					
					
				<?php | 
						|
 | 
						|
namespace core\entities\post; | 
						|
 | 
						|
use core\entities\user\User; | 
						|
use yii\db\ActiveQuery; | 
						|
use yii\db\ActiveRecord; | 
						|
use Yii; | 
						|
 | 
						|
 | 
						|
/** | 
						|
 * @property int $id | 
						|
 * @property int $created_at | 
						|
 * @property int $post_id | 
						|
 * @property int $user_id | 
						|
 * @property int $parent_id | 
						|
 * @property string $text | 
						|
 * @property bool $active | 
						|
 * | 
						|
 * @property Post $post | 
						|
 */ | 
						|
class PostComment extends ActiveRecord | 
						|
{ | 
						|
    public static function create($userId, $parentId, $text): self | 
						|
    { | 
						|
        $review = new static(); | 
						|
        $review->user_id = $userId; | 
						|
        $review->parent_id = $parentId; | 
						|
        $review->text = $text; | 
						|
        $review->created_at = time(); | 
						|
        $review->active = true; | 
						|
        return $review; | 
						|
    } | 
						|
 | 
						|
    public function edit($parentId, $text): void | 
						|
    { | 
						|
        $this->parent_id = $parentId; | 
						|
        $this->text = $text; | 
						|
    } | 
						|
 | 
						|
    public function attributeLabels() | 
						|
    { | 
						|
        return [ | 
						|
            'id' => Yii::t('post', 'ID'), | 
						|
            'user_id' => Yii::t('post', 'User'), | 
						|
            'parent_id' => Yii::t('post', 'Parent Comment ID'), | 
						|
            'created_at' => Yii::t('post', 'Created At'), | 
						|
            'active' => Yii::t('post', 'Published'), | 
						|
            'post_id' => Yii::t('post', 'Post'), | 
						|
            'text' => Yii::t('post', 'Comment'), | 
						|
        ]; | 
						|
    } | 
						|
 | 
						|
    public function activate(): void | 
						|
    { | 
						|
        $this->active = true; | 
						|
    } | 
						|
 | 
						|
    public function draft(): void | 
						|
    { | 
						|
        $this->active = false; | 
						|
    } | 
						|
 | 
						|
    public function isActive(): bool | 
						|
    { | 
						|
        return $this->active == true; | 
						|
    } | 
						|
 | 
						|
    public function isIdEqualTo($id): bool | 
						|
    { | 
						|
        return $this->id == $id; | 
						|
    } | 
						|
 | 
						|
    public function isChildOf($id): bool | 
						|
    { | 
						|
        return $this->parent_id == $id; | 
						|
    } | 
						|
 | 
						|
    public function getPost(): ActiveQuery | 
						|
    { | 
						|
        return $this->hasOne(Post::class, ['id' => 'post_id']); | 
						|
    } | 
						|
 | 
						|
    public function getUser(): ActiveQuery | 
						|
    { | 
						|
        return $this->hasOne(User::class, ['id' => 'user_id']); | 
						|
    } | 
						|
 | 
						|
    public static function tableName(): string | 
						|
    { | 
						|
        return '{{%post_comments}}'; | 
						|
    } | 
						|
} |