diff --git a/.env.example b/.env.example
new file mode 100644
index 0000000..fb2d4c3
--- /dev/null
+++ b/.env.example
@@ -0,0 +1,5 @@
+DB_DRIVER = pdo_mysql
+DB_HOST = localhost
+DB_DATABASE = ifhub
+DB_USER =
+DB_PASS =
diff --git a/.gitignore b/.gitignore
index 48b8bf9..c8cacfa 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1 +1,2 @@
vendor/
+.env
diff --git a/.phpcs.xml b/.phpcs.xml
new file mode 100644
index 0000000..2d4bba8
--- /dev/null
+++ b/.phpcs.xml
@@ -0,0 +1,23 @@
+
+
+ PSR-2 with tabs, a bit relaxed style.
+
+
+ /vendor/*
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/composer.json b/composer.json
index a4834ac..32c3865 100644
--- a/composer.json
+++ b/composer.json
@@ -1,6 +1,7 @@
{
"require": {
- "doctrine/dbal": "^2.9"
+ "doctrine/dbal": "^2.9",
+ "vlucas/phpdotenv": "^3.4"
},
"require-dev": {
"squizlabs/php_codesniffer": "^3.4"
diff --git a/composer.lock b/composer.lock
index b3ea542..9da5289 100644
--- a/composer.lock
+++ b/composer.lock
@@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file",
"This file is @generated automatically"
],
- "content-hash": "5446d382f008a47e5a5626b88beee570",
+ "content-hash": "e341dd3328614afef7506dc027f4e0e1",
"packages": [
{
"name": "doctrine/cache",
@@ -236,6 +236,166 @@
"eventmanager"
],
"time": "2018-06-11T11:59:03+00:00"
+ },
+ {
+ "name": "phpoption/phpoption",
+ "version": "1.5.0",
+ "source": {
+ "type": "git",
+ "url": "https://github.com/schmittjoh/php-option.git",
+ "reference": "94e644f7d2051a5f0fcf77d81605f152eecff0ed"
+ },
+ "dist": {
+ "type": "zip",
+ "url": "https://api.github.com/repos/schmittjoh/php-option/zipball/94e644f7d2051a5f0fcf77d81605f152eecff0ed",
+ "reference": "94e644f7d2051a5f0fcf77d81605f152eecff0ed",
+ "shasum": ""
+ },
+ "require": {
+ "php": ">=5.3.0"
+ },
+ "require-dev": {
+ "phpunit/phpunit": "4.7.*"
+ },
+ "type": "library",
+ "extra": {
+ "branch-alias": {
+ "dev-master": "1.3-dev"
+ }
+ },
+ "autoload": {
+ "psr-0": {
+ "PhpOption\\": "src/"
+ }
+ },
+ "notification-url": "https://packagist.org/downloads/",
+ "license": [
+ "Apache2"
+ ],
+ "authors": [
+ {
+ "name": "Johannes M. Schmitt",
+ "email": "schmittjoh@gmail.com"
+ }
+ ],
+ "description": "Option Type for PHP",
+ "keywords": [
+ "language",
+ "option",
+ "php",
+ "type"
+ ],
+ "time": "2015-07-25T16:39:46+00:00"
+ },
+ {
+ "name": "symfony/polyfill-ctype",
+ "version": "v1.12.0",
+ "source": {
+ "type": "git",
+ "url": "https://github.com/symfony/polyfill-ctype.git",
+ "reference": "550ebaac289296ce228a706d0867afc34687e3f4"
+ },
+ "dist": {
+ "type": "zip",
+ "url": "https://api.github.com/repos/symfony/polyfill-ctype/zipball/550ebaac289296ce228a706d0867afc34687e3f4",
+ "reference": "550ebaac289296ce228a706d0867afc34687e3f4",
+ "shasum": ""
+ },
+ "require": {
+ "php": ">=5.3.3"
+ },
+ "suggest": {
+ "ext-ctype": "For best performance"
+ },
+ "type": "library",
+ "extra": {
+ "branch-alias": {
+ "dev-master": "1.12-dev"
+ }
+ },
+ "autoload": {
+ "psr-4": {
+ "Symfony\\Polyfill\\Ctype\\": ""
+ },
+ "files": [
+ "bootstrap.php"
+ ]
+ },
+ "notification-url": "https://packagist.org/downloads/",
+ "license": [
+ "MIT"
+ ],
+ "authors": [
+ {
+ "name": "Gert de Pagter",
+ "email": "BackEndTea@gmail.com"
+ },
+ {
+ "name": "Symfony Community",
+ "homepage": "https://symfony.com/contributors"
+ }
+ ],
+ "description": "Symfony polyfill for ctype functions",
+ "homepage": "https://symfony.com",
+ "keywords": [
+ "compatibility",
+ "ctype",
+ "polyfill",
+ "portable"
+ ],
+ "time": "2019-08-06T08:03:45+00:00"
+ },
+ {
+ "name": "vlucas/phpdotenv",
+ "version": "v3.4.0",
+ "source": {
+ "type": "git",
+ "url": "https://github.com/vlucas/phpdotenv.git",
+ "reference": "5084b23845c24dbff8ac6c204290c341e4776c92"
+ },
+ "dist": {
+ "type": "zip",
+ "url": "https://api.github.com/repos/vlucas/phpdotenv/zipball/5084b23845c24dbff8ac6c204290c341e4776c92",
+ "reference": "5084b23845c24dbff8ac6c204290c341e4776c92",
+ "shasum": ""
+ },
+ "require": {
+ "php": "^5.4 || ^7.0",
+ "phpoption/phpoption": "^1.5",
+ "symfony/polyfill-ctype": "^1.9"
+ },
+ "require-dev": {
+ "phpunit/phpunit": "^4.8.35 || ^5.0 || ^6.0"
+ },
+ "type": "library",
+ "extra": {
+ "branch-alias": {
+ "dev-master": "3.4-dev"
+ }
+ },
+ "autoload": {
+ "psr-4": {
+ "Dotenv\\": "src/"
+ }
+ },
+ "notification-url": "https://packagist.org/downloads/",
+ "license": [
+ "BSD-3-Clause"
+ ],
+ "authors": [
+ {
+ "name": "Vance Lucas",
+ "email": "vance@vancelucas.com",
+ "homepage": "http://www.vancelucas.com"
+ }
+ ],
+ "description": "Loads environment variables from `.env` to `getenv()`, `$_ENV` and `$_SERVER` automagically.",
+ "keywords": [
+ "dotenv",
+ "env",
+ "environment"
+ ],
+ "time": "2019-06-15T22:40:20+00:00"
}
],
"packages-dev": [
diff --git a/statistics.php b/statistics.php
index 09d0cc0..20c89c3 100644
--- a/statistics.php
+++ b/statistics.php
@@ -1,11 +1,58 @@
- * @license ISC https://opensource.org/licenses/ISC
- * @link https://ifhub.club
+ * @package Ifhub
+ * @author Oreolek
+ * @license ISC https://opensource.org/licenses/ISC
+ * @link https://ifhub.club
*/
+
+require_once 'vendor/autoload.php';
+$config = \Dotenv\Dotenv::create(__DIR__);
+$config->load();
+$config->required(['DB_DATABASE', 'DB_USER', 'DB_PASS', 'DB_HOST', 'DB_DRIVER']);
+// $dbconfig = new \Doctrine\DBAL\Configuration();
+$conn = \Doctrine\DBAL\DriverManager::getConnection(
+ [
+ 'dbname' => getenv('DB_DATABASE'),
+ 'user' => getenv('DB_USER'),
+ 'password' => getenv('DB_PASS'),
+ 'host' => getenv('DB_HOST'),
+ 'driver' => getenv('DB_DRIVER'),
+ ],
+ null
+);
+
+$date_start = ($argv[1] ?? date('Y')).'-01-01 00:00:00';
+$date_start = new \DateTime($date_start);
+$date_start = $date_start->format('c');
+$queryBuilder = $conn->createQueryBuilder();
+
+$articles = $queryBuilder
+ ->select(
+ 't.topic_title',
+ 't.topic_rating',
+ 't.topic_date_publish',
+ 'u.user_login'
+ )
+ ->from('topic', 't')
+ ->innerJoin('t', 'user', 'u', 't.user_id = u.user_id')
+ ->where('t.topic_date_publish >= ?')
+ ->andWhere('t.topic_date_publish < CURRENT_DATE')
+ ->andWhere("t.topic_type = 'topic'")
+ ->andWhere('t.topic_rating >= 7')
+ ->andWhere('u.user_admin = 0')
+ ->orderBy('t.topic_rating', 'desc');
+$articles = $articles->getSql();
+$statement = $conn->prepare($articles);
+$statement->bindValue(1, $date_start);
+$statement->execute();
+while (($row = $statement->fetch()) !== false) {
+ $date = new \DateTime($row['topic_date_publish']);
+ $rating = (int) $row['topic_rating'];
+ echo $date->format('d.m.Y').'| '.$row['user_login'].', '.$row['topic_title'].' | '.$rating.PHP_EOL;
+}