From dee572ab48c56bc7cca8d04363c815f980f01acc Mon Sep 17 00:00:00 2001 From: Benjamin Sonntag Date: Thu, 8 Jan 2015 12:05:29 +0100 Subject: [PATCH] adding proper DOMAIN find function --- lib/Alternc/Api/Legacyobject.php | 4 +++- lib/Alternc/Api/Object/Domain.php | 16 +++++++++++----- lib/Alternc/Api/Service.php | 2 +- 3 files changed, 15 insertions(+), 7 deletions(-) diff --git a/lib/Alternc/Api/Legacyobject.php b/lib/Alternc/Api/Legacyobject.php index 3660c567..3e5e2fbe 100644 --- a/lib/Alternc/Api/Legacyobject.php +++ b/lib/Alternc/Api/Legacyobject.php @@ -11,7 +11,8 @@ class Alternc_Api_Legacyobject { protected $admin; // m_admin instance protected $cuid; // current user id protected $isAdmin; // is it an Admin account? - + protected $db; // PDO DB access to AlternC's database. + const ERR_INVALID_ARGUMENT = 111201; const ERR_ALTERNC_FUNCTION = 111202; @@ -21,6 +22,7 @@ class Alternc_Api_Legacyobject { throw new \Exception("Bad argument: service is not an Alternc_Api_Service", self::ERR_INVALID_ARGUMENT); } // We store the global $cuid to AlternC legacy classes + $this->db=$service->db; $this->cuid=$cuid=$service->token->uid; $this->isAdmin=$service->token->isAdmin; // We use the global $admin from AlternC legacy classes diff --git a/lib/Alternc/Api/Object/Domain.php b/lib/Alternc/Api/Object/Domain.php index c498ec3b..2c9fdfa3 100644 --- a/lib/Alternc/Api/Object/Domain.php +++ b/lib/Alternc/Api/Object/Domain.php @@ -35,11 +35,18 @@ class Alternc_Api_Object_Domain extends Alternc_Api_Legacyobject { } else { $uid=$cuid; } - $result=$this->dom->get_domain_list($uid); - if (!$result) { - return $this->alterncLegacyErrorManager(); + if ($uid!=-1) { + $sql=" WHERE compte=$uid "; } else { - $offset=-1; $count=-1; + $sql=""; + } + $stmt = $this->db->prepare("SELECT * FROM domaines $sql ORDER BY domaine"); + $stmt->execute(); + $result = array(); + while ($me = $stmt->fetch(PDO::FETCH_OBJ)) { + $result[$me->domaine] = $me; + } + $offset=-1; $count=-1; if (isset($options["count"])) $count=intval($options["count"]); if (isset($options["offset"])) $offset=intval($options["offset"]); if ($offset!=-1 || $count!=-1) { @@ -48,7 +55,6 @@ class Alternc_Api_Object_Domain extends Alternc_Api_Legacyobject { $result= array_slice($result, $offset, $count); } return new Alternc_Api_Response( array("content" =>$result) ); - } } diff --git a/lib/Alternc/Api/Service.php b/lib/Alternc/Api/Service.php index 40d9e345..78a712b9 100644 --- a/lib/Alternc/Api/Service.php +++ b/lib/Alternc/Api/Service.php @@ -9,7 +9,7 @@ class Alternc_Api_Service { - private $db; // PDO object + public $db; // PDO object private $loggerList; // List of loggers private $allowedAuth; // list of allowed authenticators public $token; // Token (useful for called classes)