/**
  * @param $attribute
  * @param \MongoDate|string|int $oldValue
  * @param \MongoDate|string|int $newValue
  * @return array|bool
  */
 private function getLogRow($attribute, $oldValue, $newValue)
 {
     $row = ['date' => new \MongoDate(), 'user' => \Yii::$app->user->identity['fullName']];
     switch ($attribute) {
         case 'date':
             $row['action'] = "Изменилась дата с " . \Yii::$app->formatter->asDate($oldValue->toDateTime()) . " на " . \Yii::$app->formatter->asDate($newValue->toDateTime());
             return $row;
         case 'beginTime':
             $row['action'] = "Изменилось время начала с " . MinuteFormatter::asString($oldValue) . " на " . MinuteFormatter::asString($newValue);
             return $row;
         case 'endTime':
             $row['action'] = "Изменилось время окончания с " . MinuteFormatter::asString($oldValue) . " на " . MinuteFormatter::asString($newValue);
             return $row;
         case 'participantsId':
             $action = '';
             foreach ($newValue as $item) {
                 $index = array_search($item, $oldValue);
                 if ($index !== false) {
                     unset($oldValue[$index]);
                 } else {
                     $action .= "Участник '" . Participant::findOne(['_id' => $item])->shortName . "' был добавлен\n";
                 }
             }
             foreach ($oldValue as $item) {
                 $action .= "Участник '" . Participant::findOne(['_id' => $item])->shortName . "' был удалён\n";
             }
             $row['action'] = $action;
             return $row;
         default:
             return false;
     }
 }
 /**
  * Creates data provider instance with search query applied
  *
  * @return ActiveDataProvider
  */
 public function search()
 {
     $query = Participant::find()->with('company');
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     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;
     }
     $query->andFilterWhere(['like', 'name', $this->name])->andFilterWhere(['like', 'shortName', $this->shortName])->andFilterWhere(['companyId' => $this->companyId])->andFilterWhere(['like', 'ipAddress', $this->ipAddress])->andFilterWhere(['like', 'note', $this->note]);
     return $dataProvider;
 }
Example #3
0
 public function init()
 {
     parent::init();
     $this->on(self::EVENT_STATUS_CHANGED, function (RoomStatusChangedEvent $event) {
         if ($event->roomStatus === self::STATUS_CONSIDIRATION) {
             (new Mailer())->send($event);
         } else {
             $request = $event->request;
             $count = Participant::find()->where(['log' => ['$elemMatch' => ['requestId' => $request->_id, 'status' => self::STATUS_CONSIDIRATION]]])->count();
             if ($count === 0) {
                 $request->status = Request::STATUS_OSKR_CONSIDERATION;
                 $request->save(false);
                 $request->trigger(Request::EVENT_STATUS_CHANGED, new RequestStatusChangedEvent(['request' => $request]));
             }
         }
     });
 }
 public function behaviors()
 {
     return ['verbs' => ['class' => VerbFilter::className(), 'actions' => ['index' => ['get'], 'view' => ['get'], 'create' => ['get', 'post'], 'update' => ['get', 'post'], 'delete' => ['post'], 'approve' => ['post'], 'cancel' => ['get', 'post']]], 'access' => ['class' => AccessControl::className(), 'only' => ['approve-booking', 'update', 'create'], 'rules' => [['actions' => ['create'], 'allow' => true, 'roles' => ['@']], ['actions' => ['approve-booking'], 'allow' => true, 'matchCallback' => function () {
         /** @var Participant $room */
         $room = Participant::findOne(['_id' => \Yii::$app->request->get('roomId')]);
         return \Yii::$app->user->identity['_id'] == $room->confirmPersonId;
     }], ['actions' => ['update'], 'allow' => true, 'matchCallback' => function () {
         if (\Yii::$app->user->can(SystemPermission::APPROVE_REQUEST)) {
             return true;
         }
         $request = Request::findOne(['_id' => \Yii::$app->request->get('id')]);
         if (!\Yii::$app->user->can(SystemPermission::UPDATE_REQUEST, ['object' => $request])) {
             return false;
         }
         $allowTime = $request->date->sec + ($request->beginTime - \Yii::$app->params['vks.allowRequestUpdateMinute']) * 60;
         $now = time() + 3 * 60 * 60;
         //Минус разница формата TimeZone
         if ($now > $allowTime) {
             throw new ForbiddenHttpException("Заявку нельзя редактировать менее чем за " . \Yii::$app->params['vks.allowRequestUpdateMinute'] . " минут до начала мероприятия");
         } else {
             return true;
         }
     }]]]];
 }
Example #5
0
 public function getRoomApproveList()
 {
     /** @var Collection $collection */
     $collection = \Yii::$app->get('mongodb')->getCollection(Participant::collectionName());
     $list = $collection->aggregate([['$match' => ['confirmPersonId' => $this->_id, 'log.status' => Participant::STATUS_CONSIDIRATION]], ['$unwind' => '$log'], ['$match' => ['log.status' => Participant::STATUS_CONSIDIRATION]], ['$project' => ['name' => 1, 'request' => '$log.requestId']]]);
     foreach ($list as $key => $value) {
         $list[$key]['request'] = VksRequest::findOne(['_id' => $value['request']]);
     }
     return $list;
 }
 public function actions()
 {
     return ['index' => ['class' => SearchAction::className(), 'modelClass' => VksParticipantSearch::className()], 'view' => ['class' => ViewAction::className(), 'modelClass' => Participant::className()], 'create' => ['class' => CreateAction::className(), 'modelClass' => Participant::className()], 'update' => ['class' => UpdateAction::className(), 'modelClass' => Participant::className()], 'delete' => ['class' => DeleteAction::className(), 'modelClass' => Participant::className()]];
 }
Example #7
0
 public static function roomsList()
 {
     /** @var Collection $collection */
     $collection = \Yii::$app->get('mongodb')->getCollection(Participant::collectionName());
     $cursor = $collection->find(['confirmPersonId' => \Yii::$app->user->identity['_id']], ['name' => 1]);
     $rooms = [];
     foreach ($cursor as $document) {
         $rooms[(string) $document['_id']] = $document['name'];
     }
     return $rooms;
 }
 public function __construct(Request $request)
 {
     parent::__construct($request);
     $this->_notifyParticipants = Participant::find()->with('company')->where(['_id' => ['$in' => $this->_request->participantsId], 'supportEmails' => ['$exists' => 1]])->all();
 }
Example #9
0
 public function rules()
 {
     return array_merge(parent::rules(), [[['topic', 'dateInput', 'beginTimeInput', 'endTimeInput', 'mode', 'foreignOrganizations'], 'required'], ['dateInput', MongoDateValidator::className(), 'format' => 'dd.MM.yyyy', 'min' => \Yii::$app->formatter->asDate(mktime(0, 0, 0), 'dd.MM.yyyy'), 'max' => \Yii::$app->formatter->asDate(strtotime("+1 week"), 'dd.MM.yyyy')], ['beginTimeInput', MinuteValidator::className(), 'min' => MinuteFormatter::asString(\Yii::$app->params['vks.minTime']), 'max' => $this->endTimeInput, 'minuteAttribute' => 'beginTime'], ['beginTimeInput', 'compare', 'compareAttribute' => 'endTimeInput', 'operator' => '!=='], ['beginTimeInput', function ($attribute) {
         if (\Yii::$app->user->can(SystemPermission::APPROVE_REQUEST)) {
             return;
         }
         $allowTimeStamp = $this->date->sec + ($this->beginTime - \Yii::$app->params['vks.allowRequestUpdateMinute']) * 60;
         $now = time() + 3 * 60 * 60;
         if ($now > $allowTimeStamp) {
             $this->addError($attribute, "Должно быть не меньше 20 минут от текущего времени");
         }
     }], ['endTimeInput', MinuteValidator::className(), 'min' => $this->beginTimeInput, 'max' => MinuteFormatter::asString(\Yii::$app->params['vks.maxTime']), 'minuteAttribute' => 'endTime'], ['audioRecord', 'boolean'], ['audioRecord', 'filter', 'filter' => function ($value) {
         return boolval($value);
     }], ['mode', 'in', 'range' => [self::MODE_WITH_VKS, self::MODE_WITHOUT_VKS]], ['mode', 'filter', 'filter' => function ($value) {
         return intval($value);
     }], ['participantsId', 'required', 'on' => 'default', 'message' => 'Необходимо выбрать участников'], ['participantsId', function ($attribute) {
         $value = $this->{$attribute};
         if ($this->mode === self::MODE_WITH_VKS && count($value) < 2) {
             $this->addError($attribute, 'Количество участников должно быть не менее двух');
             return;
         }
         if ($this->mode === self::MODE_WITHOUT_VKS && count($value) !== 1) {
             $this->addError($attribute, 'Помещение для совещания должно быть только одно');
             return;
         }
         $allParticipants = Participant::findAllByRequest($this);
         $allParticipantsId = ArrayHelper::getColumn($allParticipants, '_id');
         foreach ($value as $participant) {
             $key = array_search($participant, $allParticipantsId);
             if ($key === false) {
                 $this->addError($attribute, 'Участник не найден');
                 return;
             } elseif ($allParticipants[$key]->isBusy) {
                 $busyParticipant = $allParticipants[$key];
                 $this->addError($attribute, "Участник '{$busyParticipant->name}' занят с " . MinuteFormatter::asString($busyParticipant->busyFrom) . " до " . MinuteFormatter::asString($busyParticipant->busyTo));
             }
         }
     }, 'on' => 'default'], ['foreignOrganizations', 'boolean'], ['rsoUploadedFiles', 'file', 'skipOnEmpty' => false, 'mimeTypes' => ['image/*', 'application/pdf', 'application/msword', 'application/vnd.openxmlformats-officedocument.wordprocessingml.document', 'application/excel', 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'], 'maxSize' => 3 * 1024 * 1024, 'maxFiles' => 3, 'when' => function ($model) {
         return (bool) $model->foreignOrganizations && count($model->rsoFiles) == 0;
     }], [['note', 'equipment'], 'safe']]);
 }
Example #10
0
 /**
  * @param \MongoId $roomId
  * @return string
  * @throws \yii\base\InvalidConfigException
  * @throws \yii\mongodb\Exception
  */
 public function getRoomStatus(\MongoId $roomId)
 {
     if ($this->_roomsStatus === null) {
         /** @var Collection $collection */
         $collection = \Yii::$app->get('mongodb')->getCollection(Participant::collectionName());
         $pipeline = [['$unwind' => '$log'], ['$match' => ['log.requestId' => $this->_id]], ['$project' => ['status' => '$log.status']]];
         $this->_roomsStatus = ArrayHelper::map($collection->aggregate($pipeline), function ($item) {
             return (string) $item['_id'];
         }, 'status');
     }
     return $this->_roomsStatus[(string) $roomId];
 }
Example #11
0
 * teleport
 * Created: 27.10.15 9:32
 * @copyright Copyright (c) 2015 OSKR NIAEP
 */
use yii\helpers\Html;
use yii\helpers\ArrayHelper;
use common\components\MinuteFormatter;
use common\models\Company;
use yii\helpers\BaseHtml;
use common\models\vks\Participant;
/**
 * @var $form \kartik\form\ActiveForm
 * @var $this \yii\web\View
 * @var $model \frontend\models\vks\RequestForm
 */
$participants = Participant::findAllByRequest($model);
?>

<div id="vks-participants">

    <div id="checked-rooms-container" class="form-group">

        Выбрано:

        <?php 
if ($model->participantsId) {
    ?>

            <?php 
    foreach ($participants as $participant) {
        ?>
Example #12
0
        <?php 
Modal::end();
?>

        <?php 
$form = ActiveForm::begin(['id' => 'vks-search-form', 'action' => ['vks-request/index'], 'method' => 'get', 'options' => ['class' => 'form-inline'], 'enableClientValidation' => false, 'formConfig' => ['showLabels' => false]]);
?>

        <?php 
echo $form->field($model, 'dateInput')->widget(DatePicker::className(), ['type' => DatePicker::TYPE_BUTTON, 'pluginOptions' => ['autoclose' => true, 'todayHighlight' => true, 'format' => 'dd.mm.yyyy']]);
?>

        <?php 
$query = Participant::find()->select(['_id', 'name', 'companyId'])->with('company');
$participants = ArrayHelper::toArray($query->all(), [Participant::className() => ['id' => function ($item) {
    return (string) $item->primaryKey;
}, 'name', 'company' => 'company.name']]);
$participantsIdData = ArrayHelper::map($participants, 'id', 'name', 'company');
?>

        <?php 
echo $form->field($model, 'participantsId')->widget(Select2::className(), ['data' => $participantsIdData, 'showToggleAll' => false, 'options' => ['placeholder' => 'Фильтр по участникам', 'multiple' => true], 'pluginOptions' => ['width' => '600px']]);
?>

        <?php 
echo Html::resetButton('Сброс', ['class' => 'btn btn-primary']);
?>

        <?php 
ActiveForm::end();