CRM-13823 - Refactor CRM_Utils_Check_Message to calculate its own visibility
[civicrm-core.git] / CRM / Utils / Check / Message.php
index 2bf5dec90929a3dd5d9bf50c7bec4104048c0fac..ca4efbd3174c9c473b3a7d647bce4b105a865629 100644 (file)
@@ -47,7 +47,7 @@ class CRM_Utils_Check_Message {
   private $title;
 
   /**
-   * @var string
+   * @var int
    * @see Psr\Log\LogLevel
    */
   private $level;
@@ -59,6 +59,14 @@ class CRM_Utils_Check_Message {
   private $help;
 
   /**
+   * @var string
+   *   crm-i css class
+   */
+  private $icon;
+
+  /**
+   * Class constructor.
+   *
    * @param string $name
    *   Symbolic name for the check.
    * @param string $message
@@ -70,7 +78,7 @@ class CRM_Utils_Check_Message {
    *
    * @see Psr\Log\LogLevel
    */
-  public function __construct($name, $message, $title, $level = \Psr\Log\LogLevel::WARNING) {
+  public function __construct($name, $message, $title, $level = \Psr\Log\LogLevel::WARNING, $icon = NULL) {
     $this->name = $name;
     $this->message = $message;
     $this->title = $title;
@@ -79,9 +87,12 @@ class CRM_Utils_Check_Message {
       $level = CRM_Utils_Check::severityMap($level);
     }
     $this->level = $level;
+    $this->icon = $icon;
   }
 
   /**
+   * Get name.
+   *
    * @return string
    */
   public function getName() {
@@ -89,6 +100,8 @@ class CRM_Utils_Check_Message {
   }
 
   /**
+   * Get message.
+   *
    * @return string
    */
   public function getMessage() {
@@ -103,6 +116,8 @@ class CRM_Utils_Check_Message {
   }
 
   /**
+   * Get level.
+   *
    * @return string
    * @see Psr\Log\LogLevel
    */
@@ -119,7 +134,8 @@ class CRM_Utils_Check_Message {
   }
 
   /**
-   * Set optional additional help text
+   * Set optional additional help text.
+   *
    * @param string $help
    */
   public function addHelp($help) {
@@ -127,6 +143,8 @@ class CRM_Utils_Check_Message {
   }
 
   /**
+   * Convert to array.
+   *
    * @return array
    */
   public function toArray() {
@@ -135,6 +153,8 @@ class CRM_Utils_Check_Message {
       'message' => $this->message,
       'title' => $this->title,
       'severity' => $this->level,
+      'is_visible' => (int) $this->isVisible(),
+      'icon' => $this->icon,
     );
     if (!empty($this->help)) {
       $array['help'] = $this->help;
@@ -142,4 +162,13 @@ class CRM_Utils_Check_Message {
     return $array;
   }
 
+  /**
+   * Check if message is visible or has been hidden by the user.
+   *
+   * @return bool
+   */
+  public function isVisible() {
+    return !CRM_Utils_Check::checkHushSnooze($this);
+  }
+
 }