INFRA-132 - CRM/Core - Misc
[civicrm-core.git] / CRM / Core / Action.php
index 2cb78ffd6bb458c9b51b28d480ff8a944093ad21..068744b2a83fa1bd826a4bd2d783258ccd733895 100644 (file)
@@ -1,9 +1,9 @@
 <?php
 /*
  +--------------------------------------------------------------------+
- | CiviCRM version 4.4                                                |
+ | CiviCRM version 4.6                                                |
  +--------------------------------------------------------------------+
- | Copyright CiviCRM LLC (c) 2004-2013                                |
+ | Copyright CiviCRM LLC (c) 2004-2014                                |
  +--------------------------------------------------------------------+
  | This file is a part of CiviCRM.                                    |
  |                                                                    |
@@ -31,7 +31,7 @@
  * and similar across all objects (thus providing both reuse and standards)
  *
  * @package CRM
- * @copyright CiviCRM LLC (c) 2004-2013
+ * @copyright CiviCRM LLC (c) 2004-2014
  * $Id$
  *
  */
@@ -41,11 +41,10 @@ class CRM_Core_Action {
    * Different possible actions are defined here. Keep in sync with the
    * constant from CRM_Core_Form for various modes.
    *
-   * @var const
+   * @var integer const
    *
-   * @access public
    */
-  CONST
+  const
     NONE = 0,
     ADD = 1,
     UPDATE = 2,
@@ -65,20 +64,19 @@ class CRM_Core_Action {
     RENEW = 32768,
     DETACH = 65536,
     REVERT = 131072,
-    CLOSE        =  262144,
-    REOPEN       =  524288,
+    CLOSE        = 262144,
+    REOPEN       = 524288,
     MAX_ACTION   = 1048575;
 
   //make sure MAX_ACTION = 2^n - 1 ( n = total number of actions )
 
   /**
-   * map the action names to the relevant constant. We perform
+   * Map the action names to the relevant constant. We perform
    * bit manipulation operations so we can perform multiple
    * actions on the same object if needed
    *
-   * @var array  _names  tupe of variable name to action constant
+   * @var array $_names  type of variable name to action constant
    *
-   * @access private
    * @static
    *
    */
@@ -103,7 +101,7 @@ class CRM_Core_Action {
   );
 
   /**
-   * the flipped version of the names array, initialized when used
+   * The flipped version of the names array, initialized when used
    *
    * @var array
    * @static
@@ -111,17 +109,15 @@ class CRM_Core_Action {
   static $_description;
 
   /**
+   * Called by the request object to translate a string into a mask
    *
-   * called by the request object to translate a string into a mask
-   *
-   * @param string $action the action to be resolved
+   * @param string $str
+   *   The action to be resolved.
    *
    * @return int the action mask corresponding to the input string
-   * @access public
    * @static
-   *
    */
-  static function resolve($str) {
+  public static function resolve($str) {
     $action = 0;
     if ($str) {
       $items = explode('|', $str);
@@ -134,14 +130,14 @@ class CRM_Core_Action {
    * Given a string or an array of strings, determine the bitmask
    * for this set of actions
    *
-   * @param mixed either a single string or an array of strings
+   * @param mixed $item
+   *   Either a single string or an array of strings.
    *
    * @return int the action mask corresponding to the input args
-   * @access public
    * @static
    *
    */
-  static function map($item) {
+  public static function map($item) {
     $mask = 0;
 
     if (is_array($item)) {
@@ -158,14 +154,14 @@ class CRM_Core_Action {
   /**
    * Given a string determine the bitmask for this specific string
    *
-   * @param string the input action to process
+   * @param string $item
+   *   The input action to process.
    *
    * @return int the action mask corresponding to the input string
-   * @access public
    * @static
    *
    */
-  static function mapItem($item) {
+  public static function mapItem($item) {
     $mask = CRM_Utils_Array::value(trim($item), self::$_names);
     return $mask ? $mask : 0;
   }
@@ -174,14 +170,14 @@ class CRM_Core_Action {
    *
    * Given an action mask, find the corresponding description
    *
-   * @param int the action mask
+   * @param int $mask
+   *   The action mask.
    *
    * @return string the corresponding action description
-   * @access public
    * @static
    *
    */
-  static function description($mask) {
+  public static function description($mask) {
     if (!isset($_description)) {
       self::$_description = array_flip(self::$_names);
     }
@@ -190,20 +186,29 @@ class CRM_Core_Action {
   }
 
   /**
-   * given a set of links and a mask, return the html action string for
+   * Given a set of links and a mask, return the html action string for
    * the links associated with the mask
    *
-   * @param array $links  the set of link items
-   * @param int   $mask   the mask to be used. a null mask means all items
-   * @param array $values the array of values for parameter substitution in the link items
-   * @param string  $extraULName            enclosed extra links in this UL.
-   * @param boolean $enclosedAllInSingleUL  force to enclosed all links in single UL.
+   * @param array $links
+   *   The set of link items.
+   * @param int $mask
+   *   The mask to be used. a null mask means all items.
+   * @param array $values
+   *   The array of values for parameter substitution in the link items.
+   * @param string $extraULName
+   *   Enclosed extra links in this UL.
+   * @param bool $enclosedAllInSingleUL
+   *   Force to enclosed all links in single UL.
+   *
+   * @param null $op
+   * @param null $objectName
+   * @param int $objectId
    *
    * @return string       the html string
-   * @access public
    * @static
    */
-  static function formLink($links,
+  static function formLink(
+    $links,
     $mask,
     $values,
     $extraULName = 'more',
@@ -231,74 +236,54 @@ class CRM_Core_Action {
 
     $url = array();
 
-    $firstLink = TRUE;
-    foreach ($seqLinks as $link) {
+    foreach ($seqLinks as $i => $link) {
       if (!$mask || !array_key_exists('bit', $link) || ($mask & $link['bit'])) {
         $extra = isset($link['extra']) ? self::replace($link['extra'], $values) : NULL;
 
         $frontend = (isset($link['fe'])) ? TRUE : FALSE;
 
-        $urlPath = NULL;
-        if (CRM_Utils_Array::value('qs', $link) &&
-          !CRM_Utils_System::isNull($link['qs'])
-        ) {
+        if (isset($link['qs']) && !CRM_Utils_System::isNull($link['qs'])) {
           $urlPath = CRM_Utils_System::url(self::replace($link['url'], $values),
             self::replace($link['qs'], $values), TRUE, NULL, TRUE, $frontend
           );
         }
         else {
-          $urlPath = CRM_Utils_Array::value('url', $link);
+          $urlPath = CRM_Utils_Array::value('url', $link, '#');
         }
 
-        $classes = 'action-item';
-        if ($firstLink) {
-          $firstLink = FALSE;
-          $classes .= " action-item-first";
-        }
+        $classes = 'action-item crm-hover-button';
         if (isset($link['ref'])) {
           $classes .= ' ' . strtolower($link['ref']);
         }
 
         //get the user specified classes in.
         if (isset($link['class'])) {
-          $className = $link['class'];
-          if (is_array($className)) {
-            $className = implode(' ', $className);
-          }
+          $className = is_array($link['class']) ? implode(' ', $link['class']) : $link['class'];
           $classes .= ' ' . strtolower($className);
         }
 
-        $linkClasses = 'class = "' . $classes . '"';
-
-        if ($urlPath) {
-          if ($frontend) {
-            $extra .= "target=_blank";
-          }
-          $url[] = sprintf('<a href="%s" %s title="%s"' . $extra . '>%s</a>',
-            $urlPath,
-            $linkClasses,
-            CRM_Utils_Array::value('title', $link),
-            $link['name']
-          );
+        if ($urlPath !== '#' && $frontend) {
+          $extra .= ' target="_blank"';
         }
-        else {
-          $url[] = sprintf('<a title="%s"  %s ' . $extra . '>%s</a>',
-            CRM_Utils_Array::value('title', $link),
-            $linkClasses,
-            $link['name']
-          );
+        // Hack to make delete dialogs smaller
+        if (strpos($urlPath, '/delete') || strpos($urlPath, 'action=delete')) {
+          $classes .= " small-popup";
         }
+        $url[] = sprintf('<a href="%s" class="%s" %s' . $extra . '>%s</a>',
+          $urlPath,
+          $classes,
+          !empty($link['title']) ? "title='{$link['title']}' " : '',
+          $link['name']
+        );
       }
     }
 
-
-    $result = '';
     $mainLinks = $url;
     if ($enclosedAllInSingleUL) {
       $allLinks = '';
       CRM_Utils_String::append($allLinks, '</li><li>', $mainLinks);
       $allLinks = "{$extraULName}<ul class='panel'><li>{$allLinks}</li></ul>";
-      $result = "<span class='btn-slide'>{$allLinks}</span>";
+      $result = "<span class='btn-slide crm-hover-button'>{$allLinks}</span>";
     }
     else {
       $extra = '';
@@ -311,7 +296,7 @@ class CRM_Core_Action {
       $resultLinks = '';
       CRM_Utils_String::append($resultLinks, '', $mainLinks);
       if ($extra) {
-        $result = "<span>{$resultLinks}</span><span class='btn-slide'>{$extra}</span>";
+        $result = "<span>{$resultLinks}</span><span class='btn-slide crm-hover-button'>{$extra}</span>";
       }
       else {
         $result = "<span>{$resultLinks}</span>";
@@ -322,17 +307,18 @@ class CRM_Core_Action {
   }
 
   /**
-   * given a string and an array of values, substitute the real values
+   * Given a string and an array of values, substitute the real values
    * in the placeholder in the str in the CiviCRM format
    *
-   * @param string $str    the string to be replaced
-   * @param array  $values the array of values for parameter substitution in the str
+   * @param string $str
+   *   The string to be replaced.
+   * @param array $values
+   *   The array of values for parameter substitution in the str.
    *
    * @return string        the substituted string
-   * @access public
    * @static
    */
-  static function &replace(&$str, &$values) {
+  public static function &replace(&$str, &$values) {
     foreach ($values as $n => $v) {
       $str = str_replace("%%$n%%", $v, $str);
     }
@@ -340,15 +326,14 @@ class CRM_Core_Action {
   }
 
   /**
-   * get the mask for a permission (view, edit or null)
+   * Get the mask for a permission (view, edit or null)
    *
    * @param string the permission
    *
    * @return int   the mask for the above permission
    * @static
-   * @access public
    */
-  static function mask($permissions) {
+  public static function mask($permissions) {
     $mask = NULL;
     if (!is_array($permissions) || CRM_Utils_System::isNull($permissions)) {
       return $mask;
@@ -369,4 +354,3 @@ class CRM_Core_Action {
     return $mask;
   }
 }
-