*/
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.
*
+++ /dev/null
-<?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;
- }
-
-}
$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;
}
}
*/
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.
*/
+++ /dev/null
-<?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');
- }
-
-}