本文整理汇总了PHP中app\models\Product::tableName方法的典型用法代码示例。如果您正苦于以下问题:PHP Product::tableName方法的具体用法?PHP Product::tableName怎么用?PHP Product::tableName使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类app\models\Product
的用法示例。
在下文中一共展示了Product::tableName方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: search
/**
* Creates data provider instance with search query applied
*
* @param array $params
*
* @return ActiveDataProvider
*/
public function search($params)
{
$this->addParam('categoryId', $params);
$query = Product::find()->select(['`p`.*', '`pc`.`name` AS `categoryName`'])->from(Product::tableName() . '`p`')->leftJoin(ProductCategory::tableName() . ' `pc`', '`p`.`category_id` = `pc`.`id`');
$dataProvider = new ActiveDataProvider(['query' => $query]);
$this->load($params);
if (!$this->validate()) {
return $dataProvider;
}
if (!isset($params['sort'])) {
$query->orderBy('`p`.`name`');
}
$query->andFilterWhere(['`p`.`calories`' => $this->calories, '`p`.`protein`' => $this->protein, '`p`.`fat`' => $this->fat, '`p`.`carbohydrate`' => $this->carbohydrate, '`p`.`category_id`' => $this->categoryId, '`pc`.`name`' => $this->categoryName]);
$query->andFilterWhere(['like', '`p`.`name`', $this->name])->andFilterWhere(['like', '`pc`.`name`', $this->categoryName]);
$dataProvider->sort = ['attributes' => ['name', 'calories', 'protein', 'fat', 'carbohydrate', 'categoryName' => [SORT_ASC => '`pc`.`name` ASC', SORT_DESC => '`pc`.`name` DESC']]];
return $dataProvider;
}
示例2: getProductCaloriesQuery
/**
* @param integer $id
* @return Query
*/
public static function getProductCaloriesQuery($id)
{
/**
* SELECT
* SUM(`prod`.`calories`*`dp`.`weight`)
* FROM `diary_products` `dp`
* LEFT JOIN `product` `prod` ON `prod`.`id` = `dp`.`product_id`
* WHERE `dp`.`diary_id` = `d`.`id`
*/
return (new Query())->select('SUM(`prod`.`calories`*`dp`.`weight`) AS `productCalories`')->from(Diary::diary2productsTableName() . ' `dp`')->leftJoin(Product::tableName() . ' `prod`', '`prod`.`id` = `dp`.`product_id`')->where("`dp`.`diary_id` = {$id}");
}
示例3: search
/**
* @param array $params
* @return ArrayDataProvider
*/
public function search($params = [])
{
$query = IngredientEntity::find()->select(['(\'' . IngredientEntity::TYPE_WEIGHT . '\') AS type', 'p.id', 'p.name', 'rp.weight', '`rp`.`weight`*`p`.`calories` AS `calories`', '`rp`.`weight`*`p`.`protein` AS `protein`', '`rp`.`weight`*`p`.`fat` AS `fat`', '`rp`.`weight`*`p`.`carbohydrate` AS `carbohydrate`'])->from(['rp' => Recipe::recipe2productsTableName()])->leftJoin(['p' => Product::tableName()], 'p.id = rp.product_id')->where(['rp.recipe_id' => $this->id])->orderBy('calories DESC');
$dataProvider = new ArrayDataProvider(['allModels' => $query->all(), 'sort' => ['attributes' => ['name', 'weight', 'calories', 'protein', 'fat', 'carbohydrate'], 'defaultOrder' => ['name' => SORT_ASC]], 'pagination' => false]);
return $dataProvider;
}
开发者ID:remk-wadriga,项目名称:calories-calculating-yii2-project,代码行数:10,代码来源:RecipeIngredientsRepository.php
示例4: getCarbohydratesQuery
/**
* @param integer $id
* @return Query
*/
public static function getCarbohydratesQuery($id)
{
return (new Query())->select('SUM(`rp`.`weight`*`p`.`carbohydrate`)/SUM(`rp`.`weight`) AS `carbohydrate`')->from(['rp' => self::recipe2productsTableName()])->leftJoin(Product::tableName() . ' `p`', '`p`.`id` = `rp`.`product_id`')->where("`rp`.`recipe_id` = {$id}");
}
示例5: getIngredients
/**
* @return array
*/
public function getIngredients()
{
if ($this->_ingredients !== null) {
return $this->_ingredients;
}
$this->_ingredients = [];
$items = (new Query())->select(['`p`.`id` AS `id`', '`p`.`name` AS `name`', '`rp`.`weight` AS `weight`', '`p`.`calories` AS `calories`'])->from(self::recipe2productsTableName() . ' `rp`')->leftJoin(Product::tableName() . ' `p`', '`p`.`id` = `rp`.`product_id`')->where(['`rp`.`recipe_id`' => $this->id])->all();
if (!empty($items)) {
$this->_ingredients = $items;
}
return $this->_ingredients;
}
示例6: getProductsCountQuery
/**
* @param integer|string $id
* @return Query
*/
public static function getProductsCountQuery($id)
{
return (new Query())->select('COUNT(*) AS `productsCount`')->from(Product::tableName())->where("`category_id` = {$id}");
}
示例7: searchOne
/**
* @param array|string|integer $params
* @return Portion
*/
public static function searchOne($params)
{
$where = is_array($params) ? $params : ['p.id' => $params];
return Portion::find()->select(['p.*', 'p.weight', 'categoryName' => 'c.name', 'recipeName' => 'r.name', 'calories' => 'SUM(`rp`.`weight`*`prod`.`calories`)/SUM(`rp`.`weight`)*`p`.`weight`', 'proteins' => 'SUM(`rp`.`weight`*`prod`.`protein`)/SUM(`rp`.`weight`)*`p`.`weight`', 'fats' => 'SUM(`rp`.`weight`*`prod`.`fat`)/SUM(`rp`.`weight`)*`p`.`weight`', 'carbohydrates' => 'SUM(`rp`.`weight`*`prod`.`carbohydrate`)/SUM(`rp`.`weight`)*`p`.`weight`'])->from(['p' => Portion::tableName()])->innerJoin(['r' => Recipe::tableName()], '`r`.`id` = `p`.`recipe_id`')->innerJoin(['rp' => Recipe::recipe2productsTableName()], '`rp`.`recipe_id` = `r`.`id`')->leftJoin(['c' => RecipeCategory::tableName()], '`c`.`id` = `r`.`category_id`')->leftJoin(['prod' => Product::tableName()], '`prod`.`id` = `rp`.`product_id`')->where($where)->one();
}