Save the cloud after the creation

This commit is contained in:
Gregory Trolliet 2020-11-25 22:28:36 +01:00
parent fea36cb867
commit 3fbeb06948

23
db.php
View file

@ -215,6 +215,13 @@ class DataBase
} catch (PDOEXception $e) { } catch (PDOEXception $e) {
return false; return false;
} }
$this->cloud = array(
'id' => $this->db->lastInsertId(),
'code' => $ref,
'size' => $size,
'delete_t' => $duration,
'text' => $text,
);
return true; return true;
} }
public function loadCloud($ref) public function loadCloud($ref)
@ -225,6 +232,11 @@ class DataBase
return $this->loadCloudByCode($ref); return $this->loadCloudByCode($ref);
} }
} }
/**
* Load the cloud by its id
* @param int $id code of the cloud
* @return boolean True if the loading is done, False otherwise
*/
public function loadCloudById(int $id) public function loadCloudById(int $id)
{ {
$stmt = $this->db->prepare(" $stmt = $this->db->prepare("
@ -240,19 +252,24 @@ class DataBase
'code' => $data['code'], 'code' => $data['code'],
'size' => $data['size'], 'size' => $data['size'],
'delete_t' => $data['delete_t'], 'delete_t' => $data['delete_t'],
'text' => $data['test'], 'text' => $data['text'],
); );
return true; return true;
} }
$this->cloud = null; $this->cloud = null;
return false; return false;
} }
/**
* Load the cloud by its code
* @param string $code code of the cloud
* @return boolean True if the loading is done, False otherwise
*/
public function loadCloudByCode(string $code) public function loadCloudByCode(string $code)
{ {
$stmt = $this->db->prepare(" $stmt = $this->db->prepare("
SELECT * SELECT *
FROM clouds FROM clouds
WHERE code= :code; WHERE code = :code;
"); ");
$stmt->bindValue(':code', $code, PDO::PARAM_STR); $stmt->bindValue(':code', $code, PDO::PARAM_STR);
$stmt->execute(); $stmt->execute();
@ -262,7 +279,7 @@ class DataBase
'code' => $data['code'], 'code' => $data['code'],
'size' => $data['size'], 'size' => $data['size'],
'delete_t' => $data['delete_t'], 'delete_t' => $data['delete_t'],
'text' => $data['test'], 'text' => $data['text'],
); );
return true; return true;
} }