| @@ 7-77 (lines=71) @@ | ||
| 4 | ||
| 5 | use TestMonitor\ActiveCampaign\Resources\Tag; |
|
| 6 | ||
| 7 | trait ManagesTags |
|
| 8 | { |
|
| 9 | use ImplementsActions; |
|
| 10 | ||
| 11 | /** |
|
| 12 | * Get all tags. |
|
| 13 | * |
|
| 14 | * @return array |
|
| 15 | */ |
|
| 16 | public function tags() |
|
| 17 | { |
|
| 18 | return $this->transformCollection( |
|
| 19 | $this->get('tags'), |
|
| 20 | Tag::class, |
|
| 21 | 'tags' |
|
| 22 | ); |
|
| 23 | } |
|
| 24 | ||
| 25 | /** |
|
| 26 | * Find tag by name. |
|
| 27 | * |
|
| 28 | * @param string $name |
|
| 29 | * |
|
| 30 | * @return array |
|
| 31 | */ |
|
| 32 | public function findTag($name) |
|
| 33 | { |
|
| 34 | $tags = $this->transformCollection( |
|
| 35 | $this->get('tags', ['query' => ['search' => $name]]), |
|
| 36 | Tag::class, |
|
| 37 | 'tags' |
|
| 38 | ); |
|
| 39 | ||
| 40 | return array_shift($tags); |
|
| 41 | } |
|
| 42 | ||
| 43 | /** |
|
| 44 | * Create new tag. |
|
| 45 | * |
|
| 46 | * @param array $data |
|
| 47 | * |
|
| 48 | * @return Tag |
|
| 49 | */ |
|
| 50 | public function createTag(array $data = []) |
|
| 51 | { |
|
| 52 | $tags = $this->transformCollection( |
|
| 53 | $this->post('tags', ['json' => ['tag' => $data]]), |
|
| 54 | Tag::class |
|
| 55 | ); |
|
| 56 | ||
| 57 | return array_shift($tags); |
|
| 58 | } |
|
| 59 | ||
| 60 | /** |
|
| 61 | * Find or create a tag. |
|
| 62 | * |
|
| 63 | * @param string $name |
|
| 64 | * |
|
| 65 | * @return Tag |
|
| 66 | */ |
|
| 67 | public function findOrCreateTag($name) |
|
| 68 | { |
|
| 69 | $tag = $this->findTag($name); |
|
| 70 | ||
| 71 | if ($tag instanceof Tag) { |
|
| 72 | return $tag; |
|
| 73 | } |
|
| 74 | ||
| 75 | return $this->createTag(['tag' => $name]); |
|
| 76 | } |
|
| 77 | } |
|
| 78 | ||
| @@ 8-78 (lines=71) @@ | ||
| 5 | use TestMonitor\ActiveCampaign\Resources\Organization; |
|
| 6 | ||
| 7 | /** @deprecated use ManageAccounts instead */ |
|
| 8 | trait ManagesOrganizations |
|
| 9 | { |
|
| 10 | use ImplementsActions; |
|
| 11 | ||
| 12 | /** |
|
| 13 | * Get all organizations. |
|
| 14 | * |
|
| 15 | * @deprecated use accounts() instead |
|
| 16 | * @return array |
|
| 17 | */ |
|
| 18 | public function organizations() |
|
| 19 | { |
|
| 20 | return $this->transformCollection( |
|
| 21 | $this->get('organizations'), |
|
| 22 | Organization::class, |
|
| 23 | 'organizations' |
|
| 24 | ); |
|
| 25 | } |
|
| 26 | ||
| 27 | /** |
|
| 28 | * Find organization by name. |
|
| 29 | * |
|
| 30 | * @param string $name |
|
| 31 | * |
|
| 32 | * @deprecated use findAccount() instead |
|
| 33 | * @return Organization|null |
|
| 34 | */ |
|
| 35 | public function findOrganization($name) |
|
| 36 | { |
|
| 37 | $organizations = $this->transformCollection( |
|
| 38 | $this->get('organizations', ['query' => ['filters' => ['name' => $name]]]), |
|
| 39 | Organization::class, |
|
| 40 | 'organizations' |
|
| 41 | ); |
|
| 42 | ||
| 43 | return array_shift($organizations); |
|
| 44 | } |
|
| 45 | ||
| 46 | /** |
|
| 47 | * Create new organization. |
|
| 48 | * |
|
| 49 | * @param array $data |
|
| 50 | * |
|
| 51 | * @deprecated use createAccount() instead |
|
| 52 | * @return Organization|null |
|
| 53 | */ |
|
| 54 | public function createOrganization(array $data = []) |
|
| 55 | { |
|
| 56 | $organizations = $this->transformCollection( |
|
| 57 | $this->post('organizations', ['json' => ['organization' => $data]]), |
|
| 58 | Organization::class |
|
| 59 | ); |
|
| 60 | ||
| 61 | return array_shift($organizations); |
|
| 62 | } |
|
| 63 | ||
| 64 | /** |
|
| 65 | * Find or create an organization. |
|
| 66 | * |
|
| 67 | * @param $name |
|
| 68 | * |
|
| 69 | * @deprecated use findOrCreateAccount() instead |
|
| 70 | * @return Organization |
|
| 71 | */ |
|
| 72 | public function findOrCreateOrganization($name) |
|
| 73 | { |
|
| 74 | $organization = $this->findOrganization($name); |
|
| 75 | ||
| 76 | if ($organization instanceof Organization) { |
|
| 77 | return $organization; |
|
| 78 | } |
|
| 79 | ||
| 80 | return $this->createOrganization(['name' => $name]); |
|
| 81 | } |
|