не работает ооп
This commit is contained in:
101
backend/modules/reports/models/Month.php
Normal file
101
backend/modules/reports/models/Month.php
Normal file
@ -0,0 +1,101 @@
|
||||
<?php
|
||||
|
||||
namespace backend\modules\reports\models;
|
||||
|
||||
use common\classes\Debug;
|
||||
use yii\base\Model;
|
||||
use function GuzzleHttp\Psr7\str;
|
||||
|
||||
class Month
|
||||
{
|
||||
|
||||
public $inactive_begin;
|
||||
public $inactive_end;
|
||||
public $active;
|
||||
public $days;
|
||||
|
||||
public function __construct($date = null)
|
||||
{
|
||||
// $date = '2021-08-10';
|
||||
$this->inactive_begin = [];
|
||||
$this->inactive_end = [];
|
||||
// Debug::prn($date);
|
||||
if (!$date and !self::is_date($date)) {
|
||||
|
||||
$date = date('Y-m-d');
|
||||
Debug::dd($date);
|
||||
}
|
||||
// Debug::dd($date);
|
||||
|
||||
$first_day_of_week = self::get_day_week(self::get_first_day($date));
|
||||
$quantity_days = self::get_days_month($date);
|
||||
|
||||
$day = 1;
|
||||
|
||||
for (
|
||||
$index = $first_day_of_week;
|
||||
$index < $first_day_of_week + $quantity_days;
|
||||
$index++, $day++
|
||||
) {
|
||||
$this->active[$index] = $day;
|
||||
}
|
||||
|
||||
$prev_month = date('Y-m-d', strtotime(self::get_first_day($date)) - 3600 * 37);
|
||||
|
||||
$day = self::get_days_month($prev_month);
|
||||
|
||||
for ($index = $first_day_of_week - 1; $index >= 1; $index--, $day--) {
|
||||
$this->inactive_begin[$index] = $day;
|
||||
}
|
||||
|
||||
$day = 1;
|
||||
$index_end = ($first_day_of_week==7?42:35);
|
||||
for ($index = $quantity_days + $first_day_of_week; $index <=$index_end; $index++, $day++) {
|
||||
$this->inactive_end[$index] = $day;
|
||||
}
|
||||
|
||||
$this->days = array_merge($this->inactive_end, $this->inactive_begin, $this->active);
|
||||
// Debug::dd($this);
|
||||
|
||||
}
|
||||
|
||||
public static function next_day($date, $number)
|
||||
{
|
||||
return date('Y-m-d', strtotime($date) + 3600 * 24 * $number);
|
||||
}
|
||||
|
||||
public static function get_first_day($date)
|
||||
{
|
||||
return date('Y-m-01', strtotime($date));
|
||||
}
|
||||
|
||||
public static function get_day_week($date)
|
||||
{
|
||||
$day = date('w', strtotime(date($date)));
|
||||
if($day==0)
|
||||
return 7;
|
||||
return $day;
|
||||
}
|
||||
|
||||
public static function is_date($date)
|
||||
{
|
||||
$date = date_parse($date);
|
||||
if ($date or checkdate($date['month'], $date['day'], $date['year']))
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
public static function get_days_month($date)
|
||||
{
|
||||
return date("t", strtotime($date));
|
||||
}
|
||||
|
||||
|
||||
public function a()
|
||||
{
|
||||
// $a = date('w', strtotime(date('')))
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -2,16 +2,21 @@
|
||||
|
||||
namespace backend\modules\reports\models;
|
||||
|
||||
use common\classes\Debug;
|
||||
use yii\base\Model;
|
||||
use yii\data\ActiveDataProvider;
|
||||
use common\models\Reports;
|
||||
|
||||
|
||||
/**
|
||||
* ReportsSearch represents the model behind the search form of `common\models\Reports`.
|
||||
*/
|
||||
class ReportsSearch extends Reports
|
||||
{
|
||||
public $fio;
|
||||
public $month;
|
||||
public $year;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
@ -57,23 +62,36 @@ class ReportsSearch extends Reports
|
||||
|
||||
$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;
|
||||
|
||||
if (isset($params['date']) and preg_match("/^\d{4}\-(0[1-9]|1[012])\-(0[1-9]|[12][0-9]|3[01])$/", $params['date']) and !isset($params['id'])) {
|
||||
$this->created_at = $params['date'];
|
||||
}
|
||||
|
||||
// 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;
|
||||
// }
|
||||
|
||||
// grid filtering conditions
|
||||
|
||||
|
||||
// Debug::dd($params['date']);
|
||||
|
||||
$query->andFilterWhere([
|
||||
'id' => $this->id,
|
||||
'created_at' => $this->created_at,
|
||||
'user_card.id' => $this->id,
|
||||
'reports.created_at' => $this->created_at,
|
||||
'user_card_id' => $this->user_card_id,
|
||||
]);
|
||||
|
||||
$query->andFilterWhere(['like', 'today', $this->today])
|
||||
->andFilterWhere(['like', 'difficulties', $this->difficulties])
|
||||
->andFilterWhere(['like', 'tomorrow', $this->tomorrow])
|
||||
->andFilterWhere(['like', 'user_card.fio', $this->fio]);
|
||||
->andFilterWhere(['like', 'user_card.fio', $this->fio])
|
||||
->andFilterWhere(['=', 'YEAR(reports.created_at)', $this->year])
|
||||
->andFilterWhere(['=', 'MONTH(reports.created_at)', $this->month]);
|
||||
|
||||
|
||||
return $dataProvider;
|
||||
}
|
||||
|
Reference in New Issue
Block a user