SproutCMS

This is the code documentation for the SproutCMS project

source of /sprout/Helpers/DisplayConditions/DisplayCondition.php

  1. <?php
  2. /*
  3.  * Copyright (C) 2017 Karmabunny Pty Ltd.
  4.  *
  5.  * This file is a part of SproutCMS.
  6.  *
  7.  * SproutCMS is free software: you can redistribute it and/or modify it under the terms
  8.  * of the GNU General Public License as published by the Free Software Foundation, either
  9.  * version 2 of the License, or (at your option) any later version.
  10.  *
  11.  * For more information, visit <http://getsproutcms.com>.
  12.  */
  13.  
  14. namespace Sprout\Helpers\DisplayConditions;
  15.  
  16.  
  17. /**
  18.  * Base class for display conditions
  19.  *
  20.  * This is known as the Context Engine, and is a set of display rules which affect
  21.  * which widgets (content blocks) are shown or hidden on the page
  22.  */
  23. abstract class DisplayCondition
  24. {
  25.  
  26. /**
  27.   * Return the list of operators for the condition value
  28.   * Common values would be 'equals', 'not equals', 'less than', 'contains', etc
  29.   *
  30.   * @return array Key is internal value (e.g. '=') and value is the label (e.g. 'Equals')
  31.   */
  32. abstract public function getOperators();
  33.  
  34.  
  35. /**
  36.   * Return the type of parameter for UI display
  37.   * Only two types are supported - 'text' or 'dropdown'
  38.   *
  39.   * @return string
  40.   */
  41. abstract public function getParamType();
  42.  
  43.  
  44. /**
  45.   * Return the available values for dropdowns
  46.   *
  47.   * @return array Key is internal value (e.g. 'desktop') and value is the label (e.g. 'Desktop')
  48.   */
  49. public function getParamValues()
  50. {
  51. return [];
  52. }
  53.  
  54.  
  55. /**
  56.   * Does a given condition match?
  57.   *
  58.   * @param array $env Environment, such as page id etc
  59.   * @param string $op string One of the keys from the array returned by {@see DisplayCondition::getOperators}
  60.   * @param string $val string Entered value OR one of the keys from {@see DisplayCondition::getParamValues}
  61.   * @return bool True of condition matches, false if it does not
  62.   */
  63. abstract public function match(array $env, $op, $val);
  64.  
  65. }
  66.