1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 | <?php // // Open Web Analytics - An Open Source Web Analytics Framework // // Copyright 2006 Peter Adams. All rights reserved. // // Licensed under GPL v2.0 http://www.gnu.org/copyleft/gpl.html // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // // $Id$ // require_once(OWA_BASE_CLASSES_DIR.'owa_controller.php'); require_once(OWA_BASE_DIR.'/owa_lib.php'); require_once(OWA_BASE_DIR.'/owa_view.php'); /** * Abstract Widget Controller Class * * @author Peter Adams <peter@openwebanalytics.com> * @copyright Copyright © 2006 Peter Adams <peter@openwebanalytics.com> * @license http://www.gnu.org/copyleft/gpl.html GPL v2.0 * @category owa * @package owa * @version $Revision$ * @since owa 1.0.0 */ class owa_widgetController extends owa_controller { var $default_format = 'graph'; var $dom_id; /** * holding tank or metrics that need * to be shared between action methods */ var $metrics = array(); function __construct($params) { $this->type = 'widget'; //$this->setRequiredCapability('view_reports'); //print_r($params); return parent::__construct($params); } function pre() { $this->setPeriod($this->getParam('period')); // create dom safe id from do action param $this->dom_id = str_replace('.', '-', $this->params['do']); $this->data['dom_id'] = $this->dom_id; if (!array_key_exists('format', $this->params)): $this->params['format'] = $this->default_format; else: if (empty($this->params['format'])): $this->params['format'] = $this->default_format; endif; endif; return; } function post() { // calls widget format specific functions $this->doFormatAction($this->params['format']); // used to add outer wrapper to widget if it's the first view. $iv = $this->getParam('initial_view'); if ($iv == true): $this->data['subview'] = $this->data['view']; $this->data['view'] = 'base.widget'; // we dont want to keep passing this. unset($this->data['params']['initial_view']); endif; $this->data['wrapper'] = $this->getParam('wrapper'); $this->data['widget'] = $this->params['do']; $this->data['do'] = $this->params['do']; // set default dimensions if (array_key_exists('width', $this->params)): $this->setWidth($this->params['width']); endif; if (array_key_exists('height', $this->params)): $this->setHeight($this->params['height']); endif; } function enableFormat($name, $label = '') { if (empty($label)): $label = ucwords($name); endif; $this->data['widget_views'][$name] = $label; return; } function setHeight($height) { $this->data['height'] = $height; return; } function setWidth($width) { $this->data['width'] = $width; return; } function setDefaultFormat($format) { $this->default_format = $format; return; } function doFormatAction($format = '') { $method = $this->params['format'].'Action'; if (method_exists($this, $method)) { $this->$method(); } else { $this->e->debug("Widget format not implemented. No method named $method"); } } function setMetric($name, $obj) { $this->metrics[$name] = $obj; return; } function getMetric($name) { return $this->metrics[$name]; } } /** * Widget View * * @author Peter Adams <peter@openwebanalytics.com> * @copyright Copyright © 2006 Peter Adams <peter@openwebanalytics.com> * @license http://www.gnu.org/copyleft/gpl.html GPL v2.0 * @category owa * @package owa * @version $Revision$ * @since owa 1.0.0 */ class owa_widgetView extends owa_view { function owa_widgetView() { $this->owa_view(); return; } function render($data) { // load template if (array_key_exists('is_external', $data['params'])): if ($data['params']['is_external'] == true): $this->t->set_template('wrapper_widget.tpl'); else: $this->t->set_template('wrapper_blank.tpl'); endif; else: $this->t->set_template('wrapper_blank.tpl'); endif; if (array_key_exists('width', $data)): $data['params']['width'] = $data['width']; endif; if (array_key_exists('height', $data)): $data['params']['height'] = $data['height']; endif; $this->_setLinkState(); if ($data['wrapper'] === true): $this->body->set_template('widget.tpl'); elseif ($data['wrapper'] === 'inpage'): $this->body->set_template('widget_inpage.tpl'); endif; if (array_key_exists('format', $data['params'])): $this->body->set('format', $data['params']['format']); endif; $this->body->set('widget', str_replace('.', '-', $data['widget'])); $this->body->set('params', $data['params']); $this->body->set('title', $data['title']); $this->body->set('widget_views', $data['widget_views']); $this->body->set('widget_views_count', count($data['widget_views'])); $this->body->set('do', $data['widget']); return; } } ?> |