Add analytics
[bus.git] / busui / owa / owa_module.php
blob:a/busui/owa/owa_module.php -> blob:b/busui/owa/owa_module.php
  <?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$
  //
   
  /**
  * Abstract Module Class
  *
  * @author Peter Adams <peter@openwebanalytics.com>
  * @copyright Copyright &copy; 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_module extends owa_base {
   
  /**
  * Name of module
  *
  * @var string
  */
  var $name;
   
  /**
  * Description of Module
  *
  * @var string
  */
  var $description;
   
  /**
  * Version of Module
  *
  * @var string
  */
  var $version;
   
  /**
  * Schema Version of Module
  *
  * @var string
  */
  //var $schema_version = 1;
   
  /**
  * Name of author of module
  *
  * @var string
  */
  var $author;
   
  /**
  * URL for author of module
  *
  * @var unknown_type
  */
  var $author_url;
   
  /**
  * Wiki Page title. Used to generate link to OWA wiki for this module.
  *
  * Must be unique or else it will could clobber another wiki page.
  *
  * @var string
  */
  var $wiki_title;
   
  /**
  * name used in display situations
  *
  * @var unknown_type
  */
  var $display_name;
   
  /**
  * Array of event names that this module has handlers for
  *
  * @var array
  */
  var $subscribed_events;
   
  /**
  * Array of link information for admin panels that this module implements.
  *
  * @var array
  */
  var $admin_panels;
   
  /**
  * Array of navigation links that this module implements
  *
  * @var unknown_type
  */
  var $nav_links;
   
  /**
  * Array of metric names that this module implements
  *
  * @var unknown_type
  */
  var $metrics;
   
  /**
  * Array of graphs that are implemented by this module
  *
  * @var array
  */
  var $graphs;
   
  /**
  * The Module Group that the module belongs to.
  *
  * This is used often to group a module's features or functions together in the UI
  *
  * @var string
  */
  var $group;
   
  /**
  * Array of Entities that are implmented by the module
  *
  * @var array
  */
  var $entities = array();
   
  /**
  * Required Schema Version
  *
  * @var array
  */
  var $required_schema_version;
   
  /**
  * Available Updates
  *
  * @var array
  */
  var $updates = array();
   
  /**
  * Event Processors Map
  *
  * @var array
  */
  var $event_processors = array();
   
  /**
  * Dimensions
  *
  * @var array
  */
  var $dimensions = array();
   
  /**
  * Dimensions
  *
  * @var array
  */
  var $denormalizedDimensions = array();
   
  /**
  * cli_commands
  *
  * @var array
  */
  var $cli_commands = array();
   
  /**
  * API Methods
  *
  * @var array
  */
  var $api_methods = array();
   
  /**
  * Background Jobs
  *
  * @var array
  */
  var $background_jobs = array();
   
  /**
  * Update from CLI Required flag
  *
  * Used by controllers to see if an update error was becuase it needs
  * to be applied from the command line instead of via the browser.
  *
  * @var boolean
  */
  var $update_from_cli_required;
   
  /**
  * Constructor
  *
  *
  */
  function __construct() {
   
  parent::__construct();
   
  $this->_registerEventHandlers();
  $this->_registerEventProcessors();
  $this->_registerEntities();
  }
   
  /**
  * Method for registering event processors
  *
  */
  function _registerEventProcessors() {
   
  return false;
  }
   
  /**
  * Returns array of admin Links for this module to be used in navigation
  *
  * @access public
  * @return array
  */
  function getAdminPanels() {
   
  return $this->admin_panels;
  }
   
  /**
  * Returns array of report links for this module that will be
  * used in report navigation
  *
  * @access public
  * @return array
  */
  function getNavigationLinks() {
   
  return $this->nav_links;
  }
   
  /**
  * Abstract method for registering event handlers
  *
  * Must be defined by a concrete module class for any event handlers to be registered
  *
  * @access public
  * @return array
  */
  function _registerEventHandlers() {
   
  return;
  }
   
  /**
  * Attaches an event handler to the event queue
  *
  * @param array $event_name
  * @param string $handler_name
  * @return boolean
  */
  function registerEventHandler($event_name, $handler_name, $method = 'notify', $dir = 'handlers') {
   
  if (!is_object($handler_name)) {
   
  //$handler = &owa_lib::factory($handler_dir,'owa_', $handler_name);
  $handler_name = owa_coreAPI::moduleGenericFactory($this->name, $dir, $handler_name, $class_suffix = null, $params = '', $class_ns = 'owa_');
  }
   
  $eq = owa_coreAPI::getEventDispatch();
  $eq->attach($event_name, array($handler_name, $method));
  }
   
  /**
  * Attaches an event handler to the event queue
  *
  * @param array $event_name
  * @param string $handler_name
  * @return boolean
  */
  function registerFilter($filter_name, $handler_name, $method, $priority = 10, $dir = 'filters') {
   
  if (!is_object($handler_name)) {
   
  //$handler = &owa_lib::factory($handler_dir,'owa_', $handler_name);
  $handler_name = owa_coreAPI::moduleGenericFactory($this->name, $dir, $handler_name, $class_suffix = null, $params = '', $class_ns = 'owa_');
  }
   
  $eq = owa_coreAPI::getEventDispatch();
  $eq->attachFilter($filter_name, array($handler_name, $method), $priority);
  }
   
  /**
  * Attaches an event handler to the event queue
  *
  * @param array $event_name
  * @param string $handler_name
  * @return boolean
  * @depricated
  */
  function _addHandler($event_name, $handler_name) {
   
  return $this->registerEventHandler($event_name, $handler_name);
   
  }
   
  /**
  * Abstract method for registering administration/settings page
  *
  * @access public
  * @return array
  */
  function registerAdminPanels() {
   
  return;
  }
   
  /**
  * Registers an admin panel with this module
  *
  */
  function registerSettingsPanel($panel) {
   
  $this->admin_panels[] = $panel;
   
  return true;
  }
   
  /**
  * Registers an admin panel with this module
  * @depricated
  */
  function addAdminPanel($panel) {
   
  return $this->registerSettingsPanel($panel);
  }
   
  /**
  * Registers Group Link with a particular View
  *
  */
  function addNavigationLink($group, $subgroup = '', $ref, $anchortext, $order = 0, $priviledge = 'viewer') {
   
  $link = array('ref' => $ref,
  'anchortext' => $anchortext,
  'order' => $order,
  'priviledge' => $priviledge);
   
  if (!empty($subgroup)):
  $this->nav_links[$group][$subgroup]['subgroup'][] = $link;
  else:
  $this->nav_links[$group][$anchortext] = $link;
  endif;
   
  return;
  }
   
  /**
  * Abstract method for registering a module's entities
  *
  * This method must be defined in concrete module classes in order for entities to be registered.
  */
  function _registerEntities() {
   
  return false;
  }
   
  function registerNavigation() {
   
  return false;
  }
   
   
  /**
  * Registers an Entity
  *
  * Can take an array of entities or just a single entity as a string.
  * Will add an enetiy to the module's entity array. Required for entity installation, etc.
  *
  * @param $entity_name array or string
  */
  function registerEntity($entity_name) {
   
  if (is_array($entity_name)) {
  $this->entities = array_merge($this->entities, $entity_name);
  } else {
  $this->entities[] = $entity_name;
  }
  }
   
  /**
  * Registers Entity
  *
  * Depreicated see registerEntity
  *
  * @depricated
  */
  function _addEntity($entity_name) {
   
  return $this->registerEntity($entity_name);
  }
   
   
  function getEntities() {
   
  return $this->entities;
  }
 </