Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 16 |
|
0.00% |
0 / 2 |
CRAP | |
0.00% |
0 / 1 |
Relationship | |
0.00% |
0 / 16 |
|
0.00% |
0 / 2 |
6 | |
0.00% |
0 / 1 |
__construct | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
2 | |||
getRelationshipIdByContactId | |
0.00% |
0 / 13 |
|
0.00% |
0 / 1 |
2 |
1 | <?php |
2 | |
3 | namespace Drupal\crm; |
4 | |
5 | use Drupal\Core\Entity\EntityTypeManagerInterface; |
6 | |
7 | /** |
8 | * Service description. |
9 | */ |
10 | class Relationship { |
11 | |
12 | /** |
13 | * The entity type manager. |
14 | * |
15 | * @var \Drupal\Core\Entity\EntityTypeManagerInterface |
16 | */ |
17 | protected $entityTypeManager; |
18 | |
19 | |
20 | /** |
21 | * The relationship storage. |
22 | * |
23 | * @var \Drupal\Core\Entity\EntityStorageInterface |
24 | */ |
25 | protected $relationshipStorage; |
26 | |
27 | /** |
28 | * Constructs a Relationship object. |
29 | * |
30 | * @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager |
31 | * The entity type manager. |
32 | */ |
33 | public function __construct(EntityTypeManagerInterface $entity_type_manager) { |
34 | $this->entityTypeManager = $entity_type_manager; |
35 | $this->relationshipStorage = $entity_type_manager |
36 | ->getStorage('crm_relationship'); |
37 | } |
38 | |
39 | /** |
40 | * Method description. |
41 | */ |
42 | public function getRelationshipIdByContactId(int $contact_id) { |
43 | $query = $this->relationshipStorage->getQuery(); |
44 | $contact_a_ids = $query |
45 | ->condition('status', 1) |
46 | ->condition('contact_a', $contact_id) |
47 | ->accessCheck(TRUE) |
48 | ->execute(); |
49 | |
50 | $query = $this->relationshipStorage->getQuery(); |
51 | $contact_b_ids = $query |
52 | ->condition('status', 1) |
53 | ->condition('contact_b', $contact_id) |
54 | ->accessCheck(TRUE) |
55 | ->execute(); |
56 | |
57 | return array_merge($contact_a_ids, $contact_b_ids); |
58 | } |
59 | |
60 | } |