static function createToGroup($group_id, $domain, $reservation_id, $auth_id, $date = null)
 {
     $group = Group::findOne($group_id);
     $domain = Domain::findOne(['name' => $domain]);
     if (!$group || !$domain) {
         return false;
     }
     //Confere todos papeis associados ao grupo
     $roles = UserDomainRole::findByGroup($group);
     foreach ($roles->all() as $role) {
         if ($role->domain == null || $role->domain == $domain->name) {
             //Se papel for para todos dominios ou para dominio espeficido
             //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' => $role->user_id, 'type' => Notification::TYPE_AUTHORIZATION])->all();
             foreach ($notifications as $notification) {
                 $cauth = ConnectionAuth::findOne($notification->info);
                 if ($cauth) {
                     if ($cauth->domain == $domain->name) {
                         $conn = Connection::findOne($cauth->connection_id);
                         if ($conn) {
                             if ($conn->reservation_id == $reservation_id) {
                                 $not = $notification;
                                 break;
                             }
                         }
                     }
                 }
             }
             if ($not) {
                 //Se já existe, atualiza e coloca nova data
                 //Pode receber uma data por parametro, neste caso, utiliza essa data como a data da criação da notificação
                 if ($date) {
                     $not->date = $date;
                 } else {
                     //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' => $role->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 = $role->user_id;
                 if (isset($date)) {
                     $not->date = $date;
                 } else {
                     //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' => $role->user_id, 'date' => $dateAux])->one()) {
                         $date->modify('-1 second');
                         $dateAux = $date->format("Y-m-d H:i:s");
                     }
                     $not->date = $dateAux;
                 }
                 $not->date = $dateAux;
                 $not->type = Notification::TYPE_AUTHORIZATION;
                 $not->viewed = 0;
                 $not->info = (string) $auth_id;
                 $not->save();
             }
         }
     }
 }
示例#2
0
 public function actionDelete()
 {
     if (!self::can("group/delete")) {
         Yii::$app->getSession()->addFlash('warning', Yii::t('aaa', 'You are not allowed to delete groups'));
         return $this->redirect(array('index'));
     }
     if (isset($_POST['delete'])) {
         foreach ($_POST['delete'] as $groupId) {
             $group = Group::findOne($groupId);
             if ($group->delete()) {
                 Yii::$app->getSession()->addFlash('success', Yii::t("aaa", 'Group {name} deleted successfully', ['name' => $group->name]));
             } else {
                 Yii::$app->getSession()->setFlash('error', Yii::t("aaa", 'Error deleting group') . ' ' . $group->name);
             }
         }
     }
     return $this->redirect(array('index'));
 }
示例#3
0
 public function actionEditorUpdate($id = null)
 {
     $this->layout = 'wireit';
     if ($id) {
         $workflow = BpmWorkflow::findOne(['id' => $id]);
         if ($workflow) {
             $domain = Domain::findOne(['name' => $workflow->domain]);
             if ($domain) {
                 if (!self::can('workflow/update', $domain->name)) {
                     if (!self::can("workflow/read")) {
                         return $this->goHome();
                     } else {
                         Yii::$app->getSession()->setFlash('warning', Yii::t("bpm", 'You are not allowed to edit in domain {domain}', ['domain' => $domain->name]));
                         return $this->redirect(array('/bpm/workflow/index'));
                     }
                 }
                 $ownerDomain = [];
                 $ownerDomain[$domain->name] = $domain->name;
                 $domains = Domain::find()->orderBy(['name' => SORT_ASC])->all();
                 $allDomains = [];
                 foreach ($domains as $dom) {
                     $allDomains[$dom->name] = $dom->name;
                 }
                 $roles = $domain->getUserDomainsRoles()->all();
                 $adminsNames = [];
                 foreach ($roles as $role) {
                     $adminsNames[$role->getUser()->id] = $role->getUser()->name;
                 }
                 foreach (User::find()->all() as $user) {
                     $usersNames[$user->id] = $user->name;
                 }
                 $groupsNames = [];
                 foreach (Group::find()->where(['type' => Group::TYPE_DOMAIN, 'domain' => $domain->name])->orWhere(['type' => Group::TYPE_DOMAIN, 'domain' => null])->all() as $group) {
                     $groupsNames[$group->id] = $group->name;
                 }
                 $devicesNames = [];
                 foreach (Device::find()->where(['domain_id' => $domain->id])->all() as $device) {
                     $devicesNames[$device->id] = $device->name;
                 }
                 Yii::trace($roles);
                 Yii::trace($usersNames);
                 Yii::trace($groupsNames);
                 Yii::trace($devicesNames);
                 return $this->render('editor', array('owner_domain' => $ownerDomain, 'domains' => $allDomains, 'groups' => $groupsNames, 'users' => $usersNames, 'admins' => $adminsNames, 'devices' => $devicesNames, 'id' => $_GET['id']));
             }
         }
     }
     if (!self::can("workflow/read")) {
         return $this->goHome();
     } else {
         return $this->redirect(array('/bpm/workflow/index'));
     }
 }
示例#4
0
 static function getGlobalDomainGroupsNoArray()
 {
     return Group::find()->where(['type' => Group::TYPE_DOMAIN, 'domain' => null])->orderBy(['name' => SORT_ASC])->all();
 }
示例#5
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);
         }
     }
 }
示例#6
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getManagerGroup()
 {
     return $this->hasOne(Group::className(), ['id' => 'manager_group_id']);
 }