Ejemplo n.º 1
0
 /**
  * Finds the Number model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param \MongoId $id
  * @return \app\modules\mobile\models\Number the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = Number::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('Запрашиваемая страница не найдена.');
     }
 }
Ejemplo n.º 2
0
 public function getOutsideOperator()
 {
     return array_filter($this->outSideOperator, function ($item) {
         $number = Number::findOne($item['id']);
         return $number !== null && $number['operatorId'] == $this->operatorId ? true : false;
     });
 }
Ejemplo n.º 3
0
 public function actionTrip()
 {
     $this->stdout("Загружаю командировки\n", Console::FG_BLUE, Console::BOLD);
     $query = (new Query())->from($this->tripTableName);
     $this->stdout("Источник: таблица '{$this->tripTableName}' " . $query->count() . " записей.\nЦелевая коллекция: '" . Trip::collectionName() . "'\n");
     $this->cleanCollection(Trip::collectionName());
     $successCounter = 0;
     foreach ($query->all() as $item) {
         $trip = new Trip();
         $number = (new Query())->select(['number'])->from($this->numberTableName)->where(['id' => $item['mobile_id']])->one();
         $trip['numberId'] = Number::findOne(['number' => $number['number']])->getPrimaryKey();
         $trip['employeeId'] = (int) $item['employee_id'];
         $trip['duration'] = ['from' => new MongoDate(strtotime("+1 day", (int) $item['rent_date'])), 'to' => new MongoDate((int) $item['return_date'])];
         $trip['numberPossession'] = ['from' => new MongoDate((int) $item['rent_date']), 'to' => new MongoDate(strtotime($item['actual_return_date']))];
         if ($trip['numberPossession']['to'] !== null) {
             $trip['complete'] = true;
         }
         $trip['destination'] = $item['destination'];
         if ($trip->save(false)) {
             $successCounter++;
         }
     }
     $this->stdout("Успешно загружено {$successCounter} записей\n", Console::BOLD, Console::FG_GREEN);
     $this->stdout("\n");
     return Controller::EXIT_CODE_NORMAL;
 }
Ejemplo n.º 4
0
 public function testUpdateHistory()
 {
     $this->specify("History must be updated", function ($newOwnerId, array $history, array $expectedHistory) {
         $model = Number::findOne(['_id' => 'number1']);
         $model->history = $history;
         $model->ownerId = $newOwnerId;
         expect($model->updateHistory())->equals($expectedHistory);
     }, ['examples' => [[null, [], []], [1, [], []], [2, [['ownerId' => 1, 'rentDate' => new MongoDate(strtotime('13-10-2013'))]], [['ownerId' => 1, 'rentDate' => new MongoDate(strtotime('13-10-2013')), 'returnDate' => new MongoDate(time())], ['ownerId' => 2, 'rentDate' => new MongoDate(time())]]], [2, [['ownerId' => 1, 'rentDate' => new MongoDate(strtotime('13-10-2013')), 'returnDate' => new MongoDate(strtotime('13-11-2013'))]], [['ownerId' => 1, 'rentDate' => new MongoDate(strtotime('13-10-2013')), 'returnDate' => new MongoDate(strtotime('13-11-2013'))], ['ownerId' => 2, 'rentDate' => new MongoDate(time())]]], [null, [['ownerId' => 1, 'rentDate' => new MongoDate(strtotime('13-10-2013')), 'returnDate' => new MongoDate(strtotime('13-11-2013'))], ['ownerId' => 2, 'rentDate' => new MongoDate(strtotime('13-10-2014'))]], [['ownerId' => 1, 'rentDate' => new MongoDate(strtotime('13-10-2013')), 'returnDate' => new MongoDate(strtotime('13-11-2013'))], ['ownerId' => 2, 'rentDate' => new MongoDate(strtotime('13-10-2014')), 'returnDate' => new MongoDate(time())]]]]]);
 }
Ejemplo n.º 5
0
 public function beforeSave($insert)
 {
     if (parent::beforeSave($insert)) {
         switch ($this->getScenario()) {
             case 'edit':
                 $this->numberId = Number::findOne(['number' => $this->mobileNumber])->getPrimaryKey();
                 $this->employeeId = Employee::findByName($this->employeeName)->andWhere(['post' => $this->employeePost])->one()->getPrimaryKey();
                 $this->duration = ['from' => new MongoDate(strtotime($this->beginDate)), 'to' => new MongoDate(strtotime($this->endDate))];
                 $this->numberPossession = ['from' => new MongoDate(strtotime($this->rentNumberDate))];
                 break;
             case 'complete':
                 break;
         }
         return true;
     } else {
         return false;
     }
 }