reports fix
This commit is contained in:
@ -3,6 +3,7 @@
|
||||
|
||||
namespace frontend\modules\api\models;
|
||||
|
||||
use common\classes\Debug;
|
||||
use common\models\Reports;
|
||||
use yii\base\Model;
|
||||
|
||||
@ -10,6 +11,7 @@ use yii\base\Model;
|
||||
class ReportSearchForm extends Model
|
||||
{
|
||||
public $user_card_id;
|
||||
public $user_id;
|
||||
public $limit;
|
||||
public $offset;
|
||||
/** @var string */
|
||||
@ -22,6 +24,7 @@ class ReportSearchForm extends Model
|
||||
$this->limit = 10;
|
||||
$this->offset = 0;
|
||||
$this->user_card_id = null;
|
||||
$this->user_id = null;
|
||||
|
||||
$this->toDate = date('Y-m-d');
|
||||
$this->fromDate = date('Y-m-d');
|
||||
@ -36,7 +39,7 @@ class ReportSearchForm extends Model
|
||||
[['byDate'], 'safe'],
|
||||
[['fromDate', 'toDate', 'date'], 'string'],
|
||||
// [['fromDate', 'toDate', 'date'], 'date', 'format' => 'php:Y-m-d'],
|
||||
[[ 'user_card_id'], 'integer', 'min' => 0],
|
||||
[[ 'user_card_id', 'user_id'], 'integer', 'min' => 0],
|
||||
];
|
||||
}
|
||||
|
||||
@ -48,8 +51,8 @@ class ReportSearchForm extends Model
|
||||
$queryBuilder->andWhere(['between', 'reports.created_at', $this->fromDate, $this->toDate]);
|
||||
}
|
||||
|
||||
if (isset($this->user_card_id)) {
|
||||
$queryBuilder->andWhere(['reports.user_card_id' => $this->user_card_id]);
|
||||
if (isset($this->user_id)) {
|
||||
$queryBuilder->andWhere(['reports.user_id' => $this->user_id]);
|
||||
}
|
||||
|
||||
$queryBuilder->limit($this->limit)
|
||||
@ -61,7 +64,7 @@ class ReportSearchForm extends Model
|
||||
public function findByDate()
|
||||
{
|
||||
return Reports::find()->with('task')
|
||||
->where(['reports.user_card_id' => $this->user_card_id])
|
||||
->where(['reports.user_id' => $this->user_id])
|
||||
->andWhere(['reports.created_at' => $this->date])
|
||||
->asArray()->all();
|
||||
}
|
||||
@ -69,7 +72,7 @@ class ReportSearchForm extends Model
|
||||
public function reportsByDate()
|
||||
{
|
||||
return Reports::find()->with('task')
|
||||
->where(['reports.user_card_id' => $this->user_card_id])
|
||||
->where(['reports.user_id' => $this->user_id])
|
||||
->andWhere(['between', 'reports.created_at', $this->fromDate, $this->toDate])
|
||||
->asArray()->all();
|
||||
}
|
||||
|
Reference in New Issue
Block a user