<?php

namespace common\modules\school\controllers;

use common\components\BaseController;
use common\modules\school\models\UserStatistics;

class StatisticsController extends BaseController
{
    public static function actionsTitles()
    {
        return [
            'Shares' => 'Публикации в соцсетях',
        ];
    }
    
    
    public function actionShares()
    {
        if (!\Yii::$app->user->isGuest){
            $nameSoc = $_POST['name'];
            $lessonId = $_POST['lesson'] ? $_POST['lesson'] : UserStatistics::NOT_LESSON;
            $userId = \Yii::$app->user->id;
            $shareUser = UserStatistics::findOne([$nameSoc => UserStatistics::SELECTED_SOC_NETWORK, 'user_id' => $userId, 'lesson_id' => $lessonId]);
            if (!$shareUser){
                $shareUser = new UserStatistics();
                $shareUser->{$nameSoc} = UserStatistics::SELECTED_SOC_NETWORK;
                $shareUser->user_id = $userId;
                $shareUser->lesson_id = $lessonId;
                $shareUser->save();
            }  
        }
        
    }
}
