<?php

namespace common\models;

use Yii;

/**
 * This is the model class for table "product_category".
 *
 * @property integer $id_product_category
 * @property string $name
 * @property integer $status
 * @property string $created_at
 * @property string $updated_at
 */
class ProductCategory extends \common\models\BaseFitnessActiveRecord
{
	
	const STATUS_DELETED = 0;
	const STATUS_ACTIVE = 10;
	
    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return 'product_category';
    }

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['name'], 'required'],
            [['status'], 'integer'],
            [['name'], 'string', 'max' => 64]
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'id_product_category' => Yii::t('common/product_category', 'Id Product Category'),
            'name' => Yii::t('common/product_category', 'Name'),
            'status' => Yii::t('common/product_category', 'Status'),
            'created_at' => Yii::t('common/product_category', 'Created At'),
            'updated_at' => Yii::t('common/product_category', 'Updated At'),
        ];
    }
    
    static function statuses() {
    	return [
    	self::STATUS_ACTIVE => Yii::t('common/product_category', 'Active'),
    	self::STATUS_DELETED => Yii::t('common/product_category', 'Inactive'),
    	];
    }
    
    public function getStatusHuman(){
    	$result = null;
    	$s = self::statuses($this->status);
    	if ( array_key_exists($this->status, $s)){
    		$result = $s[$this->status];
    	}
    	return $result;
    }
    
    
    /**
     * $param int $forceIncludeAccount id account, that should be included in list, even if it is inactive
     * */
    public static  function read($forceIncludeObjectWithId = null){
    	$categories = null;
    	 
    	if ( $forceIncludeObjectWithId  == null){
    		$categories = ProductCategory::find()->andWhere(['status' => ProductCategory::STATUS_ACTIVE])->all();
    	}else{
    		$categories = ProductCategory::find()->andWhere( ['or', ['status' => ProductCategory::STATUS_ACTIVE], ['id_product_category' =>  $forceIncludeObjectWithId ] ])->all();
    	}
    	 
    	return $categories;
    }
    
}
