Skip to content

Commit

Permalink
Installations worked. Fixed many bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
Kero76 committed Dec 22, 2016
1 parent e8e4614 commit a460c82
Show file tree
Hide file tree
Showing 25 changed files with 333 additions and 108 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ public function buildDomain(array $services) {
)->getForms(),
'user' => $user,
'connect' => true,
'categories' => $services['dao.category']->findAll(),
'website' => $website,
'theme' => $theme,
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,17 @@ public function buildDomain(array $services) {

if ($services['session.handler']->requestFieldExist('user_id')) {
$domains = array(
'user' => $services['dao.user']->findById($services['session.handler']->getRequestField('user_id')),
'connect' => true,
'website' => $website,
'theme' => $theme,
'user' => $services['dao.user']->findById($services['session.handler']->getRequestField('user_id')),
'categories' => $services['dao.category']->findAll(),
'connect' => true,
'website' => $website,
'theme' => $theme,
);
} else {
$domains = array(
'website' => $website,
'theme' => $theme,
'categories' => $services['dao.category']->findAll(),
'website' => $website,
'theme' => $theme,
);
}

Expand Down
29 changes: 20 additions & 9 deletions src/Controller/BuildDomain/Administration/BuildArticles.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
namespace SciMS\Controller\BuildDomain\Administration;

use SciMS\Controller\BuildDomain\AbstractBuildDomain;
use SciMS\Domain\User;

/**
* Class BuildDomainArticles.
Expand Down Expand Up @@ -47,20 +48,30 @@ public function buildDomain(array $services) {
break;
}
}


$user = $services['dao.user']->findById($services['session.handler']->getRequestField('user_id'));
if ($services['session.handler']->requestFieldExist('user_id')) {
// If user is an administrator, so it retrieve all articles.
if ($user->getRole() == User::ADMINISTRATOR) {
$articles = $services['dao.article']->findAll();
} else {
$articles = $services['dao.article']->findByOwnership($user->getId());
}

$domains = array(
'articles' => $services['dao.article']->findAll(),
'user' => $services['dao.user']->findById($services['session.handler']->getRequestField('user_id')),
'connect' => true,
'website' => $website,
'theme' => $theme,
'articles' => $articles,
'categories' => $services['dao.category']->findAll(),
'user' => $services['dao.user']->findById($services['session.handler']->getRequestField('user_id')),
'connect' => true,
'website' => $website,
'theme' => $theme,
);
} else {
$domains = array(
'articles' => $services['dao.article']->findAll(),
'website' => $website,
'theme' => $theme,
'articles' => $services['dao.article']->findAll(),
'categories' => $services['dao.category']->findAll(),
'website' => $website,
'theme' => $theme,
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,7 @@ public function buildDomain(array $services) {
'user' => $user,
'connect' => true,
'article_id' => true,
'categories' => $services['dao.category']->findAll(),
'website' => $website,
'theme' => $theme,
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ public function buildDomain(array $services) {
'user' => $user,
'connect' => true,
'category_id' => true,
'categories' => $services['dao.category']->findAll(),
'website' => $website,
'theme' => $theme,
);
Expand Down
11 changes: 6 additions & 5 deletions src/Controller/BuildDomain/Administration/BuildEditProfile.php
Original file line number Diff line number Diff line change
Expand Up @@ -170,11 +170,12 @@ public function buildDomain(array $services) {
'readonly' => false,
))
)->getForms(),
'user' => $user,
'user_id' => $services['session.handler']->getRequestField('user_id'),
'connect' => true,
'website' => $website,
'theme' => $theme,
'user' => $user,
'user_id' => $services['session.handler']->getRequestField('user_id'),
'categories' => $services['dao.category']->findAll(),
'connect' => true,
'website' => $website,
'theme' => $theme,
);

return $domains;
Expand Down
18 changes: 10 additions & 8 deletions src/Controller/BuildDomain/Administration/BuildUsers.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,17 +50,19 @@ public function buildDomain(array $services) {

if ($services['session.handler']->requestFieldExist('user_id')) {
$domains = array(
'users' => $services['dao.user']->findAll(),
'user' => $services['dao.user']->findById($services['session.handler']->getRequestField('user_id')),
'connect' => true,
'website' => $website,
'theme' => $theme,
'users' => $services['dao.user']->findAll(),
'categories' => $services['dao.category']->findAll(),
'user' => $services['dao.user']->findById($services['session.handler']->getRequestField('user_id')),
'connect' => true,
'website' => $website,
'theme' => $theme,
);
} else {
$domains = array(
'users' => $services['dao.user']->findAll(),
'website' => $website,
'theme' => $theme,
'users' => $services['dao.user']->findAll(),
'categories' => $services['dao.category']->findAll(),
'website' => $website,
'theme' => $theme,
);
}

Expand Down
2 changes: 1 addition & 1 deletion src/Controller/BuildDomain/BuildHome.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public function __construct($template) {
*/
public function buildDomain(array $services) {
// Check if the database file not exist on server, and if not exist redirect the user on the installation page.
if (!$services['file.checker']->fileExist('../app/database.yml')) {
if (!$services['file.checker']->fileExist('../app/db.yml')) {
$url = '/web/index.php?action=installation';
$services['redirect.handler']->redirect($url);
}
Expand Down
14 changes: 13 additions & 1 deletion src/Controller/BuildDomain/BuildVerification.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
namespace SciMS\Controller\BuildDomain;

use \DateTime;
use SciMS\DAO\ArticleDAO;
use SciMS\DAO\CategoryDAO;
use SciMS\DAO\UserDAO;
use SciMS\Domain\Article;
use SciMS\Domain\Category;
use SciMS\Domain\User;
Expand Down Expand Up @@ -71,6 +74,14 @@ public function buildDomain(array $services) {
);
$services['yaml.file']->write($database, '../app/database.yml');

$services['dao.article'] = new ArticleDAO();
$services['dao.category'] = new CategoryDAO();
$services['dao.user'] = new UserDAO();

$services['dao.category']->createTable();
$services['dao.user']->createTable();
$services['dao.article']->createTable();

// Create an user instance.
$user = new User(array(
'email' => $services['post.handler']->getRequestField('admin_email'),
Expand Down Expand Up @@ -238,6 +249,7 @@ public function buildDomain(array $services) {
case 'edit_article' :
$edit = $services['article.checker']->checkUpdate($services);
if ($edit === true) {
$article = $services['dao.article']->findById($services['post.handler']->getRequestField('article_id'));
$category = $services['dao.category']->findById($services['post.handler']->getRequestField('category'));
$user = $services['dao.user']->findById($services['post.handler']->getRequestField('writter'));

Expand All @@ -252,7 +264,7 @@ public function buildDomain(array $services) {
'tags' => $services['post.handler']->getRequestField('tags'),
'status' => $services['post.handler']->getRequestField('status'),
'date_modified' => $date->format("Y-m-d H:i:s"),
'writter' => $user,
'writter' => $article->getWritter(),
'displayed_summary' => $services['post.handler']->getRequestField('summary'),
));

Expand Down
27 changes: 27 additions & 0 deletions src/DAO/ArticleDAO.php
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,33 @@ public function deleteArticle($id) {
$sql = "DELETE FROM `articles` WHERE id = ?";
$this->getDatabase()->update($sql, array($id));
}

/**
* Method call when you initialize for the first time the website.
*
* @since SciMS 0.5
* @version 1.0
*/
public function createTable() {
$sql = 'CREATE TABLE IF NOT EXISTS `articles` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`title` text COLLATE utf8_unicode_ci,
`abstract` text COLLATE utf8_unicode_ci,
`content` text COLLATE utf8_unicode_ci,
`authors` text COLLATE utf8_unicode_ci,
`categories` int(11) NOT NULL,
`tags` text COLLATE utf8_unicode_ci,
`status` int(3) DEFAULT NULL,
`date_creation` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
`date_modified` datetime DEFAULT NULL,
`writter` int(11) NOT NULL,
`displayed_summary` int(1) NOT NULL,
PRIMARY KEY (`id`),
KEY `writter` (`writter`),
KEY `category` (`categories`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT=\'Table articles\' AUTO_INCREMENT=1 ;';
$this->getDatabase()->exec($sql);
}

/**
* Method use for search a writter thanks to the article id.
Expand Down
15 changes: 15 additions & 0 deletions src/DAO/CategoryDAO.php
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,21 @@ public function deleteCategory($id) {
$this->getDatabase()->update($sql, array($id));
}

/**
* Method call when you initialize for the first time the website.
*
* @since SciMS 0.5
* @version 1.0
*/
public function createTable() {
$sql = 'CREATE TABLE IF NOT EXISTS `categories` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`title` varchar(70) COLLATE utf8_unicode_ci NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT=\'Table category\' AUTO_INCREMENT=1 ;';
$this->getDatabase()->exec($sql);
}

/**
* Method use for build a Domain object.
*
Expand Down
23 changes: 23 additions & 0 deletions src/DAO/UserDAO.php
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,29 @@ public function deleteUser($id) {
$this->getDatabase()->update($sql, array($id));
}

/**
* Method call when you initialize for the first time the website.
*
* @since SciMS 0.5
* @version 1.0
*/
public function createTable() {
$sql = 'CREATE TABLE IF NOT EXISTS `users` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`fname` varchar(50) COLLATE utf8_unicode_ci DEFAULT NULL,
`lname` varchar(50) COLLATE utf8_unicode_ci DEFAULT NULL,
`birthday` datetime DEFAULT NULL,
`username` varchar(50) COLLATE utf8_unicode_ci NOT NULL,
`email` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
`password` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
`avatar` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
`biography` text COLLATE utf8_unicode_ci,
`role` int(3) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT=\'Table users\' AUTO_INCREMENT=1 ;';
$this->getDatabase()->exec($sql);
}

/**
* Method use for build a Domain object.
*
Expand Down
44 changes: 33 additions & 11 deletions src/Database/Database.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

use \PDO;
use \Exception;
use SciMS\Controller\Checker\FileChecker;

/**
* Class Database.
Expand All @@ -14,15 +15,19 @@
* So, it's not necessary to develop a "close" method, but it can be possible to use it, then, it develop it.
*
* -> v1.1 :
* - Added method update($sql, array $statement) to update table on database.
* - Add method update($sql, array $statement) to update table on database.
*
* -> v1.2 :
* - Added Singleton DatabaseSetting to configure database connection on app/database.yml files.
* - Removed const defines to configure Database access.
* - Add Singleton DatabaseSetting to configure database connection on app/database.yml files.
* - Remove const defines to configure Database access.
*
* -> v1.3 :
* - Add method exec.
*
* @author Kero76
* @package \SciMS\Database
* @since SciMS 0.1
* @version 1.2
* @version 1.3
*/
class Database {

Expand Down Expand Up @@ -56,13 +61,16 @@ class Database {
* @version 1.1
*/
private function __construct() {
try {
$this->_pdo = new PDO(DatabaseSetting::getInstance()->getDns() . DatabaseSetting::getInstance()->getDbname(),
DatabaseSetting::getInstance()->getUser(), DatabaseSetting::getInstance()->getPassword());
$this->_pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
} catch (Exception $e) {
echo 'Erreur : ' . $e->getMessage().'<br />';
echo 'N° : '.$e->getCode();
$fileChecker = new FileChecker();
if ($fileChecker->fileExist(DatabaseSetting::DB_SETTING_PATH)) {
try {
$this->_pdo = new PDO(DatabaseSetting::getInstance()->getDns() . DatabaseSetting::getInstance()->getDbname(),
DatabaseSetting::getInstance()->getUser(), DatabaseSetting::getInstance()->getPassword());
$this->_pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
} catch (Exception $e) {
echo 'Erreur : ' . $e->getMessage().'<br />';
echo 'N° : '.$e->getCode();
}
}
}

Expand Down Expand Up @@ -139,6 +147,20 @@ public function query($sql, $fetch_style = PDO::ATTR_DEFAULT_FETCH_MODE, $class
return $this->_pdo->query($sql)->fetchAll($fetch_style);
}
}

/**
* Method use to execute SQL request.
*
* @param $sql
* SQL request to execute on Database.
* @return integer
* Return the number of rows update by SQL request.
* @since SciMS 0.5
* @version 1.0
*/
public function exec($sql) {
return $this->_pdo->exec($sql);
}

/**
* Method use for execute a SQL request with statement to update table present on Database.
Expand Down
8 changes: 6 additions & 2 deletions src/Database/DatabaseSetting.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
namespace SciMS\Database;

use \Symfony\Component\Yaml\Yaml;
use SciMS\Controller\Checker\FileChecker;

/**
* Class DatabaseSetting.
Expand Down Expand Up @@ -77,8 +78,11 @@ class DatabaseSetting {
* @version 1.0
*/
private function __construct() {
$database_setting = Yaml::parse(file_get_contents(self::DB_SETTING_PATH))['database'];
$this->hydrate($database_setting);
$fileChecker = new FileChecker();
if ($fileChecker->fileExist(self::DB_SETTING_PATH)) {
$database_setting = Yaml::parse(file_get_contents(self::DB_SETTING_PATH))['database'];
$this->hydrate($database_setting);
}
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Domain/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* He have an avatar, so it can using Gravatar service to add his avatar directly on website.
*
* -> V1.1 :
* Added role constante.
* Added role constants.
* -> V1.2 :
* Added Birthday and Biography attribute + corresponding Getters and Setters.
* Removed salt attribute + corresponding Getter and Setter.
Expand Down
Loading

0 comments on commit a460c82

Please sign in to comment.