Ver Fonte

Finished notifications center

Igor há 3 anos atrás
pai
commit
bdc812b7e5
3 ficheiros alterados com 288 adições e 7 exclusões
  1. 4 0
      lang/en/iassign.php
  2. 4 0
      lang/pt_br/iassign.php
  3. 280 7
      locallib.php

+ 4 - 0
lang/en/iassign.php

@@ -448,6 +448,10 @@ $string['no_edit_iassign']                = 'Blocked. Only the author can edit.'
 $string['no_iLM_PARAM_ArchiveContent']    = 'No solution was posted.';
 $string['no_MA_POST_Archive']             = 'No solution was posted.';
 $string['no_new_comment']                 = 'Messages already read ';
+$string['new_messages']                   = 'New received messages';
+$string['empty_new_messages']             = 'No new messages';
+$string['new_messages_other_blocks']      = 'New received messages in other blocks';
+$string['empty_new_messages_block']       = 'No received messages in the actual block';
 $string['no_permission_iassign']          = 'Visitors can only view activities!';
 $string['not_post']                       = 'Not submitted';
 $string['not_submissions_activity']       = 'There are no submissions relating to this activity.';

+ 4 - 0
lang/pt_br/iassign.php

@@ -445,6 +445,10 @@ $string['no_edit_iassign']                = 'Bloqueado. Somente autor pode edita
 $string['no_iLM_PARAM_ArchiveContent']    = 'Nenhuma solução foi enviada.';
 $string['no_MA_POST_Archive']             = 'Nenhuma solução foi enviada.';
 $string['no_new_comment']                 = 'Mensagens lidas';
+$string['new_messages']                   = 'Novas mensagens recebidas';
+$string['empty_new_messages']             = 'Sem mensagens novas';
+$string['new_messages_other_blocks']      = 'Novas mensagens recebidas em outros blocos';
+$string['empty_new_messages_block']       = 'Sem mensagens recebidas no bloco atual';
 $string['no_permission_iassign']          = 'Visitantes somente podem visualizar atividades!';
 $string['not_post']                       = 'Não enviado';
 $string['not_submissions_activity']       = 'Não existem submissões relacionadas a esta atividade.';

+ 280 - 7
locallib.php

@@ -3331,11 +3331,16 @@ var exercises = [ '; // '
           document.formEnvioComment.submission_comment.value = ''; 
           request.send(formData);
         }
+
+        function event_text_area (event) {
+          if (event.ctrlKey && event.keyCode == 13)
+            submit_comment('$enderecoPOSTcomment');
+        }
         //]]>
         </script>";
 
         $output .= "<center><form name='formEnvioComment' id='formEnvioComment1' enctype='multipart/form-data'>\n";
-        $output .= "<br><p><textarea class='form-control w-50' rows='2' cols='60' name='submission_comment'></textarea></p>\n";
+        $output .= "<br><p><textarea class='form-control w-50' rows='2' cols='60' name='submission_comment' onkeypress='event_text_area(event)'></textarea></p>\n";
         $output .= "<p><button class='btn btn-primary' onclick=\"submit_comment('$enderecoPOSTcomment')\" type=button value='" . get_string('submit_comment', 'iassign') . "'>".get_string('submit_comment', 'iassign')."</button> <i id='check-message-success' class='fa fa-check' aria-hidden='true' style='position: absolute; color: green; font-size: 2.0rem; margin-left: 1rem; visibility: hidden;'></i> </p> \n";
 
         $output .= "</form> </center>\n";
@@ -4200,16 +4205,280 @@ var exercises = [ '; // '
     return $total_messages->total;
   }
 
+  function get_iassign_statement_messages () {
+    global $DB, $USER, $COURSE;
+
+    if (has_capability('mod/iassign:editiassign', $this->context, $USER->id)) {
+
+      $params = array('userid' => $USER->id, 'course' => $COURSE->id, 'receiver' => '1');
+      $totais = array();
+
+      $messages = $DB->get_records_sql("SELECT c.id AS commentid, st.id AS stid, s.userid AS user, ias.id AS iasid, s.id AS subid, st.name AS stname, ias.name AS iasname FROM {iassign_submission_comment} AS c, {iassign_submission} AS s, {iassign_statement} AS st, {iassign} AS ias "
+        . " WHERE c.return_status=0 AND c.receiver=:receiver AND c.iassign_submissionid=s.id AND s.iassign_statementid=st.id AND st.iassignid=ias.id AND ias.course=:course", $params);
+      
+      foreach($messages as $item) {
+        if (isset($totais[$item->subid])) {
+          $totais[$item->subid]->total ++;
+        }
+        else {
+          $totais[$item->subid] = new stdclass();
+          $item->total = 1;
+          $totais[$item->subid] = $item;
+        }
+      }
+
+      return $totais;
+    }
+    else {
+      $params = array('userid' => $USER->id, 'course' => $COURSE->id, 'receiver' => '2');
+      $totais = array();
+
+      $messages = $DB->get_records_sql("SELECT c.id as commentid, s.id AS subid, st.id AS stid, ias.id AS iasid, s.userid AS userid, st.name AS stname, ias.name AS iasname FROM {iassign_submission_comment} AS c, {iassign_submission} AS s, {iassign_statement} AS st, {iassign} AS ias "
+        . " WHERE c.return_status=0 AND c.receiver=:receiver AND c.iassign_submissionid=s.id AND s.userid=:userid AND s.iassign_statementid=st.id AND st.iassignid=ias.id AND ias.course=:course", $params);
+
+      foreach($messages as $item) {
+        if (isset($totais[$item->subid])) {
+          $totais[$item->subid]->total ++;
+        }
+        else {
+          $totais[$item->subid] = new stdclass();
+          $item->total = 1;
+          $totais[$item->subid] = $item;
+        }
+      }
+      return $totais;
+    }
+  }
+
+  function view_notifications_teachers () {
+    global $OUTPUT, $USER, $DB;
+
+    $messages = $this->get_iassign_statement_messages();
+
+    print '<table class="table table-hover ml-4 mb-4 w-75 mt-3" style="border-bottom: 1px solid #dee2e6;">';
+
+    // 1º. listar as mensagens recebidas no bloco atual:
+    $actual_block = $this->iassign->id;
+    $id = $this->cm->id;
+    $total_include = 0;
+
+    $activities_actual_block = array();
+
+    if ($messages)
+      foreach ($messages as $item)
+        if ($item->iasid == $actual_block) 
+          if (!in_array($item->stid, $activities_actual_block)) 
+            array_push($activities_actual_block, $item->stid);
+
+    if ($activities_actual_block)
+      foreach ($activities_actual_block as $activity_id) {
+        $printed = false;
+
+        foreach ($messages as $item) {
+          if ($item->stid == $activity_id) {
+            if (!$printed) {
+              $student_url = "view.php?id=$id&userid_iassign=$USER->id&action=view&iassign_current=$item->stid";
+              $link_student = "<a href='$student_url'>" . $item->stname . "</a>";
+              print '<tr><td style="white-space: nowrap; width: 1%; padding-right: 2rem;" class="align-middle">' . $link_student . '';
+
+              print '<table class="table table-hover ml-4 mb-4 w-75 mt-3" style="border-bottom: 1px solid #dee2e6;">';
+              $printed = true;
+            }
+
+            $submission_url = "view.php?id=$id&userid_iassign=$item->user&action=viewsubmission&iassign_current=$item->stid";
+
+            $user = $DB->get_record('user', array('id' => $item->user));
+
+            $label = $item->total > 1 ? get_string('comment_unread', 'iassign') : get_string('comment_unread_one', 'iassign');
+
+            print '<tr><td style="white-space: nowrap; width: 1%; padding-right: 2rem;" class="align-middle"><i class="fa fa-user" aria-hidden="true"></i> '
+              . $user->firstname . ' ' . $user->lastname . ' </td>'.
+              '<td class="align-middle"> <a href="'.$submission_url.'#comments"><span class="badge bg-danger" style="color:white; font-size: .9em;"><i class="fa fa-envelope" aria-hidden="true"></i> ' . $label . ' <span class="badge rounded-pill bg-light text-dark" style="font-size: .8em;">'.$item->total.'</span> </span></a></td>'
+              .'</tr>';
+            
+            $total_include++;
+            
+          }
+        }
+        print '</td></tr></table>';
+      }
+
+    print '</table>';
+
+    if (count($activities_actual_block) == 0) {
+      print '<h6 class="ml-5">'.get_string('empty_new_messages_block', 'iassign').'</h6>';
+      print '<hr class="my-4">';
+    }
+    
+    if ($messages && $total_include == count($messages)) { 
+      print $OUTPUT->footer();
+      return; 
+    }
+
+    print '<h4 class="mt-4 mb-3 ml-2"><i class="fa fa-comments-o" aria-hidden="true"></i> '.get_string('new_messages_other_blocks', 'iassign').'</h4>';
+
+    $iassign_ids = array();
+    if ($messages)
+      foreach ($messages as $item)
+        if (!in_array($item->iasid, $iassign_ids) && $item->iasid != $actual_block)
+          array_push($iassign_ids, $item->iasid);
+    
+    foreach ($iassign_ids as $id_iassign) {
+      $printed = false;
+
+      $activities_in_block = array();
+
+      foreach ($messages as $subitem)
+          if ($subitem->iasid == $id_iassign) 
+            if (!in_array($item->stid, $activities_in_block)) 
+              array_push($activities_in_block, $item->stid);
+
+      foreach ($messages as $item) {
+        if ($item->iasid == $id_iassign) {
+          if (!$printed) {
+            $printed = true;
+            print '<i class="fa fa-th-large ml-4 mb-3 mt-2" aria-hidden="true"></i> ' . $item->iasname . '<br>';
+
+            print '<table class="table table-hover ml-5 w-75" style="border-bottom: 1px solid #dee2e6;">';
+          }
+
+          foreach ($activities_in_block as $id_activity) {
+            $print = false;
+            foreach ($messages as $subitem) {
+              if ($subitem->stid == $id_activity) {
+                if (!$print) {
+                  $student_url = "view.php?id=$id&userid_iassign=$USER->id&action=view&iassign_current=$subitem->stid";
+                  $link_student = "<a href='$student_url'>" . $subitem->stname . "</a>";
+                  print '<tr><td style="white-space: nowrap; width: 1%; padding-right: 2rem;" class="align-middle">' . $link_student . '';
+
+                  print '<table class="table table-hover ml-4 mb-4 w-75 mt-3" style="border-bottom: 1px solid #dee2e6;">';
+                  $print = true;
+                }
+
+                foreach ($messages as $comment_student) {
+                  if ($comment_student->stid == $id_activity) {
+                    $submission_url = "view.php?id=$id&userid_iassign=$comment_student->user&action=viewsubmission&iassign_current=$comment_student->stid";
+
+                    $user = $DB->get_record('user', array('id' => $comment_student->user));
+
+                    $label = $comment_student->total > 1 ? get_string('comment_unread', 'iassign') : get_string('comment_unread_one', 'iassign');
+
+                    print '<tr><td style="white-space: nowrap; width: 1%; padding-right: 2rem;" class="align-middle"><i class="fa fa-user" aria-hidden="true"></i> '
+                      . $user->firstname . ' ' . $user->lastname . ' </td>'.
+                      '<td class="align-middle"> <a href="'.$submission_url.'#comments"><span class="badge bg-danger" style="color:white; font-size: .9em;"><i class="fa fa-envelope" aria-hidden="true"></i> ' . $label . ' <span class="badge rounded-pill bg-light text-dark" style="font-size: .8em;">'.$comment_student->total.'</span> </span></a></td>'
+                      .'</tr>';
+                  }
+                }
+
+                break;
+              }
+            }
+          }
+
+          print '</table></td></tr></table>';
+
+          break;
+        }
+      }
+    }
+
+    print $OUTPUT->footer();
+  }
+
   function view_notifications () {
-    global $OUTPUT;
+    global $OUTPUT, $USER;
     
     print $OUTPUT->header();
 
     $this->print_main_menu();
 
+    print '<h4 class="mt-4 ml-2"><i class="fa fa-comments-o" aria-hidden="true"></i> '.get_string('new_messages', 'iassign').'</h4>';
+
+    if ($this->get_total_notifications() == 0) {
+      print '<h6 class="mt-3 ml-5">'.get_string('empty_new_messages', 'iassign').'</h6>';
+      print '<hr class="my-4">';
+      print $OUTPUT->footer();
+      return;
+    }
+
+    if (has_capability('mod/iassign:editiassign', $this->context, $USER->id)) {
+      $this->view_notifications_teachers();
+      return;
+    }
+
+    $messages = $this->get_iassign_statement_messages();
+
+    print '<table class="table table-hover ml-4 mb-4 w-75 mt-3" style="border-bottom: 1px solid #dee2e6;">';
+
+    // 1º. listar as mensagens recebidas no bloco atual:
+    $actual_block = $this->iassign->id;
+    $id = $this->cm->id;
+    $total_include = 0;
+
+    if ($messages)
+      foreach ($messages as $item) {
+        if ($item->iasid == $actual_block) {
+
+          $student_url = "view.php?id=$id&userid_iassign=$USER->id&action=view&iassign_current=$item->stid#comments";
+
+          $link_student = "<a href='$student_url'>" . $item->stname . "</a>";
+          
+          $label = $item->total > 1 ? get_string('comment_unread', 'iassign') : get_string('comment_unread_one', 'iassign');
+
+          print '<tr><td style="white-space: nowrap; width: 1%; padding-right: 2rem;" class="align-middle">' . $link_student . '</td><td class="align-middle"> <a href="'.$student_url.'"><span class="badge bg-danger" style="color:white; font-size: .9em;"><i class="fa fa-envelope" aria-hidden="true"></i> ' . $label . ' <span class="badge rounded-pill bg-light text-dark" style="font-size: .8em;">'.$item->total.'</span> </span></a></td></tr>';
+
+          $total_include ++;
+        }
+      }
+    print '</table>';
+
+    if ($total_include == 0) {
+      print '<h6 class="ml-5">'.get_string('empty_new_messages_block', 'iassign').'</h6>';
+      print '<hr class="my-4">';
+    }
     
+    if ($messages && $total_include == count($messages)) {
+      print $OUTPUT->footer();
+      return;
+    }
+
+
+    print '<h4 class="mt-4 mb-3 ml-2"><i class="fa fa-comments-o" aria-hidden="true"></i> '.get_string('new_messages_other_blocks', 'iassign').'</h4>';
+    
+    // 2º. listar as mensagens recebidas nos demais blocos do curso:
+    $iassign_ids = array();
+    if ($messages)
+      foreach ($messages as $item)
+        if (!in_array($item->iasid, $iassign_ids) && $item->iasid != $actual_block)
+          array_push($iassign_ids, $item->iasid);
+
+    foreach ($iassign_ids as $id_iassign) {
+      $printed = false;
+
+      foreach ($messages as $item) {
+        if ($item->iasid == $id_iassign) {
+          if (!$printed) {
+            $printed = true;
+            print '<i class="fa fa-th-large ml-4 mb-3 mt-2" aria-hidden="true"></i> ' . $item->iasname . '<br>';
+
+            print '<table class="table table-hover ml-5 w-75" style="border-bottom: 1px solid #dee2e6;">';
+          }
+          
+          $student_url = "view.php?id=$id&userid_iassign=$USER->id&action=view&iassign_current=$item->stid#comments";
+
+          $link_student = "<a href='$student_url'>" . $item->stname . "</a>";
+        
+          $label = $item->total > 1 ? get_string('comment_unread', 'iassign') : get_string('comment_unread_one', 'iassign');
+
+          print '<tr><td style="white-space: nowrap; width: 1%; padding-right: 2rem;" class="align-middle">' . $link_student . '</td><td class="align-middle"> <a href="'.$student_url.'"><span class="badge bg-danger" style="color:white; font-size: .9em;"><i class="fa fa-envelope" aria-hidden="true"></i> ' . $label . ' <span class="badge rounded-pill bg-light text-dark" style="font-size: .8em;">'.$item->total.'</span> </span></a> </td></tr>';
+        }
+      }
+
+      print '</table>';
+    }
 
     print $OUTPUT->footer();
+
   }
 
   function print_main_menu () {
@@ -4551,6 +4820,8 @@ var exercises = [ '; // '
         }
       </style>";
 
+    $action_links = "";
+
     if (has_capability('mod/iassign:viewiassignall', $this->context, $USER->id)) {
       print '<h5 class="fw-bold" style="font-weight: 400; margin: -1rem 0 1.5rem 0;">' . $title . "</h5>";
       print '<table class="table table-hover" style="border-bottom: 1px solid #dee2e6;">';
@@ -4576,8 +4847,8 @@ var exercises = [ '; // '
           $comment_unread_message = get_string('comment_unread', 'iassign');
           if ($sum_comment == 1)
             $comment_unread_message = get_string('comment_unread_one', 'iassign');
-          $comment_unread = "&nbsp;<a href='" . $CFG->wwwroot . "/mod/iassign/view.php?id=" . $id . "&action=report&iassignid=" . $this->iassign->id . "'><font color='red'>" .
-            iassign_icons::insert('comment_unread') . "&nbsp;($sum_comment&nbsp;" . $comment_unread_message . ")</font></a>";
+          
+            $comment_unread = ' <a href="' . $CFG->wwwroot . '/mod/iassign/view.php?id=' . $id . '&action=report&iassignid=' . $this->iassign->id . '"><span class="badge bg-danger ml-2" style="color:white; font-size: .9em;"><i class="fa fa-envelope" aria-hidden="true"></i> ' . $comment_unread_message . ' <span class="badge rounded-pill bg-light text-dark" style="font-size: .8em;">'.$sum_comment.'</span> </span></a>';
           }
 
         if ($j == $i - 1)
@@ -4629,8 +4900,8 @@ var exercises = [ '; // '
 
           $action_links .= $link_duplicate_activity . $link_move_activity;
           } // if ($USER->iassignEdit == 1 && has_capability('mod/iassign:editiassign', $this->context, $USER->id))
-
-        print '<tr><td style="white-space: nowrap; width: 1%; padding-right: 2rem;" class="align-middle">' . $links . '</td><td class="align-middle"></td></tr>' . "\n";
+          $action_links .= '</ul></nav>';
+        print '<tr><td style="white-space: nowrap; width: 1%; padding-right: 2rem;" class="align-middle">' . $links . '</td><td class="align-middle">'.$action_links.'</td></tr>' . "\n";
         }
         print '</tbody></table>';
       } // if (has_capability('mod/iassign:viewiassignall', $this->context, $USER->id))
@@ -4665,7 +4936,9 @@ var exercises = [ '; // '
              $comment_unread_message = get_string('comment_unread', 'iassign');
              if ($sum_comment == 1)
                $comment_unread_message = get_string('comment_unread_one', 'iassign');
-             $icon_comment = "&nbsp;<font color='red'>" . iassign_icons::insert('comment_unread') . "&nbsp;($sum_comment&nbsp;" . $comment_unread_message . ")</font>";
+             
+              $icon_comment = "<a href='view.php?id=$id&userid_iassign=$USER->id&action=view&iassign_current=$iassign_current#comments'>" . '<span class="badge bg-danger" style="color:white; font-size: .9em;"><i class="fa fa-envelope" aria-hidden="true"></i> ' . $comment_unread_message . ' <span class="badge rounded-pill bg-light text-dark" style="font-size: .8em;">'.$sum_comment.'</span> </span></a>';
+
              }
            // $icon_comment = iassign_icons::insert('comment_unread');