horizontal
3 days ago
leftboard
3 days ago
abstractlist.php
3 days ago
custom.php
3 days ago
factory.php
3 days ago
index.html
3 days ago
item.php
3 days ago
separator.php
3 days ago
shape.php
3 days ago
custom.php
101 lines
| 1 | <?php |
| 2 | /** |
| 3 | * @package VikAppointments |
| 4 | * @subpackage core |
| 5 | * @author E4J s.r.l. |
| 6 | * @copyright Copyright (C) 2021 E4J s.r.l. All Rights Reserved. |
| 7 | * @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL |
| 8 | * @link https://vikwp.com |
| 9 | */ |
| 10 | |
| 11 | // No direct access |
| 12 | defined('ABSPATH') or die('No script kiddies please!'); |
| 13 | |
| 14 | /** |
| 15 | * Class used to represent the shape of a custom item. |
| 16 | * |
| 17 | * @since 1.5 |
| 18 | */ |
| 19 | abstract class CustomShape |
| 20 | { |
| 21 | /** |
| 22 | * The array containing all the attributes of this custom item. |
| 23 | * The attributes of this custom item cannot be directly accessed. |
| 24 | * |
| 25 | * @var array |
| 26 | * |
| 27 | * @see get() |
| 28 | */ |
| 29 | private $params; |
| 30 | |
| 31 | /** |
| 32 | * The construct sets all the required attributes of this class. |
| 33 | * |
| 34 | * @param array $params Default empty array. |
| 35 | * |
| 36 | * @uses setParams() |
| 37 | */ |
| 38 | public function __construct(array $params = array()) |
| 39 | { |
| 40 | $this->setParams($params); |
| 41 | } |
| 42 | |
| 43 | /** |
| 44 | * Sets all the attributes of this custom item. |
| 45 | * |
| 46 | * @param array $params The attributes to use. |
| 47 | * |
| 48 | * @return self This object to support chaining. |
| 49 | */ |
| 50 | public function setParams($params) |
| 51 | { |
| 52 | if (is_array($params)) |
| 53 | { |
| 54 | $this->params = $params; |
| 55 | } |
| 56 | |
| 57 | return $this; |
| 58 | } |
| 59 | |
| 60 | /** |
| 61 | * Returns the value of the attribute specified. Returns NULL is the specified attribute doesn't exist. |
| 62 | * The attributes of this custom item are not accessible from external classes. |
| 63 | * |
| 64 | * @param string $key The name of the attribute. |
| 65 | * |
| 66 | * @return string The value of the attribute. |
| 67 | */ |
| 68 | public function get($key) |
| 69 | { |
| 70 | if (array_key_exists($key, $this->params)) |
| 71 | { |
| 72 | return $this->params[$key]; |
| 73 | } |
| 74 | |
| 75 | return null; |
| 76 | } |
| 77 | |
| 78 | /** |
| 79 | * Adds a new parameter with the specified attribute. |
| 80 | * |
| 81 | * @param string $key The attribute of the parameter. |
| 82 | * @param string $param The value of the parameter. |
| 83 | * |
| 84 | * @return self This object to support chaining. |
| 85 | */ |
| 86 | public function add($key, $param) |
| 87 | { |
| 88 | $this->params[$key] = $param; |
| 89 | |
| 90 | return $this; |
| 91 | } |
| 92 | |
| 93 | /** |
| 94 | * Builds and returns the html structure of the custom menu item. |
| 95 | * This method must be implemented to define a specific graphic of the custom item. |
| 96 | * |
| 97 | * @return string The html of the custom item. |
| 98 | */ |
| 99 | abstract public function buildHtml(); |
| 100 | } |
| 101 |