Calendar.php 1.73 KB
<?php

namespace common\modules\calendar;

use Yii;
use thread\app\base\models\ActiveRecord;
//
use thread\app\base\module\abstracts\Module as aModule;

/**
 * Class Calendar
 *
 * @package thread\modules\calendar
 * @author FilamentV <vortex.filament@gmail.com>
 * @copyright (c), Thread
 */
class Calendar extends aModule
{
    public $name = 'calendar';
    public $translationsBasePath = __DIR__ . '/messages';
    public $configPath = __DIR__ . '/config.php';

    /**
     * @return null|object
     * @throws \yii\base\InvalidConfigException
     */
    public static function getDb()
    {
        return Yii::$app->get('db-core');
    }

    /**
     * @return mixed
     */
    public function getFormatDate()
    {
        return $this->params['format']['date'];
    }

    /**
     * @param $key
     * @param ActiveRecord $model
     * @return string
     */
    public function getBaseUploadPath($key, ActiveRecord $model)
    {
        $item = [
            'article' => Yii::getAlias('@uploads') . '/calendar/articles/',
            'group' => Yii::getAlias('@uploads') . '/calendar/groups/',
        ];
        return $item[$key] . $this->getBaseDirSuffix($model);
    }

    /**
     * @param $key
     * @param ActiveRecord $model
     * @return string
     */
    public function getBaseUploadUrl($key, ActiveRecord $model)
    {
        $item = [
            'article' => '/uploads/calendar/articles/',
            'group' => '/uploads/calendar/groups/',
        ];
        return $item[$key] . $this->getBaseDirSuffix($model);
    }

    /**
     * @param ActiveRecord $model
     * @return string
     */
    public function getBaseDirSuffix(ActiveRecord $model)
    {
        return date('Y/m/d', $model['created_at']) . '/' . $model['id'];
    }
}