Ejemplo n.º 1
0
 public function actionAnswer($id = null, $domain = null)
 {
     if ($id == null || $domain == null) {
         $this->actionAuthorization();
     } else {
         if (!Domain::findOne(['name' => $domain])) {
             $this->actionAuthorization();
         } else {
             Yii::trace("Respondendo a reserva id: " . $id);
             $userId = Yii::$app->user->getId();
             //Confere se usuário pode autorizar
             $conn = Connection::find()->where(['reservation_id' => $id])->one();
             $auth = ConnectionAuth::find()->where(['connection_id' => $conn->id, 'type' => ConnectionAuth::TYPE_GROUP])->one();
             if ($auth) {
                 $onGroup = false;
                 $roles = User::findOne($userId)->getRoles()->all();
                 foreach ($roles as $role) {
                     if (($role->domain == $auth->domain || $role->domain == null) && $role->getGroup()->id == $auth->manager_group_id) {
                         $onGroup = true;
                     }
                 }
                 if (!$onGroup) {
                     return $this->goHome();
                 }
             }
             $auth = ConnectionAuth::find()->where(['connection_id' => $conn->id, 'type' => ConnectionAuth::TYPE_USER])->one();
             if ($auth && $auth->manager_user_id != $userId) {
                 return $this->goHome();
             }
             $reservation = Reservation::findOne(['id' => $id]);
             //Confere se alguma ja expirou
             $connectionsExpired = $conn = Connection::find()->where(['reservation_id' => $reservation->id])->andWhere(['<=', 'start', DateUtils::now()])->all();
             foreach ($connectionsExpired as $connection) {
                 $requests = ConnectionAuth::find()->where(['connection_id' => $connection->id, 'status' => Connection::AUTH_STATUS_PENDING])->all();
                 foreach ($requests as $request) {
                     $request->changeStatusToExpired();
                     $connection->auth_status = Connection::AUTH_STATUS_EXPIRED;
                     $connection->save();
                     ReservationNotification::create($connection->id);
                 }
             }
             $allRequest = null;
             $connections = Connection::find()->where(['reservation_id' => $id])->all();
             foreach ($connections as $conn) {
                 if ($allRequest == null) {
                     $allRequest = ConnectionAuth::find()->where(['connection_id' => $conn->id, 'domain' => $domain]);
                 } else {
                     $allRequest->union(ConnectionAuth::find()->where(['connection_id' => $conn->id, 'domain' => $domain]));
                 }
             }
             $allRequest = $allRequest->all();
             $domainRoles = User::findOne(['id' => $userId])->getRoles()->all();
             $requests = [];
             foreach ($allRequest as $request) {
                 if ($request->manager_user_id == $userId) {
                     $requests[$request->id] = $request;
                 } else {
                     foreach ($domainRoles as $domainRule) {
                         $groupId = $domainRule->getGroup()->id;
                         if ($request->manager_group_id == $groupId) {
                             $requests[$request->id] = $request;
                         }
                     }
                 }
             }
             $events = [];
             foreach ($requests as $request) {
                 $events[] = ['id' => $request->id, 'title' => "\n" . $request->getConnection()->one()->getReservation()->one()->bandwidth . " Mbps", 'start' => Yii::$app->formatter->asDatetime($request->getConnection()->one()->start, "php:Y-m-d H:i:s"), 'end' => Yii::$app->formatter->asDatetime($request->getConnection()->one()->finish, "php:Y-m-d H:i:s")];
             }
             $info = new AuthorizationDetailed($reservation, Connection::find()->where(['reservation_id' => $id])->one()->id, $domain);
             if (sizeof($requests) <= 0) {
                 return $this->redirect('index');
             } else {
                 return $this->render('detailed', array('domain' => $domain, 'info' => $info, 'requests' => $requests, 'events' => $events, 'language' => Yii::$app->language));
             }
         }
     }
 }
Ejemplo n.º 2
0
 public function searchByDomains($params)
 {
     $this->load($params);
     $userId = Yii::$app->user->getId();
     $now = DateUtils::now();
     $authorizations = [];
     //Armazena os pedidos
     $reservationsVisited = [];
     //Armazena as reservas ja incluidas nos pedidos e o dominio ao qual o pedido foi feito.
     //Pega todas requisições feitas para o usuário
     if ($this->domain) {
         $userRequests = ConnectionAuth::find()->where(['domain' => $this->domain, 'manager_user_id' => $userId, 'status' => Connection::AUTH_STATUS_PENDING])->all();
     } else {
         $userRequests = ConnectionAuth::find()->where(['manager_user_id' => $userId, 'status' => Connection::AUTH_STATUS_PENDING])->all();
     }
     foreach ($userRequests as $request) {
         //Limpa mantendo apenas 1 por reserva
         $uniq = true;
         $conn = Connection::find()->where(['id' => $request->connection_id])->andWhere(['<=', 'start', DateUtils::now()])->one();
         if (isset($conn)) {
             $request->changeStatusToExpired();
             $conn->auth_status = Connection::AUTH_STATUS_EXPIRED;
             $conn->save();
             ReservationNotification::create($conn->id);
         } else {
             $conn = Connection::find()->where(['id' => $request->connection_id])->andWhere(['>', 'start', DateUtils::now()])->one();
             foreach ($reservationsVisited as $res) {
                 if ($conn->reservation_id == $res[0] && $request->domain == $res[1]) {
                     $uniq = false;
                 }
             }
             if ($uniq) {
                 $aux = [];
                 $aux[0] = $conn->reservation_id;
                 $aux[1] = $request->domain;
                 $reservationsVisited[] = $aux;
                 $source = $conn->getFirstPath()->one();
                 $destination = $conn->getLastPath()->one();
                 if (!$this->src_domain || $this->src_domain == $source->domain) {
                     if (!$this->dst_domain || $this->dst_domain == $destination->domain) {
                         $form = new AuthorizationForm();
                         $form->setValues(Reservation::findOne(['id' => $conn->reservation_id]), $request->domain, $source->domain, $destination->domain);
                         $authorizations[] = $form;
                     }
                 }
             }
         }
     }
     //Pega todos os papeis do usuário
     $domainRoles = User::findOne(['id' => $userId])->getRoles()->all();
     foreach ($domainRoles as $role) {
         //Passa por todos papeis
         if ($this->domain) {
             $groupRequests = ConnectionAuth::find()->where(['domain' => $this->domain, 'manager_group_id' => $role->getGroup()->id, 'status' => Connection::AUTH_STATUS_PENDING])->all();
         } else {
             $groupRequests = ConnectionAuth::find()->where(['manager_group_id' => $role->getGroup()->id, 'status' => Connection::AUTH_STATUS_PENDING])->all();
         }
         foreach ($groupRequests as $request) {
             //Passa por todas requisições para testar se o dominio corresponde
             $domain = Domain::findOne(['name' => $request->domain]);
             if ($domain) {
                 if ($role->domain == NULL || $role->domain == $domain->name) {
                     $uniq = true;
                     $conn = Connection::find()->where(['id' => $request->connection_id])->andWhere(['<=', 'start', DateUtils::now()])->one();
                     if (isset($conn)) {
                         $request->changeStatusToExpired();
                         $conn->auth_status = Connection::AUTH_STATUS_EXPIRED;
                         $conn->save();
                         ReservationNotification::create($conn->id);
                     } else {
                         $conn = Connection::find()->where(['id' => $request->connection_id])->andWhere(['>', 'start', DateUtils::now()])->one();
                         foreach ($reservationsVisited as $res) {
                             if ($conn->reservation_id == $res[0] && $domain->name == $res[1]) {
                                 $uniq = false;
                             }
                         }
                         if ($uniq) {
                             $aux = [];
                             $aux[0] = $conn->reservation_id;
                             $aux[1] = $request->domain;
                             $reservationsVisited[] = $aux;
                             $source = $conn->getFirstPath()->one();
                             $destination = $conn->getLastPath()->one();
                             if (!$this->src_domain || $this->src_domain == $source->domain) {
                                 if (!$this->dst_domain || $this->dst_domain == $destination->domain) {
                                     $form = new AuthorizationForm();
                                     $form->setValues(Reservation::findOne(['id' => $conn->reservation_id]), $request->domain, $source->domain, $destination->domain);
                                     $authorizations[] = $form;
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
     $dataProvider = new ArrayDataProvider(['allModels' => $authorizations, 'sort' => false, 'pagination' => ['pageSize' => 15]]);
     return $dataProvider;
 }
Ejemplo n.º 3
0
 /**
  * GET NOTIFICATIONS
  * @param string $dateParam
  * @return string
  * Retorna o html com até 6 notificações, ja formatado para ser exibido.
  * Quando recebe uma data de entrada, a utiliza como limite, e retorna apenas o que vem depois dela
  */
 public static function getNotifications($dateParam)
 {
     $userId = Yii::$app->user->getId();
     if (!$dateParam) {
         AuthorizationNotification::clearAuthorizations($userId);
     }
     //Caso seja a primeira solicitação
     $array = "";
     $max = 0;
     $date = null;
     //Le todas reservas anteriores a data limite, ou todas reservas, caso não exista uma data limite
     if ($dateParam) {
         $notifications = Notification::find()->where(['user_id' => $userId])->andWhere(['<', 'date', $_POST['date']])->orderBy(['date' => SORT_DESC])->all();
     } else {
         $notifications = Notification::find()->where(['user_id' => $userId])->orderBy(['date' => SORT_DESC])->all();
     }
     //Se não contem, gera aviso de que o usuário não possui notificações
     if (count($notifications) == 0) {
         $info = [];
         $info['date'] = null;
         $info['array'] = "<li style='text-align: center;'><span style='float: none !important;'><h2>" . Yii::t("notify", 'You don`t have notifications yet.') . "</h2></span></li>";
         $info['more'] = false;
         return $info;
     }
     //Percorre as notificações gerando o HTML
     foreach ($notifications as $notification) {
         if ($max < 6) {
             $msg = "";
             switch ($notification->type) {
                 case self::TYPE_AUTHORIZATION:
                     $msg = AuthorizationNotification::makeHtml($notification);
                     break;
                 case self::TYPE_RESERVATION:
                     $msg = ReservationNotification::makeHtml($notification);
                     $notification->viewed = true;
                     $notification->save();
                     break;
                 case self::TYPE_NOTICE:
                     $msg = AaaNotification::makeHtml($notification);
                     $notification->viewed = true;
                     $notification->save();
                     break;
                 case self::TYPE_TOPOLOGY:
                     $msg = TopologyNotification::makeHtml($notification);
                     $notification->viewed = true;
                     $notification->save();
                     break;
             }
             if ($msg == "") {
                 $notification->delete();
             } else {
                 $array .= $msg;
                 $date = $notification->date;
             }
         }
         if ($msg != "") {
             $max++;
         }
         if ($max == 7) {
             break;
         }
     }
     $info = [];
     $info['date'] = $date;
     //Data da ultima notificação retornada, utilizada como limite para ler as proximas em leituras futuras
     $info['array'] = $array;
     //HTML a ser exibido
     if ($max == 7) {
         $info['more'] = true;
     } else {
         $info['more'] = false;
     }
     return $info;
 }
Ejemplo n.º 4
0
 /**
  * 
  * @param BpmFlow $flow
  */
 public function removeFlow($flow)
 {
     $type = $flow->type;
     $connection_id = $flow->connection_id;
     $flow->delete();
     if ($type != 'Accept_Automatically') {
         if (BpmFlow::find()->where(['domain' => $flow->domain, 'connection_id' => $connection_id])->count() == 0) {
             BpmFlow::deleteAll(['connection_id' => $connection_id]);
             $conn = Connection::findOne(['id' => $connection_id]);
             $conn->auth_status = Connection::AUTH_STATUS_REJECTED;
             if (!$conn->save()) {
                 Yii::error('Unsuccesful save in Request');
             }
             $auth = new ConnectionAuth();
             $auth->domain = $flow->domain;
             $auth->status = Connection::AUTH_STATUS_REJECTED;
             $auth->type = ConnectionAuth::TYPE_WORKFLOW;
             $auth->manager_workflow_id = $flow->workflow_id;
             $auth->connection_id = $connection_id;
             $auth->save();
             ReservationNotification::create($connection_id);
         }
     } else {
         $auth = new ConnectionAuth();
         $auth->domain = $flow->domain;
         $auth->status = Connection::AUTH_STATUS_APPROVED;
         $auth->type = ConnectionAuth::TYPE_WORKFLOW;
         $auth->manager_workflow_id = $flow->workflow_id;
         $auth->connection_id = $connection_id;
         $auth->save();
     }
 }
Ejemplo n.º 5
0
 public function failedProvision()
 {
     $this->status = self::STATUS_FAILED_PROVISION;
     $this->save();
     ReservationNotification::create($this->id);
 }