INFRA-132 - CRM/Case - Misc
[civicrm-core.git] / CRM / Extension / Mapper.php
index c70f218dad0f299ef5009fabed745b2d239d808f..fdf7c3c2ae7ad936ef2123c09202842d7a06dc87 100755 (executable)
@@ -1,7 +1,7 @@
 <?php
 /*
  +--------------------------------------------------------------------+
- | CiviCRM version 4.5                                                |
+ | CiviCRM version 4.6                                                |
  +--------------------------------------------------------------------+
  | Copyright CiviCRM LLC (c) 2004-2014                                |
  +--------------------------------------------------------------------+
@@ -51,7 +51,7 @@ class CRM_Extension_Mapper {
   /**
    * An URL for public extensions repository
    */
-  //CONST DEFAULT_EXTENSIONS_REPOSITORY = 'http://civicrm.org/extdir/ver={ver}|cms={uf}';
+  //const DEFAULT_EXTENSIONS_REPOSITORY = 'http://civicrm.org/extdir/ver={ver}|cms={uf}';
 
   /**
    * Extension info file name
@@ -84,6 +84,13 @@ class CRM_Extension_Mapper {
 
   protected $civicrmUrl;
 
+  /**
+   * @param CRM_Extension_Container_Interface $container
+   * @param CRM_Utils_Cache_Interface $cache
+   * @param null $cacheKey
+   * @param null $civicrmPath
+   * @param null $civicrmUrl
+   */
   public function __construct(CRM_Extension_Container_Interface $container, CRM_Utils_Cache_Interface $cache = NULL, $cacheKey = NULL, $civicrmPath = NULL, $civicrmUrl = NULL) {
     $this->container = $container;
     $this->cache = $cache;
@@ -95,19 +102,19 @@ class CRM_Extension_Mapper {
       $this->civicrmUrl = rtrim($config->resourceBase, '/');
     }
     if ($civicrmPath) {
-      $this->civicrmPath = rtrim($civicrmPath,'/');
+      $this->civicrmPath = rtrim($civicrmPath, '/');
     } else {
       global $civicrm_root;
-      $this->civicrmPath = rtrim($civicrm_root,'/');
+      $this->civicrmPath = rtrim($civicrm_root, '/');
     }
   }
 
   /**
    * Given the class, provides extension's key.
    *
-   * @access public
    *
-   * @param string $clazz extension class name
+   * @param string $clazz
+   *   Extension class name.
    *
    * @return string name of extension key
    */
@@ -118,12 +125,9 @@ class CRM_Extension_Mapper {
   /**
    * Given the class, provides extension path.
    *
-   * @access public
    *
    * @param $clazz
    *
-   * @internal param string $key extension key
-   *
    * @return string full path the extension .php file
    */
   public function classToPath($clazz) {
@@ -135,9 +139,9 @@ class CRM_Extension_Mapper {
   /**
    * Given the string, returns true or false if it's an extension key.
    *
-   * @access public
    *
-   * @param string $key a string which might be an extension key
+   * @param string $key
+   *   A string which might be an extension key.
    *
    * @return boolean true if given string is an extension name
    */
@@ -149,9 +153,9 @@ class CRM_Extension_Mapper {
   /**
    * Given the string, returns true or false if it's an extension class name.
    *
-   * @access public
    *
-   * @param string $clazz a string which might be an extension class name
+   * @param string $clazz
+   *   A string which might be an extension class name.
    *
    * @return boolean true if given string is an extension class name
    */
@@ -164,12 +168,13 @@ class CRM_Extension_Mapper {
   }
 
   /**
-   * @param string $key extension fully-qualified-name
+   * @param string $key
+   *   Extension fully-qualified-name.
    * @param bool $fresh
    *
    * @throws CRM_Extension_Exception
    * @throws Exception
-   * @return object CRM_Extension_Info
+   * @return CRM_Extension_Info
    */
   public function keyToInfo($key, $fresh = FALSE) {
     if ($fresh || !array_key_exists($key, $this->infos)) {
@@ -189,9 +194,9 @@ class CRM_Extension_Mapper {
   /**
    * Given the key, provides extension's class name.
    *
-   * @access public
    *
-   * @param string $key extension key
+   * @param string $key
+   *   Extension key.
    *
    * @return string name of extension's main class
    */
@@ -203,9 +208,9 @@ class CRM_Extension_Mapper {
    * Given the key, provides the path to file containing
    * extension's main class.
    *
-   * @access public
    *
-   * @param string $key extension key
+   * @param string $key
+   *   Extension key.
    *
    * @return string path to file containing extension's main class
    */
@@ -218,8 +223,8 @@ class CRM_Extension_Mapper {
    * Given the key, provides the path to file containing
    * extension's main class.
    *
-   * @access public
-   * @param string $key extension key
+   * @param string $key
+   *   Extension key.
    * @return string local path of the extension source tree
    */
   public function keyToBasePath($key) {
@@ -233,9 +238,9 @@ class CRM_Extension_Mapper {
    * Given the key, provides the path to file containing
    * extension's main class.
    *
-   * @access public
    *
-   * @param string $key extension key
+   * @param string $key
+   *   Extension key.
    *
    * @return string url for resources in this extension
    */
@@ -256,7 +261,8 @@ class CRM_Extension_Mapper {
   /**
    * Fetch the list of active extensions of type 'module'
    *
-   * @param $fresh bool whether to forcibly reload extensions list from canonical store
+   * @param $fresh
+   *   Bool whether to forcibly reload extensions list from canonical store.
    * @return array - array(array('prefix' => $, 'file' => $))
    */
   public function getActiveModuleFiles($fresh = FALSE) {
@@ -305,6 +311,29 @@ class CRM_Extension_Mapper {
     return $moduleExtensions;
   }
 
+  /**
+   * Get a list of base URLs for all active modules
+   *
+   * @return array (string $extKey => string $baseUrl)
+   */
+  public function getActiveModuleUrls() {
+    // TODO optimization/caching
+    $urls = array();
+    $urls['civicrm'] = $this->keyToUrl('civicrm');
+    foreach ($this->getModules() as $module) {
+      /** @var $module CRM_Core_Module */
+      if ($module->is_active) {
+        $urls[$module->name] = $this->keyToUrl($module->name);
+      }
+    }
+    return $urls;
+  }
+
+  /**
+   * @param string $name
+   *
+   * @return bool
+   */
   public function isActiveModule($name) {
     $activeModules = $this->getActiveModuleFiles();
     foreach ($activeModules as $activeModule) {
@@ -334,9 +363,9 @@ class CRM_Extension_Mapper {
   /**
    * Given the class, provides the template path.
    *
-   * @access public
    *
-   * @param string $clazz extension class name
+   * @param string $clazz
+   *   Extension class name.
    *
    * @return string path to extension's templates directory
    */
@@ -355,9 +384,9 @@ class CRM_Extension_Mapper {
    * Given te class, provides the template name.
    * @todo consider multiple templates, support for one template for now
    *
-   * @access public
    *
-   * @param string $clazz extension class name
+   * @param string $clazz
+   *   Extension class name.
    *
    * @return string extension's template name
    */