From 04374d9dcb8271d3c2bcc467a745fed93fd4c4ca Mon Sep 17 00:00:00 2001 From: Coleman Watts Date: Sun, 19 Apr 2015 20:56:57 -0400 Subject: [PATCH] CRM-16323 Show count and position of repeating entities --- CRM/Activity/BAO/Activity.php | 4 ++- CRM/Activity/Page/AJAX.php | 8 ++--- CRM/Activity/Selector/Search.php | 11 ++---- CRM/Core/BAO/RecurringEntity.php | 34 +++++++++++++++++++ CRM/Event/Page/ManageEvent.php | 11 ++---- .../Activity/AddRecurringActivityTest.php | 3 +- .../WebTest/Event/AddRecurringEventTest.php | 3 +- 7 files changed, 47 insertions(+), 27 deletions(-) diff --git a/CRM/Activity/BAO/Activity.php b/CRM/Activity/BAO/Activity.php index 93147a9359..f42e030d44 100644 --- a/CRM/Activity/BAO/Activity.php +++ b/CRM/Activity/BAO/Activity.php @@ -2599,7 +2599,9 @@ INNER JOIN civicrm_option_group grp ON ( grp.id = val.option_group_id AND grp.n $values['activity_id'] ); - $contactActivities[$activityId]['is_recurring_activity'] = $values['is_recurring_activity']; + if ($values['is_recurring_activity']) { + $contactActivities[$activityId]['is_recurring_activity'] = CRM_Core_BAO_RecurringEntity::getPositionAndCount($values['activity_id'], 'civicrm_activity'); + } } } diff --git a/CRM/Activity/Page/AJAX.php b/CRM/Activity/Page/AJAX.php index 789bed99cc..9c79eae36c 100644 --- a/CRM/Activity/Page/AJAX.php +++ b/CRM/Activity/Page/AJAX.php @@ -491,12 +491,8 @@ class CRM_Activity_Page_AJAX { foreach ($activities as $key => $value) { //Check if recurring activity if (!empty($value['is_recurring_activity'])) { - if ($key == $value['is_recurring_activity']) { - $activities[$key]['activity_type'] = $activities[$key]['activity_type'] . '
Recurring Activity - (Parent)'; - } - else { - $activities[$key]['activity_type'] = $activities[$key]['activity_type'] . '
Recurring Activity - (Child)'; - } + $repeat = $value['is_recurring_activity']; + $activities[$key]['activity_type'] .= '
' . ts('Repeating (%1 of %2)', array(1 => $repeat[0], 2 => $repeat[1])) . ''; } } diff --git a/CRM/Activity/Selector/Search.php b/CRM/Activity/Selector/Search.php index 3650d57c0b..e71f38063e 100644 --- a/CRM/Activity/Selector/Search.php +++ b/CRM/Activity/Selector/Search.php @@ -339,15 +339,10 @@ class CRM_Activity_Selector_Search extends CRM_Core_Selector_Base implements CRM } //Check if recurring activity - $isRecurringActivity = CRM_Core_BAO_RecurringEntity::getParentFor($row['activity_id'], 'civicrm_activity'); + $repeat = CRM_Core_BAO_RecurringEntity::getPositionAndCount($row['activity_id'], 'civicrm_activity'); $row['repeat'] = ''; - if ($isRecurringActivity) { - if ($row['activity_id'] == $isRecurringActivity) { - $row['repeat'] = 'Recurring Activity - (Parent)'; - } - else { - $row['repeat'] = 'Recurring Activity - (Child)'; - } + if ($repeat) { + $row['repeat'] = ts('Repeating (%1 of %2)', array(1 => $repeat[0], 2 => $repeat[1])); } $rows[] = $row; } diff --git a/CRM/Core/BAO/RecurringEntity.php b/CRM/Core/BAO/RecurringEntity.php index cbcee17739..5402d5a3a5 100644 --- a/CRM/Core/BAO/RecurringEntity.php +++ b/CRM/Core/BAO/RecurringEntity.php @@ -532,6 +532,40 @@ class CRM_Core_BAO_RecurringEntity extends CRM_Core_DAO_RecurringEntity { return $parentId; } + /** + * Finds the position of this entity as well as total count of the repeating set + * + * @param $entityId + * @param $entityTable + * @return array|null + */ + static public function getPositionAndCount($entityId, $entityTable) { + $position = $count = 0; + + $query = " + SELECT entity_id + FROM civicrm_recurring_entity + WHERE parent_id = (SELECT parent_id FROM civicrm_recurring_entity WHERE entity_id = %1 AND entity_table = %2) AND entity_table = %2"; + + $dao = CRM_Core_DAO::executeQuery($query, + array( + 1 => array($entityId, 'Integer'), + 2 => array($entityTable, 'String'), + ) + ); + + while ($dao->fetch()) { + ++$count; + if ($dao->entity_id <= $entityId) { + ++$position; + } + } + if ($count) { + return array($position, $count); + } + return NULL; + } + /** * This function copies the information from parent entity and creates other entities with same information. * diff --git a/CRM/Event/Page/ManageEvent.php b/CRM/Event/Page/ManageEvent.php index 75ae25dbdd..2df6673df2 100644 --- a/CRM/Event/Page/ManageEvent.php +++ b/CRM/Event/Page/ManageEvent.php @@ -319,15 +319,10 @@ ORDER BY start_date desc while ($dao->fetch()) { if (in_array($dao->id, $permissions[CRM_Core_Permission::VIEW])) { $manageEvent[$dao->id] = array(); - $isRecurringEvent = CRM_Core_BAO_RecurringEntity::getParentFor($dao->id, 'civicrm_event'); + $repeat = CRM_Core_BAO_RecurringEntity::getPositionAndCount($dao->id, 'civicrm_event'); $manageEvent[$dao->id]['repeat'] = ''; - if ($isRecurringEvent) { - if ($dao->id == $isRecurringEvent) { - $manageEvent[$dao->id]['repeat'] = 'Recurring Event - (Parent)'; - } - else { - $manageEvent[$dao->id]['repeat'] = 'Recurring Event - (Child)'; - } + if ($repeat) { + $manageEvent[$dao->id]['repeat'] = ts('Repeating (%1 of %2)', array(1 => $repeat[0], 2 => $repeat[1])); } CRM_Core_DAO::storeValues($dao, $manageEvent[$dao->id]); diff --git a/tests/phpunit/WebTest/Activity/AddRecurringActivityTest.php b/tests/phpunit/WebTest/Activity/AddRecurringActivityTest.php index a942947090..50f143900e 100644 --- a/tests/phpunit/WebTest/Activity/AddRecurringActivityTest.php +++ b/tests/phpunit/WebTest/Activity/AddRecurringActivityTest.php @@ -131,8 +131,7 @@ class WebTest_Activity_AddRecurringActivityTest extends CiviSeleniumTestCase { } $this->assertEquals($occurrences, $countOfActivities); - $this->assertTrue($this->isTextPresent("Recurring Activity - (Child)")); - $this->assertTrue($this->isTextPresent("Recurring Activity - (Parent)")); + $this->assertTrue($this->isTextPresent("Repeating")); //Cascade changes $this->click("xpath=//div[@class='crm-search-results']/table/tbody/tr[2]/td/span/a[text()='Edit']"); diff --git a/tests/phpunit/WebTest/Event/AddRecurringEventTest.php b/tests/phpunit/WebTest/Event/AddRecurringEventTest.php index 1e05fa8763..e0cd3f7054 100644 --- a/tests/phpunit/WebTest/Event/AddRecurringEventTest.php +++ b/tests/phpunit/WebTest/Event/AddRecurringEventTest.php @@ -77,8 +77,7 @@ class WebTest_Event_AddRecurringEventTest extends CiviSeleniumTestCase { $eventTitle = "Fall Fundraiser Dinner"; $this->type("title", $eventTitle); $this->click("_qf_SearchEvent_refresh"); - $this->assertTrue($this->isTextPresent("Recurring Event - (Child)")); - $this->assertTrue($this->isTextPresent("Recurring Event - (Parent)")); + $this->assertTrue($this->isTextPresent("Repeating")); //Update Mode Cascade Changes $this->click('event-configure-1'); -- 2.25.1