コード例 #1
0
ファイル: TripSearch.php プロジェクト: shubnikofff/mobiles
 public function search(array $params)
 {
     $query = Trip::find();
     $query->with('number', 'employee');
     $query->orderBy(['numberPossession.from' => SORT_DESC]);
     $dataProvider = new ActiveDataProvider(['query' => $query, 'sort' => false]);
     if (!($this->load($params) && $this->validate())) {
         return $dataProvider;
     }
     if (!empty($this->mobileNumber)) {
         $numberIds = array_map(function ($item) {
             return $item['_id'];
         }, Number::find()->select(['_id'])->asArray()->where(['like', 'number', $this->mobileNumber])->all());
         $query->andWhere(['in', 'numberId', $numberIds]);
     }
     if (!empty($this->employeeName)) {
         $employeeIds = array_map(function ($item) {
             return (int) $item['id'];
         }, Employee::findByName($this->employeeName, true)->select('id')->asArray()->all());
         $query->andWhere(['in', 'employeeId', $employeeIds]);
     }
     if ($this->complete === self::INCOMPLETE) {
         $query->andWhere(['complete' => false]);
     }
     if ($this->rentNumberFrom !== $this->rentNumberTo) {
         $query->andWhere(['numberPossession.from' => ['$gt' => new MongoDate(strtotime($this->rentNumberFrom)), '$lte' => new MongoDate(strtotime($this->rentNumberTo))]]);
     }
     $query->andFilterWhere(['like', 'destination', $this->destination]);
     return $dataProvider;
 }
コード例 #2
0
 public function actionNumberList($q = null)
 {
     $query = Number::find()->select(['number'])->where(['like', 'number', $q])->asArray();
     $query->andWhere(['options' => Number::OPTION_TRIP]);
     $out = [];
     foreach ($query->all() as $item) {
         $out[] = ['value' => $item['number']];
     }
     echo Json::encode($out);
 }
コード例 #3
0
 public function actionUpdate()
 {
     foreach (Number::find()->all() as $number) {
         $history = [];
         foreach ($number->history as $item) {
             /** @var Employee $employee */
             $employee = Employee::findOne(['id' => $item['ownerId']]);
             if (!is_null($employee)) {
                 $newItem = ['ownerName' => $employee->fullName, 'ownerPost' => $employee->post];
                 if (isset($item['rentDate'])) {
                     $newItem['rentDate'] = $item['rentDate'];
                 }
                 if (isset($item['returnDate'])) {
                     $newItem['returnDate'] = $item['returnDate'];
                 }
                 $history[] = $newItem;
             }
             $number->history = $history;
             $number->save(false);
         }
     }
 }
コード例 #4
0
ファイル: Report.php プロジェクト: shubnikofff/mobiles
 /**
  * @return array
  * @throws \yii\mongodb\Exception
  */
 public function getOutsideDb()
 {
     return array_filter($this->outSideDb, function ($item) {
         return !Number::find()->where(['number' => $item['number']])->exists();
     });
 }
コード例 #5
0
ファイル: NumberSearch.php プロジェクト: shubnikofff/mobiles
 public function export()
 {
     $dataProvider = new ActiveDataProvider(['pagination' => false]);
     $dataProvider->query = Number::find()->with('owner')->where(['destination' => self::DESTINATION_PHONE]);
     return $dataProvider;
 }
コード例 #6
0
 public function init()
 {
     parent::init();
     $this->nowInDb = Number::find()->where(['number' => $this->number])->count() ? true : false;
 }
コード例 #7
0
 public function actionAll()
 {
     $numbers = Number::find()->with('owner')->orderBy('number')->all();
     return $this->render('all', ['numbers' => $numbers]);
 }