CRM-13823 - Refactor CRM_Utils_Check_Message to calculate its own visibility
[civicrm-core.git] / CRM / Utils / Check / Message.php
index a4db669e746084c0047b00ffc04549b09bb184f4..ca4efbd3174c9c473b3a7d647bce4b105a865629 100644 (file)
@@ -29,8 +29,6 @@
  *
  * @package CRM
  * @copyright CiviCRM LLC (c) 2004-2015
- * $Id: $
- *
  */
 class CRM_Utils_Check_Message {
   /**
@@ -49,7 +47,7 @@ class CRM_Utils_Check_Message {
   private $title;
 
   /**
-   * @var string
+   * @var int
    * @see Psr\Log\LogLevel
    */
   private $level;
@@ -61,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
@@ -72,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;
@@ -81,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() {
@@ -91,6 +100,8 @@ class CRM_Utils_Check_Message {
   }
 
   /**
+   * Get message.
+   *
    * @return string
    */
   public function getMessage() {
@@ -105,6 +116,8 @@ class CRM_Utils_Check_Message {
   }
 
   /**
+   * Get level.
+   *
    * @return string
    * @see Psr\Log\LogLevel
    */
@@ -121,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) {
@@ -129,6 +143,8 @@ class CRM_Utils_Check_Message {
   }
 
   /**
+   * Convert to array.
+   *
    * @return array
    */
   public function toArray() {
@@ -137,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;
@@ -144,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);
+  }
+
 }