Merge pull request #2507 from lcdservices/CRM-14204
[civicrm-core.git] / CRM / Core / OptionValue.php
index 89f1a7249429f6014ace86a228b5ae803e465ecc..5846d64d3523f13817018c25bb7203e782be46fd 100644 (file)
@@ -1,7 +1,7 @@
 <?php
 /*
  +--------------------------------------------------------------------+
- | CiviCRM version 4.3                                                |
+ | CiviCRM version 4.4                                                |
  +--------------------------------------------------------------------+
  | Copyright CiviCRM LLC (c) 2004-2013                                |
  +--------------------------------------------------------------------+
@@ -146,17 +146,22 @@ class CRM_Core_OptionValue {
           'id' => $dao->id,
           'gid' => $optionGroupID,
           'value' => $dao->value,
-        )
+        ),
+        ts('more'),
+        FALSE,
+        'optionValue.row.actions',
+        'optionValue',
+        $dao->id
       );
 
-      if (CRM_Utils_Array::value('component_id', $optionValue[$dao->id])) {
+      if (!empty($optionValue[$dao->id]['component_id'])) {
         $optionValue[$dao->id]['component_name'] = $componentNames[$optionValue[$dao->id]['component_id']];
       }
       else {
         $optionValue[$dao->id]['component_name'] = 'Contact';
       }
 
-      if (CRM_Utils_Array::value('visibility_id', $optionValue[$dao->id])) {
+      if (!empty($optionValue[$dao->id]['visibility_id'])) {
         $optionValue[$dao->id]['visibility_label'] = $visibilityLabels[$optionValue[$dao->id]['visibility_id']];
       }
     }
@@ -201,11 +206,11 @@ class CRM_Core_OptionValue {
         $oldWeight = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_OptionValue', $optionValueID, 'weight', 'id');
       }
       $fieldValues = array('option_group_id' => $optionGroupID);
-      $params['weight'] = CRM_Utils_Weight::updateOtherWeights('CRM_Core_DAO_OptionValue', $oldWeight, $params['weight'], $fieldValues);
+      $params['weight'] = CRM_Utils_Weight::updateOtherWeights('CRM_Core_DAO_OptionValue', $oldWeight, CRM_Utils_Array::value('weight', $params), $fieldValues);
     }
     $params['option_group_id'] = $optionGroupID;
 
-    if (($action & CRM_Core_Action::ADD) && !CRM_Utils_Array::value('value', $params)) {
+    if (($action & CRM_Core_Action::ADD) && empty($params['value'])) {
       $fieldValues = array('option_group_id' => $optionGroupID);
       // use the next available value
       /* CONVERT(value, DECIMAL) is used to convert varchar
@@ -221,7 +226,7 @@ class CRM_Core_OptionValue {
     }
 
     // set name to label if it's not set - but *only* for ADD action (CRM-3522)
-    if (($action & CRM_Core_Action::ADD) && !CRM_Utils_Array::value('name', $params) && $params['label']) {
+    if (($action & CRM_Core_Action::ADD) && empty($params['name']) && $params['label']) {
       $params['name'] = $params['label'];
     }
     if ($action & CRM_Core_Action::UPDATE) {
@@ -297,13 +302,15 @@ class CRM_Core_OptionValue {
         if (in_array($contactType, array(
           'Individual', 'Household', 'Organization', 'All'))) {
           $nameTitle = array(
-            'addressee' => array('name' => 'addressee',
+            'addressee' => array(
+              'name' => 'addressee',
               'title' => ts('Addressee'),
               'headerPattern' => '/^addressee$/i',
             ),
           );
           $title = array(
-            'email_greeting' => array('name' => 'email_greeting',
+            'email_greeting' => array(
+              'name' => 'email_greeting',
               'title' => ts('Email Greeting'),
               'headerPattern' => '/^email_greeting$/i',
             ),
@@ -315,35 +322,12 @@ class CRM_Core_OptionValue {
           );
           $nameTitle = array_merge($nameTitle, $title);
         }
-
-        if ($contactType == 'Individual' || $contactType == 'All') {
-          $title = array(
-            'gender' => array('name' => 'gender',
-              'title' => ts('Gender'),
-              'headerPattern' => '/^gender$/i',
-            ),
-            'individual_prefix' => array(
-              'name' => 'individual_prefix',
-              'title' => ts('Individual Prefix'),
-              'headerPattern' => '/^(prefix|title)/i',
-            ),
-            'individual_suffix' => array(
-              'name' => 'individual_suffix',
-              'title' => ts('Individual Suffix'),
-              'headerPattern' => '/^suffix$/i',
-            ),
-          );
-          $nameTitle = array_merge($nameTitle, $title);
-        }
       }
 
       if (is_array($nameTitle)) {
         foreach ($nameTitle as $name => $attribs) {
           self::$_fields[$key][$name] = $optionName;
           list($tableName, $fieldName) = explode('.', $optionName['where']);
-          // not sure of this fix, so keeping it commented for now
-          // this is from CRM-1541
-          // self::$_fields[$mode][$name]['where'] = $name . '.' . $fieldName;
           self::$_fields[$key][$name]['where'] = "{$name}.label";
           foreach ($attribs as $k => $val) {
             self::$_fields[$key][$name][$k] = $val;
@@ -364,9 +348,12 @@ class CRM_Core_OptionValue {
   static function select(&$query) {
     if (!empty($query->_params) || !empty($query->_returnProperties)) {
       $field = self::getFields();
-      foreach ($field as $name => $title) {
-        list($tableName, $fieldName) = explode('.', $title['where']);
-        if (CRM_Utils_Array::value($name, $query->_returnProperties)) {
+      foreach ($field as $name => $values) {
+        if (!empty($values['pseudoconstant'])) {
+          continue;
+        }
+        list($tableName, $fieldName) = explode('.', $values['where']);
+        if (!empty($query->_returnProperties[$name])) {
           $query->_select["{$name}_id"] = "{$name}.value as {$name}_id";
           $query->_element["{$name}_id"] = 1;
           $query->_select[$name] = "{$name}.{$fieldName} as $name";