mirror of
https://github.com/RaspbianFrance/raspisms.git
synced 2025-06-06 06:46:25 +02:00
Fix and update models for new descartes version
This commit is contained in:
parent
e15fb3cf8c
commit
cf1746ff13
11 changed files with 967 additions and 972 deletions
|
@ -1,18 +1,19 @@
|
|||
<?php
|
||||
namespace models;
|
||||
/**
|
||||
namespace models;
|
||||
|
||||
/**
|
||||
* Cette classe gère les accès bdd pour les contactes
|
||||
*/
|
||||
class Contact extends \Model
|
||||
*/
|
||||
class Contact extends \descartes\Model
|
||||
{
|
||||
/**
|
||||
* Retourne une entrée par son id
|
||||
* @param int $id : L'id de l'entrée
|
||||
* @return array : L'entrée
|
||||
*/
|
||||
public function get_by_id ($id)
|
||||
public function get_by_id($id)
|
||||
{
|
||||
$contacts = $this->select('contact', ['id' => $id]);
|
||||
$contacts = $this->_select('contact', ['id' => $id]);
|
||||
return isset($contacts[0]) ? $contacts[0] : false;
|
||||
}
|
||||
|
||||
|
@ -21,9 +22,9 @@
|
|||
* @param string $number : Le numéro de tél
|
||||
* @return array : L'entrée
|
||||
*/
|
||||
public function get_by_number ($number)
|
||||
public function get_by_number($number)
|
||||
{
|
||||
$contacts = $this->select('contact', ['number' => $number]);
|
||||
$contacts = $this->_select('contact', ['number' => $number]);
|
||||
return isset($contacts[0]) ? $contacts[0] : false;
|
||||
}
|
||||
|
||||
|
@ -32,56 +33,56 @@
|
|||
* @param string $name : Le numéro de tél
|
||||
* @return array : L'entrée
|
||||
*/
|
||||
public function get_by_name ($name)
|
||||
public function get_by_name($name)
|
||||
{
|
||||
$contacts = $this->select('contact', ['name' => $name]);
|
||||
$contacts = $this->_select('contact', ['name' => $name]);
|
||||
return isset($contacts[0]) ? $contacts[0] : false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retourne une liste de contactes sous forme d'un tableau
|
||||
/**
|
||||
* Retourne une liste de contactes sous forme d'un tableau
|
||||
* @param int $limit : Nombre de résultat maximum à retourner
|
||||
* @param int $offset : Nombre de résultat à ingnorer
|
||||
*/
|
||||
public function get_list ($limit, $offset)
|
||||
*/
|
||||
public function get_list($limit, $offset)
|
||||
{
|
||||
$contacts = $this->select('contact', [], '', false, $limit, $offset);
|
||||
$contacts = $this->_select('contact', [], '', false, $limit, $offset);
|
||||
|
||||
return $contacts;
|
||||
}
|
||||
return $contacts;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retourne une liste de contactes sous forme d'un tableau
|
||||
* Retourne une liste de contactes sous forme d'un tableau
|
||||
* @param array $ids : un ou plusieurs id d'entrées à récupérer
|
||||
* @return array : La liste des entrées
|
||||
*/
|
||||
public function get_by_ids ($ids)
|
||||
*/
|
||||
public function get_by_ids($ids)
|
||||
{
|
||||
$query = "
|
||||
$query = "
|
||||
SELECT * FROM contact
|
||||
WHERE id ";
|
||||
|
||||
//On génère la clause IN et les paramètres adaptés depuis le tableau des id
|
||||
$generated_in = $this->generateInFromArray($ids);
|
||||
//On génère la clause IN et les paramètres adaptés depuis le tableau des id
|
||||
$generated_in = $this->_generate_in_from_array($ids);
|
||||
$query .= $generated_in['QUERY'];
|
||||
$params = $generated_in['PARAMS'];
|
||||
|
||||
return $this->runQuery($query, $params);
|
||||
return $this->_run_query($query, $params);
|
||||
}
|
||||
|
||||
/**
|
||||
* Supprimer un contact par son id
|
||||
* @param array $id : un ou plusieurs id d'entrées à supprimer
|
||||
* @return int : Le nombre de lignes supprimées
|
||||
*/
|
||||
public function delete_by_id ($id)
|
||||
*/
|
||||
public function delete_by_id($id)
|
||||
{
|
||||
$query = "
|
||||
$query = "
|
||||
DELETE FROM contact
|
||||
WHERE id = :id";
|
||||
|
||||
$params = ['id' => $id];
|
||||
return $this->runQuery($query, $params, self::ROWCOUNT);
|
||||
return $this->_run_query($query, $params, self::ROWCOUNT);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -89,16 +90,15 @@
|
|||
* @param array $contact : La contacte à insérer avec les champs name, script, admin & admin
|
||||
* @return mixed bool|int : false si echec, sinon l'id de la nouvelle lignée insérée
|
||||
*/
|
||||
public function insert ($contact)
|
||||
public function insert($contact)
|
||||
{
|
||||
$result = $this->insertIntoTable('contact', $contact);
|
||||
$result = $this->_insert('contact', $contact);
|
||||
|
||||
if (!$result)
|
||||
{
|
||||
if (!$result) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return $this->lastId();
|
||||
return $this->_last_id();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -107,17 +107,17 @@
|
|||
* @param array $contact : Les données à mettre à jour pour la contacte
|
||||
* @return int : le nombre de ligne modifiées
|
||||
*/
|
||||
public function update ($id, $contact)
|
||||
public function update($id, $contact)
|
||||
{
|
||||
return $this->updateTableWhere('contact', $contact, ['id' => $id]);
|
||||
return $this->_update('contact', $contact, ['id' => $id]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Compte le nombre d'entrées dans la table contact
|
||||
* @return int : Le nombre de contact
|
||||
*/
|
||||
public function count ()
|
||||
public function count()
|
||||
{
|
||||
return $this->countTable('contact');
|
||||
return $this->_count('contact');
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue