<commit_before><?php

namespace luya\gallery\models;

use luya\gallery\admin\Module;

class Album extends \luya\admin\ngrest\base\NgRestModel
{
    public static function tableName()
    {
        return 'gallery_album';
    }

    public function scenarios()
    {
        return [
            'restcreate' => ['title', 'description', 'cover_image_id', 'cat_id', 'sort_index', 'is_highlight'],
            'restupdate' => ['title', 'description', 'cover_image_id', 'cat_id', 'sort_index', 'is_highlight'],
        ];
    }

    public function rules()
    {
        return [
            ['cat_id', 'required', 'message' => Module::t('album_category_error')],
            ['title', 'required', 'message' => Module::t('album_title_create_error')],
        ];
    }

    public function attributeLabels()
    {
        return [
            'title' => Module::t('album_title'),
            'description' => Module::t('album_description'),
            'cover_image_id' => Module::t('album_cover_image_id'),
            'cat_id' => Module::t('album_cat_id'),
            'sort_index' => Module::t('album_sort_index'),
            'is_highlight' => Module::t('album_is_highlight'),
        ];
    }

    public function init()
    {
        parent::init();
        $this->on(self::EVENT_BEFORE_DELETE, [$this, 'eventBeforeDelete']);
    }

    public function eventBeforeDelete()
    {
        // find all gallery_album_image references and delete them
        (new \yii\db\Query())->createCommand()->delete('gallery_album_image', 'album_id = :albumId', [':albumId' => $this->id])->execute();
    }

    public function getCategoryUrl()
    {
        $category = Cat::findOne($this->cat_id);

        return \luya\helpers\Url::toManager('gallery/alben/index', ['catId' => $category->id, 'title' => \yii\helpers\Inflector::slug($category->title)]);
    }

    public function getCategoryName()
    {
        $category = Cat::findOne($this->cat_id);

        return $category->title;
    }

    public function getDetailUrl($contextNavItemId = null)
    {
        if ($contextNavItemId) {
            return \cms\helpers\Url::toMenuItem($contextNavItemId, 'gallery/album/index', ['albumId' => $this->id, 'title' => \yii\helpers\Inflector::slug($this->title)]);
        }

        return \luya\helpers\Url::toManager('gallery/album/index', ['albumId' => $this->id, 'title' => \yii\helpers\Inflector::slug($this->title)]);
    }

    public function images()
    {
        return (new \yii\db\Query())->from('gallery_album_image')->where(['album_id' => $this->id])->all();
    }

    // ngrest

    public $i18n = ['title', 'description'];

    public static function ngRestApiEndpoint()
    {
        return 'api-gallery-album';<commit_msg>fixed rc1 upgrade<commit_after><?php

namespace luya\gallery\models;

use luya\gallery\admin\Module;

class Album extends \luya\admin\ngrest\base\NgRestModel
{
    public static function tableName()
    {
        return 'gallery_album';
    }

    public function scenarios()
    {
        return [
            'restcreate' => ['title', 'description', 'cover_image_id', 'cat_id', 'sort_index', 'is_highlight'],
            'restupdate' => ['title', 'description', 'cover_image_id', 'cat_id', 'sort_index', 'is_highlight'],
        ];
    }

    public function rules()
    {
        return [
            ['cat_id', 'required', 'message' => Module::t('album_category_error')],
            ['title', 'required', 'message' => Module::t('album_title_create_error')],
        ];
    }

    public function attributeLabels()
    {
        return [
            'title' => Module::t('album_title'),
            'description' => Module::t('album_description'),
            'cover_image_id' => Module::t('album_cover_image_id'),
            'cat_id' => Module::t('album_cat_id'),
            'sort_index' => Module::t('album_sort_index'),
            'is_highlight' => Module::t('album_is_highlight'),
        ];
    }

    public function init()
    {
        parent::init();
        $this->on(self::EVENT_BEFORE_DELETE, [$this, 'eventBeforeDelete']);
    }

    public function eventBeforeDelete()
    {
        // find all gallery_album_image references and delete them
        (new \yii\db\Query())->createCommand()->delete('gallery_album_image', 'album_id = :albumId', [':albumId' => $this->id])->execute();
    }

    public function getCategoryUrl()
    {
        $category = Cat::findOne($this->cat_id);

        return \luya\helpers\Url::toManager('gallery/alben/index', ['catId' => $category->id, 'title' => \yii\helpers\Inflector::slug($category->title)]);
    }

    public function getCategoryName()
    {
        $category = Cat::findOne($this->cat_id);

        return $category->title;
    }

    public function getDetailUrl($contextNavItemId = null)
    {
        if ($contextNavItemId) {
            return \luya\cms\helpers\Url::toMenuItem($contextNavItemId, 'gallery/album/index', ['albumId' => $this->id, 'title' => \yii\helpers\Inflector::slug($this->title)]);
        }

        return \luya\helpers\Url::toManager('gallery/album/index', ['albumId' => $this->id, 'title' => \yii\helpers\Inflector::slug($this->title)]);
    }

    public function images()
    {
        return (new \yii\db\Query())->from('gallery_album_image')->where(['album_id' => $this->id])->all();
    }

    // ngrest

    public $i18n = ['title', 'description'];

    public static function ngRestApiEndpoint()
    {
        return 'api-gallery-album';
{'fraction_non_alphanumeric': 0.17455675379272528, 'fraction_numerical': 0.0009139097057210748, 'mean_word_length': 2.880851063829787, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 75, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7469804', 'n_tokens_mistral': 1726, 'n_tokens_neox': 1680, 'n_words': 279}