Update all controllers get_model

This commit is contained in:
osaajani 2019-11-14 21:44:31 +01:00
parent bc622285a4
commit 27d2a6c5b2
14 changed files with 69 additions and 40 deletions

View File

@ -13,7 +13,7 @@ namespace controllers\internals;
class Command extends StandardController
{
protected $model = false;
protected $model = null;
/**
* Get the model for the Controller

View File

@ -13,7 +13,7 @@ namespace controllers\internals;
class Contact extends StandardController
{
protected $model = false;
protected $model = null;
/**
* Get the model for the Controller
@ -31,7 +31,7 @@ namespace controllers\internals;
* @param string $number : Contact number
* @return array
*/
public function get_by_number_and_user(int $id_user, string $number,)
public function get_by_number_and_user(int $id_user, string $number)
{
return $this->get_model()->get_by_number_and_user($id_user, $number);
}

View File

@ -13,7 +13,7 @@ namespace controllers\internals;
class Event extends StandardController
{
protected $model = false;
protected $model = null;
/**
* Get the model for the Controller

View File

@ -16,7 +16,7 @@ namespace controllers\internals;
*/
class Group extends StandardController
{
protected $model = false;
protected $model = null;
/**
* Get the model for the Controller

View File

@ -13,7 +13,7 @@ namespace controllers\internals;
class Phone extends StandardController
{
protected $model = false;
protected $model = null;
/**
* Get the model for the Controller
@ -31,7 +31,7 @@ namespace controllers\internals;
* @param string $number : Phone number
* @return array
*/
public function get_by_number_and_user(int $id_user, string $number,)
public function get_by_number_and_user(int $id_user, string $number)
{
return $this->model_phone->get_by_number_and_user($id_user, $number);
}

View File

@ -13,7 +13,7 @@ namespace controllers\internals;
class Received extends StandardController
{
protected $model = false;
protected $model = null;
/**
* Get the model for the Controller

View File

@ -13,7 +13,7 @@ namespace controllers\internals;
class Scheduled extends StandardController
{
protected $model = false;
protected $model = null;
/**
* Get the model for the Controller

View File

@ -13,7 +13,7 @@ namespace controllers\internals;
class Sended extends StandardController
{
protected $model = false;
protected $model = null;
/**
* Get the model for the Controller

View File

@ -13,7 +13,7 @@ namespace controllers\internals;
class Setting extends StandardController
{
protected $model = false;
protected $model = null;
/**
* Get the model for the Controller

View File

@ -13,7 +13,7 @@ namespace controllers\internals;
class SmsStop extends StandardController
{
protected $model = false;
protected $model = null;
/**
* Get the model for the Controller

View File

@ -25,20 +25,6 @@ namespace controllers\internals;
abstract protected function get_model () : \descartes\Model;
/**
* Create a new entry
* @return mixed bool|int : False if cannot create entry, id of the new entry else
*/
abstract public function create();
/**
* Update a entry
* @return mixed bool|int : False if cannot update entry, number of modified rows else
*/
abstract public function update_for_user();
/**
* Return a entry by his id
* @param int $id : Entry id
@ -75,18 +61,6 @@ namespace controllers\internals;
}
/**
* Insert a entry
* @param
* @param array $entry : Entry to insert
* @return mixed bool|int : false on error, new entry id else
*/
public function create ($entry)
{
$result = $this->get_model()->insert($entry);
}
/**
* Delete a entry by his id for a user
* @param int $id_user : User id

View File

@ -30,6 +30,29 @@ namespace models;
* @return array
*/
public function get_for_user(int $id_user, int $id)
{
$query = '
SELECT * FROM `' . $this->get_table_name() . '`
WHERE destination IN (SELECT number FROM phone WHERE id_user = :id_user)
AND id = :id
';
$params = [
'id_user' => $id_user,
'id' => $id,
];
$receiveds = $this->_run_query($query, $params);
return $receiveds[0] ?? [];
}
/**
* Return all entries for a user
* @param int $id_user : user id
* @return array
*/
public function gets_for_user(int $id_user)
{
$query = '
SELECT * FROM `' . $this->get_table_name() . '`
@ -41,7 +64,6 @@ namespace models;
];
$receiveds = $this->_run_query($query, $params);
return $receiveds[0] ?? [];
}

View File

@ -30,6 +30,29 @@ namespace models;
* @return array
*/
public function get_for_user(int $id_user, int $id)
{
$query = '
SELECT * FROM `' . $this->get_table_name() . '`
WHERE origin IN (SELECT number FROM phone WHERE id_user = :id_user)
AND id = :id
';
$params = [
'id' => $id,
'id_user' => $id_user,
];
$receiveds = $this->_run_query($query, $params);
return $receiveds[0] ?? [];
}
/**
* Return all entries for a user
* @param int $id_user : user id
* @return array
*/
public function gets_for_user(int $id_user)
{
$query = '
SELECT * FROM `' . $this->get_table_name() . '`
@ -41,7 +64,6 @@ namespace models;
];
$receiveds = $this->_run_query($query, $params);
return $receiveds[0] ?? [];
}

View File

@ -45,6 +45,17 @@ namespace models;
{
return $this->_select_one($this->get_table_name(), ['id' => $id]);
}
/**
* Return all entries for a user
* @param int $id_user : user id
* @return array
*/
public function gets_for_user(int $id_user)
{
return $this->_select($this->get_table_name(), ['id_user' => $id_user]);
}
/**