2019-11-12 20:46:45 +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;
|
|
|
|
|
|
|
|
abstract class StandardController extends \descartes\InternalController
|
|
|
|
{
|
2020-01-17 18:36:53 +01:00
|
|
|
protected $bdd;
|
|
|
|
|
2020-04-02 19:10:54 +02:00
|
|
|
public function __construct(?\PDO $bdd = null)
|
2019-11-12 20:46:45 +01:00
|
|
|
{
|
2020-06-23 21:06:13 +02:00
|
|
|
if (null === $bdd)
|
2020-04-02 19:10:54 +02:00
|
|
|
{
|
|
|
|
$bdd = \descartes\Model::_connect(DATABASE_HOST, DATABASE_NAME, DATABASE_USER, DATABASE_PASSWORD);
|
|
|
|
}
|
2019-11-12 20:46:45 +01:00
|
|
|
$this->bdd = $bdd;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2020-01-17 18:19:25 +01:00
|
|
|
* Return all the entries.
|
|
|
|
*
|
2019-12-12 00:56:30 +01:00
|
|
|
* @return array
|
|
|
|
*/
|
2020-01-17 18:19:25 +01:00
|
|
|
public function get_all()
|
2019-12-12 00:56:30 +01:00
|
|
|
{
|
|
|
|
return $this->get_model()->get_all();
|
|
|
|
}
|
|
|
|
|
2019-11-12 20:46:45 +01:00
|
|
|
/**
|
2020-01-17 18:19:25 +01:00
|
|
|
* Return a entry by his id.
|
|
|
|
*
|
2019-11-12 20:46:45 +01:00
|
|
|
* @param int $id : Entry id
|
2020-01-17 18:19:25 +01:00
|
|
|
*
|
2019-11-12 20:46:45 +01:00
|
|
|
* @return array
|
|
|
|
*/
|
2020-01-17 18:19:25 +01:00
|
|
|
public function get(int $id)
|
2019-11-12 20:46:45 +01:00
|
|
|
{
|
|
|
|
return $this->get_model()->get($id);
|
|
|
|
}
|
2020-01-17 18:19:25 +01:00
|
|
|
|
2019-11-15 06:30:23 +01:00
|
|
|
/**
|
2020-01-17 18:19:25 +01:00
|
|
|
* Return a entry by his id and a user.
|
|
|
|
*
|
2019-11-15 06:30:23 +01:00
|
|
|
* @param int $id_user : Entry id
|
2020-01-17 18:19:25 +01:00
|
|
|
* @param int $id : Entry id
|
|
|
|
*
|
2019-11-15 06:30:23 +01:00
|
|
|
* @return array
|
|
|
|
*/
|
2020-01-17 18:19:25 +01:00
|
|
|
public function get_for_user(int $id_user, int $id)
|
2019-11-15 06:30:23 +01:00
|
|
|
{
|
|
|
|
return $this->get_model()->get_for_user($id_user, $id);
|
|
|
|
}
|
2020-01-17 18:19:25 +01:00
|
|
|
|
2020-01-06 23:41:18 +01:00
|
|
|
/**
|
2020-01-17 18:19:25 +01:00
|
|
|
* Return all entries for a user.
|
|
|
|
*
|
2020-01-06 23:41:18 +01:00
|
|
|
* @param int $id_user : Entry id
|
2020-01-17 18:19:25 +01:00
|
|
|
*
|
2020-01-06 23:41:18 +01:00
|
|
|
* @return array
|
|
|
|
*/
|
2020-01-17 18:19:25 +01:00
|
|
|
public function gets_for_user(int $id_user)
|
2020-01-06 23:41:18 +01:00
|
|
|
{
|
|
|
|
return $this->get_model()->gets_for_user($id_user);
|
|
|
|
}
|
2019-11-12 20:46:45 +01:00
|
|
|
|
|
|
|
/**
|
2020-01-17 18:19:25 +01:00
|
|
|
* Return the list of entries for a user.
|
|
|
|
*
|
|
|
|
* @param int $id_user : User id
|
2019-11-12 20:46:45 +01:00
|
|
|
* @param ?int $nb_entry : Number of entry to return
|
|
|
|
* @param ?int $page : Pagination, used to calcul offset, $nb_entry * $page
|
2020-01-17 18:19:25 +01:00
|
|
|
*
|
2019-11-12 20:46:45 +01:00
|
|
|
* @return array : Entrys list
|
|
|
|
*/
|
2020-01-17 18:19:25 +01:00
|
|
|
public function list_for_user(int $id_user, ?int $nb_entry = null, ?int $page = null)
|
2019-11-12 20:46:45 +01:00
|
|
|
{
|
|
|
|
return $this->get_model()->list_for_user($id_user, $nb_entry, $nb_entry * $page);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2020-01-17 18:19:25 +01:00
|
|
|
* Return a list of entries in a group of ids and for a user.
|
|
|
|
*
|
|
|
|
* @param int $id_user : user id
|
|
|
|
* @param array $ids : ids of entries to find
|
|
|
|
*
|
2019-11-12 20:46:45 +01:00
|
|
|
* @return array
|
|
|
|
*/
|
2020-01-17 18:19:25 +01:00
|
|
|
public function gets_in_for_user(int $id_user, array $ids)
|
2019-11-12 20:46:45 +01:00
|
|
|
{
|
|
|
|
return $this->get_model()->gets_in_for_user($id_user, $ids);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2020-01-17 18:19:25 +01:00
|
|
|
* Delete a entry by his id for a user.
|
|
|
|
*
|
2019-11-12 20:46:45 +01:00
|
|
|
* @param int $id_user : User id
|
2020-01-17 18:19:25 +01:00
|
|
|
* @param int $id : Entry id
|
|
|
|
*
|
2019-11-12 20:46:45 +01:00
|
|
|
* @return int : Number of removed rows
|
|
|
|
*/
|
|
|
|
public function delete_for_user(int $id_user, int $id)
|
|
|
|
{
|
|
|
|
return $this->get_model()->delete_for_user($id_user, $id);
|
|
|
|
}
|
2020-01-17 18:19:25 +01:00
|
|
|
|
2019-12-20 18:31:19 +01:00
|
|
|
/**
|
2020-01-17 18:19:25 +01:00
|
|
|
* Delete a entry by his id.
|
|
|
|
*
|
2019-12-20 18:31:19 +01:00
|
|
|
* @param int $id : Entry id
|
2020-01-17 18:19:25 +01:00
|
|
|
*
|
2019-12-20 18:31:19 +01:00
|
|
|
* @return int : Number of removed rows
|
|
|
|
*/
|
2020-01-17 18:19:25 +01:00
|
|
|
public function delete(int $id)
|
2019-12-20 18:31:19 +01:00
|
|
|
{
|
|
|
|
return $this->get_model()->delete($id);
|
|
|
|
}
|
2019-11-12 20:46:45 +01:00
|
|
|
|
|
|
|
/**
|
2020-01-17 18:19:25 +01:00
|
|
|
* Count number of entry for a user.
|
|
|
|
*
|
2019-11-12 20:46:45 +01:00
|
|
|
* @param int $id_user : User id
|
2020-01-17 18:19:25 +01:00
|
|
|
*
|
2019-11-12 20:46:45 +01:00
|
|
|
* @return int : number of entries
|
|
|
|
*/
|
|
|
|
public function count_for_user(int $id_user)
|
|
|
|
{
|
|
|
|
return $this->get_model()->count_for_user($id_user);
|
|
|
|
}
|
2020-01-17 18:19:25 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the model for the Controller.
|
2022-03-15 02:24:28 +01:00
|
|
|
*
|
2021-07-19 20:56:44 +02:00
|
|
|
* @return \models\StandardModel
|
2020-01-17 18:19:25 +01:00
|
|
|
*/
|
2021-07-19 20:55:45 +02:00
|
|
|
abstract protected function get_model();
|
2019-11-12 20:46:45 +01:00
|
|
|
}
|