Skip to content

Commit 1c333dc

Browse files
author
Pavel Kacha
committed
initial commit
0 parents  commit 1c333dc

File tree

304 files changed

+66648
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

304 files changed

+66648
-0
lines changed

.gitignore

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/log
2+
/db
3+
/nbproject
4+
/temp/*
5+
!/temp/.gitignore
6+
/app/config.db.neon
7+
.DS_Store
8+
Thumbs.db
9+
*.log
10+
*.bak
11+
*.orig
12+
*.swp
13+
*~
14+
15+
# project specific files
16+
changeloger.sqlite

app/.htaccess

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Order Allow,Deny
2+
Deny from all

app/bootstrap.php

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<?php
2+
3+
use Nette\Diagnostics\Debugger,
4+
Nette\Application\Routers\SimpleRouter,
5+
Nette\Application\Routers\Route;
6+
7+
// Load Nette Framework
8+
require LIBS_DIR . '/Nette/loader.php';
9+
10+
// Enable Nette Debugger for error visualisation & logging
11+
Debugger::$logDirectory = __DIR__ . '/../log';
12+
Debugger::$strictMode = TRUE;
13+
Debugger::enable(Debugger::DEVELOPMENT);
14+
15+
// Configure application
16+
$configurator = new Nette\Config\Configurator;
17+
$configurator->setProductionMode(FALSE);
18+
$configurator->setTempDirectory(__DIR__ . '/../temp');
19+
20+
// Enable RobotLoader - this will load all classes automatically
21+
$configurator->createRobotLoader()
22+
->addDirectory(APP_DIR)
23+
->addDirectory(LIBS_DIR)
24+
->register();
25+
26+
// Create Dependency Injection container from config.neon file
27+
$configurator->addConfig(__DIR__ . '/config.neon');
28+
29+
$configurator->onCompile[] = function ($configurator, $compiler) {
30+
$compiler->addExtension('dibi', new DibiNetteExtension);
31+
};
32+
33+
$container = $configurator->createContainer();
34+
35+
$container->router[] = new SimpleRouter('Changelog:default');
36+
37+
38+
// expirace prihlaseni
39+
$container->user->setExpiration('+ 7 days', FALSE);
40+
41+
// Run the application!
42+
$application = $container->application;
43+
$application->run();

app/config.db.default.neon

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
dibi:
2+
driver: sqlite3
3+
file: . # add path to your db
4+
lazy: TRUE

app/config.neon

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
#
2+
# SECURITY WARNING: it is CRITICAL that this file & directory are NOT accessible directly via a web browser!
3+
#
4+
# If you don't protect this directory from direct web access, anybody will be able to see your passwords.
5+
# http://nette.org/security-warning
6+
7+
8+
common:
9+
10+
includes:
11+
- config.db.neon
12+
13+
#dibi:
14+
#dibi loads config from config.db.neon
15+
16+
parameters:
17+
models: # parameters for models (example)
18+
key: val
19+
20+
php:
21+
date.timezone: Europe/Prague
22+
23+
nette:
24+
container:
25+
debugger: true
26+
27+
session:
28+
expiration: 14 days
29+
30+
services:
31+
database: @dibi.connection # just create alias for @dibi.connection
32+
33+
authenticator:
34+
class: DatabaseAuthenticator(@database)
35+
36+
modelLoader:
37+
class: ModelLoader(@container) # loader picks up only interesting parts from whole container
38+
39+
production < common:
40+
41+
42+
development < common:

app/models/Base.php

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?php
2+
3+
namespace Models;
4+
5+
/**
6+
* Base model
7+
* @link http://wiki.nette.org/cs/cookbook/dynamicke-nacitani-modelu
8+
* @author Majkl578
9+
*/
10+
abstract class Base extends \Nette\Object
11+
{
12+
/** @var \Nette\DI\Container */
13+
private $context;
14+
15+
public function __construct(\Nette\DI\Container $container)
16+
{
17+
$this->context = $container;
18+
}
19+
20+
/** @return \Nette\DI\Container */
21+
final public function getContext()
22+
{
23+
return $this->context;
24+
}
25+
26+
/** @return \DibiConnection */
27+
final public function getDatabase()
28+
{
29+
return $this->context->database;
30+
}
31+
}

app/models/Changelog.php

Lines changed: 140 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,140 @@
1+
<?php
2+
3+
namespace Models;
4+
5+
class Changelog extends Base
6+
{
7+
8+
/** @var \DibiConnection */
9+
private $database;
10+
11+
public function __construct(\Nette\DI\Container $context)
12+
{
13+
parent::__construct($context);
14+
$this->database = $this->getDatabase();
15+
}
16+
17+
public function getProjects()
18+
{
19+
return $this->database->query("SELECT * FROM [projects]
20+
ORDER BY [project_name]")->fetchAll();
21+
}
22+
23+
public function getProject($id)
24+
{
25+
return $this->database->query("SELECT * FROM [projects]
26+
WHERE [id_project] = %i", $id)->fetch();
27+
}
28+
29+
public function getChangelogRecepients($id)
30+
{
31+
return $this->database->query("SELECT * FROM [users_projects]
32+
LEFT JOIN [users] ON [users].[id_user] = [users_projects].[id_user]
33+
WHERE [users_projects].[id_project] = %i", $id)->fetchAll();
34+
}
35+
36+
public function getAvailableUsers($projectId)
37+
{
38+
return $this->database->query("SELECT [id_user], [name]
39+
FROM [users]
40+
WHERE [id_user] NOT IN (
41+
SELECT [id_user] FROM [users_projects] WHERE [id_project] = %i
42+
)", $projectId)
43+
->fetchPairs();
44+
}
45+
46+
public function newUserProject($userId, $projectId)
47+
{
48+
$data = array(
49+
"id_user" => (int) $userId,
50+
"id_project" => (int) $projectId,
51+
);
52+
$this->database->query("INSERT INTO [users_projects]", $data);
53+
}
54+
55+
public function getActualChangelog($projectId)
56+
{
57+
return $this->database->query("SELECT [changelog_text]
58+
FROM [changelogs]
59+
WHERE [id_project] = %i
60+
ORDER BY [id_changelog] DESC
61+
LIMIT 1", $projectId)->fetchSingle();
62+
}
63+
64+
public function getUserInfo($idUser)
65+
{
66+
return $this->database->query("SELECT * FROM [users]
67+
WHERE [id_user] = %i", $idUser)->fetch();
68+
}
69+
70+
public function getChangelogHistory($projectId)
71+
{
72+
return $this->database->query("SELECT [changelogs].*, [users].[name], [users].[email]
73+
FROM [changelogs]
74+
LEFT JOIN [users] ON [users].[id_user] = [changelogs].[id_user]
75+
WHERE [id_project] = %i
76+
ORDER BY [date] DESC", $projectId)->fetchAll();
77+
}
78+
79+
public function prepareChangelog($values)
80+
{
81+
$log = "";
82+
if(trim($values->newRows) != "")
83+
{
84+
foreach(explode("\n", $values->newRows) as $zmena)
85+
{
86+
if(trim($zmena) != "")
87+
{
88+
$log .= date("Y-m-d") . " " . $zmena . "\n";
89+
}
90+
}
91+
}
92+
93+
$values->log = $log . $values->changelog;
94+
return $values;
95+
}
96+
97+
public function saveChangelogToDb($values, $userId)
98+
{
99+
$changelogData = array(
100+
"id_project" => $values->projectId,
101+
"id_user" => $userId,
102+
"date" => date("c"),
103+
"sent" => ((isset($values->sent) && $values->sent == "1") ? "1" : "0"),
104+
"changelog_text" => $values->log,
105+
);
106+
107+
$this->database->query("INSERT INTO [changelogs] ", $changelogData);
108+
}
109+
110+
public function sendMail($values, $userId)
111+
{
112+
$values = $this->prepareMail($values, $userId);
113+
114+
$mail = new \Nette\Mail\Message;
115+
foreach($values->recepients as $r)
116+
{
117+
if(trim($r["email"]) != "")
118+
{
119+
$mail->addTo($r["email"], $r["name"]);
120+
}
121+
}
122+
123+
$mail->setFrom($values->sender["email"], $values->sender["name"]);
124+
$mail->setSubject("Changelog " . $values->projectInfo["project_name"] . " " . $values->projectInfo["project_version"] . " (" . date("Y-m-d") . ") - " . $values->projectInfo["project_shortname"]);
125+
126+
$mail->setBody("Dobrý den,\n\nzasílám aktuální changelog pro " . $values->projectInfo["project_name"] . " - " . $values->projectInfo["project_shortname"] . "\n\n" . $values->sender["name"]);
127+
128+
$mail->addAttachment('changelog.txt', $values->log);
129+
$mail->send();
130+
}
131+
132+
private function prepareMail($values, $userId)
133+
{
134+
$values->projectInfo = $this->getProject($values->projectId);
135+
$values->recepients = $this->getChangelogRecepients($values->projectId);
136+
$values->sender = $this->getUserInfo($userId);
137+
return $values;
138+
}
139+
140+
}

app/presenters/BasePresenter.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?php
2+
3+
/**
4+
* Base presenter
5+
* @link http://wiki.nette.org/cs/cookbook/dynamicke-nacitani-modelu
6+
* @author Majkl578
7+
*/
8+
abstract class BasePresenter extends \Nette\Application\UI\Presenter
9+
{
10+
/** @return \ModelLoader */
11+
final public function getModels()
12+
{
13+
return $this->context->modelLoader;
14+
}
15+
}

0 commit comments

Comments
 (0)