[ Index ]
 

Code source de vtiger CRM 5.0.2

Accédez au Source d'autres logiciels libresSoutenez Angelica Josefina !

title

Body

[fermer]

/Image/Graph/ -> Common.php (source)

   1  <?php
   2  
   3  /* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
   4  
   5  /**
   6   * Image_Graph - Main class for the graph creation.
   7   *
   8   * PHP versions 4 and 5
   9   *
  10   * LICENSE: This library is free software; you can redistribute it and/or modify
  11   * it under the terms of the GNU Lesser General Public License as published by
  12   * the Free Software Foundation; either version 2.1 of the License, or (at your
  13   * option) any later version. This library is distributed in the hope that it
  14   * will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
  15   * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser
  16   * General Public License for more details. You should have received a copy of
  17   * the GNU Lesser General Public License along with this library; if not, write
  18   * to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
  19   * 02111-1307 USA
  20   *
  21   * @category   Images
  22   * @package    Image_Graph
  23   * @author     Jesper Veggerby <pear.nosey@veggerby.dk>
  24   * @copyright  Copyright (C) 2003, 2004 Jesper Veggerby Hansen
  25   * @license    http://www.gnu.org/copyleft/lesser.html  LGPL License 2.1
  26   * @version    CVS: $Id: Common.php,v 1.16 2006/02/28 22:48:07 nosey Exp $
  27   * @link       http://pear.php.net/package/Image_Graph
  28   */
  29  
  30  if (!function_exists('is_a')) {
  31  
  32      /**
  33       * Check if an object is of a given class, this function is available as of PHP 4.2.0, so if it exist it will not be declared
  34       *
  35       * @link http://www.php.net/manual/en/function.is-a.php PHP.net Online Manual for function is_a()
  36       * @param object $object The object to check class for
  37       * @param string $class_name The name of the class to check the object for
  38       * @return bool Returns TRUE if the object is of this class or has this class as one of its parents
  39       */
  40      function is_a($object, $class_name)
  41      {
  42          if (empty ($object)) {
  43              return false;
  44          }
  45          $object = is_object($object) ? get_class($object) : $object;
  46          if (strtolower($object) == strtolower($class_name)) {
  47              return true;
  48          }
  49          return is_a(get_parent_class($object), $class_name);
  50      }
  51  }
  52  
  53  /**
  54   * Include file Image/Canvas.php
  55   */
  56  require_once  'Image/Canvas.php';
  57  
  58  /**
  59   * The ultimate ancestor of all Image_Graph classes.
  60   *
  61   * This class contains common functionality needed by all Image_Graph classes.
  62   *
  63   * @category   Images
  64   * @package    Image_Graph
  65   * @author     Jesper Veggerby <pear.nosey@veggerby.dk>
  66   * @copyright  Copyright (C) 2003, 2004 Jesper Veggerby Hansen
  67   * @license    http://www.gnu.org/copyleft/lesser.html  LGPL License 2.1
  68   * @version    Release: 0.7.2
  69   * @link       http://pear.php.net/package/Image_Graph
  70   * @abstract
  71   */
  72  class Image_Graph_Common
  73  {
  74  
  75      /**
  76       * The parent container of the current Image_Graph object
  77       *
  78       * @var Image_Graph_Common
  79       * @access private
  80       */
  81      var $_parent = null;
  82  
  83      /**
  84       * The sub-elements of the current Image_Graph container object
  85       *
  86       * @var array
  87       * @access private
  88       */
  89      var $_elements;
  90  
  91      /**
  92       * The canvas for output.
  93       *
  94       * Enables support for multiple output formats.
  95       *
  96       * @var Image_Canvas
  97       * @access private
  98       */
  99      var $_canvas = null;
 100      
 101      /**
 102       * Is the object visible?
 103       * 
 104       * @var bool
 105       * @access private
 106       */
 107      var $_visible = true;
 108  
 109      /**
 110       * Constructor [Image_Graph_Common]
 111       */
 112      function Image_Graph_Common()
 113      {
 114      }
 115  
 116      /**
 117       * Resets the elements
 118       *
 119       * @access private
 120       */
 121      function _reset()
 122      {
 123          if (is_array($this->_elements)) {
 124              $keys = array_keys($this->_elements);
 125              foreach ($keys as $key) {
 126                  if (is_object($this->_elements[$key])) {
 127                      $this->_elements[$key]->_setParent($this);
 128                      $result =& $this->_elements[$key]->_reset();
 129                      if (PEAR::isError($result)) {
 130                          return $result;
 131                      }
 132                  }
 133              }
 134              unset($keys);
 135          }
 136          return true;
 137      }
 138  
 139      /**
 140       * Sets the parent. The parent chain should ultimately be a GraPHP object
 141       *
 142       * @see Image_Graph_Common
 143       * @param Image_Graph_Common $parent The parent
 144       * @access private
 145       */
 146      function _setParent(& $parent)
 147      {
 148          $this->_parent =& $parent;
 149          $this->_canvas =& $this->_parent->_getCanvas();
 150  
 151          if (is_array($this->_elements)) {
 152              $keys = array_keys($this->_elements);
 153              foreach ($keys as $key) {
 154                  if (is_object($this->_elements[$key])) {
 155                      $this->_elements[$key]->_setParent($this);
 156                  }
 157              }
 158              unset($keys);
 159          }
 160      }
 161  
 162      /**
 163       * Hide the element
 164       */
 165      function hide()
 166      {
 167          $this->_visible = false;
 168      }        
 169  
 170      /**
 171       * Get the canvas
 172       *
 173       * @return Image_Canvas The canvas
 174       * @access private
 175       */
 176      function &_getCanvas()
 177      { 
 178          if (($this->_canvas !== null) || ($this->_canvas !== false)) {
 179              return $this->_canvas;
 180          } elseif (is_a($this->_parent, 'Image_Graph_Common')) {
 181              $this->_canvas =& $this->_parent->_getCanvas();
 182              return $this->_canvas;
 183          } else {
 184              $this->_error('Invalid canvas');
 185              $result = null;
 186              return $result;
 187          }
 188      }
 189  
 190      /**
 191       * Adds an element to the objects element list.
 192       *
 193       * The new Image_Graph_elements parent is automatically set.
 194       *
 195       * @param Image_Graph_Common $element The new Image_Graph_element
 196       * @return Image_Graph_Common The new Image_Graph_element
 197       */
 198      function &add(& $element)
 199      {
 200          if (!is_a($element, 'Image_Graph_Font')) {
 201              $this->_elements[] = &$element;
 202          }
 203          $element->_setParent($this);
 204          return $element;
 205      }
 206  
 207      /**
 208       * Creates an object from the class and adds it to the objects element list.
 209       *
 210       * Creates an object from the class specified and adds it to the objects
 211       * element list. If only one parameter is required for the constructor of
 212       * the class simply pass this parameter as the $params parameter, unless the
 213       * parameter is an array or a reference to a value, in that case you must
 214       * 'enclose' the parameter in an array. Similar if the constructor takes
 215       * more than one parameter specify the parameters in an array.
 216       *
 217       * @see Image_Graph::factory()
 218       * @param string $class The class for the object
 219       * @param mixed $params The paramaters to pass to the constructor
 220       * @return Image_Graph_Common The new Image_Graph_element
 221       */
 222      function &addNew($class, $params = null, $additional = false)
 223      {
 224          include_once  'Image/Graph.php';
 225          $element =& Image_Graph::factory($class, $params);
 226          if ($additional === false) {
 227              $obj =& $this->add($element);
 228          } else {
 229              $obj =& $this->add($element, $additional);
 230          }
 231          return $obj;
 232      }
 233  
 234      /**
 235       * Shows an error message box on the canvas
 236       *
 237       * @param string $text The error text
 238       * @param array $params An array containing error specific details
 239       * @param int $error_code Error code
 240       * @access private
 241       */
 242      function _error($text, $params = false, $error_code = IMAGE_GRAPH_ERROR_GENERIC)
 243      {       
 244          if ((is_array($params)) && (count($params) > 0)) {
 245              foreach ($params as $name => $key) {
 246                  if (isset($parameters)) {
 247                      $parameters .= ' ';
 248                  } 
 249                  else {
 250                      $parameters = '';
 251                  }
 252                  $parameters .= $name . '=' . $key;
 253              }
 254          }        
 255          $error =& PEAR::raiseError(
 256              $text .
 257              ($error_code != IMAGE_GRAPH_ERROR_GENERIC ? ' error:' . IMAGE_GRAPH_ERROR_GENERIC : '') .
 258              (isset($parameters) ? ' parameters:[' . $parameters . ']' : '')            
 259          );         
 260      }
 261  
 262      /**
 263       * Causes the object to update all sub elements coordinates
 264       *
 265       * (Image_Graph_Common, does not itself have coordinates, this is basically
 266       * an abstract method)
 267       *
 268       * @access private
 269       */
 270      function _updateCoords()
 271      {
 272          if (is_array($this->_elements)) {
 273              $keys = array_keys($this->_elements);
 274              foreach ($keys as $key) {
 275                  if (is_object($this->_elements[$key])) {
 276                      $this->_elements[$key]->_updateCoords();
 277                  }
 278              }
 279              unset($keys);
 280          }
 281          return true;
 282      }
 283  
 284      /**
 285       * Causes output to canvas
 286       *
 287       * The last method to call. Calling Done causes output to the canvas. All
 288       * sub elements done() method will be invoked
 289       *
 290       * @return bool Was the output 'good' (true) or 'bad' (false).
 291       * @access private
 292       */
 293      function _done()
 294      {
 295          if (($this->_canvas == null) || (!is_a($this->_canvas, 'Image_Canvas'))) {
 296              return false;
 297          }
 298  
 299          if (is_array($this->_elements)) {
 300              $keys = array_keys($this->_elements);
 301              foreach ($keys as $key) {
 302                  if (($this->_elements[$key]->_visible) && ($this->_elements[$key]->_done() === false)) {
 303                      return false;
 304                  }
 305              }
 306              unset($keys);
 307          }
 308          return true;
 309      }
 310  
 311  }
 312  
 313  ?>


Généré le : Sun Feb 25 10:22:19 2007 par Balluche grâce à PHPXref 0.7