initial release
This commit is contained in:
@@ -2,6 +2,9 @@
|
||||
|
||||
namespace common\models;
|
||||
|
||||
use yii\behaviors\TimestampBehavior;
|
||||
use yii\db\ActiveRecord;
|
||||
|
||||
/**
|
||||
* This is the model class for table "meal".
|
||||
*
|
||||
@@ -13,12 +16,11 @@ namespace common\models;
|
||||
* @property int $fat
|
||||
* @property int $carbohydrates
|
||||
* @property int $fiber
|
||||
* @property int $meal
|
||||
* @property int $user_id
|
||||
* @property int $created_at
|
||||
* @property int $updated_at
|
||||
*/
|
||||
class Meal extends \yii\db\ActiveRecord
|
||||
class Meal extends ActiveRecord
|
||||
{
|
||||
|
||||
public $base64File;
|
||||
@@ -31,14 +33,28 @@ class Meal extends \yii\db\ActiveRecord
|
||||
return 'meal';
|
||||
}
|
||||
|
||||
|
||||
public function behaviors()
|
||||
{
|
||||
return [
|
||||
[
|
||||
'class' => TimestampBehavior::class,
|
||||
'attributes' => [
|
||||
ActiveRecord::EVENT_BEFORE_INSERT => ['created_at', 'updated_at'],
|
||||
ActiveRecord::EVENT_BEFORE_UPDATE => ['updated_at'],
|
||||
],
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function rules()
|
||||
{
|
||||
return [
|
||||
[['food_name', 'file_name', 'calories', 'protein', 'fat', 'carbohydrates', 'fiber', 'meal', 'created_at', 'updated_at'], 'required'],
|
||||
[['user_id', 'calories', 'protein', 'fat', 'carbohydrates', 'fiber', 'meal', 'created_at', 'updated_at'], 'integer'],
|
||||
[['food_name', 'file_name', 'calories', 'protein', 'fat', 'carbohydrates', 'fiber'], 'required'],
|
||||
[['user_id', 'calories', 'protein', 'fat', 'carbohydrates', 'fiber', 'created_at', 'updated_at'], 'integer'],
|
||||
[['file_name'], 'string', 'max' => 255],
|
||||
];
|
||||
}
|
||||
@@ -56,10 +72,8 @@ class Meal extends \yii\db\ActiveRecord
|
||||
'fat' => 'Fat',
|
||||
'carbohydrates' => 'Carbohydrates',
|
||||
'fiber' => 'Fiber',
|
||||
'meal' => 'Meal',
|
||||
'created_at' => 'Created At',
|
||||
'updated_at' => 'Updated At',
|
||||
];
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -89,7 +89,7 @@ class User extends ActiveRecord implements IdentityInterface
|
||||
public function rules()
|
||||
{
|
||||
return [
|
||||
['status', 'default', 'value' => self::STATUS_VERIFIED],
|
||||
['status', 'default', 'value' => self::STATUS_ACTIVE],
|
||||
[['email'], 'email'],
|
||||
[['email'], 'unique'],
|
||||
[['sales_agent_id', 'created_at', 'updated_at'], 'integer'],
|
||||
|
||||
39
common/models/search/MealSearch.php
Normal file
39
common/models/search/MealSearch.php
Normal file
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
|
||||
namespace common\models\search;
|
||||
|
||||
use common\models\Meal;
|
||||
use Yii;
|
||||
use yii\data\ActiveDataProvider;
|
||||
|
||||
class MealSearch extends Meal
|
||||
{
|
||||
|
||||
/**
|
||||
* Creates data provider instance with search query applied
|
||||
*
|
||||
* @param array $params
|
||||
*
|
||||
* @return ActiveDataProvider
|
||||
*/
|
||||
public function search($params)
|
||||
{
|
||||
$query = Meal::find();
|
||||
|
||||
$dataProvider = new ActiveDataProvider([
|
||||
'query' => $query,
|
||||
]);
|
||||
|
||||
$this->load($params);
|
||||
|
||||
// ALWAYS filter by user_id that is signed in
|
||||
$query->andFilterWhere(['user_id' => Yii::$app->user->id]);
|
||||
|
||||
if (!$this->validate()) {
|
||||
return $dataProvider;
|
||||
}
|
||||
|
||||
|
||||
return $dataProvider;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user