$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);
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];
}
*/
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);
}
}
*/
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';
array(
0 => ts('- select -')) + $discounts,
FALSE,
- array('onchange' => "buildFeeBlock( {$form->_eventId}, this.value );")
+ array('class' => "crm-select2")
);
if ($form->_online) {
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();
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'));
$baoName = $this->_BAOName;
$baoName::retrieve($params, $defaults);
}
- $defaults['is_active'] = 1;
+ else {
+ $defaults['is_active'] = 1;
+ }
return $defaults;
}
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
*
* 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);
}
/**
* @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');
}
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();