mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-06-01 06:44:37 -04:00
Handle single contact object passed into array
This commit is contained in:
parent
b35bdebccf
commit
84e634c28c
@ -28,9 +28,11 @@ class ClientContactRepository extends BaseRepository
|
|||||||
|
|
||||||
public function save(array $data, Client $client) : void
|
public function save(array $data, Client $client) : void
|
||||||
{
|
{
|
||||||
|
//06-09-2022 sometimes users pass a contact object instead of a nested array, this sequence handles this scenario
|
||||||
if (isset($data['contacts']) && (count($data['contacts']) !== count($data['contacts'], COUNT_RECURSIVE))) {
|
if (isset($data['contacts']) && (count($data['contacts']) !== count($data['contacts'], COUNT_RECURSIVE))) {
|
||||||
|
|
||||||
$contacts = collect($data['contacts']);
|
$contacts = collect($data['contacts']);
|
||||||
|
|
||||||
} elseif(isset($data['contacts'])){
|
} elseif(isset($data['contacts'])){
|
||||||
|
|
||||||
$temp_array[] = $data['contacts'];
|
$temp_array[] = $data['contacts'];
|
||||||
@ -38,7 +40,9 @@ class ClientContactRepository extends BaseRepository
|
|||||||
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|
||||||
$contacts = collect();
|
$contacts = collect();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$client->contacts->pluck('id')->diff($contacts->pluck('id'))->each(function ($contact) {
|
$client->contacts->pluck('id')->diff($contacts->pluck('id'))->each(function ($contact) {
|
||||||
@ -50,13 +54,9 @@ class ClientContactRepository extends BaseRepository
|
|||||||
$this->set_send_email_on_contact = true;
|
$this->set_send_email_on_contact = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
nlog($contacts->toArray());
|
|
||||||
|
|
||||||
/* Set first record to primary - always */
|
/* Set first record to primary - always */
|
||||||
$contacts = $contacts->sortByDesc('is_primary')->map(function ($contact) {
|
$contacts = $contacts->sortByDesc('is_primary')->map(function ($contact) {
|
||||||
|
|
||||||
nlog($contact);
|
|
||||||
|
|
||||||
$contact['is_primary'] = $this->is_primary;
|
$contact['is_primary'] = $this->is_primary;
|
||||||
$this->is_primary = false;
|
$this->is_primary = false;
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user