Example #1
0
 function getCustomData($clientID, $activityDAO, &$activityTypeInfo)
 {
     list($typeValues, $options, $sql) = $this->getActivityTypeCustomSQL($activityTypeInfo['id'], '%Y-%m-%d');
     $params = array(1 => array($activityDAO->id, 'Integer'));
     $customGroups = array();
     foreach ($sql as $tableName => $sqlClause) {
         $dao = CRM_Core_DAO::executeQuery($sqlClause, $params);
         if ($dao->fetch()) {
             $customGroup = array();
             foreach ($typeValues[$tableName] as $columnName => $typeValue) {
                 $value = CRM_Core_BAO_CustomField::getDisplayValue($dao->{$columnName}, $typeValue['fieldID'], $options);
                 if (CRM_Utils_Array::value('type', $typeValue) == 'Date') {
                     $value = $dao->{$columnName};
                 }
                 if ($value) {
                     // Note: this is already taken care in getDisplayValue above, but sometimes
                     // strings like '^A^A' creates problem. So to fix this special case -
                     if (strstr($value, CRM_Core_DAO::VALUE_SEPARATOR)) {
                         $value = trim($value, CRM_Core_DAO::VALUE_SEPARATOR);
                     }
                     if (CRM_Utils_Array::value('type', $typeValue) == 'String' || CRM_Utils_Array::value('type', $typeValue) == 'Memo') {
                         $value = $this->redact($value);
                     } elseif (CRM_Utils_Array::value('type', $typeValue) == 'File') {
                         $tableName = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_EntityFile', $typeValue, 'entity_table');
                         $value = CRM_Core_BAO_File::attachmentInfo($tableName, $activityDAO->id);
                     } elseif (CRM_Utils_Array::value('type', $typeValue) == 'Link') {
                         $value = CRM_Utils_System::formatWikiURL($value);
                     }
                 }
                 //$typeValue
                 $customGroup[] = array('label' => $typeValue['label'], 'value' => $value, 'type' => $typeValue['type']);
             }
             $customGroups[$dao->groupTitle] = $customGroup;
         }
     }
     return empty($customGroups) ? NULL : $customGroups;
 }
 /** 
  * Format custom value according to data, view mode
  * @param array $values associated array of custom values
  * @param array $field associated array
  * @param boolean $dncOptionPerLine true if optionPerLine should not be consider
  *
  */
 static function formatCustomValues(&$values, &$field, $dncOptionPerLine = false)
 {
     $value = $values['data'];
     //changed isset CRM-4601
     if (CRM_Utils_System::isNull($value)) {
         return;
     }
     $htmlType = CRM_Utils_Array::value('html_type', $field);
     $dataType = CRM_Utils_Array::value('data_type', $field);
     $option_group_id = CRM_Utils_Array::value('option_group_id', $field);
     $timeFormat = CRM_Utils_Array::value('time_format', $field);
     $optionPerLine = CRM_Utils_Array::value('options_per_line', $field);
     $freezeString = "";
     $freezeStringChecked = "";
     switch ($dataType) {
         case 'Date':
             $customTimeFormat = '';
             $customFormat = null;
             if ($timeFormat == 1) {
                 $customTimeFormat = '%l:%M %P';
             } else {
                 if ($timeFormat == 2) {
                     $customTimeFormat = '%H:%M';
                 }
             }
             $supportableFormats = array('mm/dd' => "%B %E%f {$customTimeFormat}", 'dd-mm' => "%E%f %B {$customTimeFormat}", 'yy' => "%Y {$customTimeFormat}");
             if ($format = CRM_Utils_Array::value('date_format', $field)) {
                 if (array_key_exists($format, $supportableFormats)) {
                     $customFormat = $supportableFormats["{$format}"];
                 }
             }
             $retValue = CRM_Utils_Date::customFormat($value, $customFormat);
             break;
         case 'Boolean':
             if ($value == '1') {
                 $retValue = $freezeStringChecked . ts('Yes') . "\n";
             } else {
                 $retValue = $freezeStringChecked . ts('No') . "\n";
             }
             break;
         case 'Link':
             if ($value) {
                 $retValue = CRM_Utils_System::formatWikiURL($value);
             }
             break;
         case 'File':
             $retValue = $values;
             break;
         case 'ContactReference':
             if (CRM_Utils_Array::value('data', $values)) {
                 $retValue = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $values['data'], 'display_name');
             }
             break;
         case 'Memo':
             $retValue = $value;
             break;
         case 'Float':
             if ($htmlType == 'Text') {
                 $retValue = (double) $value;
                 break;
             }
         case 'Money':
             if ($htmlType == 'Text') {
                 require_once 'CRM/Utils/Money.php';
                 $retValue = CRM_Utils_Money::format($value, null, '%a');
                 break;
             }
         case 'String':
         case 'Int':
             if (in_array($htmlType, array('Text', 'TextArea'))) {
                 $retValue = $value;
                 break;
             }
         case 'StateProvince':
         case 'Country':
             //added check for Multi-Select in the below if-statement
             $customData[] = $value;
             //form custom data for multiple-valued custom data
             switch ($htmlType) {
                 case 'Multi-Select Country':
                 case 'Select Country':
                     $customData = $value;
                     if (!is_array($value)) {
                         $customData = explode(CRM_Core_DAO::VALUE_SEPARATOR, $value);
                     }
                     $query = "\n                    SELECT id as value, name as label  \n                    FROM civicrm_country";
                     $coDAO = CRM_Core_DAO::executeQuery($query);
                     break;
                 case 'Select State/Province':
                 case 'Multi-Select State/Province':
                     $customData = $value;
                     if (!is_array($value)) {
                         $customData = explode(CRM_Core_DAO::VALUE_SEPARATOR, $value);
                     }
                     $query = "\n                    SELECT id as value, name as label  \n                    FROM civicrm_state_province";
                     $coDAO = CRM_Core_DAO::executeQuery($query);
                     break;
                 case 'Select':
                     $customData = explode(CRM_Core_DAO::VALUE_SEPARATOR, $value);
                     if ($option_group_id) {
                         $query = "\n                        SELECT label, value\n                        FROM civicrm_option_value\n                        WHERE option_group_id = %1\n                        ORDER BY weight ASC, label ASC";
                         $params = array(1 => array($option_group_id, 'Integer'));
                         $coDAO = CRM_Core_DAO::executeQuery($query, $params);
                     }
                     break;
                 case 'CheckBox':
                 case 'AdvMulti-Select':
                 case 'Multi-Select':
                     $customData = explode(CRM_Core_DAO::VALUE_SEPARATOR, $value);
                 default:
                     if ($option_group_id) {
                         $query = "\n                        SELECT label, value\n                        FROM civicrm_option_value\n                        WHERE option_group_id = %1\n                        ORDER BY weight ASC, label ASC";
                         $params = array(1 => array($option_group_id, 'Integer'));
                         $coDAO = CRM_Core_DAO::executeQuery($query, $params);
                     }
             }
             $options = array();
             if (is_object($coDAO)) {
                 while ($coDAO->fetch()) {
                     $options[$coDAO->value] = $coDAO->label;
                 }
             } else {
                 CRM_Core_Error::fatal(ts('You have hit issue CRM-4716. Please post a report with as much detail as possible on the CiviCRM forums. You can truncate civicr_cache to get around this problem'));
             }
             require_once 'CRM/Utils/Hook.php';
             CRM_Utils_Hook::customFieldOptions($field['id'], $options, false);
             $retValue = null;
             foreach ($options as $optionValue => $optionLabel) {
                 //to show only values that are checked
                 if (in_array((string) $optionValue, $customData)) {
                     $checked = in_array($optionValue, $customData) ? $freezeStringChecked : $freezeString;
                     if (!$optionPerLine || $dncOptionPerLine) {
                         if ($retValue) {
                             $retValue .= ", ";
                         }
                         $retValue .= $checked . $optionLabel;
                     } else {
                         $retValue[] = $checked . $optionLabel;
                     }
                 }
             }
             break;
     }
     //special case for option per line formatting
     if ($optionPerLine > 1 && is_array($retValue)) {
         $rowCounter = 0;
         $fieldCounter = 0;
         $displayValues = array();
         $displayString = null;
         foreach ($retValue as $val) {
             if ($displayString) {
                 $displayString .= ", ";
             }
             $displayString .= $val;
             $rowCounter++;
             $fieldCounter++;
             if ($rowCounter == $optionPerLine || $fieldCounter == count($retValue)) {
                 $displayValues[] = $displayString;
                 $displayString = null;
                 $rowCounter = 0;
             }
         }
         $retValue = $displayValues;
     }
     $retValue = isset($retValue) ? $retValue : null;
     return $retValue;
 }
Example #3
0
 /**
  * Format custom values.
  *
  * @param mixed $value
  * @param array $customField
  * @param array $fieldValueMap
  *
  * @return float|string|void
  */
 public function formatCustomValues($value, $customField, $fieldValueMap)
 {
     if (CRM_Utils_System::isNull($value)) {
         return NULL;
     }
     $htmlType = $customField['html_type'];
     switch ($customField['data_type']) {
         case 'Boolean':
             if ($value == '1') {
                 $retValue = ts('Yes');
             } else {
                 $retValue = ts('No');
             }
             break;
         case 'Link':
             $retValue = CRM_Utils_System::formatWikiURL($value);
             break;
         case 'File':
             $retValue = $value;
             break;
         case 'Memo':
             $retValue = $value;
             break;
         case 'Float':
             if ($htmlType == 'Text') {
                 $retValue = (double) $value;
                 break;
             }
         case 'Money':
             if ($htmlType == 'Text') {
                 $retValue = CRM_Utils_Money::format($value, NULL, '%a');
                 break;
             }
         case 'String':
         case 'Int':
             if (in_array($htmlType, array('Text', 'TextArea'))) {
                 $retValue = $value;
                 break;
             }
         case 'StateProvince':
         case 'Country':
             switch ($htmlType) {
                 case 'Multi-Select Country':
                     $value = explode(CRM_Core_DAO::VALUE_SEPARATOR, $value);
                     $customData = array();
                     foreach ($value as $val) {
                         if ($val) {
                             $customData[] = CRM_Core_PseudoConstant::country($val, FALSE);
                         }
                     }
                     $retValue = implode(', ', $customData);
                     break;
                 case 'Select Country':
                     $retValue = CRM_Core_PseudoConstant::country($value, FALSE);
                     break;
                 case 'Select State/Province':
                     $retValue = CRM_Core_PseudoConstant::stateProvince($value, FALSE);
                     break;
                 case 'Multi-Select State/Province':
                     $value = explode(CRM_Core_DAO::VALUE_SEPARATOR, $value);
                     $customData = array();
                     foreach ($value as $val) {
                         if ($val) {
                             $customData[] = CRM_Core_PseudoConstant::stateProvince($val, FALSE);
                         }
                     }
                     $retValue = implode(', ', $customData);
                     break;
                 case 'Select':
                 case 'Radio':
                 case 'Autocomplete-Select':
                     $retValue = $fieldValueMap[$customField['option_group_id']][$value];
                     break;
                 case 'CheckBox':
                 case 'AdvMulti-Select':
                 case 'Multi-Select':
                     $value = explode(CRM_Core_DAO::VALUE_SEPARATOR, $value);
                     $customData = array();
                     foreach ($value as $val) {
                         if ($val) {
                             $customData[] = $fieldValueMap[$customField['option_group_id']][$val];
                         }
                     }
                     $retValue = implode(', ', $customData);
                     break;
                 default:
                     $retValue = $value;
             }
             break;
         default:
             $retValue = $value;
     }
     return $retValue;
 }
Example #4
0
  /**
   * We are overriding this function to apply crm-editable where appropriate
   * It would be more efficient if we knew the entity being extended (which the parent function
   * does know) but we want to avoid extending any functions we don't have to
   *
   * @param $value
   * @param $customField
   * @param $fieldValueMap
   * @param array $row
   *
   * @return float|string|void
   */
  function formatCustomValues($value, $customField, $fieldValueMap, $row = array()) {
    if (!empty($this->_customGroupExtends) && count($this->_customGroupExtends) == 1) {
      //lets only extend apply editability where only one entity extended
      // we can easily extend to contact combos
      list($entity) = $this->_customGroupExtends;
      $entity_table = strtolower('civicrm_' . $entity);
      $idKeyArray = array($this->_aliases[$entity_table] . '.id');
      if (empty($this->_groupByArray) || $this->_groupByArray == $idKeyArray) {
        $entity_field = $entity_table . '_id';
        $entityID = $row[$entity_field];
      }
    }
    if (CRM_Utils_System::isNull($value) && !in_array($customField['data_type'], array(
        'String',
        'Int'
      ))
    ) {
      // we will return unless it is potentially an editable field
      return;
    }

    $htmlType = $customField['html_type'];

    switch ($customField['data_type']) {
      case 'Boolean':
        if ($value == '1') {
          $retValue = ts('Yes');
        }
        else {
          $retValue = ts('No');
        }
        break;

      case 'Link':
        $retValue = CRM_Utils_System::formatWikiURL($value);
        break;

      case 'File':
        $retValue = $value;
        break;

      case 'Memo':
        $retValue = $value;
        break;

      case 'Float':
        if ($htmlType == 'Text') {
          $retValue = (float) $value;
          break;
        }
      case 'Money':
        if ($htmlType == 'Text') {
          $retValue = CRM_Utils_Money::format($value, NULL, '%a');
          break;
        }
      case 'String':
      case 'Int':
        if (in_array($htmlType, array(
          'Text',
          'TextArea',
          'Select',
          'Radio'
        ))
        ) {
          $retValue = $value;
          $extra = '';
          if (($htmlType == 'Select' || $htmlType == 'Radio') && !empty($entity)) {
            $options = civicrm_api($entity, 'getoptions', array(
              'version' => 3,
              'field' => 'custom_' . $customField['id']
            ));
            $options = $options['values'];
            $options['selected'] = $value;
            $extra = "data-type='select' data-options='" . json_encode($options) . "'";
            $value = $options[$value];
          }
          if (!empty($entity_field)) {
            //$
            $retValue = "<div id={$entity}-{$entityID} class='crm-entity'>
          <span class='crm-editable crmf-custom_{$customField['id']} crm-editable' data-action='create' $extra >" . $value . "</span></div>";
          }
          break;
        }
      case 'StateProvince':
      case 'Country':

        switch ($htmlType) {
          case 'Multi-Select Country':
            $value = explode(CRM_Core_DAO::VALUE_SEPARATOR, $value);
            $customData = array();
            foreach ($value as $val) {
              if ($val) {
                $customData[] = CRM_Core_PseudoConstant::country($val, FALSE);
              }
            }
            $retValue = implode(', ', $customData);
            break;

          case 'Select Country':
            $retValue = CRM_Core_PseudoConstant::country($value, FALSE);
            break;

          case 'Select State/Province':
            $retValue = CRM_Core_PseudoConstant::stateProvince($value, FALSE);
            break;

          case 'Multi-Select State/Province':
            $value = explode(CRM_Core_DAO::VALUE_SEPARATOR, $value);
            $customData = array();
            foreach ($value as $val) {
              if ($val) {
                $customData[] = CRM_Core_PseudoConstant::stateProvince($val, FALSE);
              }
            }
            $retValue = implode(', ', $customData);
            break;

          case 'Select':
          case 'Radio':
          case 'Autocomplete-Select':
            $retValue = $fieldValueMap[$customField['option_group_id']][$value];
            break;

          case 'CheckBox':
          case 'AdvMulti-Select':
          case 'Multi-Select':
            $value = explode(CRM_Core_DAO::VALUE_SEPARATOR, $value);
            $customData = array();
            foreach ($value as $val) {
              if ($val) {
                $customData[] = $fieldValueMap[$customField['option_group_id']][$val];
              }
            }
            $retValue = implode(', ', $customData);
            break;

          default:
            $retValue = $value;
        }
        break;

      default:
        $retValue = $value;
    }

    return $retValue;
  }
Example #5
0
 /**
  * Format custom value according to data, view mode
  *
  * @param array $values associated array of custom values
  * @param array $field associated array
  * @param boolean $dncOptionPerLine true if optionPerLine should not be consider
  *
  */
 static function formatCustomValues(&$values, &$field, $dncOptionPerLine = FALSE)
 {
     $value = $values['data'];
     //changed isset CRM-4601
     if (CRM_Utils_System::isNull($value)) {
         return;
     }
     $htmlType = CRM_Utils_Array::value('html_type', $field);
     $dataType = CRM_Utils_Array::value('data_type', $field);
     $option_group_id = CRM_Utils_Array::value('option_group_id', $field);
     $timeFormat = CRM_Utils_Array::value('time_format', $field);
     $optionPerLine = CRM_Utils_Array::value('options_per_line', $field);
     $freezeString = "";
     $freezeStringChecked = "";
     switch ($dataType) {
         case 'Date':
             $customTimeFormat = '';
             $customFormat = NULL;
             switch ($timeFormat) {
                 case 1:
                     $customTimeFormat = '%l:%M %P';
                     break;
                 case 2:
                     $customTimeFormat = '%H:%M';
                     break;
                 default:
                     // if time is not selected remove time from value
                     $value = substr($value, 0, 10);
             }
             $supportableFormats = array('mm/dd' => "%B %E%f {$customTimeFormat}", 'dd-mm' => "%E%f %B {$customTimeFormat}", 'yy' => "%Y {$customTimeFormat}", 'M yy' => "%b %Y {$customTimeFormat}", 'yy-mm' => "%Y-%m {$customTimeFormat}");
             if ($format = CRM_Utils_Array::value('date_format', $field)) {
                 if (array_key_exists($format, $supportableFormats)) {
                     $customFormat = $supportableFormats["{$format}"];
                 }
             }
             $retValue = CRM_Utils_Date::customFormat($value, $customFormat);
             break;
         case 'Boolean':
             if ($value == '1') {
                 $retValue = $freezeStringChecked . ts('Yes') . "\n";
             } else {
                 $retValue = $freezeStringChecked . ts('No') . "\n";
             }
             break;
         case 'Link':
             if ($value) {
                 $retValue = CRM_Utils_System::formatWikiURL($value);
             }
             break;
         case 'File':
             $retValue = $values;
             break;
         case 'ContactReference':
             if (CRM_Utils_Array::value('data', $values)) {
                 $retValue = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $values['data'], 'display_name');
             }
             break;
         case 'Memo':
             $retValue = $value;
             break;
         case 'Float':
             if ($htmlType == 'Text') {
                 $retValue = (double) $value;
                 break;
             }
         case 'Money':
             if ($htmlType == 'Text') {
                 $retValue = CRM_Utils_Money::format($value, NULL, '%a');
                 break;
             }
         case 'String':
         case 'Int':
             if (in_array($htmlType, array('Text', 'TextArea'))) {
                 $retValue = $value;
                 break;
             }
             // note that if its not text / textarea, the code falls thru and executes
             // the below case also
         // note that if its not text / textarea, the code falls thru and executes
         // the below case also
         case 'StateProvince':
         case 'Country':
             $options = array();
             $coDAO = NULL;
             //added check for Multi-Select in the below if-statement
             $customData[] = $value;
             //form custom data for multiple-valued custom data
             switch ($htmlType) {
                 case 'Multi-Select Country':
                 case 'Select Country':
                     $customData = $value;
                     if (!is_array($value)) {
                         $customData = explode(CRM_Core_DAO::VALUE_SEPARATOR, $value);
                     }
                     $query = "\n                    SELECT id as value, name as label\n                    FROM civicrm_country";
                     $coDAO = CRM_Core_DAO::executeQuery($query);
                     break;
                 case 'Select State/Province':
                 case 'Multi-Select State/Province':
                     $customData = $value;
                     if (!is_array($value)) {
                         $customData = explode(CRM_Core_DAO::VALUE_SEPARATOR, $value);
                     }
                     $query = "\n                    SELECT id as value, name as label\n                    FROM civicrm_state_province";
                     $coDAO = CRM_Core_DAO::executeQuery($query);
                     break;
                 case 'Select':
                     $customData = explode(CRM_Core_DAO::VALUE_SEPARATOR, $value);
                     if ($option_group_id) {
                         $options = CRM_Core_BAO_OptionValue::getOptionValuesAssocArray($option_group_id);
                     }
                     break;
                 case 'CheckBox':
                 case 'AdvMulti-Select':
                 case 'Multi-Select':
                     $customData = explode(CRM_Core_DAO::VALUE_SEPARATOR, $value);
                 default:
                     if ($option_group_id) {
                         $options = CRM_Core_BAO_OptionValue::getOptionValuesAssocArray($option_group_id);
                     }
             }
             if (is_object($coDAO)) {
                 while ($coDAO->fetch()) {
                     if ($dataType == 'Country') {
                         // NB: using ts() on a variable here is OK, since the value is pre-determined, not variable
                         // and already extracted to .pot files.
                         $options[$coDAO->value] = ts($coDAO->label, array('context' => 'country'));
                     } elseif ($dataType == 'StateProvince') {
                         $options[$coDAO->value] = ts($coDAO->label, array('context' => 'province'));
                     } else {
                         $options[$coDAO->value] = $coDAO->label;
                     }
                 }
             }
             CRM_Utils_Hook::customFieldOptions($field['id'], $options, FALSE);
             $retValue = NULL;
             foreach ($options as $optionValue => $optionLabel) {
                 if ($dataType == 'Money') {
                     foreach ($customData as $k => $v) {
                         $customData[] = CRM_Utils_Money::format($v, NULL, '%a');
                     }
                 }
                 //to show only values that are checked
                 if (in_array((string) $optionValue, $customData)) {
                     $checked = in_array($optionValue, $customData) ? $freezeStringChecked : $freezeString;
                     if (!$optionPerLine || $dncOptionPerLine) {
                         if ($retValue) {
                             $retValue .= ", ";
                         }
                         $retValue .= $checked . $optionLabel;
                     } else {
                         $retValue[] = $checked . $optionLabel;
                     }
                 }
             }
             break;
     }
     //special case for option per line formatting
     if ($optionPerLine > 1 && is_array($retValue)) {
         $rowCounter = 0;
         $fieldCounter = 0;
         $displayValues = array();
         $displayString = '';
         foreach ($retValue as $val) {
             if ($displayString) {
                 $displayString .= ", ";
             }
             $displayString .= $val;
             $rowCounter++;
             $fieldCounter++;
             if ($rowCounter == $optionPerLine || $fieldCounter == count($retValue)) {
                 $displayValues[] = $displayString;
                 $displayString = '';
                 $rowCounter = 0;
             }
         }
         $retValue = $displayValues;
     }
     $retValue = isset($retValue) ? $retValue : NULL;
     return $retValue;
 }