--- /dev/null
+<?php
+
+ require_once('protected/required.php');
+
+ class PdoChangelogManager extends AbstractPdoManager {
+
+ public function createChangelog($changelog) {
+
+ $query = $this -> pdo -> prepare(
+ 'INSERT INTO changelogs (warnings, versions) VALUES (:warnings, :versions)'
+ );
+ $query -> bindValue(':warnings', implode("|", $changelog -> getWarnings()));
+ $query -> bindValue(':versions', implode("|", $changelog -> getVersions()));
+ $query -> execute();
+ $query -> closeCursor();
+ }
+
+ public function updateChangelog($changelog) {
+
+ $query = $this -> pdo -> prepare(
+ 'UPDATE changelogs SET
+ warnings = :warnings,
+ versions = :versions
+ WHERE id = :id'
+ );
+ $query -> bindValue(':id', $changelog -> getId());
+ $query -> bindValue(':warnings', implode("|", $changelog -> getWarnings()));
+ $query -> bindValue(':versions', implode("|", $changelog -> getVersions()));
+ $query -> execute();
+ $query -> closeCursor();
+ }
+
+ public function getChangelog($id) {
+
+ $query = $this -> pdo -> prepare('SELECT * FROM changelogs WHERE id = :id');
+ $query -> bindValue(':id', $id);
+ $query -> execute();
+
+ $result = $query -> fetch(PDO::FETCH_ASSOC);
+ $changelog = new Changelog($result['id'], explode("|", $result['warnings']), explode("|", $result['versions']));
+
+ $query->closeCursor();
+
+ return $changelog;
+ }
+
+ public function getLastChangelog() {
+
+ $query = $this -> pdo -> prepare('SELECT * FROM changelogs WHERE id = LAST_INSERT_ID()');
+ $query -> execute();
+
+ $result = $query -> fetch(PDO::FETCH_ASSOC);
+ $changelog = new Changelog($result['id'], explode("|", $result['warnings']), explode("|", $result['versions']));
+
+ $query->closeCursor();
+
+ return $changelog;
+ }
+
+ public function getChangelogs() {
+
+ $query = $this -> pdo -> prepare('SELECT * FROM changelogs');
+ $query -> execute();
+
+ $results = $query -> fetchAll(PDO::FETCH_ASSOC);
+ $changelogs = array();
+ foreach ($results as $result) {
+ $changelogs[] = new Changelog($result['id'], explode("|", $result['warnings']), explode("|", $result['versions']));
+ }
+
+ $query->closeCursor();
+
+ return $changelogs;
+ }
+
+ public function removeChangelog($changelog) {
+
+ $query = $this -> pdo -> prepare('DELETE FROM changelog WHERE id = :id');
+ $query -> bindValue('id', $changelog -> getId());
+ $query -> execute();
+
+ }
+
+ public function findLastVersion() {
+
+ $query = $this -> pdo -> prepare('SELECT versions FROM changelogs');
+ $query -> execute();
+
+ // GETTING LAST DECLARED VERSION ID
+ $lastVersionId = null;
+ $results = $query -> fetchAll(PDO::FETCH_ASSOC);
+ foreach ($results as $result) {
+ $versionArray = explode(';',$result['versions']);
+ $versionId = $versionArray[0];
+ $versionDeclaration = $versionArray[1];
+ if(!isset($lastVersionDeclaration) || $versionDeclaration > $lastVersionDeclaration) {
+ $lastVersionDeclaration = $versionDeclaration;
+ $lastVersionId = $versionId;
+ }
+ }
+ $query->closeCursor();
+
+ // GETTING VERSION
+ $versionManager = new PdoVersionManager();
+ if(isset($lastVersionId)) {
+ $version = $versionManager->getVersion($lastVersionId);
+ } else {
+ $version = new Version();
+ }
+ return $version;
+ }
+
+ public function findLastVersionDeclaration() {
+
+ $query = $this -> pdo -> prepare('SELECT versions FROM changelogs');
+ $query -> execute();
+
+ // GETTING LAST VERSION DECLARATION
+ $lastVersionDeclaration = null;
+ $results = $query -> fetchAll(PDO::FETCH_ASSOC);
+ foreach ($results as $result) {
+ $versionArray = explode(';',$result['versions']);
+ $versionDeclaration = $versionArray[1];
+ if(!isset($lastVersionDeclaration) || $versionDeclaration > $lastVersionDeclaration) {
+ $lastVersionDeclaration = $versionDeclaration;
+ }
+ }
+ $query->closeCursor();
+
+ return $lastVersionDeclaration;
+ }
+
+ }
+