diff --git a/db.php b/db.php index 841d48b..5e9fbbe 100644 --- a/db.php +++ b/db.php @@ -308,38 +308,27 @@ class DataBase } return null; } - public function getCloudSize(string $ref) + public function getCloudSize() { - $stmt = $this->db->prepare(" - SELECT * - FROM clouds - WHERE code= :code; - "); - $stmt->bindValue(':code', $ref, PDO::PARAM_STR); - $stmt->execute(); - if ($data = $stmt->fetch()) { - return $data['size']; - } - return 0; - } - - public function getCloudText(string $ref) - { - $stmt = $this->db->prepare(" - SELECT * - FROM clouds - WHERE code = :code; - "); - $stmt->bindValue(':code', $ref, PDO::PARAM_STR); - $stmt->execute(); - if ($data = $stmt->fetch()) { - return $data['text']; + if ($this->isCloudSet()) { + return $this->cloud['size']; } return null; } - public function countWords(string $cloud) + public function getCloudText() { + if ($this->isCloudSet()) { + return $this->cloud['text']; + } + return null; + } + + public function countWords() + { + if (!$this->isCloudSet()) { + return null; + } $stmt = $this->db->prepare(" SELECT count(*) as count FROM clouds @@ -347,7 +336,7 @@ class DataBase ON id_cloud = cloud_id WHERE code = :code; "); - $stmt->bindValue(':code', $cloud, PDO::PARAM_STR); + $stmt->bindValue(':code', $this->cloud['code'], PDO::PARAM_STR); $stmt->execute(); if ($data = $stmt->fetch()) { return $data['count']; diff --git a/index.php b/index.php index 470eb15..ced4ef2 100644 --- a/index.php +++ b/index.php @@ -4,12 +4,12 @@ include('templates/header.php'); if (isset($_GET['id'])) { $id = $_GET['id']; - if (!$db->isCloud($id)) { + if (!$db->loadCloud($id)) { echo L::cloud_noId; return; } - $nbWords = $db->getCloudSize($id); - echo sprintf('
%s
', $db->getCloudText($id)); + $nbWords = $db->getCloudSize(); + echo sprintf('%s
', $db->getCloudText()); ?>