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(); } } } }
/** * 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(); } } }