<commit_before><?php

/**
 * This is the model class for table "Gallery".
 *
 * The followings are the available columns in table 'Gallery':
 * @property string $id
 * @property string $name
 * @property string $description
 * @property integer $status
 */
class Gallery extends YModel
{
    const STATUS_DRAFT    = 0;
    const STATUS_PUBLIC   = 1;
    const STATUS_PERSONAL = 2;
    const STATUS_PRIVATE  = 3;

    /**
     * Returns the static model of the specified AR class.
     * @param string $className
     * @return Gallery the static model class
     */
    public static function model($className = __CLASS__)
    {
        return parent::model($className);
    }

    /**
     * @return string the associated database table name
     */
    public function tableName()
    {
        return '{{gallery_gallery}}';
    }

    /**
     * @return array validation rules for model attributes.
     */
    public function rules()
    {
        // NOTE: you should only define rules for those attributes that
        // will receive user inputs.
        return array(
            array('name, description, owner', 'required'),
            array('status, owner', 'numerical', 'integerOnly' => true),
            array('name', 'length', 'max' => 250),            
            // The following rule is used by search().
            // Please remove those attributes that should not be searched.
            array('id, name, description, status, owner', 'safe', 'on' => 'search'),
        );
    }

    /**
     * @return array relational rules.
     */
    public function relations()
    {
        // NOTE: you may need to adjust the relation name and the related
        // class name for the relations automatically generated below.
        return array(
            'imagesRell'  => array(self::HAS_MANY, 'ImageToGallery', array('gallery_id' => 'id')),
            'images'      => array(self::HAS_MANY, 'Image', 'image_id', 'through' => 'imagesRell'),
            'imagesCount' => array(self::STAT, 'ImageToGallery', 'gallery_id'),
            'user'        => array(self::BELONGS_TO, 'User', 'owner'),
        );
    }

    /**
     * beforeValidate
     *
     * @return parent::beforeValidate()
     **/
    public function beforeValidate()
    {
        // Проверяем наличие установленного хозяина галереи
        if (isset($this->owner) && empty($this->owner))
            $this->owner = Yii::app()->user->getId();

        return parent::beforeValidate();
    }

    /**
     * @return array customized attribute labels (name=>label)
     */
    public function attributeLabels()
    {
        return array(
            'id'          => Yii::t('GalleryModule.gallery', 'Id'),
            'name'        => Yii::t('GalleryModule.gallery', 'Название'),
            'owner'       => Yii::t('GalleryModule.gallery', 'Владелец'),
            'description' => Yii::t('GalleryModule.gallery', 'Описание'),
            'status'      => Yii::t('GalleryModule.gallery', 'Статус'),
        );
    }

    /**
     * Retrieves a list of models based on the current search/filter conditions.
     * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
     */
    public function search()
    {
        // Warning: Please modify the following code to remove attributes that
        // should not be searched.

        $criteria = new CDbCriteria;

        $criteria->compare('id', $this->id, true);
        $criteria->compare('name', $this->name, true);
        $criteria->compare('description', $this->description, true);
        $criteria->compare('owner', $this->owner);
        $criteria->compare('status', $this->status);

        return new CActiveDataProvider(get_class($this), array('criteria' => $criteria));
    }

    public function getStatusList()
    {
        return array(
            self::STATUS_DRAFT    => Yii::t('GalleryModule.gallery', 'скрытая'),
            self::STATUS_PUBLIC   => Yii::t('GalleryModule.gallery', 'публичная'),
            self::STATUS_PERSONAL => Yii::t('GalleryModule.gallery', 'личная'),
            self::STATUS_PRIVATE  => Yii::t('GalleryModule.gallery', 'приватная'),
        );
    }

    public function getStatus()
    {
        $data = $this->statusList;
        return isset($data[$this->status]) ? $data[$this->status] : Yii::t('GalleryModule.gallery', '*неизвестно*');
    }

    public function addImage(Image $image)
    {
        $im2g = new ImageToGallery;

        $im2g->setAttributes(array(
            'image_id'  => $image->id,
            'gallery_id' => $this->id,
        ));

        return $im2g->save();
    }

    /**
     * Получаем картинку для галереи:
     *
     * @param int $width  - ширина
     * @param int $height - высота
     * 
     * @return string image Url
     **/
    public function previewImage($width = 190, $height = 0)
    {
        return $this->imagesCount > 0
            ? $this->images[0]->getUrl($width, $height)
            : Yii::app()->theme->baseUrl . '/web/images/thumbnail.png';
    }

    /**
     * get user list
     *
     * @return array of user list
     **/
    public function getUsersList()
    {
        return CHtml::listData(<commit_msg>fix publication of thumbnail<commit_after><?php

/**
 * This is the model class for table "Gallery".
 *
 * The followings are the available columns in table 'Gallery':
 * @property string $id
 * @property string $name
 * @property string $description
 * @property integer $status
 */
class Gallery extends YModel
{
    const STATUS_DRAFT    = 0;
    const STATUS_PUBLIC   = 1;
    const STATUS_PERSONAL = 2;
    const STATUS_PRIVATE  = 3;

    /**
     * Returns the static model of the specified AR class.
     * @param string $className
     * @return Gallery the static model class
     */
    public static function model($className = __CLASS__)
    {
        return parent::model($className);
    }

    /**
     * @return string the associated database table name
     */
    public function tableName()
    {
        return '{{gallery_gallery}}';
    }

    /**
     * @return array validation rules for model attributes.
     */
    public function rules()
    {
        // NOTE: you should only define rules for those attributes that
        // will receive user inputs.
        return array(
            array('name, description, owner', 'required'),
            array('status, owner', 'numerical', 'integerOnly' => true),
            array('name', 'length', 'max' => 250),            
            // The following rule is used by search().
            // Please remove those attributes that should not be searched.
            array('id, name, description, status, owner', 'safe', 'on' => 'search'),
        );
    }

    /**
     * @return array relational rules.
     */
    public function relations()
    {
        // NOTE: you may need to adjust the relation name and the related
        // class name for the relations automatically generated below.
        return array(
            'imagesRell'  => array(self::HAS_MANY, 'ImageToGallery', array('gallery_id' => 'id')),
            'images'      => array(self::HAS_MANY, 'Image', 'image_id', 'through' => 'imagesRell'),
            'imagesCount' => array(self::STAT, 'ImageToGallery', 'gallery_id'),
            'user'        => array(self::BELONGS_TO, 'User', 'owner'),
        );
    }

    /**
     * beforeValidate
     *
     * @return parent::beforeValidate()
     **/
    public function beforeValidate()
    {
        // Проверяем наличие установленного хозяина галереи
        if (isset($this->owner) && empty($this->owner))
            $this->owner = Yii::app()->user->getId();

        return parent::beforeValidate();
    }

    /**
     * @return array customized attribute labels (name=>label)
     */
    public function attributeLabels()
    {
        return array(
            'id'          => Yii::t('GalleryModule.gallery', 'Id'),
            'name'        => Yii::t('GalleryModule.gallery', 'Название'),
            'owner'       => Yii::t('GalleryModule.gallery', 'Владелец'),
            'description' => Yii::t('GalleryModule.gallery', 'Описание'),
            'status'      => Yii::t('GalleryModule.gallery', 'Статус'),
        );
    }

    /**
     * Retrieves a list of models based on the current search/filter conditions.
     * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
     */
    public function search()
    {
        // Warning: Please modify the following code to remove attributes that
        // should not be searched.

        $criteria = new CDbCriteria;

        $criteria->compare('id', $this->id, true);
        $criteria->compare('name', $this->name, true);
        $criteria->compare('description', $this->description, true);
        $criteria->compare('owner', $this->owner);
        $criteria->compare('status', $this->status);

        return new CActiveDataProvider(get_class($this), array('criteria' => $criteria));
    }

    public function getStatusList()
    {
        return array(
            self::STATUS_DRAFT    => Yii::t('GalleryModule.gallery', 'скрытая'),
            self::STATUS_PUBLIC   => Yii::t('GalleryModule.gallery', 'публичная'),
            self::STATUS_PERSONAL => Yii::t('GalleryModule.gallery', 'личная'),
            self::STATUS_PRIVATE  => Yii::t('GalleryModule.gallery', 'приватная'),
        );
    }

    public function getStatus()
    {
        $data = $this->statusList;
        return isset($data[$this->status]) ? $data[$this->status] : Yii::t('GalleryModule.gallery', '*неизвестно*');
    }

    public function addImage(Image $image)
    {
        $im2g = new ImageToGallery;

        $im2g->setAttributes(array(
            'image_id'  => $image->id,
            'gallery_id' => $this->id,
        ));

        return $im2g->save();
    }

    /**
     * Получаем картинку для галереи:
     *
     * @param int $width  - ширина
     * @param int $height - высота
     * 
     * @return string image Url
     **/
    public function previewImage($width = 190, $height = 0)
    {
        return $this->imagesCount > 0
            ? $this->images[0]->getUrl($width, $height)
            : Yii::app()->assetManager->publish(
                Yii::app()->theme->basePath . '/web/images/thumbnail.png'
            );
    }

    /**
     * get user list
     *
     * @return array of user list
     **/
    public function getUsersList()
    {
        return CHtml::listData(
{'fraction_non_alphanumeric': 0.14045104196403083, 'fraction_numerical': 0.0030450090398705873, 'mean_word_length': 2.243827160493827, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 105, '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': '2130464', 'n_tokens_mistral': 3079, 'n_tokens_neox': 3034, 'n_words': 773}