74 lines
2.1 KiB
PHP
74 lines
2.1 KiB
PHP
<?php
|
|
namespace OCA\Gestion\Db;
|
|
|
|
use OCA\Gestion\Constants\OrderStatusConstant;
|
|
use OCA\Gestion\Constants\ThanatoTypeConstant;
|
|
use OCA\Gestion\Helpers\OrderHelpers;
|
|
use OCP\IDBConnection;
|
|
use \Datetime;
|
|
use OCA\Gestion\Constants\BddConstant;
|
|
use Ramsey\Uuid\Uuid;
|
|
|
|
class ProviderRepository {
|
|
private $gestionTablePrefix;
|
|
|
|
private $defaultTablePrefix;
|
|
private IDbConnection $pdo;
|
|
|
|
public function __construct(IDbConnection $db) {
|
|
$this->gestionTablePrefix = BddConstant::DEFAULT_TABLE_PREFIX ."gestion_";
|
|
$this->defaultTablePrefix = BddConstant::DEFAULT_TABLE_PREFIX;
|
|
$this->pdo = $db;
|
|
}
|
|
|
|
private function execSQL($sql, $conditions){
|
|
$stmt = $this->pdo->prepare($sql);
|
|
$stmt->execute($conditions);
|
|
$data = $stmt->fetchAll(\PDO::FETCH_ASSOC);
|
|
$stmt->closeCursor();
|
|
return json_encode($data);
|
|
}
|
|
|
|
private function execSQLNoData($sql, $conditions){
|
|
$stmt = $this->pdo->prepare($sql);
|
|
$stmt->execute($conditions);
|
|
$stmt->closeCursor();
|
|
}
|
|
|
|
private function execSQLNoJsonReturn($sql, $conditions){
|
|
$stmt = $this->pdo->prepare($sql);
|
|
$stmt->execute($conditions);
|
|
$data = $stmt->fetchAll(\PDO::FETCH_ASSOC);
|
|
$stmt->closeCursor();
|
|
return $data;
|
|
}
|
|
|
|
public function getProvidersList(){
|
|
$sql = "SELECT * FROM ".$this->gestionTablePrefix."provider as provider";
|
|
return $this->execSQLNoJsonReturn($sql,[]);
|
|
}
|
|
|
|
public function createDefaultProvider($idNextCloud){
|
|
$sql = "INSERT INTO `".$this->gestionTablePrefix."provider` (
|
|
`id_nextcloud`
|
|
)
|
|
VALUES (?);";
|
|
$this->execSQLNoData($sql, array(
|
|
$idNextCloud
|
|
)
|
|
);
|
|
}
|
|
|
|
public function getProviderCount(){
|
|
$count = 0;
|
|
$sql = "SELECT COUNT(provider.id) as provider_count
|
|
FROM ".$this->gestionTablePrefix."provider as provider;";
|
|
|
|
$result = $this->execSQLNoJsonReturn($sql,[]);
|
|
if(!empty($result)){
|
|
$count = $result[0]["provider_count"];
|
|
}
|
|
return $count;
|
|
}
|
|
|
|
} |