mirror of
https://github.com/RaspbianFrance/raspisms.git
synced 2025-06-07 07:06:26 +02:00
Update all controllers to standard behavior
This commit is contained in:
parent
18c7cb019d
commit
ccfc69baca
25 changed files with 112 additions and 125 deletions
|
@ -70,7 +70,8 @@ namespace controllers\internals;
|
|||
return $result;
|
||||
}
|
||||
|
||||
$this->internal_event->create($id_user, 'CONTACT_ADD', 'Ajout contact : '.$name.' ('.\controllers\internals\Tool::phone_format($number).')');
|
||||
$internal_event = new Event($this->bdd);
|
||||
$internal_event->create($id_user, 'CONTACT_ADD', 'Ajout contact : '.$name.' ('.\controllers\internals\Tool::phone_format($number).')');
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
|
|
@ -24,7 +24,7 @@ namespace controllers\internals;
|
|||
*/
|
||||
protected function get_model () : \descartes\Model
|
||||
{
|
||||
$this->model = $this->model ?? new \models\Event($this->bdd);
|
||||
$this->model = $this->model ?? new \models\Group($this->bdd);
|
||||
return $this->model;
|
||||
}
|
||||
|
||||
|
@ -43,23 +43,22 @@ namespace controllers\internals;
|
|||
'name' => $name,
|
||||
];
|
||||
|
||||
foreach ($contacts_ids as $key => $contact_id)
|
||||
{
|
||||
$contact = $this->get_model()->get_for_user($id_user, $contact_id);
|
||||
if (!$contact)
|
||||
{
|
||||
unset($contacts_ids[$key]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
$id_group = $this->get_model()->insert($group);
|
||||
if (!$id_group)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
$internal_contact = new Contact($this->bdd);
|
||||
foreach ($contacts_ids as $contact_id)
|
||||
{
|
||||
$contact = $internal_contact->get_for_user($id_user, $contact_id);
|
||||
if (!$contact)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
$this->get_model()->insert_group_contact_relation($id_group, $contact_id);
|
||||
}
|
||||
|
||||
|
@ -88,10 +87,11 @@ namespace controllers\internals;
|
|||
|
||||
$this->get_model()->delete_group_contact_relations($id_group);
|
||||
|
||||
$internal_contact = new Contact($this->bdd);
|
||||
$nb_contact_insert = 0;
|
||||
foreach ($contacts_ids as $contact_id)
|
||||
{
|
||||
$contact = $this->get_model()->get_for_user($id_user, $contact_id);
|
||||
$contact = $internal_contact->get_for_user($id_user, $contact_id);
|
||||
if (!$contact)
|
||||
{
|
||||
continue;
|
||||
|
|
|
@ -26,6 +26,17 @@ namespace controllers\internals;
|
|||
}
|
||||
|
||||
|
||||
/**
|
||||
* Return all phones of a user.
|
||||
* @param int $id_user : user id
|
||||
* @return array
|
||||
*/
|
||||
public function gets_for_user (int $id_user)
|
||||
{
|
||||
return $this->get_model()->gets_for_user($id_user);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Return a phone by his number
|
||||
* @param string $number : Phone number
|
||||
|
|
|
@ -91,9 +91,9 @@ namespace controllers\internals;
|
|||
* @param string $origin : Number who sent the message
|
||||
* @return array
|
||||
*/
|
||||
public function gets_by_origin_for_user(int $id_user, string $origin)
|
||||
public function gets_by_origin_and_user(int $id_user, string $origin)
|
||||
{
|
||||
return $this->get_model()->gets_by_origin_for_user($id_user, $origin);
|
||||
return $this->get_model()->gets_by_origin_and_user($id_user, $origin);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -73,26 +73,28 @@ namespace controllers\internals;
|
|||
$this->get_model()->insert_scheduled_number($id_scheduled, $number);
|
||||
}
|
||||
|
||||
$internal_contact = new Contact($this->bdd);
|
||||
foreach ($contacts_ids as $contact_id)
|
||||
{
|
||||
$find_contact = $this->get_model()->get_for_user($id_user, $contact_id);
|
||||
$find_contact = $internal_contact->get_for_user($id_user, $contact_id);
|
||||
if (!$find_contact)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
$this->get_model()->insert_scheduled_contact($id_scheduled, $contact_id);
|
||||
$this->get_model()->insert_scheduled_contact_relation($id_scheduled, $contact_id);
|
||||
}
|
||||
|
||||
$internal_group = new Group($this->bdd);
|
||||
foreach ($groups_ids as $group_id)
|
||||
{
|
||||
$find_group = $this->get_model()->get_for_user($id_user, $group_id);
|
||||
$find_group = $internal_group->get_for_user($id_user, $group_id);
|
||||
if (!$find_group)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
$this->get_model()->insert_scheduled_group($id_scheduled, $group_id);
|
||||
$this->get_model()->insert_scheduled_group_relation($id_scheduled, $group_id);
|
||||
}
|
||||
|
||||
return $id_scheduled;
|
||||
|
@ -122,6 +124,7 @@ namespace controllers\internals;
|
|||
'flash' => $flash,
|
||||
];
|
||||
|
||||
|
||||
if ($origin)
|
||||
{
|
||||
$internal_phone = new Phone($this->bdd);
|
||||
|
@ -135,35 +138,37 @@ namespace controllers\internals;
|
|||
|
||||
$success = (bool) $this->get_model()->update_for_user($id_user, $id_scheduled, $scheduled);
|
||||
|
||||
$this->model_scheduled->delete_scheduled_numbers($id);
|
||||
$this->model_scheduled->delete_scheduled_contacts($id);
|
||||
$this->model_scheduled->delete_scheduled_groups($id);
|
||||
$this->get_model()->delete_scheduled_numbers($id_scheduled);
|
||||
$this->get_model()->delete_scheduled_contact_relations($id_scheduled);
|
||||
$this->get_model()->delete_scheduled_group_relations($id_scheduled);
|
||||
|
||||
foreach ($numbers as $number)
|
||||
{
|
||||
$this->get_model()->insert_scheduled_number($id_scheduled, $number);
|
||||
}
|
||||
|
||||
|
||||
$internal_contact = new Contact($this->bdd);
|
||||
foreach ($contacts_ids as $contact_id)
|
||||
{
|
||||
$find_contact = $this->get_model()->get_for_user($id_user, $contact_id);
|
||||
$find_contact = $internal_contact->get_for_user($id_user, $contact_id);
|
||||
if (!$find_contact)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
$this->get_model()->insert_scheduled_contact($id_scheduled, $contact_id);
|
||||
$this->get_model()->insert_scheduled_contact_relation($id_scheduled, $contact_id);
|
||||
}
|
||||
|
||||
$internal_group = new Group($this->bdd);
|
||||
foreach ($groups_ids as $group_id)
|
||||
{
|
||||
$find_group = $this->get_model()->get_for_user($id_user, $group_id);
|
||||
$find_group = $internal_group->get_for_user($id_user, $group_id);
|
||||
if (!$find_group)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
$this->get_model()->insert_scheduled_group($id_scheduled, $group_id);
|
||||
$this->get_model()->insert_scheduled_group_relation($id_scheduled, $group_id);
|
||||
}
|
||||
|
||||
return true;
|
||||
|
@ -177,9 +182,9 @@ namespace controllers\internals;
|
|||
* @param string $number : Number for which we want messages
|
||||
* @return array
|
||||
*/
|
||||
public function get_before_date_for_number_and_user (int $id_user, $date, string $number)
|
||||
public function gets_before_date_for_number_and_user (int $id_user, $date, string $number)
|
||||
{
|
||||
return $this->get_model()->get_before_date_for_number_and_user($id_user, $date, $number);
|
||||
return $this->get_model()->gets_before_date_for_number_and_user($id_user, $date, $number);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -112,9 +112,9 @@ namespace controllers\internals;
|
|||
* @param string $origin : Number who sent the message
|
||||
* @return array
|
||||
*/
|
||||
public function gets_by_destination_for_user(int $id_user, string $origin)
|
||||
public function gets_by_destination_and_user(int $id_user, string $origin)
|
||||
{
|
||||
return $this->get_model()->gets_by_destination_for_user($id_user, $origin);
|
||||
return $this->get_model()->gets_by_destination_and_user($id_user, $origin);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -34,6 +34,18 @@ namespace controllers\internals;
|
|||
{
|
||||
return $this->get_model()->get($id);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Return a entry by his id and a user
|
||||
* @param int $id_user : Entry id
|
||||
* @param int $id : Entry id
|
||||
* @return array
|
||||
*/
|
||||
public function get_for_user (int $id_user, int $id)
|
||||
{
|
||||
return $this->get_model()->get_for_user($id_user, $id);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue