fitness-web/backend/models/ProductSearch.php
Roland Schneider 09cd4660b8 add csrf , product and account_state changes
csrf - previous settings were not working on dev1
product - allow sale  , if count > stock
prodcut - admin - allow search by name
account_state - auto sum up money from notes

add csrf , product and account_state changes

csrf - previous settings were not working on dev1
product - allow sale  , if count > stock
prodcut - admin - allow search by name
account_state - auto sum up money from notes
2015-11-29 15:04:09 +01:00

77 lines
2.0 KiB
PHP

<?php
namespace backend\models;
use Yii;
use yii\base\Model;
use yii\data\ActiveDataProvider;
use common\models\Product;
use common\components\RoleDefinition;
/**
* ProductSearch represents the model behind the search form about `common\models\Product`.
*/
class ProductSearch extends Product
{
/**
* @inheritdoc
*/
public function rules()
{
return [
[[ 'id_product_category', 'id_account', 'status'], 'integer'],
[['product_number', 'barcode' ,'name'], 'safe'],
];
}
/**
* @inheritdoc
*/
public function scenarios()
{
// bypass scenarios() implementation in the parent class
return Model::scenarios();
}
/**
* Creates data provider instance with search query applied
*
* @param array $params
*
* @return ActiveDataProvider
*/
public function search($params)
{
$query = Product::find();
if ( !RoleDefinition::isAdmin() ){
$query->innerJoin("user_account_assignment",'product.id_account = user_account_assignment.id_account' );
$query->andWhere(['user_account_assignment.id_user' => Yii::$app->user->id ]);
}
$dataProvider = new ActiveDataProvider([
'query' => $query,
]);
$this->load($params);
if (!$this->validate()) {
// uncomment the following line if you do not want to return any records when validation fails
// $query->where('0=1');
return $dataProvider;
}
$query->andFilterWhere([
'product.id_product_category' => $this->id_product_category,
'product.id_account' => $this->id_account,
'product.status' => $this->status,
]);
$query->andFilterWhere(['like', 'product_number', $this->product_number])
->andFilterWhere(['like', 'barcode', $this->barcode])
->andFilterWhere(['like', 'name', $this->name]);
return $dataProvider;
}
}