Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convert ManageEvent Fees to datepicker #12977

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 13 additions & 24 deletions CRM/Event/Form/ManageEvent/Fee.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public function preProcess() {
* For edit/view mode the default values are retrieved from the database.
*/
public function setDefaultValues() {
$parentDefaults = parent::setDefaultValues();
parent::setDefaultValues();

$eventId = $this->_id;
$params = array();
Expand Down Expand Up @@ -118,14 +118,12 @@ public function setDefaultValues() {
$totalLables = $maxSize = $defaultDiscounts = array();
foreach ($discountedEvent as $optionGroupId) {
$defaults['discount_price_set'][] = $optionGroupId;
$name = $defaults["discount_name[$i]"] = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceSet', $optionGroupId, 'title');

list($defaults["discount_start_date[$i]"]) = CRM_Utils_Date::setDateDefaults(CRM_Core_DAO::getFieldValue('CRM_Core_DAO_Discount', $optionGroupId,
'start_date', 'price_set_id'
));
list($defaults["discount_end_date[$i]"]) = CRM_Utils_Date::setDateDefaults(CRM_Core_DAO::getFieldValue('CRM_Core_DAO_Discount', $optionGroupId,
'end_date', 'price_set_id'
));
$defaults["discount_name[$i]"] = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceSet', $optionGroupId, 'title');

$defaults["discount_start_date[$i]"] = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_Discount', $optionGroupId,
'start_date', 'price_set_id');
$defaults["discount_end_date[$i]"] = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_Discount', $optionGroupId,
'end_date', 'price_set_id');
$defaultDiscounts[] = CRM_Price_BAO_PriceSet::getSetDetail($optionGroupId);
$i++;
}
Expand Down Expand Up @@ -241,7 +239,6 @@ public function setDefaultValues() {
* Build the form object.
*/
public function buildQuickForm() {

$this->addYesNo('is_monetary',
ts('Paid Event'),
NULL,
Expand Down Expand Up @@ -342,11 +339,10 @@ public function buildQuickForm() {
isset($this->_submitValues['discount_end_date'][$i]) &&
$i < self::NUM_DISCOUNT - 1
) {
$end_date = CRM_Utils_Date::processDate($this->_submitValues['discount_end_date'][$i]);
if (!empty($this->_submitValues['discount_end_date'][$i + 1])
&& empty($this->_submitValues['discount_start_date'][$i + 1])
) {
list($this->_submitValues['discount_start_date'][$i + 1]) = CRM_Utils_Date::setDateDefaults(date('Y-m-d', strtotime("+1 days $end_date")));
$this->_submitValues['discount_start_date'][$i + 1] = date('Y-m-d', strtotime("+1 days " . $this->_submitValues['discount_end_date'][$i]));
}
}
//Decrement by 1 of end date from next start date.
Expand All @@ -357,26 +353,19 @@ public function buildQuickForm() {
isset($this->_submitValues['discount_start_date']) &&
isset($this->_submitValues['discount_start_date'][$i])
) {
$start_date = CRM_Utils_Date::processDate($this->_submitValues['discount_start_date'][$i]);
if (!empty($this->_submitValues['discount_start_date'][$i])
&& empty($this->_submitValues['discount_end_date'][$i - 1])
) {
list($this->_submitValues['discount_end_date'][$i - 1]) = CRM_Utils_Date::setDateDefaults(date('Y-m-d', strtotime("-1 days $start_date")));
list($this->_submitValues['discount_end_date'][$i - 1]) = date('Y-m-d', strtotime("-1 days " . $this->_submitValues['discount_start_date'][$i]));
}
}

//discount name
$this->add('text', 'discount_name[' . $i . ']', ts('Discount Name'),
CRM_Core_DAO::getAttribute('CRM_Price_DAO_PriceSet', 'title')
);

$this->add('hidden', "discount_price_set[$i]", '', array('id' => "discount_price_set[$i]"));

//discount start date
$this->addDate('discount_start_date[' . $i . ']', ts('Discount Start Date'), FALSE, array('formatType' => 'activityDate'));

//discount end date
$this->addDate('discount_end_date[' . $i . ']', ts('Discount End Date'), FALSE, array('formatType' => 'activityDate'));
$this->add('datepicker', 'discount_start_date[' . $i . ']', ts('Discount Start Date'), [], FALSE, array('time' => FALSE));
$this->add('datepicker', 'discount_end_date[' . $i . ']', ts('Discount End Date'), [], FALSE, array('time' => FALSE));
}
$_showHide->addToTemplate();
$this->addElement('submit', $this->getButtonName('submit'), ts('Add Discount Set to Fee Table'),
Expand Down Expand Up @@ -768,8 +757,8 @@ public function postProcess() {
'entity_table' => 'civicrm_event',
'entity_id' => $this->_id,
'price_set_id' => $priceSetID,
'start_date' => CRM_Utils_Date::processDate($params['discount_start_date'][$j]),
'end_date' => CRM_Utils_Date::processDate($params['discount_end_date'][$j]),
'start_date' => $params['discount_start_date'][$j],
'end_date' => $params['discount_end_date'][$j],
);
CRM_Core_BAO_Discount::add($discountParams);
}
Expand Down
4 changes: 2 additions & 2 deletions templates/CRM/Event/Form/ManageEvent/Fee.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -193,8 +193,8 @@
<td>{if $index GT 1} <a onclick="showHideDiscountRow('discount_{$index}', false, {$index}); return false;" name="discount_{$index}" href="#" class="form-link"><img src="{$config->resourceBase}i/TreeMinus.gif" class="action-icon" alt="{ts}hide field or section{/ts}"/></a>{/if}
</td>
<td class="crm-event-manage-fee-form-block-discount_name"> {$form.discount_name.$index.html}</td>
<td class="crm-event-manage-fee-form-block-discount_start_date"> {include file="CRM/common/jcalendar.tpl" elementName='discount_start_date' elementIndex=$index} </td>
<td class="crm-event-manage-fee-form-block-discount_end_date"> {include file="CRM/common/jcalendar.tpl" elementName='discount_end_date' elementIndex=$index} </td>
<td class="crm-event-manage-fee-form-block-discount_start_date"> {$form.discount_start_date.$index.html} </td>
<td class="crm-event-manage-fee-form-block-discount_end_date"> {$form.discount_end_date.$index.html} </td>
</tr>
{/section}
</table>
Expand Down