[ Index ]

PHP Cross Reference of vtigercrm-6.1.0

title

Body

[close]

/vtlib/Vtiger/ -> Module.php (source)

   1  <?php
   2  /*+**********************************************************************************
   3   * The contents of this file are subject to the vtiger CRM Public License Version 1.0
   4   * ("License"); You may not use this file except in compliance with the License
   5   * The Original Code is:  vtiger CRM Open Source
   6   * The Initial Developer of the Original Code is vtiger.
   7   * Portions created by vtiger are Copyright (C) vtiger.
   8   * All Rights Reserved.
   9   ************************************************************************************/
  10  
  11  require_once  'includes/runtime/Cache.php';
  12  include_once ('vtlib/Vtiger/ModuleBasic.php');
  13  /**
  14   * Provides API to work with vtiger CRM Modules
  15   * @package vtlib
  16   */
  17  class Vtiger_Module extends Vtiger_ModuleBasic {
  18  
  19          /**
  20       * Function to get the Module/Tab id
  21       * @return <Number>
  22       */
  23  	public function getId() {
  24          return $this->id;
  25      }
  26          
  27      /**
  28       * Get unique id for related list
  29       * @access private
  30       */
  31  	function __getRelatedListUniqueId() {
  32          global $adb;
  33          return $adb->getUniqueID('vtiger_relatedlists');
  34      }
  35  
  36      /**
  37       * Get related list sequence to use
  38       * @access private
  39       */
  40  	function __getNextRelatedListSequence() {
  41          global $adb;
  42          $max_sequence = 0;
  43          $result = $adb->pquery("SELECT max(sequence) as maxsequence FROM vtiger_relatedlists WHERE tabid=?", Array($this->id));
  44          if($adb->num_rows($result)) $max_sequence = $adb->query_result($result, 0, 'maxsequence');
  45          return ++$max_sequence;
  46      }
  47  
  48      /**
  49       * Set related list information between other module
  50       * @param Vtiger_Module Instance of target module with which relation should be setup
  51       * @param String Label to display in related list (default is target module name)
  52       * @param Array List of action button to show ('ADD', 'SELECT')
  53       * @param String Callback function name of this module to use as handler
  54       *
  55       * @internal Creates table vtiger_crmentityrel if it does not exists
  56       */
  57  	function setRelatedList($moduleInstance, $label='', $actions=false, $function_name='get_related_list') {
  58          global $adb;
  59  
  60          if(empty($moduleInstance)) return;
  61  
  62          if(!Vtiger_Utils::CheckTable('vtiger_crmentityrel')) {
  63              Vtiger_Utils::CreateTable(
  64                  'vtiger_crmentityrel',
  65                  '(crmid INT NOT NULL, module VARCHAR(100) NOT NULL, relcrmid INT NOT NULL, relmodule VARCHAR(100) NOT NULL)',
  66                  true
  67              );
  68          }
  69  
  70          $relation_id = $this->__getRelatedListUniqueId();
  71          $sequence = $this->__getNextRelatedListSequence();
  72          $presence = 0; // 0 - Enabled, 1 - Disabled
  73  
  74          if(empty($label)) $label = $moduleInstance->name;
  75  
  76          // Allow ADD action of other module records (default)
  77          if($actions === false) $actions = Array('ADD');
  78  
  79          $useactions_text = $actions;
  80          if(is_array($actions)) $useactions_text = implode(',', $actions);
  81          $useactions_text = strtoupper($useactions_text);
  82  
  83          // Add column to vtiger_relatedlists to save extended actions
  84          Vtiger_Utils::AddColumn('vtiger_relatedlists', 'actions', 'VARCHAR(50)');
  85  
  86          $adb->pquery("INSERT INTO vtiger_relatedlists(relation_id,tabid,related_tabid,name,sequence,label,presence,actions) VALUES(?,?,?,?,?,?,?,?)",
  87              Array($relation_id,$this->id,$moduleInstance->id,$function_name,$sequence,$label,$presence,$useactions_text));
  88  
  89          self::log("Setting relation with $moduleInstance->name [$useactions_text] ... DONE");
  90      }
  91  
  92      /**
  93       * Unset related list information that exists with other module
  94       * @param Vtiger_Module Instance of target module with which relation should be setup
  95       * @param String Label to display in related list (default is target module name)
  96       * @param String Callback function name of this module to use as handler
  97       */
  98  	function unsetRelatedList($moduleInstance, $label='', $function_name='get_related_list') {
  99          global $adb;
 100  
 101          if(empty($moduleInstance)) return;
 102  
 103          if(empty($label)) $label = $moduleInstance->name;
 104  
 105          $adb->pquery("DELETE FROM vtiger_relatedlists WHERE tabid=? AND related_tabid=? AND name=? AND label=?",
 106              Array($this->id, $moduleInstance->id, $function_name, $label));
 107  
 108          self::log("Unsetting relation with $moduleInstance->name ... DONE");
 109      }
 110  
 111      /**
 112       * Add custom link for a module page
 113       * @param String Type can be like 'DETAILVIEW', 'LISTVIEW' etc..
 114        * @param String Label to use for display
 115       * @param String HREF value to use for generated link
 116       * @param String Path to the image file (relative or absolute)
 117       * @param Integer Sequence of appearance
 118       *
 119       * NOTE: $url can have variables like $MODULE (module for which link is associated),
 120       * $RECORD (record on which link is dispalyed)
 121       */
 122  	function addLink($type, $label, $url, $iconpath='', $sequence=0, $handlerInfo=null) {
 123          Vtiger_Link::addLink($this->id, $type, $label, $url, $iconpath, $sequence, $handlerInfo);
 124      }
 125  
 126      /**
 127       * Delete custom link of a module
 128       * @param String Type can be like 'DETAILVIEW', 'LISTVIEW' etc..
 129        * @param String Display label to lookup
 130       * @param String URL value to lookup
 131       */
 132  	function deleteLink($type, $label, $url=false) {
 133          Vtiger_Link::deleteLink($this->id, $type, $label, $url);
 134      }
 135  
 136      /**
 137       * Get all the custom links related to this module.
 138       */
 139  	function getLinks() {
 140          return Vtiger_Link::getAll($this->id);
 141      }
 142  
 143  
 144      /**
 145       * Get all the custom links related to this module for exporting.
 146       */
 147  	function getLinksForExport() {
 148          return Vtiger_Link::getAllForExport($this->id);
 149      }
 150  
 151      /**
 152       * Initialize webservice setup for this module instance.
 153       */
 154  	function initWebservice() {
 155          Vtiger_Webservice::initialize($this);
 156      }
 157  
 158      /**
 159       * De-Initialize webservice setup for this module instance.
 160       */
 161  	function deinitWebservice() {
 162          Vtiger_Webservice::uninitialize($this);
 163      }
 164  
 165      /**
 166       * Get instance by id or name
 167       * @param mixed id or name of the module
 168       */
 169  	static function getInstance($value) {
 170          $instance = false;
 171          $data = Vtiger_Functions::getModuleData($value);
 172          if ($data) {
 173              $instance = new self();
 174              $instance->initialize($data);
 175          }
 176          return $instance;
 177      }
 178  
 179      /**
 180       * Get instance of the module class.
 181       * @param String Module name
 182       */
 183  	static function getClassInstance($modulename) {
 184          if($modulename == 'Calendar') $modulename = 'Activity';
 185  
 186          $instance = false;
 187          $filepath = "modules/$modulename/$modulename.php";
 188          if(Vtiger_Utils::checkFileAccessForInclusion($filepath, false)) {
 189              checkFileAccessForInclusion($filepath);
 190              include_once($filepath);
 191              if(class_exists($modulename)) {
 192                  $instance = new $modulename();
 193              }
 194          }
 195          return $instance;
 196      }
 197  
 198      /**
 199       * Fire the event for the module (if vtlib_handler is defined)
 200       */
 201  	static function fireEvent($modulename, $event_type) {
 202          $instance = self::getClassInstance((string)$modulename);
 203          if($instance) {
 204              if(method_exists($instance, 'vtlib_handler')) {
 205                  self::log("Invoking vtlib_handler for $event_type ...START");
 206                  $instance->vtlib_handler((string)$modulename, (string)$event_type);
 207                  self::log("Invoking vtlib_handler for $event_type ...DONE");
 208              }
 209          }
 210      }
 211  }
 212  ?>


Generated: Fri Nov 28 20:08:37 2014 Cross-referenced by PHPXref 0.7.1