Change BSApi::remove() to BSApi::delete()
[isso.git] / PrinterAbstract.php
1 <?php
2 /*=====================================================================*
3 || ###################################################################
4 || # Blue Static ISSO Framework
5 || # Copyright (c)2005-2008 Blue Static
6 || #
7 || # This program is free software; you can redistribute it and/or modify
8 || # it under the terms of the GNU General Public License as published by
9 || # the Free Software Foundation; version 2 of the License.
10 || #
11 || # This program is distributed in the hope that it will be useful, but
12 || # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13 || # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14 || # more details.
15 || #
16 || # You should have received a copy of the GNU General Public License along
17 || # with this program; if not, write to the Free Software Foundation, Inc.,
18 || # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
19 || ###################################################################
20 \*=====================================================================*/
21
22 /**
23 * Printer Element Abstract Class (PrinterAbstract.php)
24 *
25 * @package ISSO
26 */
27
28 /**
29 * Printer Element
30 *
31 * This abstract class is used for all printer elements and describes
32 * the basic functionality of an element.
33 *
34 * @author Blue Static
35 * @copyright Copyright (c)2005 - 2008, Blue Static
36 * @package ISSO
37 *
38 */
39 abstract class BSPrinterAbstract
40 {
41 /**
42 * Style information
43 * @var array
44 */
45 protected $style = array();
46
47 /**
48 * The CSS class to use
49 * @var string
50 */
51 protected $cssClass = ':swap:';
52
53 /**
54 * DOM ID of the element
55 * @var string
56 */
57 protected $id;
58
59 /**
60 * Fluent object instantiation
61 */
62 public abstract static function make();
63
64 /**
65 * Tells the element to paint itself (and any children)
66 */
67 public abstract function paint();
68
69 /**
70 * To-string method which invokes paint()
71 */
72 public function __toString()
73 {
74 return $this->paint();
75 }
76
77 /**
78 * Sets the CSS class to use. Use ":swap:" to alternate
79 *
80 * @param string CSS class
81 *
82 * @return fluent interface
83 */
84 public function setCssClass($class)
85 {
86 $this->cssClass = $class;
87 return $this;
88 }
89
90 /**
91 * Sets the style information
92 *
93 * @param array Style attributes
94 *
95 * @return fluent interface
96 */
97 public function setStyle(Array $attributes)
98 {
99 $this->style = $attributes;
100 return $this;
101 }
102
103 /**
104 * Sets the DOM/CSS ID of the element
105 *
106 * @param string The ID
107 *
108 * @return fluent interface
109 */
110 public function setId($id)
111 {
112 $this->id = $id;
113 return $this;
114 }
115
116 /**
117 * Returns a string of style attributes, that include id, style, and class
118 *
119 * @return string Style attributes
120 */
121 protected function _prepareStyle()
122 {
123 if (empty($this->style) && empty($this->cssClass) && empty($this->id))
124 {
125 return;
126 }
127
128 if ($this->cssClass == ':swap:')
129 {
130 BSFunctions::swap_css_classes();
131 $class = BSFunctions::$cssClass;
132 }
133 else
134 {
135 $class = $this->cssClass;
136 }
137
138 $attrs = array();
139
140 foreach ($this->style as $prop => $value)
141 {
142 $attrs[] = $prop . ': ' . $value;
143 }
144
145 $style = implode('; ', $attrs);
146
147 $string = '';
148 if ($class)
149 {
150 $string .= ' class="' . $class . '"';
151 }
152 if ($style)
153 {
154 $string .= ' style="' . $style . '"';
155 }
156 if ($this->id)
157 {
158 $string .= ' id="' . $this->id . '"';
159 }
160
161 return $string;
162 }
163 }
164
165 ?>