source of /sprout/Helpers/DisplayConditions/DisplayCondition.php<?php /* * Copyright (C) 2017 Karmabunny Pty Ltd. * * This file is a part of SproutCMS. * * SproutCMS is free software: you can redistribute it and/or modify it under the terms * of the GNU General Public License as published by the Free Software Foundation, either * version 2 of the License, or (at your option) any later version. * * For more information, visit <http://getsproutcms.com>. */ namespace Sprout\Helpers\DisplayConditions; /** * Base class for display conditions * * This is known as the Context Engine, and is a set of display rules which affect * which widgets (content blocks) are shown or hidden on the page */ abstract class DisplayCondition { /** * Return the list of operators for the condition value * Common values would be 'equals', 'not equals', 'less than', 'contains', etc * * @return array Key is internal value (e.g. '=') and value is the label (e.g. 'Equals') */ abstract public function getOperators(); /** * Return the type of parameter for UI display * Only two types are supported - 'text' or 'dropdown' * * @return string */ abstract public function getParamType(); /** * Return the available values for dropdowns * * @return array Key is internal value (e.g. 'desktop') and value is the label (e.g. 'Desktop') */ public function getParamValues() { return []; } /** * Does a given condition match? * * @param array $env Environment, such as page id etc * @param string $op string One of the keys from the array returned by {@see DisplayCondition::getOperators} * @param string $val string Entered value OR one of the keys from {@see DisplayCondition::getParamValues} * @return bool True of condition matches, false if it does not */ abstract public function match (array $env, $op, $val); }
|