use Civi\Api4\Event\PostSelectQueryEvent;
use Civi\Api4\Service\Schema\Joinable\CustomGroupJoinable;
use Civi\Api4\Service\Schema\Joinable\Joinable;
+use Civi\Api4\Service\Schema\Joinable\OptionValueJoinable;
use Civi\Api4\Utils\FormattingUtil;
use Civi\Api4\Utils\CoreUtil;
use Civi\Api4\Utils\SelectUtil;
if ($joinable->getJoinType() === Joinable::JOIN_TYPE_ONE_TO_MANY) {
$isMany = TRUE;
}
+ if ($joinable instanceof OptionValueJoinable) {
+ \Civi::log()->warning('Use API pseudoconstant suffix like :name or :label instead of join.', ['civi.tag' => 'deprecated']);
+ }
}
/** @var \Civi\Api4\Service\Schema\Joinable\Joinable $lastLink */
public function testGetAllHousingSupportActivities() {
$results = Activity::get()
->setCheckPermissions(FALSE)
- ->addWhere('activity_type.name', '=', 'Phone Call')
+ ->addWhere('activity_type_id:name', '=', 'Phone Call')
->execute();
$this->assertGreaterThan(0, count($results));
$result = Contact::get()
->setCheckPermissions(FALSE)
->addSelect('first_name')
- ->addSelect("$group.$colorField.label")
- ->addSelect("$group.$foodField.label")
+ ->addSelect("$group.$colorField:label")
+ ->addSelect("$group.$foodField:label")
->addSelect('FinancialStuff.Salary')
- ->addWhere("$group.$foodField.label", 'IN', ['Corn', 'Potatoes'])
+ ->addWhere("$group.$foodField:label", 'IN', ['Corn', 'Potatoes'])
->addWhere('FinancialStuff.Salary', '>', '10000')
->execute()
->first();
- $this->assertEquals('Red', $result["$group.$colorField.label"]);
- $this->assertEquals('Corn', $result["$group.$foodField.label"]);
+ $this->assertEquals('Red', $result["$group.$colorField:label"]);
+ $this->assertEquals('Corn', $result["$group.$foodField:label"]);
$this->assertEquals(50000, $result['FinancialStuff.Salary']);
}
->setCheckPermissions(FALSE)
->addSelect('first_name')
->addSelect('last_name')
- ->addSelect("$group.$colorField.label")
- ->addSelect("$group.$foodField.label")
+ ->addSelect("$group.$colorField:label")
+ ->addSelect("$group.$foodField:label")
->addSelect('FinancialStuff.Salary')
- ->addWhere("$group.$foodField.label", 'IN', ['Corn', 'Cheese'])
+ ->addWhere("$group.$foodField:label", 'IN', ['Corn', 'Cheese'])
->execute();
$blueCheese = NULL;
}
}
- $this->assertEquals('Blue', $blueCheese["$group.$colorField.label"]);
- $this->assertEquals('Cheese', $blueCheese["$group.$foodField.label"]);
+ $this->assertEquals('Blue', $blueCheese["$group.$colorField:label"]);
+ $this->assertEquals('Cheese', $blueCheese["$group.$foodField:label"]);
$this->assertEquals(500000, $blueCheese['FinancialStuff.Salary']);
}
public function testThreeLevelJoin() {
$results = Activity::get()
->setCheckPermissions(FALSE)
- ->addWhere('activity_type.name', '=', 'Phone Call')
+ ->addWhere('activity_type_id:name', '=', 'Phone Call')
->execute();
$this->assertCount(1, $results);
public function readNameByActSubjectJoin_4($cid, $strs) {
$get = ActivityContact::get()
- ->addWhere('activity_contacts.label', '=', 'Activity Source')
+ ->addWhere('record_type_id:label', '=', 'Activity Source')
->addWhere('activity.subject', '=', $strs['api'])
->addSelect('contact.first_name')
->execute();
public function readNameByActSubjectChain_4($cid, $strs) {
$get = ActivityContact::get()
- ->addWhere('activity_contacts.label', '=', 'Activity Source')
+ ->addWhere('record_type_id:label', '=', 'Activity Source')
->addWhere('activity.subject', '=', $strs['api'])
->setSelect(['activity_id', 'contact_id'])
->setChain([
public function readNameByActDetailsJoin_4($cid, $strs) {
$get = ActivityContact::get()
- ->addWhere('activity_contacts.label', '=', 'Activity Source')
+ ->addWhere('record_type_id:label', '=', 'Activity Source')
->addWhere('activity.details', '=', $strs['api'])
->addSelect('contact.first_name')
->execute();
public function readNameByActDetailsChain_4($cid, $strs) {
$get = ActivityContact::get()
- ->addWhere('activity_contacts.label', '=', 'Activity Source')
+ ->addWhere('record_type_id:label', '=', 'Activity Source')
->addWhere('activity.details', '=', $strs['api'])
->setSelect(['activity_id', 'contact_id'])
->setChain([
public function testJoinToPCMOptionValueWillShowLabel() {
$options = OptionValue::get()
- ->addWhere('option_group.name', '=', 'preferred_communication_method')
+ ->addWhere('option_group_id:name', '=', 'preferred_communication_method')
->execute()
->getArrayCopy();
$fetchedContact = Contact::get()
->addWhere('id', 'IN', $contactIds)
- ->addSelect('preferred_communication_method.label')
+ ->addSelect('preferred_communication_method:label')
->execute()
->first();
- $preferredMethod = $fetchedContact['preferred_communication_method'];
- $returnedLabels = array_column($preferredMethod, 'label');
-
- $this->assertEquals($labels, $returnedLabels);
+ $this->assertEquals($labels, $fetchedContact['preferred_communication_method:label']);
}
}
$query->select[] = 'emails.location_type.name';
$query->select[] = 'created_activities.contact_id';
$query->select[] = 'created_activities.activity.subject';
- $query->select[] = 'created_activities.activity.activity_type.name';
+ $query->select[] = 'created_activities.activity.activity_type_id:name';
$query->where[] = ['first_name', '=', 'Single'];
$query->where[] = ['id', '=', $this->getReference('test_contact_1')['id']];
$results = $query->run();
$this->assertArrayHasKey('activity', $firstCreatedActivity);
$firstActivity = $firstCreatedActivity['activity'];
$this->assertContains($firstActivity['subject'], $activitySubjects);
- $this->assertArrayHasKey('activity_type', $firstActivity);
- $activityType = $firstActivity['activity_type'];
- $this->assertArrayHasKey('name', $activityType);
+ $this->assertArrayHasKey('activity_type_id:name', $firstActivity);
$this->assertArrayHasKey('name', $firstResult['emails'][0]['location_type']);
$this->assertArrayHasKey('location_type_id', $firstResult['phones'][0]);
$contacts = Contact::get()
->addWhere('id', 'IN', [$armenianContact['id'], $basqueContact['id']])
- ->addSelect('preferred_language.label')
+ ->addSelect('preferred_language:label')
->addSelect('last_name')
->execute()
->indexBy('last_name')
->getArrayCopy();
- $this->assertEquals($contacts['One']['preferred_language.label'], 'Armenian');
- $this->assertEquals($contacts['Two']['preferred_language.label'], 'Basque');
+ $this->assertEquals($contacts['One']['preferred_language:label'], 'Armenian');
+ $this->assertEquals($contacts['Two']['preferred_language:label'], 'Basque');
}
}
$api = \Civi\API\Request::create('Contact', 'get', ['version' => 4, 'checkPermissions' => FALSE]);
$query = new Api4SelectQuery($api);
$query->select[] = 'first_name';
- $query->select[] = 'preferred_communication_method.label';
+ $query->select[] = 'preferred_communication_method:label';
$query->where[] = ['preferred_communication_method', 'IS NOT NULL'];
$results = $query->run();
$first = array_shift($results);
$keys = array_keys($first);
sort($keys);
- $this->assertEquals(['first_name', 'id', 'preferred_communication_method'], $keys);
- $firstPreferredMethod = array_shift($first['preferred_communication_method']);
+ $this->assertEquals(['first_name', 'id', 'preferred_communication_method:label'], $keys);
+ $firstPreferredMethod = array_shift($first['preferred_communication_method:label']);
$this->assertEquals(
'Phone',
- $firstPreferredMethod['label']
+ $firstPreferredMethod
);
}