Projekt

Obecné

Profil

« Předchozí | Další » 

Revize ee62b2c5

Přidáno uživatelem Filip Jani před asi 6 roky(ů)

Re #7178 vytvoření repository pro práci s tabulkama

Zobrazit rozdíly:

.gitignore
1 1
.idea/
2 2
vendor/
3
app/config/config.local.neon
app/bootstrap.php
16 16

  
17 17
$configurator->addConfig(__DIR__ . '/config/config.neon');
18 18
$configurator->addConfig(__DIR__ . '/config/config.local.neon');
19
$configurator->addConfig(__DIR__ . '/config/model.neon');
19 20

  
20 21
$container = $configurator->createContainer();
21 22

  
app/config/config.local.example.neon
1
parameters:
2

  
3

  
4
database:
5
	dsn: 'mysql:host=127.0.0.1;dbname=test'
6
	user:
7
	password:
app/config/model.neon
1
services:
2
    - Model\Repository\Repository
3
    - Model\Repository\BookRepository
4
    - Model\Repository\BookTypeRepository
5
    - Model\Repository\LineRepository
6
    - Model\Repository\LitReferenceRepository
7
    - Model\Repository\MuseumRepository
8
    - Model\Repository\ObjectTypeRepository
9
    - Model\Repository\OriginRepository
10
    - Model\Repository\RevHistoryRepository
11
    - Model\Repository\SurfaceRepository
12
    - Model\Repository\SurfaceTypeRepository
13
    - Model\Repository\TransliterationRepository
14
    - Model\Repository\UserLogRepository
15
    - Model\Repository\UserRepository
16
    - Model\Repository\UserRoleRepository
app/model/repository/BookRepository.php
1
<?php
2

  
3
namespace Model\Repository;
4

  
5
/**
6
 * Repository pro práci s tabulkou `book`
7
 *
8
 * @package Model
9
 */
10
class BookRepository extends Repository
11
{
12
    /** @var string Název tabulky */
13
    const TABLE_NAME = 'book';
14
    protected $tableName = self::TABLE_NAME;
15

  
16
    /** Sloupečky tabulky */
17
    const COLUMN_ID = 'id_book';
18
    const COLUMN_BOOK_ABREV = 'book_abrev';
19
    const COLUMN_BOOK_AUTHOR = 'book_autor';
20
    const COLUMN_BOOK_DESCRIPTION = 'book_description';
21
    const COLUMN_BOOK_NAME = 'book_name';
22
    const COLUMN_BOOK_SUBTITLE = 'book_subtitle';
23
    const COLUMN_PLACE_OF_PUB = 'place_of_pub';
24
    const COLUMN_DATE_OF_PUB = 'date_of_pub';
25
    const COLUMN_PAGES = 'pages';
26
    const COLUMN_VOLUME = 'volume';
27
    const COLUMN_VOLUME_NO = 'volume_no';
28
    const COLUMN_REVISION_HISTORY = 'revision_history';
29
}
app/model/repository/BookTypeRepository.php
1
<?php
2

  
3
namespace Model\Repository;
4

  
5
/**
6
 * Repository pro práci s tabulkou `book_type`
7
 *
8
 * @package model\repository
9
 */
10
class BookTypeRepository extends Repository
11
{
12
    /** @var string Název tabulky */
13
    const TABLE_NAME = 'book_type';
14
    protected $tableName = self::TABLE_NAME;
15

  
16
    /** Sloupečky tabulky */
17
    const COLUMN_ID = 'id_book_type';
18
    const COLUMN_BOOK_TYPE = 'book_type';
19
}
app/model/repository/LineRepository.php
1
<?php
2

  
3
namespace Model\Repository;
4

  
5
/**
6
 * Repository pro práci s tabulkou `line`
7
 *
8
 * @package model\repository
9
 */
10
class LineRepository extends Repository
11
{
12
    /** @var string Název tabulky */
13
    const TABLE_NAME = 'line';
14
    protected $tableName = self::TABLE_NAME;
15

  
16
    /** Sloupečky tabulky */
17
    const COLUMN_ID = 'id_line';
18
    const COLUMN_TRANSLITERATION = 'transliteration';
19
    const COLUMN_SURFACE_ID = 'id_surface';
20
    const COLUMN_BROKEN = 'broken';
21
    const COLUMN_OLD_BOOKANDCHAPTER = 'old_bookandchapter';
22
    const COLUMN_LINE_NUMBER = 'line_number';
23
}
app/model/repository/LitReferenceRepository.php
1
<?php
2

  
3
namespace Model\Repository;
4

  
5
/**
6
 * Repository pro práci s tabulkou `lit_reference`
7
 *
8
 * @package Model\Repository
9
 */
10
class LitReferenceRepository extends Repository
11
{
12
    /** @var string Název tabulky */
13
    const TABLE_NAME = 'lit_reference';
14
    protected $tableName = self::TABLE_NAME;
15

  
16
    /** Sloupečky tabulky */
17
    const COLUMN_ID = 'id_lit_reference';
18
    const COLUMN_SERIES = 'series';
19
    const COLUMN_NUMBER = 'number';
20
    const COLUMN_PLATE = 'plate';
21
    const COLUMN_TRANSLITERATION_ID = 'id_transliteration';
22
}
app/model/repository/MuseumRepository.php
1
<?php
2

  
3
namespace Model\Repository;
4

  
5
/**
6
 * Repository pro práci s tabulkou `museum`
7
 *
8
 * @package Model\Repository
9
 */
10
class MuseumRepository extends Repository
11
{
12
    /** @var string Název tabulky */
13
    const TABLE_NAME = 'museum';
14
    protected $tableName = self::TABLE_NAME;
15

  
16
    /** Sloupečky tabulky */
17
    const COLUMN_ID = 'id_museum';
18
    const COLUMN_TITLE = 'museum';
19
    const COLUMN_PLACE = 'place';
20
}
app/model/repository/ObjectTypeRepository.php
1
<?php
2

  
3
namespace Model\Repository;
4

  
5
/**
6
 * Repository pro práci s tabulkou `object_type`
7
 *
8
 * @package model\repository
9
 */
10
class ObjectTypeRepository extends Repository
11
{
12
    /** @var string Název tabulky */
13
    const TABLE_NAME = 'object_type';
14
    protected $tableName = self::TABLE_NAME;
15

  
16
    /** Sloupečky tabulky */
17
    const COLUMN_ID = 'id_object_type';
18
    const COLUMN_OBJECT_TYPE = 'object_type';
19
}
app/model/repository/OriginRepository.php
1
<?php
2

  
3
namespace Model\Repository;
4

  
5
/**
6
 * Repository pro práci s tabulkou `origin`
7
 *
8
 * @package model\repository
9
 */
10
class OriginRepository extends Repository
11
{
12
    /** @var string Název tabulky */
13
    const TABLE_NAME = 'origin';
14
    protected $tableName = self::TABLE_NAME;
15

  
16
    /** Sloupečky tabulky */
17
    const COLUMN_ID = 'id_origin';
18
    const COLUMN_ORIGIN = 'origin';
19
    const COLUMN_OLD_NAME = 'old_name';
20
}
app/model/repository/Repository.php
1
<?php
2

  
3
namespace Model\Repository;
4

  
5
use Nette;
6

  
7
/**
8
 * Základní repository s operacemi pro práci s tabulkou
9
 *
10
 * @package Model
11
 */
12
class Repository
13
{
14
    use Nette\SmartObject;
15

  
16
    /** @var string Název tabulky */
17
    protected $tableName;
18

  
19
    /** @var \Nette\Database\Context */
20
    protected $context;
21

  
22
    public function __construct(Nette\Database\Context $context)
23
    {
24
        $this->context = $context;
25
    }
26

  
27
    /**
28
     * Vrací název tabulky
29
     *  - pokud není definovaný odvodí se název tabulky podle názvu třídy
30
     *
31
     * @return string
32
     */
33
    public function getTableName(): string
34
    {
35
        if (empty($this->tableName))
36
        {
37
            preg_match('#(\w+)Repository$#', get_class($this), $m);
38
            $this->tableName = strtolower($m[1]);
39
        }
40

  
41
        return $this->tableName;
42
    }
43

  
44
    /**
45
     * Vrací Selection reprezentující danou tabulku
46
     *
47
     * @return Nette\Database\Table\Selection
48
     */
49
    public function getTable(): Nette\Database\Table\Selection
50
    {
51
        if (empty($this->tableName))
52
        {
53
            $this->getTableName();
54
        }
55

  
56
        return $this->context->table($this->tableName);
57
    }
58

  
59
    /**
60
     * Vrací všechny řádky z tabulky
61
     *
62
     * @return Nette\Database\Table\Selection
63
     */
64
    public function findAll(): Nette\Database\Table\Selection
65
    {
66
        return $this->getTable();
67
    }
68

  
69
    /**
70
     * Vrací řádky podle filtru
71
     *
72
     * @param array $by : associativní pole s filtry, např. array('id' => 5)
73
     * @return Nette\Database\Table\Selection
74
     */
75
    public function findBy(array $by): Nette\Database\Table\Selection
76
    {
77
        return $this->getTable()->where($by);
78
    }
79

  
80
    /**
81
     * Vrací záznam z tabulky podle primárního klíče
82
     *
83
     * @param int $id
84
     * @return Nette\Database\Table\ActiveRow
85
     */
86
    public function findRow(int $id): Nette\Database\Table\ActiveRow
87
    {
88
        return $this->getTable()->get($id);
89
    }
90

  
91
    /**
92
     * Vložení dat do tabulky
93
     *
94
     * @param array $data
95
     * @return bool|int|Nette\Database\Table\ActiveRow
96
     */
97
    public function insert(array $data)
98
    {
99
        return $this->getTable()->insert($data);
100
    }
101

  
102
    /**
103
     * Smaže záznam podle primárního klíče
104
     *
105
     * @param int $id
106
     * @return int
107
     */
108
    public function delete(int $id): int
109
    {
110
        return $this->findRow($id)->delete();
111
    }
112

  
113
    /**
114
     * Uloží nebo updatuje záznam v tabulce
115
     *  - pokud je $id NULL -> vloží nový záznam
116
     *  - pokud $id není NULL -> aktualizace existujícího záznamu
117
     *
118
     * @param array $data
119
     * @param int|NULL $id
120
     * @return Nette\Database\Table\ActiveRow
121
     */
122
    public function save(array $data, int $id = NULL): Nette\Database\Table\ActiveRow
123
    {
124
        if ($id == NULL)
125
        {
126
            $record = $this->insert($data);
127
        } else
128
        {
129
            $record = $this->findRow($id);
130
            $record->update($data);
131
        }
132

  
133
        return $record;
134
    }
135
}
app/model/repository/RevHistoryRepository.php
1
<?php
2

  
3
namespace Model\Repository;
4

  
5
/**
6
 * Repository pro práci s tabulkou `rev_hisotry`
7
 *
8
 * @package Model\Repository
9
 */
10
class RevHistoryRepository extends Repository
11
{
12
    /** @var string Název tabulky */
13
    const TABLE_NAME = 'rev_history';
14
    protected $tableName = self::TABLE_NAME;
15

  
16
    /** Sloupečky tabulky */
17
    const COLUMN_ID = 'id_rev_history';
18
    const COLUMN_TRANSLITERATION_ID = 'id_transliteration';
19
    const COLUMN_DATE = 'date';
20
    const COLUMN_NAME = 'name';
21
    const COLUMN_DESCRIPTION = 'description';
22
}
app/model/repository/SurfaceRepository.php
1
<?php
2

  
3
namespace Model\Repository;
4

  
5
/**
6
 * Repository pro práci s tabulkou `surface`
7
 *
8
 * @package model\repository
9
 */
10
class SurfaceRepository extends Repository
11
{
12
    /** @var string Název tabulky */
13
    const TABLE_NAME = 'surface';
14
    protected $tableName = self::TABLE_NAME;
15

  
16
    /** Sloupečky tabulky */
17
    const COLUMN_ID = 'id_surface';
18
    const COLUMN_COLUMN_NUMBER = 'column_number';
19
    const COLUMN_TRANSLITERATION_ID = 'id_transliteration';
20
    const COLUMN_OBJECT_TYPE_ID = 'id_object_type';
21
    const COLUMN_SURFACE_TYPE_ID = 'id_surface_type';
22
}
app/model/repository/SurfaceTypeRepository.php
1
<?php
2

  
3
namespace Model\Repository;
4

  
5
/**
6
 * Repository pro práci s tabulkou `surface_type`
7
 *
8
 * @package model\repository
9
 */
10
class SurfaceTypeRepository extends Repository
11
{
12
    /** @var string Název tabulky */
13
    const TABLE_NAME = 'surface_type';
14
    protected $tableName = self::TABLE_NAME;
15

  
16
    /** Sloupečky tabulky */
17
    const COLUMN_ID = 'id_surface_type';
18
    const COLUMN_SURFACE_TYPE = 'surface_type';
19
    const COLUMN_SORTER = 'sorter';
20
}
app/model/repository/TransliterationRepository.php
1
<?php
2

  
3
namespace Model\Repository;
4

  
5
/**
6
 * Repository pro práci s tabulkou `transliteration`
7
 *
8
 * @package Model\Repository
9
 */
10
class TransliterationRepository extends Repository
11
{
12
    /** @var string Název tabulky */
13
    const TABLE_NAME = 'transliteration';
14
    protected $tableName = self::TABLE_NAME;
15

  
16
    /** Sloupečky tabulky */
17
    const COLUMN_ID = 'id_transliteration';
18
    const COLUMN_CHAPTER = 'chapter';
19
    const COLUMN_BOOK_ID = 'id_book';
20
    const COLUMN_MUSEUM_NO = 'museum_no';
21
    const COLUMN_MUSEUM_ID = 'id_museum';
22
    const COLUMN_ORIGIN_ID = 'id_origin';
23
    const COLUMN_OLD_BOOKANDCHAPTER = 'old_bookandchapter';
24
    const COLUMN_BOOK_TYPE_ID = 'id_book_type';
25
    const COLUMN_REG_NO = 'reg_no';
26
    const COLUMN_DATE = 'date';
27
    const COLUMN_NOTE = 'note';
28
}
app/model/repository/UserLogRepository.php
1
<?php
2

  
3
namespace Model\Repository;
4

  
5
/**
6
 * Repository pro práci s tabulkou `user_log`
7
 *
8
 * @package model\repository
9
 */
10
class UserLogRepository extends Repository
11
{
12
    /** @var string Název tabulky */
13
    const TABLE_NAME = 'user_log';
14
    protected $tableName = self::TABLE_NAME;
15

  
16
    /** Sloupečky tabulky */
17
    const COLUMN_ID = 'id';
18
    const COLUMN_LOGGED_DATE = 'logged';
19
    const COLUMN_IP = 'ip';
20
    const COLUMN_CLIENT = 'client';
21
    const COLUMN_USER_ID = 'user_id';
22
}
app/model/repository/UserRepository.php
1
<?php
2

  
3
namespace Model\Repository;
4

  
5
/**
6
 * Repository pro práci s tabulkou `user`
7
 *
8
 * @package model\repository
9
 */
10
class UserRepository extends Repository
11
{
12
    /** @var string Název tabulky */
13
    const TABLE_NAME = 'user';
14
    protected $tableName = self::TABLE_NAME;
15

  
16
    /** Sloupečky tabulky */
17
    const COLUMN_ID = 'id';
18
    const COLUMN_USERNAME = 'username';
19
    const COLUMN_LOGIN = 'login';
20
    const COLUMN_PASSWORD = 'password';
21
    const COLUMN_EMAIL = 'email';
22
    const COLUMN_CREATED = 'created';
23
    const COLUMN_UPDATED = 'updated';
24
}
app/model/repository/UserRoleRepository.php
1
<?php
2

  
3
namespace Model\Repository;
4

  
5
/**
6
 * Repository pro práci s tabulkou `user_role`
7
 *
8
 * @package model\repository
9
 */
10
class UserRoleRepository extends Repository
11
{
12
    /** @var string Název tabulky */
13
    const TABLE_NAME = 'user_role';
14
    protected $tableName = self::TABLE_NAME;
15

  
16
    /** Sloupečky tabulky */
17
    const COLUMN_USER_ID = 'user_id';
18
    const COLUMN_ROLE_ID = 'role_id';
19
}
composer.json
5 5
	"type": "project",
6 6
	"license": ["MIT", "BSD-3-Clause", "GPL-2.0", "GPL-3.0"],
7 7
	"require": {
8
		"php": ">= 5.6",
8
		"php": ">= 7.0",
9 9
		"nette/application": "^2.4",
10 10
		"nette/bootstrap": "^2.4.2",
11 11
		"nette/caching": "^2.5",
......
27 27
	"minimum-stability": "stable",
28 28
	"config": {
29 29
		"platform": {
30
			"php": "7"
30
			"php": "7.0"
31 31
		}
32 32
	}
33 33
}
composer.lock
4 4
        "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
5 5
        "This file is @generated automatically"
6 6
    ],
7
    "content-hash": "b0c293d4de647886af79ecc8786cc114",
7
    "content-hash": "29742b99e1ba0714587bf91cdbaecb4d",
8 8
    "packages": [
9 9
        {
10 10
            "name": "latte/latte",
......
1182 1182
        },
1183 1183
        {
1184 1184
            "name": "tracy/tracy",
1185
            "version": "v2.5.7",
1185
            "version": "v2.5.8",
1186 1186
            "source": {
1187 1187
                "type": "git",
1188 1188
                "url": "https://github.com/nette/tracy.git",
1189
                "reference": "36191fd045a0b9cb31a6f1ae658a921b90110454"
1189
                "reference": "3c874946fc403f728af9118cd602cac56bd493d3"
1190 1190
            },
1191 1191
            "dist": {
1192 1192
                "type": "zip",
1193
                "url": "https://api.github.com/repos/nette/tracy/zipball/36191fd045a0b9cb31a6f1ae658a921b90110454",
1194
                "reference": "36191fd045a0b9cb31a6f1ae658a921b90110454",
1193
                "url": "https://api.github.com/repos/nette/tracy/zipball/3c874946fc403f728af9118cd602cac56bd493d3",
1194
                "reference": "3c874946fc403f728af9118cd602cac56bd493d3",
1195 1195
                "shasum": ""
1196 1196
            },
1197 1197
            "require": {
......
1235 1235
                    "homepage": "https://nette.org/contributors"
1236 1236
                }
1237 1237
            ],
1238
            "description": "😎 Tracy: the addictive tool to ease debugging PHP code for cool developers. Friendly design, logging, profiler, advanced features like debugging AJAX calls or CLI support. You will love it.",
1238
            "description": "? Tracy: the addictive tool to ease debugging PHP code for cool developers. Friendly design, logging, profiler, advanced features like debugging AJAX calls or CLI support. You will love it.",
1239 1239
            "homepage": "https://tracy.nette.org",
1240 1240
            "keywords": [
1241 1241
                "Xdebug",
......
1244 1244
                "nette",
1245 1245
                "profiler"
1246 1246
            ],
1247
            "time": "2019-03-13T19:52:49+00:00"
1247
            "time": "2019-03-21T15:06:29+00:00"
1248 1248
        }
1249 1249
    ],
1250 1250
    "packages-dev": [
......
1317 1317
    "prefer-stable": false,
1318 1318
    "prefer-lowest": false,
1319 1319
    "platform": {
1320
        "php": ">= 5.6"
1320
        "php": ">= 7.0"
1321 1321
    },
1322 1322
    "platform-dev": [],
1323 1323
    "platform-overrides": {
1324
        "php": "7"
1324
        "php": "7.0"
1325 1325
    }
1326 1326
}
docker/docker-compose.yml
1 1
version: '2'
2 2
services:
3
  server:
3
  klinopis:
4 4
    container_name: klinopis.local
5 5
    ports:
6 6
      - '80:80'
docker/dockerfile
8 8
RUN sed -i "s/^exit 101$/exit 0/" /usr/sbin/policy-rc.d
9 9

  
10 10
RUN apt-get update && \
11
    apt-get install -y apache2 php7.0 php7.0-zip php7.0-mbstring php7.0-gd php7.0-intl php7.0-xml curl git unzip
11
    apt-get install -y apache2 php7.0 php7.0-zip php7.0-mbstring php7.0-gd php7.0-intl php7.0-xml php7.0-mysql curl git unzip
12 12

  
13 13
COPY ./conf.d/apache/apache2.conf /etc/apache2
14 14
COPY ./conf.d/apache/000-default.conf /etc/apache2/sites-enabled

Také k dispozici: Unified diff