Activity BAO - Remove unused classes/functions
authorColeman Watts <coleman@civicrm.org>
Sat, 1 Apr 2023 20:52:45 +0000 (16:52 -0400)
committerColeman Watts <coleman@civicrm.org>
Sat, 1 Apr 2023 20:52:45 +0000 (16:52 -0400)
CRM/Activity/BAO/ActivityAssignment.php
CRM/Activity/BAO/ActivityTarget.php [deleted file]
CRM/Activity/Form/Task/Batch.php
tests/phpunit/CRM/Activity/BAO/ActivityAssignmentTest.php
tests/phpunit/CRM/Activity/BAO/ActivityTargetTest.php [deleted file]

index 95dde5bc0d3c23f61f9dcfafcb939b4b5cb784ae..de463a195515530c644c2332b0ef29caa98c8fed 100644 (file)
  */
 class CRM_Activity_BAO_ActivityAssignment extends CRM_Activity_DAO_ActivityContact {
 
-  /**
-   * Add activity assignment.
-   *
-   * @param array $params
-   *   (reference ) an assoc array of name/value pairs.
-   *
-   * @return object
-   *   activity type of object that is added
-   */
-  public static function create(&$params) {
-    $assignment = new CRM_Activity_BAO_ActivityContact();
-    $activityContacts = CRM_Activity_BAO_ActivityContact::buildOptions('record_type_id', 'validate');
-    $assigneeID = CRM_Utils_Array::key('Activity Assignees', $activityContacts);
-
-    $assignment->copyValues($params);
-    $assignment->record_type_id = $assigneeID;
-
-    return $assignment->save();
-  }
-
-  /**
-   * Retrieve assignee_id by activity_id.
-   *
-   * @param int $activity_id
-   *
-   * @return array
-   */
-  public static function retrieveAssigneeIdsByActivityId($activity_id) {
-    $assigneeArray = [];
-    if (!CRM_Utils_Rule::positiveInteger($activity_id)) {
-      return $assigneeArray;
-    }
-
-    $activityContacts = CRM_Activity_BAO_ActivityContact::buildOptions('record_type_id', 'validate');
-    $assigneeID = CRM_Utils_Array::key('Activity Assignees', $activityContacts);
-
-    $sql = "
-SELECT     contact_id
-FROM       civicrm_activity_contact
-INNER JOIN civicrm_contact ON contact_id = civicrm_contact.id
-WHERE      activity_id = %1
-AND        record_type_id = $assigneeID
-AND        civicrm_contact.is_deleted = 0
-";
-    $assignment = CRM_Core_DAO::executeQuery($sql, [
-      1 => [
-        $activity_id,
-        'Integer',
-      ],
-    ]);
-    while ($assignment->fetch()) {
-      $assigneeArray[] = $assignment->contact_id;
-    }
-
-    return $assigneeArray;
-  }
-
   /**
    * Retrieve assignee names by activity_id.
    *
diff --git a/CRM/Activity/BAO/ActivityTarget.php b/CRM/Activity/BAO/ActivityTarget.php
deleted file mode 100644 (file)
index d20c3b5..0000000
+++ /dev/null
@@ -1,111 +0,0 @@
-<?php
-/*
- +--------------------------------------------------------------------+
- | Copyright CiviCRM LLC. All rights reserved.                        |
- |                                                                    |
- | This work is published under the GNU AGPLv3 license with some      |
- | permitted exceptions and without any warranty. For full license    |
- | and copyright information, see https://civicrm.org/licensing       |
- +--------------------------------------------------------------------+
- */
-
-/**
- *
- * @package CRM
- * @copyright CiviCRM LLC https://civicrm.org/licensing
- */
-
-/**
- * This class is for activity assignment functions.
- */
-class CRM_Activity_BAO_ActivityTarget extends CRM_Activity_DAO_ActivityContact {
-
-  /**
-   * Add activity target.
-   *
-   * @param array $params
-   *
-   * @return object
-   *   activity type of object that is added
-   */
-  public static function create(&$params) {
-    $target = new CRM_Activity_BAO_ActivityContact();
-    $activityContacts = CRM_Activity_BAO_ActivityContact::buildOptions('record_type_id', 'validate');
-    $targetID = CRM_Utils_Array::key('Activity Targets', $activityContacts);
-
-    $target->copyValues($params);
-    $target->record_type_id = $targetID;
-    return $target->save();
-  }
-
-  /**
-   * Retrieve id of target contact by activity_id.
-   *
-   * @param int $activity_id
-   *
-   * @return mixed
-   */
-  public static function retrieveTargetIdsByActivityId($activity_id) {
-    $targetArray = [];
-    if (!CRM_Utils_Rule::positiveInteger($activity_id)) {
-      return $targetArray;
-    }
-
-    $activityContacts = CRM_Activity_BAO_ActivityContact::buildOptions('record_type_id', 'validate');
-    $targetID = CRM_Utils_Array::key('Activity Targets', $activityContacts);
-
-    $sql = "
-SELECT     contact_id
-FROM       civicrm_activity_contact
-INNER JOIN civicrm_contact ON contact_id = civicrm_contact.id
-WHERE      activity_id = %1
-AND        record_type_id = $targetID
-AND        civicrm_contact.is_deleted = 0
-";
-    $target = CRM_Core_DAO::executeQuery($sql, [
-      1 => [
-        $activity_id,
-        'Integer',
-      ],
-    ]);
-    while ($target->fetch()) {
-      $targetArray[] = $target->contact_id;
-    }
-    return $targetArray;
-  }
-
-  /**
-   * Retrieve names of target contact by activity_id.
-   *
-   * @param int $activityID
-   *
-   * @return array
-   */
-  public static function getTargetNames($activityID) {
-    $targetNames = [];
-
-    if (empty($activityID)) {
-      return $targetNames;
-    }
-    $activityContacts = CRM_Activity_BAO_ActivityContact::buildOptions('record_type_id', 'validate');
-    $targetID = CRM_Utils_Array::key('Activity Targets', $activityContacts);
-
-    $query = "
-SELECT     contact_a.id, contact_a.sort_name
-FROM       civicrm_contact contact_a
-INNER JOIN civicrm_activity_contact ON civicrm_activity_contact.contact_id = contact_a.id
-WHERE      civicrm_activity_contact.activity_id = %1
-AND        civicrm_activity_contact.record_type_id = $targetID
-AND        contact_a.is_deleted = 0
-";
-    $queryParam = [1 => [$activityID, 'Integer']];
-
-    $dao = CRM_Core_DAO::executeQuery($query, $queryParam);
-    while ($dao->fetch()) {
-      $targetNames[$dao->id] = $dao->sort_name;
-    }
-
-    return $targetNames;
-  }
-
-}
index db778bf1d173c6b61c719329033e85de7401cc24..1dff4f66cbcb8471af3f453475ad30ca511dedd1 100644 (file)
@@ -68,11 +68,7 @@ class CRM_Activity_Form_Task_Batch extends CRM_Activity_Form_Task {
     $readOnlyFields['assignee_display_name'] = ts('Assigned to');
     if (!empty($contactDetails)) {
       foreach ($contactDetails as $key => $value) {
-        $assignee = CRM_Activity_BAO_ActivityAssignment::retrieveAssigneeIdsByActivityId($key);
-        $assigneeContact = [];
-        foreach ($assignee as $values) {
-          $assigneeContact[] = CRM_Contact_BAO_Contact::displayName($values);
-        }
+        $assigneeContact = CRM_Activity_BAO_ActivityAssignment::getAssigneeNames([$key], TRUE);
         $contactDetails[$key]['assignee_display_name'] = !empty($assigneeContact) ? implode(';', $assigneeContact) : NULL;
       }
     }
index 66607cbd512a3defa9bb28a290a87f5a4520de37..c5ff3964f317166ba034601536c4bc52c3136f41 100644 (file)
  */
 class CRM_Activity_BAO_ActivityAssignmentTest extends CiviUnitTestCase {
 
-  /**
-   *  Pass zero as an id and make sure no Assignees are retrieved.
-   */
-  public function testRetrieveAssigneeIdsByActivityIdNoId() {
-    $activity = $this->activityCreate();
-    $activityId = CRM_Activity_BAO_ActivityAssignment::retrieveAssigneeIdsByActivityId(0);
-
-    $this->assertEquals(count($activityId), 0, '0 assignees retrieved');
-  }
-
-  /**
-   *  Pass null as an id and make sure no Assignees are retrieved.
-   */
-  public function testRetrieveAssigneeIdsByActivityIdNullId() {
-    $activity = $this->activityCreate();
-    $activityId = CRM_Activity_BAO_ActivityAssignment::retrieveAssigneeIdsByActivityId(NULL);
-
-    $this->assertEquals(count($activityId), 0, '0 assignees retrieved using null');
-  }
-
-  /**
-   *  Pass a string as an id and make sure no Assignees are retrieved.
-   */
-  public function testRetrieveAssigneeIdsByActivityIdString() {
-    $activity = $this->activityCreate();
-    $activityId = CRM_Activity_BAO_ActivityAssignment::retrieveAssigneeIdsByActivityId('test');
-
-    $this->assertEquals(count($activityId), 0, '0 assignees retrieved using string');
-  }
-
-  /**
-   *  Pass a known activity id as an id and make sure 1 Assignees is retrieved
-   */
-  public function testRetrieveAssigneeIdsByActivityIdOneId() {
-    $activity = $this->activityCreate();
-    $activityId = CRM_Activity_BAO_ActivityAssignment::retrieveAssigneeIdsByActivityId($activity['id']);
-
-    $this->assertEquals(count($activityId), 1, 'One record retrieved');
-  }
-
   /**
    *  Pass zero as an id and make sure no Assignees are retrieved.
    */
diff --git a/tests/phpunit/CRM/Activity/BAO/ActivityTargetTest.php b/tests/phpunit/CRM/Activity/BAO/ActivityTargetTest.php
deleted file mode 100644 (file)
index fb504ac..0000000
+++ /dev/null
@@ -1,36 +0,0 @@
-<?php
-/*
- +--------------------------------------------------------------------+
- | Copyright CiviCRM LLC. All rights reserved.                        |
- |                                                                    |
- | This work is published under the GNU AGPLv3 license with some      |
- | permitted exceptions and without any warranty. For full license    |
- | and copyright information, see https://civicrm.org/licensing       |
- +--------------------------------------------------------------------+
- */
-
-/**
- * Test class for CRM_Activity_BAO_ActivityTarget BAO
- *
- * @package   CiviCRM
- * @group headless
- */
-class CRM_Activity_BAO_ActivityTargetTest extends CiviUnitTestCase {
-
-  public function testRetrieveTargetIdsByActivityIdZeroID() {
-    $this->activityCreate();
-    $target = CRM_Activity_BAO_ActivityTarget::retrieveTargetIdsByActivityId(0);
-    $this->assertSame($target, [], 'No targets returned');
-  }
-
-  public function testRetrieveTargetIdsByActivityIdOneID() {
-    $activity = $this->activityCreate();
-
-    $targetIDs = CRM_Activity_BAO_ActivityTarget::retrieveTargetIdsByActivityId($activity['id']);
-
-    // assert that we have at least one targetID
-    $this->assertEquals(count($targetIDs), 1, 'One target ID match for activity');
-    $this->assertEquals($targetIDs[0], $activity['target_contact_id'], 'The returned target contacts ids match');
-  }
-
-}