Пример #1
0
 public function save()
 {
     if ($this->validate()) {
         $changes = [];
         $conn = Connection::findOne($this->id);
         if ($this->acceptRelease) {
             if ($conn->getStartDateTime() != DateUtils::fromLocal($this->start)) {
                 $changes['needRelease'] = true;
                 $changes['start'] = DateUtils::localToUTC($this->start);
             }
             if ($conn->bandwidth != $this->bandwidth) {
                 $changes['needRelease'] = true;
                 $changes['bandwidth'] = $this->bandwidth;
             }
         }
         if ($conn->getEndDateTime() != DateUtils::fromLocal($this->end)) {
             $changes['end'] = DateUtils::localToUTC($this->end);
         }
         if (count($changes) > 0) {
             return $conn->buildEvent(ConnectionEvent::TYPE_USER_UPDATE)->setData(json_encode($changes))->setAuthor(Yii::$app->user->getId())->save();
         }
         return false;
     }
     return false;
 }
 static function create($connection_id)
 {
     $connection = Connection::findOne($connection_id);
     if (!$connection) {
         return;
     }
     $reservation = Reservation::findOne($connection->reservation_id);
     if (!$reservation) {
         return;
     }
     if ($reservation->type == Reservation::TYPE_TEST) {
         return;
     }
     $user_id = $reservation->request_user_id;
     //Confere se já foi feita uma notificação de algum circuito desta reserva, se sim, reutiliza a mesma notificação
     $not = null;
     $notifications = Notification::find()->where(['user_id' => $reservation->request_user_id, 'type' => Notification::TYPE_RESERVATION])->all();
     foreach ($notifications as $notification) {
         if ($notification->info == $reservation->id) {
             $not = $notification;
             break;
         }
     }
     if ($not) {
         //Se já existe, atualiza e coloca nova data
         //Pequena maquipulação do horário para que nunca existam duas notificações com o mesmo horário
         $date = new \DateTime('now', new \DateTimeZone("UTC"));
         $dateAux = $date->format("Y-m-d H:i:s");
         while (Notification::find()->where(['user_id' => $user_id, 'date' => $dateAux])->one()) {
             $date->modify('-1 second');
             $dateAux = $date->format("Y-m-d H:i:s");
         }
         $not->date = $dateAux;
         $not->viewed = 0;
         $not->save();
     } else {
         //Se for nova, cria notificação
         $not = new Notification();
         $not->user_id = $reservation->request_user_id;
         //Pequena maquipulação do horário para que nunca existam duas notificações com o mesmo horário
         $date = new \DateTime('now', new \DateTimeZone("UTC"));
         $dateAux = $date->format("Y-m-d H:i:s");
         while (Notification::find()->where(['user_id' => $user_id, 'date' => $dateAux])->one()) {
             $date->modify('-1 second');
             $dateAux = $date->format("Y-m-d H:i:s");
         }
         $not->date = $dateAux;
         $not->type = Notification::TYPE_RESERVATION;
         $not->viewed = 0;
         $not->info = (string) $reservation->id;
         $not->save();
     }
 }
Пример #3
0
 private static function saveCircuit($gri, $desc, $status, $start, $end, $bandwidth, $path)
 {
     $conn = Connection::findOne(['external_id' => $gri]);
     if ($conn == null) {
         $conn = new Connection();
         $conn->external_id = $gri;
         $conn->name = $desc;
         $conn->type = 'OSCARS';
         $conn->status = 'PROVISIONED';
         $conn->version = 1;
         $conn->dataplane_status = $status == 'ACTIVE' ? 'ACTIVE' : 'INACTIVE';
         $conn->auth_status = 'UNEXECUTED';
         $conn->resources_status = 'PROVISIONED';
         $conn->start = DateUtils::timestampToDB($start);
         $conn->finish = DateUtils::timestampToDB($end);
         $conn->bandwidth = $bandwidth;
         if ($conn->save()) {
             Yii::trace($path);
             for ($i = 0; $i < count($path); $i++) {
                 $point = new ConnectionPath();
                 $point->conn_id = $conn->id;
                 $point->path_order = $i;
                 $urnArray = explode(":", $path[$i]);
                 Yii::trace($urnArray);
                 $point->vlan = explode('=', $urnArray[7])[1];
                 Yii::trace($point->vlan);
                 $point->domain = explode('=', $urnArray[3])[1];
                 Yii::trace($point->domain);
                 $urnArray[7] = '';
                 $urnArray[6] = '';
                 $point->port_urn = substr(implode(':', $urnArray), 0, -2);
                 Yii::trace($point->port_urn);
                 $point->save();
             }
             OscarsService::associateNSICircuits($conn);
         } else {
             Yii::trace($conn->getErrors());
         }
     } else {
         $conn->dataplane_status = $status == 'ACTIVE' ? 'ACTIVE' : 'INACTIVE';
         $conn->save();
     }
 }
 static function clearAuthorizations($userId)
 {
     //Limpa as notificações de autorização que ja foram respondidas
     $notAuth = Notification::find()->where(['user_id' => $userId, 'type' => Notification::TYPE_AUTHORIZATION, 'viewed' => false])->all();
     foreach ($notAuth as $not) {
         //Confere todas notificações do tipo autorização
         $auth = ConnectionAuth::findOne($not->info);
         if ($auth) {
             $connection = Connection::findOne($auth->connection_id);
             if ($connection) {
                 $connections = Connection::find()->where(['reservation_id' => $connection->reservation_id])->all();
                 $answered = true;
                 foreach ($connections as $conn) {
                     //Confere todas conexões da reserva conferindo se alguma ainda esta pendente
                     $auths = ConnectionAuth::find()->where(['domain' => $auth->domain, 'connection_id' => $conn->id])->all();
                     foreach ($auths as $a) {
                         //Confere as autorizaçòes daquela conexão
                         if ($a->type != ConnectionAuth::TYPE_WORKFLOW && $a->status == Connection::AUTH_STATUS_PENDING) {
                             $answered = false;
                             break;
                         }
                     }
                     if ($answered == false) {
                         break;
                     }
                 }
                 if ($answered) {
                     //Se ja foi respondida modifica notificação para visualizada
                     $not->viewed = true;
                     $not->save();
                 }
             }
         }
     }
 }
 public function actionGetOthers($domainTop = null, $reservationId = null, $type = null)
 {
     if ($domainTop && $reservationId && $type) {
         $connectionsPath = ConnectionPath::find()->select('DISTINCT `conn_id`')->where(['domain' => $domainTop])->all();
         $others = [];
         foreach ($connectionsPath as $path) {
             $con = Connection::findOne(['id' => $path->conn_id]);
             //Tipo 1 significa que esta retornando os provisionados
             if ($type == 1 && $con->status == Connection::STATUS_PROVISIONED) {
                 //Se é a mesma reserva, testa para garantir que é de outro dominio antes de exibir
                 if ($con->reservation_id != $reservationId) {
                     $others[] = ['id' => $con->id, 'title' => "\n" . $con->getReservation()->one()->bandwidth . " Mbps", 'start' => Yii::$app->formatter->asDatetime($con->start, "php:Y-m-d H:i:s"), 'end' => Yii::$app->formatter->asDatetime($con->finish, "php:Y-m-d H:i:s")];
                 }
             } else {
                 if ($type == 2 && $con->status != Connection::STATUS_PROVISIONED && $con->auth_status == Connection::AUTH_STATUS_PENDING) {
                     //Se é a mesma reserva, testa para garantir que é de outro dominio antes de exibir
                     if ($con->reservation_id == $reservationId) {
                         if (ConnectionAuth::findOne(['connection_id' => $con->id, 'status' => Connection::AUTH_STATUS_PENDING])->domain != $domainTop) {
                             $others[] = ['id' => $con->id, 'title' => "\n" . $con->getReservation()->one()->bandwidth . " Mbps", 'start' => Yii::$app->formatter->asDatetime($con->start, "php:Y-m-d H:i:s"), 'end' => Yii::$app->formatter->asDatetime($con->finish, "php:Y-m-d H:i:s")];
                         }
                     } else {
                         $others[] = ['id' => $con->id, 'title' => "\n" . $con->getReservation()->one()->bandwidth . " Mbps", 'start' => Yii::$app->formatter->asDatetime($con->start, "php:Y-m-d H:i:s"), 'end' => Yii::$app->formatter->asDatetime($con->finish, "php:Y-m-d H:i:s")];
                     }
                 }
             }
         }
         echo json_encode($others);
     }
 }
Пример #6
0
 public function actionRefresh($id)
 {
     self::beginAsyncAction();
     $conn = Connection::findOne($id);
     //circuitos pendentes nao possuem external ID e nao existem nos provedores
     if ($conn && $conn->status != Connection::STATUS_PENDING) {
         $conn->requestRead();
     }
     return true;
 }
Пример #7
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();
     }
 }
Пример #8
0
 static function createNotificationsGroup($user_id, $group_name, $domain)
 {
     $user = User::findOne($user_id);
     $group = Group::findOne(['role_name' => $group_name]);
     if ($user && $group) {
         Yii::trace("Criar notificações do grupo " . $group->name . " para usuário " . $user->name);
         //Busca todas autorizações pendentes do grupo
         //Se tem dominio, procura só as relacionadas ao dominio do papel
         if ($domain) {
             $auths = ConnectionAuth::find()->where(['status' => Connection::AUTH_STATUS_PENDING, 'domain' => $domain, 'type' => ConnectionAuth::TYPE_GROUP, 'manager_group_id' => $group->id])->all();
         } else {
             $auths = ConnectionAuth::find()->where(['status' => Connection::AUTH_STATUS_PENDING, 'type' => ConnectionAuth::TYPE_GROUP, 'manager_group_id' => $group->id])->all();
         }
         //Passa por todas criando uma notificação
         foreach ($auths as $auth) {
             $connection = Connection::findOne($auth->connection_id);
             $reservation = Reservation::findOne($connection->reservation_id);
             AuthorizationNotification::createToUser($user->id, $auth->domain, $connection->reservation_id, $auth->id, $reservation->date);
         }
     }
 }
Пример #9
0
			    	<?php 
echo Grid::widget(['options' => ['class' => 'list'], 'dataProvider' => new ArrayDataProvider(['allModels' => $requests, 'sort' => false, 'pagination' => ['pageSize' => 4]]), 'id' => 'gridRequest', 'layout' => "{items}{summary}{pager}", 'rowOptions' => function ($model, $key, $index, $grid) {
    return ['id' => $model['id'], 'onclick' => 'toDate(id)'];
}, 'columns' => array(['class' => 'yii\\grid\\ActionColumn', 'template' => '{accept}{reject}', 'contentOptions' => function ($model) {
    return ['style' => 'white-space: nowrap;'];
}, 'buttons' => ['accept' => function ($url, $model) {
    return Html::a('<span class="fa fa-thumbs-o-up"></span>', null, ['disabled' => $model->isAnswered(), 'class' => 'btn btn-accept', 'id' => $model->id]);
}, 'reject' => function ($url, $model) {
    return Html::a('<span class="fa fa-thumbs-o-down"></span>', null, ['disabled' => $model->isAnswered(), 'class' => 'btn btn-reject', 'id' => $model->id]);
}]], ['label' => Yii::t('circuits', 'Initial Date/Time'), 'value' => function ($req) {
    return Yii::$app->formatter->asDatetime(Connection::findOne(['id' => $req->connection_id])->start);
}, 'contentOptions' => ['style' => 'min-width: 70px;']], ['label' => Yii::t('circuits', 'Final Date/Time'), 'value' => function ($req) {
    return Yii::$app->formatter->asDatetime(Connection::findOne(['id' => $req->connection_id])->finish);
}, 'contentOptions' => ['style' => 'min-width: 70px;']], ['label' => Yii::t('circuits', 'Duration'), 'value' => function ($req) {
    $start = strtotime(Connection::findOne(['id' => $req->connection_id])->start);
    $finish = strtotime(Connection::findOne(['id' => $req->connection_id])->finish);
    $mins = ($finish - $start) / 60;
    $hours = 0;
    while ($mins > 59) {
        $hours++;
        $mins -= 60;
    }
    return $hours . "h" . $mins . "m";
}, 'contentOptions' => ['style' => 'min-width: 70px;']], ['format' => 'raw', 'label' => Yii::t('circuits', 'Status'), 'value' => function ($req) {
    if ($req->status == Connection::AUTH_STATUS_APPROVED) {
        return '<span class="label label-success">' . $req->getStatus() . '</span>';
    }
    if ($req->status == Connection::AUTH_STATUS_REJECTED || $req->status == Connection::AUTH_STATUS_EXPIRED) {
        return '<span class="label label-danger">' . $req->getStatus() . '</span>';
    }
    return '<span class="label label-warning">' . $req->getStatus() . '</span>';
Пример #10
0
 public static function cancelConnAuthRequest($connId)
 {
     $types = [self::TYPE_USER, self::TYPE_GROUP];
     $auth = ConnectionAuth::find()->where(['connection_id' => $connId, 'status' => Connection::AUTH_STATUS_PENDING])->andWhere(['in', 'type', $types])->one();
     if ($auth) {
         $auth->changeStatusToExpired();
         $connection = Connection::findOne($connId);
         $connection->auth_status = Connection::AUTH_STATUS_EXPIRED;
         $connection->save();
     }
 }
Пример #11
0
 public static function continueWorkflows($id, $asking = true)
 {
     Yii::trace("CONTINUA WORKFLOWS");
     $paths = ConnectionPath::find()->select('DISTINCT `domain`')->where(['conn_id' => $id])->all();
     Yii::trace("Dominios envolvidos:");
     foreach ($paths as $path) {
         Yii::trace($path->domain);
     }
     //Analisa se existem pedidos em espera. Neste momento, realiza as perguntas aos admins.
     foreach ($paths as $path) {
         if (Connection::findOne(['id' => $id])->auth_status == self::AUTH_STATUS_REJECTED) {
             break;
         } else {
             $domain = Domain::findOne(['name' => $path->domain]);
             if (isset($domain)) {
                 BpmFlow::doRequest($id, $domain->name, $asking);
             }
         }
         if (ConnectionAuth::find()->where(['connection_id' => $id, 'status' => self::AUTH_STATUS_PENDING])->count() > 0) {
             break;
         }
         //Se tem uma pergunta ativa.
     }
     if (!$asking || ConnectionAuth::find()->where(['connection_id' => $id, 'status' => self::AUTH_STATUS_PENDING])->count() > 0) {
         return;
     }
     $conn = Connection::findOne(['id' => $id]);
     if ($conn->auth_status == self::AUTH_STATUS_PENDING) {
         $conn->auth_status = self::AUTH_STATUS_APPROVED;
         if (!$conn->save()) {
         }
         if (!$conn->isCancelStatus()) {
             $conn->requestProvision();
         }
     }
     //Remove fluxos não finalizados
     BpmFlow::removeFlows($id);
 }