本文整理汇总了PHP中CRM_Core_BAO_RecurringEntity::getInterval方法的典型用法代码示例。如果您正苦于以下问题:PHP CRM_Core_BAO_RecurringEntity::getInterval方法的具体用法?PHP CRM_Core_BAO_RecurringEntity::getInterval怎么用?PHP CRM_Core_BAO_RecurringEntity::getInterval使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CRM_Core_BAO_RecurringEntity
的用法示例。
在下文中一共展示了CRM_Core_BAO_RecurringEntity::getInterval方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testEventGeneration
/**
* Testing Event Generation through Entity Recursion.
*/
public function testEventGeneration()
{
//Event set initial params
$daoEvent = new CRM_Event_DAO_Event();
$daoEvent->title = 'Test event for Recurring Entity';
$daoEvent->event_type_id = 3;
$daoEvent->is_public = 1;
$daoEvent->start_date = date('YmdHis', strtotime('2014-10-26 10:30:00'));
$daoEvent->end_date = date('YmdHis', strtotime('2014-10-28 10:30:00'));
$daoEvent->created_date = date('YmdHis');
$daoEvent->is_active = 1;
$daoEvent->save();
$this->assertDBNotNull('CRM_Event_DAO_Event', $daoEvent->id, 'id', 'id', 'Check DB if event was created');
//Create tell a friend for event
$daoTellAFriend = new CRM_Friend_DAO_Friend();
$daoTellAFriend->entity_table = 'civicrm_event';
$daoTellAFriend->entity_id = $daoEvent->id;
// join with event
$daoTellAFriend->title = 'Testing tell a friend';
$daoTellAFriend->is_active = 1;
$daoTellAFriend->save();
$this->assertDBNotNull('CRM_Friend_DAO_Friend', $daoTellAFriend->id, 'id', 'id', 'Check DB if tell a friend was created');
// time to use recursion
$recursion = new CRM_Core_BAO_RecurringEntity();
$recursion->entity_id = $daoEvent->id;
$recursion->entity_table = 'civicrm_event';
$recursion->dateColumns = array('start_date');
$recursion->schedule = array('entity_value' => $daoEvent->id, 'start_action_date' => $daoEvent->start_date, 'start_action_condition' => 'monday', 'repetition_frequency_unit' => 'week', 'repetition_frequency_interval' => 1, 'start_action_offset' => 4, 'used_for' => 'event');
$recursion->linkedEntities = array(array('table' => 'civicrm_tell_friend', 'findCriteria' => array('entity_id' => $recursion->entity_id, 'entity_table' => 'civicrm_event'), 'linkedColumns' => array('entity_id'), 'isRecurringEntityRecord' => TRUE));
$interval = $recursion->getInterval($daoEvent->start_date, $daoEvent->end_date);
$recursion->intervalDateColumns = array('end_date' => $interval);
$generatedEntities = $recursion->generate();
$this->assertArrayHasKey('civicrm_event', $generatedEntities, 'Check if generatedEntities has civicrm_event as required key');
$expectedDates = array('20141027103000' => '20141029103000', '20141103103000' => '20141105103000', '20141110103000' => '20141112103000', '20141117103000' => '20141119103000');
$this->assertCount($recursion->schedule['start_action_offset'], $generatedEntities['civicrm_event'], 'Check if the number of events created are right');
$actualDates = array();
foreach ($generatedEntities['civicrm_event'] as $key => $val) {
$this->assertDBNotNull('CRM_Event_DAO_Event', $val, 'id', 'id', 'Check if repeating events were created.');
$startDate = date('YmdHis', strtotime(CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Event', $val, 'start_date', 'id')));
$endDate = date('YmdHis', strtotime(CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Event', $val, 'end_date', 'id')));
$actualDates[$startDate] = $endDate;
}
$resultDates = array_diff($actualDates, $expectedDates);
$this->assertEquals(0, count($resultDates), "Check if all the value in expected array matches actual array");
foreach ($generatedEntities['civicrm_tell_friend'] as $key => $val) {
$this->assertDBNotNull('CRM_Friend_DAO_Friend', $val, 'id', 'id', 'Check if friends were created in loop');
$this->assertDBCompareValue('CRM_Friend_DAO_Friend', $val, 'entity_id', 'id', $generatedEntities['civicrm_event'][$key], 'Check DB if correct FK was maintained with event for Friend');
}
$this->assertCount($recursion->schedule['start_action_offset'], $generatedEntities['civicrm_tell_friend'], 'Check if the number of tell a friend records are right');
// set mode to ALL, i.e any change to changing event affects all related recurring activities
$recursion->mode(3);
$daoEvent->find(TRUE);
$daoEvent->title = 'Event Changed';
$daoEvent->save();
// check if other events were affected
foreach ($generatedEntities['civicrm_event'] as $entityID) {
$this->assertDBCompareValue('CRM_Event_DAO_Event', $entityID, 'title', 'id', 'Event Changed', 'Check if title was updated');
}
end($generatedEntities['civicrm_event']);
$key = key($generatedEntities['civicrm_event']);
end($generatedEntities['civicrm_tell_friend']);
$actKey = key($generatedEntities['civicrm_tell_friend']);
//Check if both(event/tell a friend) keys are same
$this->assertEquals($key, $actKey, "Check if both the keys are same");
//Cross check event exists before we test deletion
$searchParamsEventBeforeDelete = array('entity_id' => $generatedEntities['civicrm_event'][$key], 'entity_table' => 'civicrm_event');
$expectedValuesEventBeforeDelete = array('entity_id' => $generatedEntities['civicrm_event'][$key], 'entity_table' => 'civicrm_event');
$this->assertDBCompareValues('CRM_Core_DAO_RecurringEntity', $searchParamsEventBeforeDelete, $expectedValuesEventBeforeDelete);
//Cross check event exists before we test deletion
$searchParamsTellAFriendBeforeDelete = array('entity_id' => $generatedEntities['civicrm_tell_friend'][$actKey], 'entity_table' => 'civicrm_tell_friend');
$expectedValuesTellAFriendBeforeDelete = array('entity_id' => $generatedEntities['civicrm_tell_friend'][$actKey], 'entity_table' => 'civicrm_tell_friend');
$this->assertDBCompareValues('CRM_Core_DAO_RecurringEntity', $searchParamsTellAFriendBeforeDelete, $expectedValuesTellAFriendBeforeDelete);
//Delete an event from recurring set and respective linked entity should be deleted from civicrm_recurring_entity_table
$daoRecurEvent = new CRM_Event_DAO_Event();
$daoRecurEvent->id = $generatedEntities['civicrm_event'][$key];
if ($daoRecurEvent->find(TRUE)) {
$daoRecurEvent->delete();
$daoRecurEvent->free();
}
//Check if this event_id was deleted
$this->assertDBNull('CRM_Event_DAO_Event', $generatedEntities['civicrm_event'][$key], 'id', 'id', 'Check if event was deleted');
$searchParams = array('entity_id' => $generatedEntities['civicrm_event'][$key], 'entity_table' => 'civicrm_event');
$compareParams = array();
$this->assertDBCompareValues('CRM_Core_DAO_RecurringEntity', $searchParams, $compareParams);
//Find tell_a_friend id if that was deleted from civicrm
$searchActParams = array('entity_id' => $generatedEntities['civicrm_tell_friend'][$actKey], 'entity_table' => 'civicrm_tell_friend');
$compareActParams = array();
$this->assertDBCompareValues('CRM_Friend_DAO_Friend', $searchActParams, $compareActParams);
}
示例2: postProcess
public function postProcess()
{
if ($this->_id) {
$params = $this->controller->exportValues($this->_name);
if ($this->_parentEventStartDate && $this->_parentEventEndDate) {
$interval = CRM_Core_BAO_RecurringEntity::getInterval($this->_parentEventStartDate, $this->_parentEventEndDate);
$params['intervalDateColumns'] = array('end_date' => $interval);
}
$params['dateColumns'] = array('start_date');
$params['excludeDateRangeColumns'] = array('start_date', 'end_date');
$params['entity_table'] = 'civicrm_event';
$params['entity_id'] = $this->_id;
// CRM-16568 - check if parent exist for the event.
$parentId = CRM_Core_BAO_RecurringEntity::getParentFor($this->_id, 'civicrm_event');
$params['parent_entity_id'] = !empty($parentId) ? $parentId : $params['entity_id'];
//Unset event id
unset($params['id']);
$url = 'civicrm/event/manage/repeat';
$urlParams = "action=update&reset=1&id={$this->_id}";
$linkedEntities = array(array('table' => 'civicrm_price_set_entity', 'findCriteria' => array('entity_id' => $this->_id, 'entity_table' => 'civicrm_event'), 'linkedColumns' => array('entity_id'), 'isRecurringEntityRecord' => FALSE), array('table' => 'civicrm_uf_join', 'findCriteria' => array('entity_id' => $this->_id, 'entity_table' => 'civicrm_event'), 'linkedColumns' => array('entity_id'), 'isRecurringEntityRecord' => FALSE), array('table' => 'civicrm_tell_friend', 'findCriteria' => array('entity_id' => $this->_id, 'entity_table' => 'civicrm_event'), 'linkedColumns' => array('entity_id'), 'isRecurringEntityRecord' => TRUE), array('table' => 'civicrm_pcp_block', 'findCriteria' => array('entity_id' => $this->_id, 'entity_table' => 'civicrm_event'), 'linkedColumns' => array('entity_id'), 'isRecurringEntityRecord' => TRUE));
CRM_Core_Form_RecurringEntity::postProcess($params, 'civicrm_event', $linkedEntities);
CRM_Utils_System::redirect(CRM_Utils_System::url($url, $urlParams));
} else {
CRM_Core_Error::fatal("Could not find Event ID");
}
parent::endPostProcess();
}
示例3: run
/**
* Run the basic page (run essentially starts execution for that page).
*/
public function run()
{
$parentEventId = $startDate = $endDate = NULL;
$dates = $original = array();
$formValues = $_REQUEST;
if (!empty($formValues['entity_table'])) {
$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 = explode(',', $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'];
}
if (!empty($formValues['entity_id'])) {
$parentEventId = CRM_Core_BAO_RecurringEntity::getParentFor($formValues['entity_id'], $formValues['entity_table']);
}
// Get original entity
$original[$startDateColumnName] = CRM_Utils_Date::processDate($formValues['repetition_start_date']);
$daoName = CRM_Core_BAO_RecurringEntity::$_tableDAOMapper[$formValues['entity_table']];
if ($parentEventId) {
$startDate = $original[$startDateColumnName] = CRM_Core_DAO::getFieldValue($daoName, $parentEventId, $startDateColumnName);
$endDate = $original[$startDateColumnName] = $endDateColumnName ? CRM_Core_DAO::getFieldValue($daoName, $parentEventId, $endDateColumnName) : NULL;
}
//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']])) {
if ($endDate) {
$interval = $recursion->getInterval($startDate, $endDate);
$recursion->intervalDateColumns = array($endDateColumnName => $interval);
}
}
$dates = array_merge(array($original), $recursion->generateRecursiveDates());
foreach ($dates as $key => &$value) {
if ($startDateColumnName) {
$value['start_date'] = CRM_Utils_Date::customFormat($value[$startDateColumnName]);
}
if ($endDateColumnName && !empty($value[$endDateColumnName])) {
$value['end_date'] = CRM_Utils_Date::customFormat($value[$endDateColumnName]);
$endDates = TRUE;
}
}
//Show the list of participants registered for the events if any
if ($formValues['entity_table'] == "civicrm_event" && !empty($parentEventId)) {
$getConnectedEntities = CRM_Core_BAO_RecurringEntity::getEntitiesForParent($parentEventId, 'civicrm_event', TRUE);
if ($getConnectedEntities) {
$participantDetails = CRM_Event_Form_ManageEvent_Repeat::getParticipantCountforEvent($getConnectedEntities);
if (!empty($participantDetails['countByName'])) {
$this->assign('participantData', $participantDetails['countByName']);
}
}
}
}
$this->assign('dates', $dates);
$this->assign('endDates', !empty($endDates));
return parent::run();
}