Merge pull request #5326 from jmcclelland/smart-groups-data
authorcolemanw <coleman@civicrm.org>
Fri, 13 Mar 2015 18:23:06 +0000 (14:23 -0400)
committercolemanw <coleman@civicrm.org>
Fri, 13 Mar 2015 18:23:06 +0000 (14:23 -0400)
Smart groups data

CRM/Contact/BAO/ContactType.php
CRM/Core/BAO/CustomField.php
CRM/Core/Form.php
CRM/Event/Form/EventFees.php
CRM/Mailing/BAO/Component.php
CRM/Mailing/Form/Component.php
api/v3/MailingComponent.php
api/v3/MessageTemplate.php
templates/CRM/Event/Form/Participant.tpl

index 77657dd27cc10d5ff70ebe3c4db3357008ef5c76..60f28d8d8533a96c64126e0a87241d4cd9560f40 100644 (file)
@@ -391,6 +391,7 @@ WHERE  type.name IS NOT NULL
 
     $argString = $all ? 'CRM_CT_GSE_1' : 'CRM_CT_GSE_0';
     $argString .= $isSeparator ? '_1' : '_0';
+    $argString .= $separator;
     if (!array_key_exists($argString, $_cache)) {
       $cache = CRM_Utils_Cache::singleton();
       $_cache[$argString] = $cache->get($argString);
index 5ea64fb31c694b7509484656e0e4360b3e4d41fb..883db2ae36ed2570047c15d31022c860c275e088 100644 (file)
@@ -1286,7 +1286,15 @@ class CRM_Core_BAO_CustomField extends CRM_Core_DAO_CustomField {
         break;
 
       case 'File':
-        if ($value) {
+        // In the context of displaying a profile, show file/image
+        if ($contactID && $value) {
+          $url = self::getFileURL($contactID, $fieldID, $value);
+          if ($url) {
+            $display = $url['file_url'];
+          }
+        }
+        // In other contexts show a paperclip icon
+        elseif ($value) {
           $icons = CRM_Core_BAO_File::paperIconAttachment('*', $value);
           $display = $icons[$value];
         }
index fd0ad0d96ab523732c2d9fd7b50f1342fd3bb713..47303ba3b41849283824c71d1dc7aa02bf0fcf57 100644 (file)
@@ -1768,42 +1768,45 @@ class CRM_Core_Form extends HTML_QuickForm_Page {
    */
   private function preProcessChainSelectFields() {
     foreach ($this->_chainSelectFields as $control => $target) {
-      $targetField = $this->getElement($target);
-      $targetType = $targetField->getAttribute('data-callback') == 'civicrm/ajax/jqCounty' ? 'county' : 'stateProvince';
-      $options = array();
-      // If the control field is on the form, setup chain-select and dynamically populate options
-      if ($this->elementExists($control)) {
-        $controlField = $this->getElement($control);
-        $controlType = $targetType == 'county' ? 'stateProvince' : 'country';
-
-        $targetField->setAttribute('class', $targetField->getAttribute('class') . ' crm-chain-select-target');
-
-        $css = (string) $controlField->getAttribute('class');
-        $controlField->updateAttributes(array(
-          'class' => ($css ? "$css " : 'crm-select2 ') . 'crm-chain-select-control',
-          'data-target' => $target,
-        ));
-        $controlValue = $controlField->getValue();
-        if ($controlValue) {
-          $options = CRM_Core_BAO_Location::getChainSelectValues($controlValue, $controlType, TRUE);
-          if (!$options) {
-            $targetField->setAttribute('placeholder', $targetField->getAttribute('data-none-prompt'));
+      // The 'target' might get missing if extensions do removeElement() in a form hook.
+      if ($this->elementExists($target)) {
+        $targetField = $this->getElement($target);
+        $targetType = $targetField->getAttribute('data-callback') == 'civicrm/ajax/jqCounty' ? 'county' : 'stateProvince';
+        $options = array();
+        // If the control field is on the form, setup chain-select and dynamically populate options
+        if ($this->elementExists($control)) {
+          $controlField = $this->getElement($control);
+          $controlType = $targetType == 'county' ? 'stateProvince' : 'country';
+
+          $targetField->setAttribute('class', $targetField->getAttribute('class') . ' crm-chain-select-target');
+
+          $css = (string) $controlField->getAttribute('class');
+          $controlField->updateAttributes(array(
+            'class' => ($css ? "$css " : 'crm-select2 ') . 'crm-chain-select-control',
+            'data-target' => $target,
+          ));
+          $controlValue = $controlField->getValue();
+          if ($controlValue) {
+            $options = CRM_Core_BAO_Location::getChainSelectValues($controlValue, $controlType, TRUE);
+            if (!$options) {
+              $targetField->setAttribute('placeholder', $targetField->getAttribute('data-none-prompt'));
+            }
+          } else {
+            $targetField->setAttribute('placeholder', $targetField->getAttribute('data-empty-prompt'));
+            $targetField->setAttribute('disabled', 'disabled');
           }
-        } else {
-          $targetField->setAttribute('placeholder', $targetField->getAttribute('data-empty-prompt'));
-          $targetField->setAttribute('disabled', 'disabled');
         }
+        // Control field not present - fall back to loading default options
+        else {
+          $options = CRM_Core_PseudoConstant::$targetType();
+        }
+        if (!$targetField->getAttribute('multiple')) {
+          $options = array('' => $targetField->getAttribute('placeholder')) + $options;
+          $targetField->removeAttribute('placeholder');
+        }
+        $targetField->_options = array();
+        $targetField->loadArray($options);
       }
-      // Control field not present - fall back to loading default options
-      else {
-        $options = CRM_Core_PseudoConstant::$targetType();
-      }
-      if (!$targetField->getAttribute('multiple')) {
-        $options = array('' => $targetField->getAttribute('placeholder')) + $options;
-        $targetField->removeAttribute('placeholder');
-      }
-      $targetField->_options = array();
-      $targetField->loadArray($options);
     }
   }
 
@@ -1812,7 +1815,7 @@ class CRM_Core_Form extends HTML_QuickForm_Page {
    */
   private function validateChainSelectFields() {
     foreach ($this->_chainSelectFields as $control => $target) {
-      if ($this->elementExists($control)) {
+      if ($this->elementExists($control) && $this->elementExists($target)) {
         $controlValue = (array)$this->getElementValue($control);
         $targetField = $this->getElement($target);
         $controlType = $targetField->getAttribute('data-callback') == 'civicrm/ajax/jqCounty' ? 'stateProvince' : 'country';
index 898bbf90405a8a7d589dca2a082b7787153741ee..e102ec4831d28a440aa4957fff49bd89e928115e 100644 (file)
@@ -393,7 +393,7 @@ SELECT  id, html_type
           array(
             0 => ts('- select -')) + $discounts,
           FALSE,
-          array('onchange' => "buildFeeBlock( {$form->_eventId}, this.value );")
+          array('class' => "crm-select2")
         );
 
         if ($form->_online) {
index 55dd8b35fb3d99492322ec1b1f7d8c056b2ffff6..3da5da0dbcaeb0dc2a9431a4f498dfce99bd8d81 100644 (file)
@@ -92,14 +92,31 @@ class CRM_Mailing_BAO_Component extends CRM_Mailing_DAO_Component {
   static function add(&$params, $ids = array()) {
     $id = CRM_Utils_Array::value('id', $params, CRM_Utils_Array::value('id', $ids));
     $component = new CRM_Mailing_DAO_Component();
-    $component->id = $id;
+    if ($id) {
+      $component->id = $id;
+      $component->find(TRUE);
+    }
+
     $component->copyValues($params);
     if (empty($id) && empty($params['body_text'])) {
       $component->body_text = CRM_Utils_String::htmlToText(CRM_Utils_Array::value('body_html', $params));
     }
 
-    if ($component->is_default && !empty($id)) {
-      CRM_Core_DAO::executeQuery("UPDATE civicrm_mailing_component SET is_default = 0 WHERE component_type ='{$component->component_type}' AND id <> $id");
+    if ($component->is_default) {
+      if (!empty($id)) {
+        $sql = 'UPDATE civicrm_mailing_component SET is_default = 0 WHERE component_type = %1 AND id <> %2';
+        $sqlParams = array(
+          1 => array($component->component_type, 'String'),
+          2 => array($id, 'Positive'),
+        );
+      }
+      else {
+        $sql = 'UPDATE civicrm_mailing_component SET is_default = 0 WHERE component_type = %1';
+        $sqlParams = array(
+          1 => array($component->component_type, 'String'),
+        );
+      }
+      CRM_Core_DAO::executeQuery($sql, $sqlParams);
     }
 
     $component->save();
index f6ca5a05ccfddcfa56eb5ca21ab1baa15012bfef..b1734586cffb7d47312bbe4c02b90a04c5515ff1 100644 (file)
@@ -86,8 +86,8 @@ class CRM_Mailing_Form_Component extends CRM_Core_Form {
       CRM_Core_DAO::getAttribute('CRM_Mailing_DAO_Component', 'body_html')
     );
 
-    $this->add('checkbox', 'is_default', ts('Default?'));
-    $this->add('checkbox', 'is_active', ts('Enabled?'));
+    $this->addYesNo('is_default', ts('Default?'));
+    $this->addYesNo('is_active', ts('Enabled?'));
 
     $this->addFormRule(array('CRM_Mailing_Form_Component', 'dataRule'));
 
@@ -121,7 +121,9 @@ class CRM_Mailing_Form_Component extends CRM_Core_Form {
       $baoName = $this->_BAOName;
       $baoName::retrieve($params, $defaults);
     }
-    $defaults['is_active'] = 1;
+    else {
+      $defaults['is_active'] = 1;
+    }
 
     return $defaults;
   }
index 811fdefb85df4162105f3f294faf8b967db49a8f..6284cdbc0cb874a73c502e011299778bb76c3238 100644 (file)
@@ -51,6 +51,19 @@ function civicrm_api3_mailing_component_create($params) {
   return _civicrm_api3_basic_create(_civicrm_api3_get_BAO(__FUNCTION__), $params);
 }
 
+
+/**
+ * Adjust Metadata for Create action.
+ *
+ * The metadata is used for setting defaults, documentation & validation.
+ *
+ * @param array $spec
+ *   Array of parameters determined by getfields.
+ */
+function _civicrm_api3_mailing_component_create_spec(&$spec) {
+  $spec['is_active']['api.default'] = 1;
+}
+
 /**
  * Get a mailing_component
  *
index 6dd039d72c96df783698751eb7f64cf5de8f3e0e..07b77ba2520fcae4af7da27065308cea0d3b8ce5 100644 (file)
@@ -93,7 +93,27 @@ function civicrm_api3_message_template_get($params) {
  * Sends a template.
  */
 function civicrm_api3_message_template_send($params) {
-  CRM_Core_BAO_MessageTemplates::sendTemplate($params);
+  // Change external param names to internal ones
+  $fieldSpec = array();
+  _civicrm_api3_message_template_send_spec($fieldSpec);
+
+  foreach ($fieldSpec as $field => $spec) {
+    if (isset($spec['api.aliases']) && array_key_exists($field, $params)) {
+      $params[CRM_Utils_Array::first($spec['api.aliases'])] = $params[$field];
+      unset($params[$field]);
+    }
+  }
+  if (empty($params['messageTemplateID'])) {
+    if (empty($params['groupName']) || empty($params['valueName'])) {
+      // Can't use civicrm_api3_verify_mandatory for this because it would give the wrong field names
+      throw new API_Exception(
+        "Mandatory key(s) missing from params array: requires id or option_group_name + option_value_name",
+        "mandatory_missing",
+        array("fields" => array('id', 'option_group_name', 'option_value_name'))
+      );
+    }
+  }
+  CRM_Core_BAO_MessageTemplate::sendTemplate($params);
 }
 
 /**
@@ -105,12 +125,55 @@ function civicrm_api3_message_template_send($params) {
  * @param array $params array or parameters determined by getfields
  */
 function _civicrm_api3_message_template_send_spec(&$params) {
-  $params['messageTemplateID']['api.required'] = 1;
-  $params['messageTemplateID']['title'] = 'Message Template ID';
-  $params['contactId']['api.required'] = 1;
-  $params['contactId']['title'] = 'Contact ID';
-  $params['toEmail']['api.required'] = 1;
-  $params['toEmail']['title'] = 'To Email';
-  $params['toName']['api.required'] = 1;
-  $params['toName']['title'] = 'To Name';
+  $params['id']['description'] = 'ID of the template';
+  $params['id']['title'] = 'Message Template ID';
+  $params['id']['api.aliases'] = array('messageTemplateID', 'message_template_id');
+
+  $params['option_group_name']['description'] = 'option group name of the template (required if no id supplied)';
+  $params['option_group_name']['title'] = 'Option Group Name';
+  $params['option_group_name']['api.aliases'] = array('groupName');
+
+  $params['option_value_name']['description'] = 'option value name of the template (required if no id supplied)';
+  $params['option_value_name']['title'] = 'Option Value Name';
+  $params['option_value_name']['api.aliases'] = array('valueName');
+
+  $params['contact_id']['description'] = 'contact id if contact tokens are to be replaced';
+  $params['contact_id']['title'] = 'Contact ID';
+  $params['contact_id']['api.aliases'] = array('contactId');
+
+  $params['template_params']['description'] = 'additional template params (other than the ones already set in the template singleton)';
+  $params['template_params']['title'] = 'Template Params';
+  $params['template_params']['api.aliases'] = array('tplParams');
+
+  $params['from']['description'] = 'the From: header';
+  $params['from']['title'] = 'From';
+
+  $params['to_name']['description'] = 'the recipient’s name';
+  $params['to_name']['title'] = 'Recipient Name';
+  $params['to_name']['api.aliases'] = array('toName');
+
+  $params['to_email']['description'] = 'the recipient’s email - mail is sent only if set';
+  $params['to_email']['title'] = 'Recipient Email';
+  $params['to_email']['api.aliases'] = array('toEmail');
+
+  $params['cc']['description'] = 'the Cc: header';
+  $params['cc']['title'] = 'CC';
+
+  $params['bcc']['description'] = 'the Bcc: header';
+  $params['bcc']['title'] = 'BCC';
+
+  $params['reply_to']['description'] = 'the Reply-To: header';
+  $params['reply_to']['title'] = 'Reply To';
+  $params['reply_to']['api.aliases'] = array('replyTo');
+
+  $params['attachments']['description'] = 'email attachments';
+  $params['attachments']['title'] = 'Attachments';
+
+  $params['is_test']['description'] = 'whether this is a test email (and hence should include the test banner)';
+  $params['is_test']['title'] = 'Is Test';
+  $params['is_test']['api.aliases'] = array('isTest');
+
+  $params['pdf_filename']['description'] = 'filename of optional PDF version to add as attachment (do not include path)';
+  $params['pdf_filename']['title'] = 'PDF Filename';
+  $params['pdf_filename']['api.aliases'] = array('PDFFilename');
 }
index 3c5822baf1d15d38abab20aadf0f53a2d1a44035..2858c322b8c952b6c635433e2df9ac80c3ae3814 100644 (file)
         if ($('#discount_id', $form).val()) {
           buildFeeBlock($('#discount_id', $form).val());
         }
+        $($form).on('change', '#discount_id', function() {
+          buildFeeBlock($(this).val());
+        });
 
         function buildRoleCustomData() {
           var roleId = $('select[name^=role_id]', $form).val().join();