Строим скрипт вывода
This commit is contained in:
parent
3faa829801
commit
82e74e350c
5
.env.example
Normal file
5
.env.example
Normal file
|
@ -0,0 +1,5 @@
|
|||
DB_DRIVER = pdo_mysql
|
||||
DB_HOST = localhost
|
||||
DB_DATABASE = ifhub
|
||||
DB_USER =
|
||||
DB_PASS =
|
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -1 +1,2 @@
|
|||
vendor/
|
||||
.env
|
||||
|
|
23
.phpcs.xml
Normal file
23
.phpcs.xml
Normal file
|
@ -0,0 +1,23 @@
|
|||
<?xml version="1.0"?>
|
||||
<ruleset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" name="Oreolek" xsi:noNamespaceSchemaLocation="https://raw.githubusercontent.com/squizlabs/PHP_CodeSniffer/master/phpcs.xsd">
|
||||
<description>PSR-2 with tabs, a bit relaxed style.</description>
|
||||
|
||||
<!-- Exclude the Composer Vendor directory. -->
|
||||
<exclude-pattern>/vendor/*</exclude-pattern>
|
||||
|
||||
<arg name="basepath" value="."/>
|
||||
<arg name="colors"/>
|
||||
|
||||
<!-- Include whole PSR2 except tabs, not spaces -->
|
||||
<rule ref="PSR2">
|
||||
<exclude name="Generic.WhiteSpace.DisallowTabIndent"/>
|
||||
</rule>
|
||||
|
||||
<rule ref="Generic.WhiteSpace.DisallowSpaceIndent"/>
|
||||
<rule ref="Generic.WhiteSpace.ScopeIndent">
|
||||
<properties>
|
||||
<property name="indent" value="2"/>
|
||||
<property name="tabIndent" value="true"/>
|
||||
</properties>
|
||||
</rule>
|
||||
</ruleset>
|
|
@ -1,6 +1,7 @@
|
|||
{
|
||||
"require": {
|
||||
"doctrine/dbal": "^2.9"
|
||||
"doctrine/dbal": "^2.9",
|
||||
"vlucas/phpdotenv": "^3.4"
|
||||
},
|
||||
"require-dev": {
|
||||
"squizlabs/php_codesniffer": "^3.4"
|
||||
|
|
162
composer.lock
generated
162
composer.lock
generated
|
@ -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": [
|
||||
|
|
|
@ -1,11 +1,58 @@
|
|||
<?php declare(strict_types=1);
|
||||
/**
|
||||
|
||||
/*
|
||||
* Подсчёт топа авторов по статьям
|
||||
* php version 7.2.0
|
||||
*
|
||||
* @category Utilities
|
||||
* @package Ifhub
|
||||
* @author Oreolek <keloero@oreolek.ru>
|
||||
* @license ISC https://opensource.org/licenses/ISC
|
||||
* @link https://ifhub.club
|
||||
* @package Ifhub
|
||||
* @author Oreolek <keloero@oreolek.ru>
|
||||
* @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;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue