コード例 #1
0
 static function makeHtml($notification = null)
 {
     if ($notification == null) {
         return "";
     }
     $eventId = json_decode($notification->info);
     $changesSize = Change::find()->where(['sync_event_id' => $eventId])->count();
     $pendingChangesSize = Change::find()->where(['sync_event_id' => $eventId])->andWhere(['in', 'status', [Change::STATUS_PENDING, Change::STATUS_FAILED]])->count();
     $appliedChangesSize = Change::find()->where(['sync_event_id' => $eventId, 'status' => Change::STATUS_APPLIED])->count();
     $changes = Change::find()->where(['sync_event_id' => $eventId])->asArray()->groupBy(['domain'])->select(['domain'])->all();
     $title = Yii::t("notify", 'Topology change');
     if (count($changes) > 1) {
         $msg = Yii::t("notify", 'The topologies of') . " <b>" . count($changes) . "</b> " . Yii::t("notify", 'domains has been updated.') . " <b>" . $appliedChangesSize . "</b> " . Yii::t("notify", 'changes were applied.') . ' ' . ($pendingChangesSize > 0 ? " <b>" . $pendingChangesSize . "</b> " . Yii::t("notify", 'are pending.') : '');
     } else {
         if (count($changes) == 1) {
             $msg = Yii::t("notify", 'The') . " <b>" . $changes[0]['domain'] . "</b> " . Yii::t("notify", 'topology has been updated.') . " <b>" . $appliedChangesSize . "</b> " . Yii::t("notify", 'changes were applied.') . ' ' . ($pendingChangesSize > 0 ? " <b>" . $pendingChangesSize . "</b> " . Yii::t("notify", 'are pending.') : '');
         } else {
             return "";
         }
     }
     $date = Yii::$app->formatter->asDatetime($notification->date);
     $link = '/topology/change/applied?eventId=' . $eventId;
     $text = '<span><h1>' . $title . '</h1><h2>' . $msg . '</h2><h3>' . $date . '</h3></span>';
     $html = Notification::makeHtml('topology.png', $text);
     if ($notification->viewed == true) {
         return '<li>' . Html::a($html, array($link)) . '</li>';
     }
     return '<li class="new">' . Html::a($html, array($link)) . '</li>';
 }
コード例 #2
0
 public function actionGetAll()
 {
     if (isset($_POST['date'])) {
         echo json_encode(Notification::getNotifications($_POST['date']));
     } else {
         echo json_encode(Notification::getNotifications(null));
     }
 }
コード例 #3
0
ファイル: index.php プロジェクト: ufrgs-hyman/meican
<?php

/**
 * @copyright Copyright (c) 2012-2016 RNP
 * @license http://github.com/ufrgs-hyman/meican#license
 */
use yii\helpers\Html;
use yii\grid\GridView;
use yii\i18n\Formatter;
use meican\notify\models\Notification;
?>


<?php 
echo Html::csrfMetaTags();
?>


<?php 
echo GridView::widget(['options' => ['class' => 'list'], 'dataProvider' => $data, 'formatter' => new Formatter(['nullDisplay' => '']), 'id' => 'gridRequest', 'layout' => "{items}{pager}", 'rowOptions' => function ($model, $key, $index, $grid) {
}, 'columns' => array(['format' => 'raw', 'value' => function ($noti) {
    return Notification::makeHtmlNotificationAuth($noti);
}])]);
?>
	
コード例 #4
0
 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();
                 }
             }
         }
     }
 }
コード例 #5
0
 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();
     }
 }
コード例 #6
0
ファイル: navbar-menu.php プロジェクト: ufrgs-hyman/meican
    <ul id="not_body" class="dropdown-menu">
      <li class="header"><?php 
    echo Yii::t("notify", "You have {number} notifications", ['number' => Notification::getNumberNotifications()]);
    ?>
</li>
      <li id="not_content_li">
      	<?php 
    echo Html::img('@web' . '/images/ajax-loader.gif', ['id' => "not_loader", 'style' => 'padding: 10px;']);
    ?>
        <!-- Inner Menu: contains the notifications -->
        <ul id="not_content" class="menu">
        </ul>
      </li>
      <!-- <li class="footer"><a href="#">View All</a></li> -->
      <li class="footer"><?php 
    echo Html::a(Yii::t("notify", "View Authorizations") . " (<span id='authN'>" . Notification::getNumberAuthorizations() . "</span>)", array('/circuits/authorization/index'));
    ?>
</li>
    </ul>
  </li>
  
  <?php 
}
?>
  <li><?php 
echo Html::a(Yii::t("home", "About"), array('/home/support/about'));
?>
</li>
  <li><?php 
echo Html::a(Yii::t("home", "Help"), array('/home/support/help'));
?>
コード例 #7
0
 static function deleteNotificationsGroup($user_id, $group, $domain)
 {
     $user = User::findOne($user_id);
     if ($user && $group) {
         Yii::trace("Remover notificações do grupo " . $group->name . " para usuário " . $user->name);
         //Busca todas autorizações do grupo
         //Se tem domínio, procura só as relacionadas ao domínio do papel
         if ($domain) {
             $auths = ConnectionAuth::find()->where(['domain' => $domain, 'type' => ConnectionAuth::TYPE_GROUP, 'manager_group_id' => $group->id])->all();
         } else {
             $auths = ConnectionAuth::find()->where(['type' => ConnectionAuth::TYPE_GROUP, 'manager_group_id' => $group->id])->all();
         }
         //Passa por todas deletando uma notificação
         foreach ($auths as $auth) {
             $notification = Notification::findOne(['user_id' => $user_id, 'type' => Notification::TYPE_AUTHORIZATION, 'info' => $auth->id]);
             if ($notification) {
                 $notification->delete();
             }
         }
     }
 }
コード例 #8
0
ファイル: Notification.php プロジェクト: ufrgs-hyman/meican
 /**
  * CREATE TOPOLOGY NOTIFICAION
  * @param string $msg (A tag no caso)
  * @param string $date
  * Cria notificação de mudança na topologia. VERSÃO BETA
  */
 public static function createTopologyNotification($msg, $date = null)
 {
     $users = User::find()->all();
     foreach ($users as $user) {
         $not = Notification::findOne(['user_id' => $user->id, 'type' => self::TYPE_TOPOLOGY, 'info' => $msg]);
         if ($not) {
             //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 {
                 $not->date = DateUtils::now();
             }
             $not->viewed = 0;
             $not->save();
         } else {
             $not = new Notification();
             $not->user_id = $user->id;
             //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 {
                 $not->date = DateUtils::now();
             }
             $not->type = self::TYPE_TOPOLOGY;
             $not->viewed = 0;
             $not->info = $msg;
             $not->save();
         }
     }
 }