Skip to content

Commit 8c4ede6

Browse files
committed
Merge branch 'master' into dev-pm
2 parents 606ce8f + 5b2121c commit 8c4ede6

File tree

90 files changed

+2766
-1396
lines changed

Some content is hidden

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

90 files changed

+2766
-1396
lines changed

README.md

Lines changed: 72 additions & 153 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,79 @@
1-
# FYKOS-webs
1+
# FYKOS webs
22

3-
Nette multisite codebase for the [Fyziklani](https://fyziklani.cz) and [Online Physics Brawl](https://online.fyziklani.cz) competitions.
3+
Codebase pro Nette weby pro účely FYKOSu a Výfuk.
44

5-
This project uses modified bootstrap file to support multiple websites sharing components and models.
5+
Weby jsou naprogramovány v PHP pomocí frameworku Nette. Běží pod Apache v rámci
6+
docker kontejnerů.
67

7-
## Requirements
8-
- `PHP 8.1`
9-
- `Apache` with `mod_rewrite`
10-
- sql database
8+
## Vývoj
119

12-
## Development
10+
### Prerekvizity
11+
12+
Aby bylo možné spustit weby, je potřeba mít nainstalovaný docker. Pokud jste na
13+
Linuxu, využijte [návodu na instalaci](https://docs.docker.com/engine/install/).
14+
15+
Pokud jste na Windows, je asi nejlepším způsobem nainstalovat WSL (Ubuntu nebo
16+
Debian) a využít návodu pro Linux. Alternativně lze nainstalovat [Docker
17+
desktop](https://docs.docker.com/desktop/setup/install/windows-install/) přímo
18+
na Windows.
19+
20+
Pro MacOS je možné použít pouze [Docker desktop](https://docs.docker.com/desktop/setup/install/mac-install/).
21+
22+
Při instalaci na Linuxu chcete hlavně balíčky `docker` a
23+
`docker-compose-plugin` (případně např. u Arch Linuxu pojmenováno
24+
`docker-compose`). Po instalaci je možné, že nebude docker spuštěn, stačí jej
25+
`systemctl` zapnout nebo restartovat počítač.
26+
27+
Po instalaci je možné, že váš linuxový uživatel nebude mít přístup k dockeru.
28+
Je nutné se přidat do unixové skupiny `docker`, abyste dostali přístup k
29+
souboru `/var/run/docker.sock`.
30+
31+
### První nastavení
32+
33+
V root složce se nachází script `setup.sh`. Ten po spuštění vykoná několik kroků:
34+
35+
- vytvoří konfigurační soubory a doplní do nich přístupové údaje
36+
- vytvoří docker compose soubor a vytvoří příslušné kontejnery
37+
- pomocí kontejneru nainstaluje přes `composer` a `npm` příslušné balíčky a zkompiluje css/js
38+
39+
Postup:
40+
41+
1. Spusťte setup script v **hlavní složce** pomocí `./setup.sh`
42+
2. Vyplňte hodnoty požadované scriptem
43+
3. Běžte do podložky `docker` (`cd docker`)
44+
4. Spusťte docker kontejnery pomocí `docker compose up`
45+
5. V prohlížeči běžte na url `http://localhost:<port>`, kde `<port>` je číslo od 8080 až 8084:
46+
- Výfuk -- [http://localhost:8080](http://localhost:8080)
47+
- FYKOS -- [http://localhost:8081](http://localhost:8081)
48+
- Fyziklání Online -- [http://localhost:8082](http://localhost:8082)
49+
- Fyziklání -- [http://localhost:8083](http://localhost:8083)
50+
- DSEF -- [http://localhost:8084](http://localhost:8084)
51+
6. Spuštěný docker compose v terminálu lze ukončit pomocí CTRL+C
52+
53+
### Následný vývoj
54+
55+
Po prvotním nastavení stačí opakovat kroky 3--6 ze sekce první nastavení. Není
56+
tedy třeba pokaždé spouštět script `setup.sh`.
57+
58+
Pokud chcete, aby vám weby běžely nepřetržitě a nemuseli jste mít otevřený
59+
terminál, ve je docker spuštěn, lze pomocí `docker compose up -d` ve složce
60+
`docker` spustit kontejnery na pozadí. Následně je lze zastavit přes
61+
`docker compose stop`.
62+
63+
Více informací o tom, jak používat docker a jak v něm spouštět příkazy
64+
naleznete v [Docker README](docker/README.md).
65+
66+
## Manuální instalace
67+
68+
Script `setup.sh` provádí úkony, které by bylo nutné udělat jinak ručně. Jedná
69+
se o:
70+
71+
- ve složce `app/config/` zkopírování konfiguračního souboru `config.local.neon.sample` do složky `local` pod názvy `fykos.neon`, `vyfuk.neon`, `fol.neon`, `fof.neon`, `dsef.neon`
72+
- zkopíruje soubor `docker/docker-compose.yml.sample` do `docker/docker-compose.yml` a vyplní `UID` a `GID` uživatele
73+
- buildne kontejnery přes `docker compose build`
74+
- pomocí vytvořeného kontejneru nainstaluje balíčky pro composer a npm a spustí `npm run build`
75+
76+
## Development using podman
1377

1478
As a convenience for `podman` based setups, you can use [just](https://just.systems/)
1579
command runner for your development environment. For `docker` see below. All
@@ -27,148 +91,3 @@ To use `docker` instead of `podman`, instead of `just cmd` write `just runner=do
2791
This is untested, so contact @rkuklik if you run into issues.
2892

2993
To access the websites (after running `just dev`), following links can be used:
30-
31-
- [vyfuk](http://localhost:8080)
32-
- [fykos](http://localhost:8081)
33-
- [fol](http://localhost:8082)
34-
- [fof](http://localhost:8083)
35-
- [dsef](http://localhost:8084)
36-
37-
## Installation
38-
39-
1. Clone the repository `git clone --recurse-submodules ...`
40-
2. Configure the web server (see below for example configuration)
41-
3. Create a configuration files and fill all the necessary information
42-
- `cp app/config/config.local.neon.example app/config/config.fof.local.neon`
43-
- `cp app/config/config.local.neon.example app/config/config.fol.local.neon`
44-
- `cp app/config/config.local.neon.example app/config/config.dsef.local.neon`
45-
4. Follow the build instructions
46-
47-
### Example Apache configuration
48-
Following configuration expects repository located in `/var/www/fykos-webs`.
49-
```apacheconf
50-
<Directory /var/www/fykos-webs>
51-
AllowOverride All
52-
Require all granted
53-
</Directory>
54-
55-
<VirtualHost online.fyziklani.cz.local online.fyziklani.org.local>
56-
ServerName online.fyziklani.cz.local
57-
ServerAlias online.fyziklani.org.local
58-
DocumentRoot /var/www/fykos-webs/www/fol
59-
SetEnv NETTE_DEVEL 1
60-
</VirtualHost>
61-
62-
<VirtualHost fyziklani.cz.local fyziklani.org.local>
63-
ServerName fyziklani.cz.local
64-
ServerAlias fyziklani.org.local
65-
DocumentRoot /var/www/fykos-webs/www/fof
66-
SetEnv NETTE_DEVEL 1
67-
</VirtualHost>
68-
69-
<VirtualHost dsef.cz.local dsef.org.local>
70-
ServerName dsef.cz.local
71-
ServerAlias dsef.org.local
72-
DocumentRoot /var/www/fykos-webs/www/dsef
73-
SetEnv NETTE_DEVEL 1
74-
</VirtualHost>
75-
76-
<VirtualHost fykos.cz.local fykos.org.local>
77-
ServerName fykos.cz.local
78-
ServerAlias fykos.org.local
79-
DocumentRoot /var/www/fykos-webs/www/fykos
80-
SetEnv NETTE_DEVEL 1
81-
</VirtualHost>
82-
```
83-
84-
Do not forget to modify your `/etc/hosts` file to point to the correct IP address of your server.
85-
```etc/hosts
86-
127.0.0.1 online.fyziklani.cz.local
87-
127.0.0.1 online.fyziklani.org.local
88-
127.0.0.1 fyziklani.cz.local
89-
127.0.0.1 fyziklani.org.local
90-
127.0.0.1 dsef.cz.local
91-
127.0.0.1 dsef.org.local
92-
127.0.0.1 fykos.cz.local
93-
127.0.0.1 fykos.org.local
94-
```
95-
96-
These domains need to be configured in `app/config/config.*.local.neon` under `parameters.domains` in order to work.
97-
98-
## Build instructions
99-
100-
*You need `composer` and `npm` with `node` to build this project.*
101-
102-
1. Run `composer install` to install php dependencies.
103-
2. Run `npm install` to install javascript dependencies and build tools.
104-
3. Run `npm run build` to compile css and js files.
105-
106-
You can use `npm run dev` to automatically rebuild files when they are changed.
107-
108-
## Detailed manual for WSL, Ubuntu
109-
110-
Installing Prerequisites
111-
1. open wsl
112-
2. if not installed, install `apache2` (`sudo apt install apache2`)
113-
3. if not installed, install `php8.1` (`sudo apt install php8.1`, you might also need `php8.1-dom` and `php8.1-soap`)
114-
4. if not installed, install `mysql` (google how to do that - e.g. via `sudo apt install mysql-server`)
115-
5. if not installed, install `composer` (google how to do that - sudo apt install composer does not work as of July 2022)
116-
6. if not installed, install `node`, version at least 16. Alternatively, install nvm and then `nvm use 16`
117-
7. if not installed, install `gettext` (via `sudo apt install gettext`), check `locale -a` if you have `cs_CZ` and `en_US` installed, otherwise use `sudo locale-gen cs_CZ`, `sudo locale-gen cs_CZ.UTF-8` and then `sudo update-locale`
118-
8. pull this repository to a location where you want to have it (e.g. `cd C:/data/fykos && git pull <repourl>`)
119-
* Note: you may encounter various problems, e.g. php not being executed (try `sudo apt install libapache2-mod-php` and `sudo a2enmod php8.1`) or with "ERROR: Module mpm_event is enabled" (try `sudo a2dismod mpm_event` and `sudo a2enmod mpm_prefork`, and then `sudo service apache2 restart`)
120-
121-
Configuring Apache
122-
* Explanation: the webserver reads all files from `sites-enabled` and loads the configuration from them.
123-
Other files in these directories are symlinks which point to files in `sites-available` (handy for turning off
124-
the page by deleting the symlink without deleting the actual configuration)
125-
1. open wsl
126-
2. create a new file `sudo nano /etc/apache2/sites-enabled/fykos-webs.conf`
127-
3. paste the example apache configuration (above) into this file
128-
4. change the Directory and all DocumentRoots to be where you have downloaded your repo (e.g. `<Directory /mnt/c/data/fykos/webs>` and `DocumentRoot /mnt/c/data/fykos/webs/www/fol`)
129-
4. save it
130-
131-
Configuring hosts file
132-
* Explanation: Since wsl has its own IP adress, and we use a browser over on Windows, we need
133-
to configure Windows's DNS to route us over to wsl.
134-
1. open the file `C:/Windows/System32/drivers/etc/hosts` as administrator
135-
2. paste the example contents of `/etc/hosts` and save
136-
3. open wsl and type `ip a` and find out the IP adress of WSL (usually something like eth0: ... *inet 172.22.207.240/20* ...)
137-
4. replace all occurrences of `127.0.0.1` in `C:/Windows/System32/drivers/etc/hosts` with the found IP (e.g. `172.22.207.240`)
138-
5. Sadly, steps 3 and 4 need to be repeated everytime wsl gets restarted, because a new IP is generated every time.
139-
140-
141-
Configuring MySql
142-
* Explanation: some parts of the web need an access to a database to work.
143-
1. open wsl
144-
2. start mysql (`sudo mysql`). You may encounter errors, in which case google how to solve them.
145-
3. you are now in mysql shell (the line starts with `mysql>`).
146-
4. Create databases for FOL and FOF: (a) `create database fol ;` (b) `create database fof ;`
147-
5. Create user with a password, e.g.: `CREATE USER 'fykos'@'localhost' IDENTIFIED BY 'password';`
148-
6. Set privileges for the newly created user: (a) `GRANT ALL PRIVILEGES ON fol.* TO 'fykos'@'localhost' WITH GRANT OPTION;` (b) same, only with fof
149-
7. Close mysql by ctrl+D
150-
151-
152-
Inserting tables and data
153-
* Explanation: In FOL, we the database also needs to have some tables and preferably dummy data.
154-
1. open wsl terminal and `sudo mysql`
155-
2. type `use fol` (tells mysql to modify the `fol` database)
156-
3. copy and paste the contents of the file `data/sql/schema_fol.sql` into mysql shell and press Enter (creates tables)
157-
4. copy and paste the contents of the file `data/sql/example_fol.sql` into mysql shell and press Enter (inserts data)
158-
159-
160-
Configuring neon files
161-
* Explanation: these files contain secret data such as passwords and connection strings.
162-
It is something like appsettings.json. These data are then used in the application to
163-
connect to various resources, such as the database.
164-
* `.local` files always override the configurations from files without the `.local`. We only
165-
edit the `.local` files, which are intentionally excluded from git.
166-
1. tell somebody to send you at least the `fksdbDownloader` credentials and fill them out
167-
2. fill out the database name in the connection strings (e.g. `dsn: 'mysql:host=localhost;dbname=fof'`)
168-
3. fill out the `parameters.database` section with the credentials that you've used in MySql (`user: fykos`, `password: password`)
169-
4. set gameApiURL to an empty string: `gameApiURL: ''`
170-
171-
172-
## Troubleshooting
173-
174-
* "could not find driver" ... if this error is shown `Nette\Database\ConnectionException could not find driver Caused by PDOException`, it is likely because you do not have something installed, see https://stackoverflow.com/questions/2852748/pdoexception-could-not-find-driver

app/Bootstrap.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ private static function boot(string $site): Configurator
2020
$configurator->setDebugMode(true);
2121
}
2222
$configurator->enableTracy(__DIR__ . '/../log');
23-
error_reporting(~E_USER_DEPRECATED & ~E_DEPRECATED);
2423
$configurator->setTimeZone('Europe/Prague');
2524
$configurator->setTempDirectory(__DIR__ . '/../temp/' . $site);
2625

app/Components/OrgSneakPeak/orgSneakPeak.latte

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@
1010

1111
<div class="person-dropcard organizers">
1212
<div class="card h-100">
13-
<img src="{$basePath}/media/images/people/person{$organizer['personId']}.jpg"
13+
<img src="https://db.fykos.cz/photo/person/person_{$organizer['personId']}.jpg"
1414
class="card-img-top"
15-
onerror="this.src = '/images/personUnknown.jpg'"
15+
onerror="this.src = '/images/person-unknown.jpg'"
1616
alt="{$organizer['name']}">
1717
<h4 class="card-header">{$organizer['name']}</h4>
1818
<div class="card-body">

app/Components/Problem/problem.latte

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,21 @@
2828
</div>
2929
<div class="card-body">
3030
<div class="card-title">
31-
{if $series->contestYear['contestId'] == 4 && $problem->seriesOrder == 1 && (int)$series->label < 7}
32-
<p><small><i>Tato úloha je určena pouze pro žáky šestých a sedmých ročníků.</i></small></p>
31+
{if $series->contestYear['contestId'] == 4}
32+
{if $problem->number == 1 && $problem->series < 7}
33+
<p><small><i>Tato úloha je určena pouze pro žáky šestých a sedmých ročníků.</i></small></p>
34+
{/if}
35+
{if $problem->number == 7 && $problem->series < 7}
36+
<p><small><i>S řešením této úlohy ti může pomoct krátký naučný text – tzv. Výfučtení. To můžeš nalézt pod odkazem níže.</i></small></p>
37+
{/if}
3338
{/if}
34-
{if $series->contestYear['contestId'] == 4 && $problem->seriesOrder == 7 && (int)$series->label < 7}
35-
<p><small><i>S řešením této úlohy ti může pomoct krátký naučný text – tzv. Výfučtení. To můžeš nalézt pod odkazem níže.</i></small></p>
39+
{if $series->contestYear['contestId'] == 1 && $problem->number == 6}
40+
<p><small><i>
41+
{switch $language->value}
42+
{case 'cs'}Tato úloha má otevřené řešení, proto nezapomeňte uvést všechny použité zdroje.
43+
{default}This problem has an open solution, so be sure to cite all sources used.
44+
{/switch}
45+
</i></small></p>
3646
{/if}
3747
{var $textHtml = $problem->getText('task', $language)['html']}
3848
{if $textHtml}

app/Modules/Core/BasePresenter.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public function injectServices(GettextTranslator $translator, SettingsService $s
3535
* @throws UnsupportedLanguageException
3636
* @throws \Throwable
3737
*/
38-
protected function startUp(): void
38+
protected function startup(): void
3939
{
4040
parent::startup();
4141
$this->localize();

app/Modules/Core/ContestPresenter.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ final public function inject(FKSDBDownloader $downloader): void
2525
$this->downloader = $downloader;
2626
}
2727

28-
2928
public function injectDummyService(DummyService $dummyService): void
3029
{
3130
$this->dummyService = $dummyService;
@@ -72,7 +71,7 @@ public function getPointsYear(): ?ContestYearModel
7271
}
7372
}
7473
}
75-
} finally {
74+
} catch (\Throwable) {
7675
}
7776
}
7877
return null;

app/Modules/Dsef/Core/templates/@layout.latte

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -65,15 +65,9 @@
6565
<a n:href=":Default:Registration:" class="btn btn-outline-light">{switch $language->value}{case 'cs'}Zaregistrovat se{default}Registration{/switch}</a>
6666
{else}
6767
{if $newestEvent->getRegistrationPeriod()->is(Fykosak\Utils\DateTime\Phase::before)}
68-
{switch $language->value}
69-
{case 'cs'}Registrace se otevře na konci září!
70-
{default} Registration will open in September!
71-
{/switch}
68+
Registrace se otevře 10. 10. 2025 v 00:00!
7269
{else}
73-
{switch $language->value}
74-
{case 'cs'}Registrace na další ročník ještě není otevřena.
75-
{default} Registration for the next year is not open yet.
76-
{/switch}
70+
Registrace na další ročník ještě není otevřena.
7771
{/if}
7872
{/if}
7973
</div>
@@ -111,14 +105,20 @@
111105
</a>
112106
</div>
113107
</div>
114-
{* <div class="category">
115-
<div class="category-title">{switch $language->value}{case cs}Partner{default}Partner{/switch}</div>
108+
<div class="category">
109+
<div class="category-title">{switch $language->value}{case cs}Partneři{default}Partners{/switch}</div>
116110
<div class="category-sponsors">
117-
<a href="https://www.iaps.info/" style="text-align: center">
111+
{*<a href="https://www.iaps.info/" style="text-align: center">
118112
<img src="{$basePath}/images/logos/iaps_logo.png" alt="IAPS logo" style="max-height: 10rem; max-width: 13rem">
113+
</a>*}
114+
<a href="https://qminers.com/cs/" style="text-align: center">
115+
<img src="{$basePath}/images/logos/logo-qminers.png" alt="Qminers logo" style="max-width: 12rem">
116+
</a>
117+
<a href="https://www.nadaceneuron.cz" style="text-align: center">
118+
<img class="logo" src="{$basePath}/images/logos/logo-neuron-zlate-CZ.png" alt="Neuron logo" style="max-width: 12rem">
119119
</a>
120120
</div>
121-
</div> *}
121+
</div>
122122
</div>
123123
</div>
124124

app/Modules/Dsef/DefaultModule/CurrentPresenter.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,19 @@
44

55
namespace App\Modules\Dsef\DefaultModule;
66

7+
use App\Models\Downloader\Downloaders\FKSDBDownloader;
78
use App\Models\Downloader\Models\EventModel;
9+
use App\Models\Downloader\Requests\ScheduleRequest;
810
use Nette\Application\BadRequestException;
911

1012
class CurrentPresenter extends BasePresenter
1113
{
14+
private readonly FKSDBDownloader $downloader;
15+
16+
final public function inject(FKSDBDownloader $downloader): void
17+
{
18+
$this->downloader = $downloader;
19+
}
1220
/**
1321
* @throws \Throwable
1422
*/
@@ -26,4 +34,19 @@ public function actionDefault(): void
2634
$this->error();
2735
}
2836
}
37+
38+
/**
39+
* @throws \Throwable
40+
*/
41+
public function renderDefault(): void
42+
{
43+
$data = $this->downloader->download(new ScheduleRequest($this->getNewestEvent()->eventId, ['excursion']));
44+
$filteredData = [];
45+
foreach ($data as $datum) {
46+
if (in_array($datum['groupId'], [245, 246], true)) {
47+
$filteredData[$datum['groupId']] = $datum;
48+
}
49+
}
50+
$this->template->data = $filteredData;
51+
}
2952
}

0 commit comments

Comments
 (0)