Skip to content

Commit

Permalink
fixed notification widget and notification history errors
Browse files Browse the repository at this point in the history
  • Loading branch information
katmastt committed Oct 9, 2023
1 parent 4dc3a48 commit 6baa7d0
Show file tree
Hide file tree
Showing 11 changed files with 73 additions and 34 deletions.
9 changes: 5 additions & 4 deletions components/NotificationWidget.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,17 +73,18 @@ public static function createMenuItem()
$items[]=['label'=>'View notification history', 'url'=>['site/notification-history'],'options'=>['class'=>'notification-history']];


if ($notifCount!=0)
{
$items[]=['label'=>'Mark all as seen','options'=>['id'=>'mark_all_seen']];
}

foreach ($notifications as $notification)
{
$type=$typeClass[$notification->type];
$items[]=['label'=>$notification->message, 'url'=>['/site/notification-redirect','id'=>$notification->id],
'options'=>['class'=>"notification $type"]];
}
// $items[]=['label'=>'View notification history', 'url'=>['site/notification-history'],'options'=>['class'=>'notification-history']];
if ($notifCount!=0)
{
$items[]=['label'=>'Mark all as seen','options'=>['id'=>'mark_all_seen']];
}
return [$label,$items];


Expand Down
18 changes: 11 additions & 7 deletions controllers/SiteController.php
Original file line number Diff line number Diff line change
Expand Up @@ -260,18 +260,22 @@ public function actionNotificationRedirect($id)
{
return $this->redirect(['project/index']);
}
// if ($notification->type == 0 && Userw::hasRole('Admin', $superadminAllowed=true)){
if ($notification->type == 0 && Userw::hasRole('Admin', $superadminAllowed=true)){
// $url=$notification->url.'&mode=0';
// return $this->redirect($url);
// } else {
// $ticket_id = substr($notification->url, -2);
// $url = 'index.php?r=ticket-user%2Fview&id='.$ticket_id;
return $this->redirect($notification->url);
} elseif ($notification->type == 0) {
$url_split = explode('=', $notification->url);
$ticket_id = $url_split[2];
$url = 'index.php?r=ticket-user%2Fview&id='.$ticket_id;
// // $url=$notification->url.'&mode=0';
// Yii::$app->session->setFlash('success', "HEY");
// return $this->redirect($url);
// }
// Yii::$app->session->setFlash('success', "HEY 2");
return $this->redirect($notification->url);
return $this->redirect($url);
} else{
return $this->redirect($notification->url);
}


}
Expand All @@ -290,7 +294,7 @@ public function actionNotificationHistory()
$notifications=$results[1];


return $this->render('notification_history',['notifications'=>$notifications,'pages'=>$pages,'typeClass'=>$typeClass,]);
return $this->render('notification_history',['notifications'=>$notifications,'pages'=>$pages,'typeClass'=>$typeClass]);
}

public function actionSshTutorial()
Expand Down
15 changes: 13 additions & 2 deletions controllers/TicketAdminController.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ public function actionAnswer($id, $mode, $url1=1)

$username=explode('@',$newTicket->name_user)[0];
$message="Administrator <strong>$username</strong> posted an answer for ticket <strong>$ticketHead->topic.</strong>";
$url=Url::to(['/ticket-admin/view','id'=>$id]);
$url=Url::to(['/ticket-admin/view','id'=>$id, 'mode'=>$mode]);
$currentUser=Yii::$app->user->identity->id;

/*
Expand All @@ -117,9 +117,20 @@ public function actionAnswer($id, $mode, $url1=1)
->andWhere(['<>','u.id',$currentUser])
->all();

//but send only one notification to each user, despite of how many times he answered to the ticket
$id_already_sent = array();
foreach ($ids as $id)
{
Notification::notify($id['id'], $message, Notification::NORMAL ,$url);
$found=0;
foreach ($id_already_sent as $id_already){
if ($id_already==$id['id']){
$found=1;
}
}
if ($found==0){
array_push($id_already_sent, $id['id']);
Notification::notify($id['id'], $message, Notification::NORMAL ,$url);
}
}

return $this->redirect(Url::to(['/ticket-admin/index']));
Expand Down
4 changes: 2 additions & 2 deletions controllers/TicketUserController.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ public function actionView($id)

$username=explode('@',$newTicket->name_user)[0];
$message="User <strong>$username</strong> posted an answer for ticket <strong>$ticket->topic</strong>.";
$url=Url::to(['/ticket-user/view','id'=>$id]);
$url=Url::to(['/ticket-admin/answer','id'=>$id, 'mode'=>0]);

//added to fix the following error
foreach (User::getAdminIds() as $admin)
Expand Down Expand Up @@ -193,7 +193,7 @@ public function actionOpen($link='', $upgrade=0)

$username=explode('@',$ticketBody->name_user)[0];
$message="User <strong>$username</strong> created a new <strong>$ticketHead->department</strong> ticket with the following topic: <br /> <strong>$ticketHead->topic</strong>.";
$url=Url::to(['/ticket-admin/answer','id'=>$ticketHead->id]);
$url=Url::to(['/ticket-admin/answer','id'=>$ticketHead->id, 'mode'=>0]);
foreach (User::getAdminIds() as $admin)
{
Notification::notify($admin, $message, '0' ,$url);
Expand Down
8 changes: 4 additions & 4 deletions models/JupyterRequestNew.php
Original file line number Diff line number Diff line change
Expand Up @@ -200,8 +200,8 @@ public function uploadNew($requestId)
foreach ($request->user_list as $user)
{

//need to create a new type of notifications
Notification::notify($user,$message,2,Url::to(['project/user-request-list','filter'=>'approved']));
Notification::notify($user,$message,2,Url::to(['project/user-request-list','filter'=>'auto-approved']));
// Notification::notify($user,$message,2,Url::to(['project/user-request-list','filter'=>'approved']));
}

$project->latest_project_request_id=$request->id;
Expand Down Expand Up @@ -297,8 +297,8 @@ public function uploadNewEdit($requestId,$uchanged)

foreach ($request->user_list as $user)
{

Notification::notify($user,$message,2,Url::to(['project/user-request-list','filter'=>'approved']));
Notification::notify($user,$message,2,Url::to(['project/user-request-list','filter'=>'auto-approved']));
// Notification::notify($user,$message,2,Url::to(['project/user-request-list','filter'=>'approved']));
}


Expand Down
6 changes: 6 additions & 0 deletions models/MachineComputeRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@ public function init()
$flavors=$response->data['flavors'];
// print_r($flavors);
// exit(0);
usort($flavors, "self::cmp");

foreach ($flavors as $flavor)
{
$name=$flavor['name'];
Expand Down Expand Up @@ -389,4 +391,8 @@ public function getDiff($other) {

return $diff;
}

public function cmp($a, $b){
return strcmp($a['vcpus'], $b['vcpus']);
}
}
7 changes: 4 additions & 3 deletions models/OndemandRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,8 @@ public function uploadNew($requestId)
{


Notification::notify($user,$message,2,Url::to(['project/user-request-list','filter'=>'approved']));
// Notification::notify($user,$message,2,Url::to(['project/user-request-list','filter'=>'approved']));
Notification::notify($user,$message,2,Url::to(['project/user-request-list','filter'=>'auto-approved']));
}

$project->latest_project_request_id=$request->id;
Expand Down Expand Up @@ -279,8 +280,8 @@ public function uploadNewEdit($requestId,$uchanged)

foreach ($request->user_list as $user)
{

Notification::notify($user,$message,2,Url::to(['project/user-request-list','filter'=>'approved']));
Notification::notify($user,$message,2,Url::to(['project/user-request-list','filter'=>'auto-approved']));
// Notification::notify($user,$message,2,Url::to(['project/user-request-list','filter'=>'approved']));
}


Expand Down
2 changes: 1 addition & 1 deletion views/project/new_jupyter_request.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@

<?php Headers::begin(); ?>
<?php echo Headers::widget(
['title'=>'Request a new books project',
['title'=>'Request a new on-demand notebooks project',
])
?>
<?Headers::end()?>
Expand Down
2 changes: 1 addition & 1 deletion views/project/new_machine_compute_request.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@
</div>
<div class="row">&nbsp;</div>

<?= $form->field($service,'flavour')->dropDownList($service->flavours)->label($flavour_label)?>
<?= $form->field($service,'flavour')->dropDownList(array_reverse($service->flavours))->label($flavour_label)?>
<?= $form->field($service,'num_of_vms')->dropDownList($num_vms_dropdown)?>

<div class="row">
Expand Down
2 changes: 1 addition & 1 deletion views/project/new_service_request.php
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@
</div>
<div class="row">&nbsp;</div>

<?= $form->field($service,'flavour')->dropDownList($service->flavours)->label($flavour_label)?>
<?= $form->field($service,'flavour')->dropDownList(array_reverse($service->flavours))->label($flavour_label)?>


<div class="row">
Expand Down
34 changes: 25 additions & 9 deletions views/site/notification_history.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

use yii\helpers\Html;
use yii\widgets\LinkPager;
use webvimark\modules\UserManagement\models\User as Userw;

$this->title="Notification History";

Expand Down Expand Up @@ -38,9 +39,10 @@

if (!empty($notifications))
{
//table-striped didn't show the correct color for every second same type notification
?>

<table class="table table-responsive table-striped">
<table class="table table-responsive table">
<thead>
<tr>
<th class="col-md-10">Notification message</th>
Expand All @@ -56,15 +58,29 @@
?>

<tr class="<?=$typeClass[$notif['type']]?>">
<?php if ($notif['type']==0){
$ticket_id = substr($notif['url'], -2);
$url = 'index.php?r=ticket-user%2Fview&id='.$ticket_id;
?>
<td class="col-md-10"><?=Html::a($notif['message'],$url)?></th>
<?php }else {?>
<td class="col-md-10"><?=Html::a($notif['message'],$notif['url'])?></th>
<?php }?>
<?php
if ($notif['type']==0 && Userw::hasRole('Admin')){
$url_split = explode('=', $notif['url']);
$ticket_id = $url_split[2];
$url = 'index.php?r=ticket-admin%2Fanswer&id='.$ticket_id;
?>
<td class="col-md-10"><?=Html::a($notif['message'],$url)?></th>
<td class="col-md-2"><?= date("j-m-Y, H:i:s",strtotime($notif['created_at']))?></td>
<?php
}elseif ($notif['type']==0) {
$url_split = explode('=', $notif['url']);
$ticket_id = $url_split[2];
$url = 'index.php?r=ticket-user%2Fview&id='.$ticket_id;
?>
<td class="col-md-10"><?=Html::a($notif['message'],$url)?></th>
<td class="col-md-2"><?= date("j-m-Y, H:i:s",strtotime($notif['created_at']))?></td>
<?php
}elseif($notif['type']!=0){
?>
<td class="col-md-10"><?=Html::a($notif['message'],$notif['url'])?>
<td class="col-md-2"><?= date("j-m-Y, H:i:s",strtotime($notif['created_at']))?></td>
<?php
}?>
</tr>
<?php
}
Expand Down

0 comments on commit 6baa7d0

Please sign in to comment.