raspisms/controllers/internals/Phone.php

147 lines
4.3 KiB
PHP
Raw Normal View History

2019-11-10 22:56:26 +01:00
<?php
/*
* This file is part of RaspiSMS.
*
* (c) Pierre-Lin Bonnemaison <plebwebsas@gmail.com>
*
* This source file is subject to the GPL-3.0 license that is bundled
* with this source code in the file LICENSE.
*/
namespace controllers\internals;
class Phone extends \descartes\InternalController
{
private $model_phone;
private $internal_event;
public function __construct(\PDO $bdd)
{
$this->model_phone = new \models\Phone($bdd);
$this->internal_event = new \controllers\internals\Event($bdd);
}
2019-11-12 05:16:59 +01:00
/**
* Return list of phones
* @param int $id_user : User id
* @param mixed(int|bool) $nb_entry : Number of entry to return
* @param mixed(int|bool) $page : Numero of page
*
* @return array|bool : List of user or false
*/
public function list(int $id_user, ?int $nb_entry = null, ?int $page = null)
{
return $this->model_phone->list($id_user, $nb_entry, $page * $nb_entry);
}
2019-11-10 22:56:26 +01:00
/**
* Return a phone
* @param int $id : id of the phone
* @return array
*/
public function get (int $id)
{
2019-11-12 05:16:59 +01:00
return $this->model_phone->get($id);
}
/**
* Return a phone by is number
* @param string $number : phone number
* @return array
*/
public function get_by_number (string $number)
{
return $this->model_phone->get_by_number($number);
}
/**
* Return a phone by his number and user
* @param string $number : phone number
* @param int $id_user : user id
* @return array
*/
public function get_by_number_and_user (string $number, int $id_user)
{
return $this->model_phone->get_by_number_and_user($number, $id_user);
2019-11-10 22:56:26 +01:00
}
/**
* Return phones of a user
* @param int $id_user : id of the user
* @return array
*/
public function gets_for_user (int $id_user)
{
2019-11-12 05:16:59 +01:00
return $this->model_phone->gets_for_user($id_user);
2019-11-10 22:56:26 +01:00
}
/**
* Return all phones
* @return array
*/
public function get_all ()
{
2019-11-12 05:16:59 +01:00
return $this->model_phone->get_all();
2019-11-10 22:56:26 +01:00
}
/**
* Delete a phone
* @param int $id : Phone id
* @return bool
*/
2019-11-12 05:16:59 +01:00
public function delete (int $id) : bool
2019-11-10 22:56:26 +01:00
{
return (bool) $this->model_phone->delete($id);
}
/**
* Create a phone
* @param int $id_user : User to insert phone for
* @param string $number : The number of the phone
2019-11-12 05:16:59 +01:00
* @param string $adapter : The adapter to use the phone
* @param ?string json $adapter_datas : A JSON string representing adapter's datas (for example credentials for an api)
2019-11-10 22:56:26 +01:00
* @return bool : false on error, true on success
*/
2019-11-12 05:16:59 +01:00
public function create (int $id_user, string $number, string $adapter, ?string $adapter_datas) : bool
2019-11-10 22:56:26 +01:00
{
$phone = [
'id_user' => $id_user,
'number' => $number,
2019-11-12 05:16:59 +01:00
'adapter' => $adapter,
'adapter_datas' => $adapter_datas,
2019-11-10 22:56:26 +01:00
];
return (bool) $this->model_phone->insert($phone);
}
/**
* Update a phone
* @param int $id : Phone id
* @param int $id_user : User to insert phone for
* @param string $number : The number of the phone
2019-11-12 05:16:59 +01:00
* @param string $adapter : The adapter to use the phone
* @param array $adapter_datas : An array of the datas of the adapter (for example credentials for an api)
2019-11-10 22:56:26 +01:00
* @return bool : false on error, true on success
*/
2019-11-12 05:16:59 +01:00
public function update (int $id, int $id_user, string $number, string $adapter, array $adapter_datas) : bool
2019-11-10 22:56:26 +01:00
{
$phone = [
'id_user' => $id_user,
'number' => $number,
2019-11-12 05:16:59 +01:00
'adapter' => $adapter,
'adapter_datas' => json_encode($adapter_datas),
2019-11-10 22:56:26 +01:00
];
return (bool) $this->model_phone->update($id, $phone);
}
}