/**
  * ACTION REJECT
  * @param string $id
  * @param string $message
  */
 public function actionReject($id = null, $message = null)
 {
     Yii::trace("Reject");
     Yii::trace("ID: " . $id);
     Yii::trace("Msg: " . $message);
     if ($id) {
         $req = ConnectionAuth::findOne(['id' => $id]);
         if ($req->type == ConnectionAuth::TYPE_GROUP) {
             $req->manager_user_id = Yii::$app->user->getId();
         }
         if ($message != null) {
             $req->manager_message = $message;
         }
         $req->status = Connection::AUTH_STATUS_REJECTED;
         $req->save();
         $flow = new BpmFlow();
         $flow->response($req->connection_id, $req->domain, BpmFlow::STATUS_NO);
     }
 }
 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();
                 }
             }
         }
     }
 }
Example #3
0
 public function createUserAuth($flow, $reservation)
 {
     Yii::trace("Criando Request User Authorization");
     //Confere se o usuário ja respondeu exatamente mesma requisição, se sim, não questiona novamente.
     $auth = ConnectionAuth::findOne(['type' => ConnectionAuth::TYPE_USER, 'domain' => $flow->domain, 'manager_user_id' => $flow->value, 'connection_id' => $flow->connection_id]);
     if ($auth) {
         return true;
     }
     //Confere se usuário requisitante é o mesmo que deve responder. Se sim, não pergunta, considera aceito.
     if ($flow->value == $reservation->request_user_id) {
         $flow->status = self::STATUS_YES;
         $flow->save();
         return true;
     }
     $auth = new ConnectionAuth();
     $auth->domain = $flow->domain;
     $auth->status = Connection::AUTH_STATUS_PENDING;
     $auth->type = ConnectionAuth::TYPE_USER;
     $auth->manager_user_id = $flow->value;
     $auth->connection_id = $flow->connection_id;
     $auth->save();
     AuthorizationNotification::createToUser($flow->value, $flow->domain, $reservation->id, $auth->id);
     return false;
 }