Ejemplo n.º 1
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getCategories()
 {
     return $this->hasMany(Category::className(), ['parent_id' => 'id']);
 }
Ejemplo n.º 2
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = $this->find();
     $query->joinWith(['author']);
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $userClass = Yii::$app->getModule('yes')->userClass;
     /* uncomment to sort by relations table on respective column		
     		$dataProvider->sort->attributes['salesId'] = [			
     			'asc' => ['{{%sales}}.id' => SORT_ASC],
     			'desc' => ['{{%sales}}.id' => SORT_DESC],
     		];
     		$dataProvider->sort->attributes['catprosId'] = [			
     			'asc' => ['{{%catpros}}.id' => SORT_ASC],
     			'desc' => ['{{%catpros}}.id' => SORT_DESC],
     		];*/
     $dataProvider->sort->attributes['authorName'] = ['asc' => [$userClass::tableName() . '.username' => SORT_ASC], 'desc' => [$userClass::tableName() . '.username' => SORT_DESC]];
     $dataProvider->sort->attributes['term'] = ['asc' => ['title' => SORT_ASC], 'desc' => ['title' => SORT_DESC]];
     if (!($this->load($params) && $this->validate())) {
         return $dataProvider;
     }
     $query->andFilterWhere(['status' => $this->status, 'isdel' => $this->isdel, 'isfeatured' => $this->isfeatured]);
     $params = self::queryNumber([['id', $this->tableName()], ['author_id'], ['price'], ['discount']]);
     foreach ($params as $p) {
         $query->andFilterWhere($p);
     }
     $params = self::queryString([['title'], ['sku'], ['description'], ['content'], ['data'], ['tags'], ['images']]);
     foreach ($params as $p) {
         $query->andFilterWhere($p);
     }
     $params = self::queryTime([['time']]);
     foreach ($params as $p) {
         $query->andFilterWhere($p);
     }
     $query->andFilterWhere(['like', 'lower(' . $userClass::tableName() . '.username)', strtolower($this->authorName)]);
     if ($this->category || $this->term) {
         $term = $this->term ? $this->term : $this->category;
         $cquery = $this->find()->select(["array_agg(" . $this->tableName() . ".id)"])->leftJoin(CatPro::tableName() . " as cp", $this->tableName() . ".id = cp.product_id")->leftJoin(Category::tableName() . " as c", "cp.category_id = c.id");
         if ($this->category) {
             $cquery->andWhere("lower(c.title) = '" . strtolower($term) . "'");
         } else {
             $cquery->andWhere("lower(c.title) like '%" . strtolower($term) . "%' or lower(c.description) like '%" . strtolower($term) . "%'");
         }
         $res = $cquery->scalar();
         $res = $res == "" ? "{}" : $res;
         if ($this->category) {
             //$query->andFilterWhere(["OR","false",$this->tableName().".id = ANY ('".$res."')"]);
             $query->andFilterWhere(["OR", "false", "'," . str_replace(["{", "}"], "", $res) . ",' like concat('%,'," . $this->tableName() . ".id,',%') "]);
         } else {
             $query->andFilterWhere(["OR", "lower(title) like '%" . strtolower($this->term) . "%'", ["OR", "lower(description) like '%" . strtolower($this->term) . "%'", ["OR", "lower(tags) like '%" . strtolower($this->term) . "%'", ["OR", "lower(sku) like '%" . strtolower($this->term) . "%'", ["OR", "lower(content) like '%" . strtolower($this->term) . "%'", "'," . str_replace(["{", "}"], "", $res) . ",' like concat('%,'," . $this->tableName() . ".id,',%') "]]]]]);
         }
     }
     return $dataProvider;
 }
 /**
  * Finds the Category model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return Category the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = Category::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
Ejemplo n.º 4
0
use yii\helpers\HtmlPurifier;
use yii\widgets\ActiveForm;
use yii\widgets\DetailView;
use amilna\yes\models\Category;
use himiklab\colorbox\Colorbox;
use amilna\elevatezoom\ElevateZoom;
use kartik\widgets\Select2;
use kartik\touchspin\TouchSpin;
/* @var $this yii\web\View */
/* @var $model amilna\yes\models\Product */
$this->title = $model->title;
$this->params['breadcrumbs'][] = ['label' => Yii::t('app', 'Products'), 'url' => ['index']];
$this->params['breadcrumbs'][] = $this->title;
$this->registerMetaTag(['name' => 'title', 'content' => Html::encode($model->title)]);
$this->registerMetaTag(['name' => 'description', 'content' => Html::encode($model->description)]);
$cat = new Category();
$module = Yii::$app->getModule("yes");
?>
<div class="product-view">

    <h1><?php 
echo Html::encode($this->title);
?>
</h1>    

	<div class="row">
		<!-- Product -->
		<div class="col-sm-8 panel">
			<div class="panel-body">
				<div>
					<h3><?php 
Ejemplo n.º 5
0
use kartik\widgets\SwitchInput;
use kartik\datetime\DateTimePicker;
use amilna\yes\models\Category;
use iutbay\yii2kcfinder\KCFinderInputWidget;
$module = Yii::$app->getModule('yes');
if ($module->enableUpload) {
    // kcfinder options
    // http://kcfinder.sunhater.com/install#dynamic
    $kcfOptions = array_merge([], ['uploadURL' => Yii::getAlias($module->uploadURL), 'uploadDir' => Yii::getAlias($module->uploadDir), 'access' => ['files' => ['upload' => true, 'delete' => false, 'copy' => false, 'move' => false, 'rename' => false], 'dirs' => ['create' => true, 'delete' => false, 'rename' => false]], 'types' => ['files' => "", 'images' => "*img"], 'thumbWidth' => 260, 'thumbHeight' => 260]);
    // Set kcfinder session options
    Yii::$app->session->set('KCFINDER', $kcfOptions);
}
/* @var $this yii\web\View */
/* @var $model amilna\yes\models\Product */
/* @var $form yii\widgets\ActiveForm */
$cat = new Category();
$listCategory = [] + ArrayHelper::map($cat->parents(), 'id', 'title');
$category = $model->isNewRecord ? $model->id['category'] : [];
foreach ($model->catPro as $c) {
    array_push($category, $c->category_id);
}
?>

<div class="product-form">

    <?php 
$form = ActiveForm::begin();
?>

	<div class="row">
		<div class="col-md-9">
Ejemplo n.º 6
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getCategory()
 {
     return $this->hasOne(Category::className(), ['id' => 'category_id']);
 }
Ejemplo n.º 7
0
 public static function find()
 {
     return parent::find()->where([Category::tableName() . '.isdel' => 0]);
 }