Commit 8cec51b0 authored by unknown's avatar unknown

few Recurring Entity Form improvements and generate_preview ajax call needs to be genralised

parent fbdee7b7
......@@ -505,7 +505,7 @@ class CRM_Activity_Form_Activity extends CRM_Contact_Form_Task {
}
if ($this->_action & CRM_Core_Action::UPDATE) {
CRM_Core_Form_RecurringEntity::preProcess('activity');
CRM_Core_Form_RecurringEntity::preProcess('civicrm_activity');
}
}
......@@ -951,7 +951,6 @@ class CRM_Activity_Form_Activity extends CRM_Contact_Form_Task {
$activity = $this->processActivity($params);
$params['parent_entity_start_date'] = $this->_parentActivityStartDate;
$params['dateColumns'] = array('activity_date_time');
$params['excludeDateRangeColumns'] = array('activity_date_time');
$params['entity_table'] = 'civicrm_activity';
//Unset activity id
unset($params['id']);
......
......@@ -67,6 +67,18 @@ class CRM_Core_BAO_RecurringEntity extends CRM_Core_DAO_RecurringEntity {
'pre_delete_func' => ''
)
);
static $_dateColumns =
array(
'civicrm_event' => array(
'dateColumns' => array('start_date'),
'excludeDateRangeColumns' => array('start_date', 'end_date'),
'intervalDateColumns' => array('end_date')
),
'civicrm_activity' => array(
'dateColumns' => array('activity_date_time'),
)
);
static $_tableDAOMapper =
array(
......
......@@ -64,7 +64,12 @@ class CRM_Core_Form_RecurringEntity {
public static $_excludeDateInfo = array();
/**
* Entity Type
* Entity Table
*/
public static $_entityTable;
/**
* Entity Type
*/
public static $_entityType;
......@@ -73,29 +78,37 @@ class CRM_Core_Form_RecurringEntity {
*/
public static $_hasParent = FALSE;
static function preProcess($entityType) {
self::$_entityId = (int) CRM_Utils_Request::retrieve('id', 'Positive');
self::$_entityType = $entityType;
if (self::$_entityId && $entityType) {
$checkParentExistsForThisId = CRM_Core_BAO_RecurringEntity::getParentFor(self::$_entityId, 'civicrm_'.$entityType);
if ($checkParentExistsForThisId) {
self::$_hasParent = TRUE;
self::$_parentEntityId = $checkParentExistsForThisId;
self::$_scheduleReminderDetails = CRM_Core_BAO_RecurringEntity::getReminderDetailsByEntityId($checkParentExistsForThisId, $entityType);
}
else {
self::$_parentEntityId = self::$_entityId;
self::$_scheduleReminderDetails = CRM_Core_BAO_RecurringEntity::getReminderDetailsByEntityId(self::$_entityId, $entityType);
}
self::$_scheduleReminderID = self::$_scheduleReminderDetails->id;
}
CRM_Core_OptionValue::getValues(array('name' => $entityType.'_repeat_exclude_dates_'.self::$_parentEntityId), $optionValue);
$excludeOptionValues = array();
if (!empty($optionValue)) {
foreach($optionValue as $key => $val) {
$excludeOptionValues[$val['value']] = date('m/d/Y', strtotime($val['value']));
static function preProcess($entityTable) {
self::$_entityId = (int) CRM_Utils_Request::retrieve('id', 'Positive');
self::$_entityTable = $entityTable;
$entityType = array();
if (self::$_entityId && $entityTable) {
$checkParentExistsForThisId = CRM_Core_BAO_RecurringEntity::getParentFor(self::$_entityId, $entityTable);
$entityType = explode("_", $entityTable);
self::$_entityType = $entityType[1];
if (self::$_entityType) {
self::$_entityType = self::$_entityType;
}
if ($checkParentExistsForThisId) {
self::$_hasParent = TRUE;
self::$_parentEntityId = $checkParentExistsForThisId;
self::$_scheduleReminderDetails = CRM_Core_BAO_RecurringEntity::getReminderDetailsByEntityId($checkParentExistsForThisId, self::$_entityType);
}
else {
self::$_parentEntityId = self::$_entityId;
self::$_scheduleReminderDetails = CRM_Core_BAO_RecurringEntity::getReminderDetailsByEntityId(self::$_entityId, self::$_entityType);
}
self::$_scheduleReminderID = self::$_scheduleReminderDetails->id;
}
if (self::$_entityType) {
CRM_Core_OptionValue::getValues(array('name' => self::$_entityType.'_repeat_exclude_dates_'.self::$_parentEntityId), $optionValue);
$excludeOptionValues = array();
if (!empty($optionValue)) {
foreach($optionValue as $key => $val) {
$excludeOptionValues[$val['value']] = date('m/d/Y', strtotime($val['value']));
}
self::$_excludeDateInfo = $excludeOptionValues;
}
self::$_excludeDateInfo = $excludeOptionValues;
}
}
......@@ -144,7 +157,7 @@ class CRM_Core_Form_RecurringEntity {
static function buildQuickForm(&$form) {
$form->assign('currentEntityId', self::$_entityId);
$form->assign('entityType', self::$_entityType);
$form->assign('entityTable', self::$_entityTable);
$form->assign('scheduleReminderId', self::$_scheduleReminderID);
$form->assign('hasParent', self::$_hasParent);
......
......@@ -53,44 +53,63 @@ class CRM_Core_Page_AJAX_RecurringEntity {
public static function generatePreview() {
$params = $formValues = $genericResult = array();
$formValues = $_REQUEST;
if (!empty($formValues)) {
$recursion = new CRM_Core_BAO_RecurringEntity();
$recursion->dateColumns = array('start_date');
$recursion->scheduleFormValues = $formValues;
if (!empty($formValues['exclude_date_list'])) {
$recursion->excludeDates = $formValues['exclude_date_list'];
$recursion->excludeDateRangeColumns = array('start_date', 'end_date');
}
$parentEventId = CRM_Core_BAO_RecurringEntity::getParentFor($formValues['entity_id'], 'civicrm_event');
if (!$parentEventId) {
$parentEventId = $formValues['entity_id'];
}
if (!empty($formValues) &&
CRM_Utils_Array::value('entity_table', $formValues) &&
CRM_Utils_Array::value('entity_id', $formValues)) {
$startDateColumnName = CRM_Core_BAO_RecurringEntity::$_dateColumns[$formValues['entity_table']]['dateColumns'][0];
$endDateColumnName = CRM_Core_BAO_RecurringEntity::$_dateColumns[$formValues['entity_table']]['intervalDateColumns'][0];
$recursion = new CRM_Core_BAO_RecurringEntity();
if (CRM_Utils_Array::value('dateColumns', CRM_Core_BAO_RecurringEntity::$_dateColumns[$formValues['entity_table']])) {
$recursion->dateColumns = CRM_Core_BAO_RecurringEntity::$_dateColumns[$formValues['entity_table']]['dateColumns'];
}
$recursion->scheduleFormValues = $formValues;
if (!empty($formValues['exclude_date_list'])) {
$recursion->excludeDates = $formValues['exclude_date_list'];
}
if (CRM_Utils_Array::value('excludeDateRangeColumns', CRM_Core_BAO_RecurringEntity::$_dateColumns[$formValues['entity_table']])) {
$recursion->excludeDateRangeColumns = CRM_Core_BAO_RecurringEntity::$_dateColumns[$formValues['entity_table']]['excludeDateRangeColumns'];
}
$parentEventId = CRM_Core_BAO_RecurringEntity::getParentFor($formValues['entity_id'], $formValues['entity_table']);
if (!$parentEventId) {
$parentEventId = $formValues['entity_id'];
}
$endDate = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Event', $parentEventId, 'end_date');
if ($endDate) {
$startDate = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Event', $parentEventId, 'start_date');
$interval = $recursion->getInterval($startDate, $endDate);
$recursion->intervalDateColumns = array('end_date' => $interval);
}
//Check if there is any enddate column defined to find out the interval between the two range
if (CRM_Utils_Array::value('intervalDateColumns', CRM_Core_BAO_RecurringEntity::$_dateColumns[$formValues['entity_table']])) {
$daoName = CRM_Core_BAO_RecurringEntity::$_tableDAOMapper[$formValues['entity_table']];
$startDate = CRM_Core_DAO::getFieldValue($daoName, $parentEventId, $startDateColumnName);
$endDate = CRM_Core_DAO::getFieldValue($daoName, $parentEventId, $endDateColumnName);
if ($endDate) {
$interval = $recursion->getInterval($startDate, $endDate);
$recursion->intervalDateColumns = array($endDateColumnName => $interval);
}
}
$result = $recursion->generateRecursiveDates();
$result = $recursion->generateRecursiveDates();
foreach ($result as $key => $value) {
$result[$key]['start_date'] = date('M d, Y h:i:s A \o\n l', strtotime($value['start_date']));
if ($value['end_date']) {
$result[$key]['end_date'] = date('M d, Y h:i:s A \o\n l', strtotime($value['end_date']));
foreach ($result as $key => $value) {
if ($startDateColumnName) {
$result[$key]['start_date'] = date('M d, Y h:i:s A \o\n l', strtotime($value[$startDateColumnName]));
}
if ($value[$endDateColumnName]) {
if ($endDateColumnName) {
$result[$key]['end_date'] = date('M d, Y h:i:s A \o\n l', strtotime($value[$endDateColumnName]));
}
}
}
}
//Show the list of participants registered for the events if any
$getConnectedEntities = CRM_Core_BAO_RecurringEntity::getEntitiesForParent($parentEventId, 'civicrm_event', TRUE);
if ($getConnectedEntities) {
$participantDetails = CRM_Event_Form_ManageEvent_Repeat::getParticipantCountforEvent($getConnectedEntities);
if (!empty($participantDetails['countByName'])) {
$result['participantData'] = $participantDetails['countByName'];
//Show the list of participants registered for the events if any
if ($formValues['entity_table']) {
$getConnectedEntities = CRM_Core_BAO_RecurringEntity::getEntitiesForParent($parentEventId, 'civicrm_event', TRUE);
if ($getConnectedEntities) {
$participantDetails = CRM_Event_Form_ManageEvent_Repeat::getParticipantCountforEvent($getConnectedEntities);
if (!empty($participantDetails['countByName'])) {
$result['participantData'] = $participantDetails['countByName'];
}
}
}
}
}
echo json_encode($result);
CRM_Utils_System::civiExit();
......
......@@ -26,7 +26,7 @@ class CRM_Event_Form_ManageEvent_Repeat extends CRM_Event_Form_ManageEvent {
function preProcess() {
parent::preProcess();
CRM_Core_Form_RecurringEntity::preProcess('event');
CRM_Core_Form_RecurringEntity::preProcess('civicrm_event');
$this->assign('currentEventId', $this->_id);
$checkParentExistsForThisId = CRM_Core_BAO_RecurringEntity::getParentFor($this->_id, 'civicrm_event');
......
......@@ -248,9 +248,9 @@
});
var ajaxurl = CRM.url("civicrm/ajax/recurringentity/generate-preview");
var entityID = {/literal}{$currentEntityId}{literal};
var entityType = '{/literal}{$entityType}{literal}';
if (entityID != "" && entityType != "") {
ajaxurl += "?entity_id="+entityID+"&entity_type="+entityType;
var entityTable = '{/literal}{$entityTable}{literal}';
if (entityID != "" && entityTable != "") {
ajaxurl += "?entity_id="+entityID+"&entity_table="+entityTable;
}
var formData = cj('form').serializeArray();
cj.ajax({
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment