Example #1
0
 /**
  * @param \MongoDate $date
  * @return array|string
  */
 public static function participantsCountPerHour(\MongoDate $date)
 {
     /** @var $collection Collection */
     $collection = \Yii::$app->get('mongodb')->getCollection(Request::collectionName());
     $map = new \MongoCode("function() {\n            for (var i = 8 * 60; i < 19 * 60; i = i + 30) {\n                if (this.beginTime < i + 30 && this.endTime > i) {\n                    emit(i, this.participantsId.length);\n                }\n            }\n        }");
     $reduce = new \MongoCode("function (key, values) {return Array.sum(values)}");
     $out = ['inline' => true];
     $condition = ['date' => $date, 'mode' => Request::MODE_WITH_VKS, 'status' => ['$ne' => Request::STATUS_CANCEL]];
     $result = $collection->mapReduce($map, $reduce, $out, $condition);
     return ArrayHelper::map($result, '_id', 'value');
 }
Example #2
0
 public function approveRoom($roomId)
 {
     $request = $this->request;
     $roomMongoId = new \MongoId($roomId);
     $approvedRoomMongoId = new \MongoId($this->approvedRoomId);
     /** @var Collection $participantCollection*/
     $participantCollection = \Yii::$app->get('mongodb')->getCollection(Participant::collectionName());
     /** @var Collection $requestCollection*/
     $requestCollection = \Yii::$app->get('mongodb')->getCollection(Request::collectionName());
     $newLogRecord = false;
     if ($this->approvedRoomId !== $roomId) {
         $key = array_search($roomMongoId, $request->participantsId);
         /** Если меняется комната в заявке */
         if ($key !== false) {
             $requestCollection->update(['_id' => $request->_id, 'participantsId' => $roomMongoId], ['$set' => ['participantsId.$' => $approvedRoomMongoId]]);
             $participantCollection->update(['_id' => $roomMongoId], ['$pull' => ['log' => ['requestId' => $request->_id]]]);
             \Yii::$app->mailer->compose(['html' => 'changeRoom'], ['request' => $request, 'oldRoom' => Participant::findOne(['_id' => $roomMongoId]), 'newRoom' => Participant::findOne(['_id' => $approvedRoomMongoId])])->setFrom([\Yii::$app->params['email.admin'] => 'Служба технической поддержки ' . \Yii::$app->name])->setTo($request->owner->email)->setSubject("Изменение помещения в заявке")->send();
             $newLogRecord = true;
         }
     }
     $this->saveRoomStatus($approvedRoomMongoId, Participant::STATUS_APPROVE, $newLogRecord);
 }
Example #3
0
 /**
  * @param Request $request
  * @return Participant[]
  * @throws \yii\base\InvalidConfigException
  * @throws \yii\mongodb\Exception
  */
 public static function findAllByRequest(Request $request)
 {
     /** @var $collection Collection */
     $collection = \Yii::$app->get('mongodb')->getCollection(Request::collectionName());
     $busyParticipants = $collection->aggregate([['$match' => ['_id' => ['$ne' => $request->primaryKey], 'date' => $request->date, 'beginTime' => ['$lt' => $request->endTime], 'endTime' => ['$gt' => $request->beginTime], 'status' => ['$ne' => $request::STATUS_CANCEL]]], ['$unwind' => '$participantsId'], ['$project' => ['_id' => 0, 'id' => '$participantsId', 'beginTime' => 1, 'endTime' => 1]]]);
     /** @var Participant[] $participants */
     $participants = self::find()->with('company', 'confirmPerson')->orderBy('name')->all();
     $busyParticipantsId = ArrayHelper::getColumn($busyParticipants, 'id');
     foreach ($participants as $key => $participant) {
         $busyParticipantKey = array_search($participant->primaryKey, $busyParticipantsId);
         if ($busyParticipantKey !== false) {
             $participants[$key]->setBusy();
             $participants[$key]->busyFrom = $busyParticipants[$busyParticipantKey]['beginTime'];
             $participants[$key]->busyTo = $busyParticipants[$busyParticipantKey]['endTime'];
         }
     }
     return $participants;
 }