Skip to content

Commit 5ffbcf6

Browse files
Merge pull request #28 from williamespindola/feature/new-schema-multilanguage
Improve database schema, implement multi linguage and some fixes
2 parents 7dc86ad + 2faed9d commit 5ffbcf6

24 files changed

+689
-200
lines changed

CHANGELOG.md

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,27 @@
22

33
All Notable changes to `field` will be documented in this file
44

5-
## NEXT - YYYY-MM-DD
5+
## 2015-09-23
66

77
### Added
8-
- Nothing
8+
- Multi language support #24
9+
- Refactoring cli Create class to work with language
10+
- Add option via cli
11+
- Add language via cli
12+
- Update mysql schema with new schema without collection and field many to many relationship
13+
- Improve readme
914

1015
### Deprecated
1116
- Nothing
1217

1318
### Fixed
14-
- Nothing
19+
- option word is reserved on mysql #18
20+
- Config path on WilliamEspindola\Field\Console\Command\Database\DoctrineStorage
21+
- getMapperInstance method on WilliamEspindola\Field\Console\Command\Database\DoctrineStorage must return instance of WilliamEspindola\Field\Storage\ORM\Doctrine not mapper
22+
1523

1624
### Removed
17-
- Nothing
25+
- Remove collection and field n to n relationship #25
1826

1927
### Security
20-
- Nothing
28+
- Nothing

README.md

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,28 +7,46 @@
77
[![Quality Score][ico-code-quality]][link-code-quality]
88
[![Total Downloads][ico-downloads]][link-downloads]
99

10-
Field is a blueprint to work as a CMS inpired on [cockpit](http://getcockpit.com/).
10+
Field is a blueprint to work as a CMS inspired on [cockpit](http://getcockpit.com/).
1111
Via command line you can create fields for your partials and consume in your project using Repository, Services or Extensions.
1212

13+
## Features
14+
- Mult language database schema
15+
- Collection of fields
16+
- Options of fields
17+
- CLI interface
18+
- Services, Repositories and Storage
19+
- [Doctrine](https://github.com/doctrine/doctrine2) and [Relational](https://github.com/Respect/Relational) suport (cli only work with relational see issue #27)
20+
1321
### Example
1422

15-
Create some field, running this in your terminal
23+
You can create Languages, Collections, Fields and Options. Here some examples:
1624
```bash
17-
php vendor/bin/field create Collection about "About page"
18-
php vendor/bin/field create Field textfield "About text" text about
19-
php vendor/bin/field create Field imagefield "About image" text about
25+
php vendor/bin/field create Language en_EN English
26+
27+
php vendor/bin/field create Collection header Header en_EN
28+
29+
php vendor/bin/field create Field about "About text" en_EN html
30+
php vendor/bin/field create Field meta-keys Metakeys en_EN text header
31+
php vendor/bin/field create Field contact Contact en_EN text
32+
33+
php vendor/bin/field create Option Girl contact en_EN
34+
php vendor/bin/field create Option Boy contact en_EN
35+
2036
```
2137

22-
With this code you will create a collection called "About page" and two field for him "About text" and "About image". So you can get this using the Repository:
38+
Now you can use some repository or services to consume, or implement the storage as you need and white you own repository and services.
39+
Example!
2340
```php
2441
use WilliamEspindola\Field\Storage\ORM\Doctrine;
25-
use WilliamEspindola\Field\Repository\CollectionFieldRepository;
42+
use WilliamEspindola\Field\Repository\FieldRepository;
2643

2744
$doctrineStorage = new Doctrine(/** doctrine setup */); // you can uss orther ORM as you want
28-
$repository = new CollectionFieldRepository($doctrineStorage);
45+
$repository = new FieldRepository($doctrineStorage);
2946

3047
$repository->findAll()
3148
```
49+
[Checkout the docs on wiki!](https://github.com/williamespindola/field/wiki)
3250

3351
## Install
3452

composer.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@
1919
],
2020
"require": {
2121
"php" : ">=5.4",
22-
"ocramius/generated-hydrator": "1.1.0"
22+
"ocramius/generated-hydrator": "1.1.0",
23+
"doctrine/orm": "2.5.0",
24+
"respect/relational": "^0.8"
2325
},
2426
"require-dev": {
2527
"phpunit/phpunit" : "4.*",

config/xml/WilliamEspindola.Field.Entity.Collection.dcm.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,7 @@
1111

1212
<field name="name" type="string" />
1313
<field name="label" type="string" />
14+
15+
<one-to-one target-entity="WilliamEspindola\Field\Entity\Language" field="language" mapped-by="collection" />
1416
</entity>
1517
</doctrine-mapping>

config/xml/WilliamEspindola.Field.Entity.Field.dcm.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,7 @@
1313
<field name="type" type="string" />
1414
<field name="value" type="text" />
1515
<field name="label" type="string" />
16+
17+
<one-to-one target-entity="WilliamEspindola\Field\Entity\Language" field="language" mapped-by="collection" />
1618
</entity>
1719
</doctrine-mapping>

config/xml/WilliamEspindola.Field.Entity.CollectionField.dcm.xml renamed to config/xml/WilliamEspindola.Field.Entity.Language.dcm.xml

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
1-
<!-- config/xml/CollectionField.dcm.xml -->
1+
<!-- config/xml/Language.dcm.xml -->
22
<doctrine-mapping
33
xmlns="http://doctrine-project.org/schemas/orm/doctrine-mapping"
44
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
55
xsi:schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping http://raw.github.com/doctrine/doctrine2/master/doctrine-mapping.xsd">
66

7-
<entity name="WilliamEspindola\Field\Entity\CollectionField" table="collectionfield">
7+
<entity name="WilliamEspindola\Field\Entity\Language" table="language">
88
<id name="id" type="integer">
99
<generator strategy="AUTO" />
1010
</id>
1111

12-
<many-to-one field="field" target-entity="WilliamEspindola\Field\Entity\Field" />
13-
<many-to-one field="collection" target-entity="WilliamEspindola\Field\Entity\Collection" />
12+
<field name="name" type="string" />
1413
</entity>
1514
</doctrine-mapping>

config/xml/WilliamEspindola.Field.Entity.Options.dcm.xml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,14 @@
1111

1212
<field name="value" type="string" />
1313

14-
<many-to-one target-entity="WilliamEspindola\Field\Entity\Field" field="field" />
14+
<one-to-many field="options" target-entity="WilliamEspindola\Field\Entity\Field" mapped-by="field">
15+
<cascade>
16+
<cascade-persist/>
17+
</cascade>
18+
<order-by>
19+
<order-by-field name="text" direction="ASC" />
20+
</order-by>
21+
</one-to-many>
22+
<one-to-one target-entity="WilliamEspindola\Field\Entity\Language" field="language" mapped-by="collection" />
1523
</entity>
1624
</doctrine-mapping>

data/field.png

58.6 KB
Loading

data/mysql-schema.sql

Lines changed: 56 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -1,73 +1,70 @@
1-
-- MySQL Script generated by MySQL Workbench
2-
-- Wed Jul 8 02:30:20 2015
3-
-- Model: New Model Version: 1.0
41
SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0;
52
SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0;
63
SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='TRADITIONAL,ALLOW_INVALID_DATES';
74

8-
-- -----------------------------------------------------
9-
-- Table `field`
10-
-- -----------------------------------------------------
11-
CREATE TABLE IF NOT EXISTS `field` (
12-
`id` INT NOT NULL AUTO_INCREMENT,
13-
`name` VARCHAR(255) NOT NULL,
14-
`type` VARCHAR(255) NOT NULL,
15-
`value` TEXT NULL,
16-
`label` VARCHAR(255) NOT NULL,
17-
PRIMARY KEY (`id`))
18-
ENGINE = InnoDB;
19-
20-
21-
-- -----------------------------------------------------
22-
-- Table `option`
23-
-- -----------------------------------------------------
24-
CREATE TABLE IF NOT EXISTS `option` (
25-
`id` INT NOT NULL,
26-
`option` TEXT NULL,
27-
`field_id` INT NOT NULL,
28-
PRIMARY KEY (`id`),
29-
INDEX `fk_options_field_idx` (`field_id` ASC),
30-
CONSTRAINT `fk_options_field`
31-
FOREIGN KEY (`field_id`)
32-
REFERENCES `field` (`id`)
33-
ON DELETE NO ACTION
34-
ON UPDATE NO ACTION)
35-
ENGINE = InnoDB;
5+
CREATE TABLE IF NOT EXISTS `language` (
6+
`id` INT NOT NULL AUTO_INCREMENT,
7+
`name` VARCHAR(50) NULL,
8+
`label` VARCHAR(50) NULL,
9+
PRIMARY KEY (`id`))
10+
ENGINE = InnoDB;
3611

37-
38-
-- -----------------------------------------------------
39-
-- Table `collection`
40-
-- -----------------------------------------------------
4112
CREATE TABLE IF NOT EXISTS `collection` (
42-
`id` INT NOT NULL AUTO_INCREMENT,
43-
`name` VARCHAR(255) NOT NULL,
44-
`label` VARCHAR(255) NOT NULL,
45-
PRIMARY KEY (`id`))
46-
ENGINE = InnoDB;
47-
13+
`id` INT NOT NULL AUTO_INCREMENT,
14+
`language_id` INT NULL,
15+
`name` VARCHAR(255) NOT NULL,
16+
`label` VARCHAR(255) NOT NULL,
17+
PRIMARY KEY (`id`),
18+
INDEX `fk_collection_language1_idx` (`language_id` ASC),
19+
CONSTRAINT `fk_collection_language1`
20+
FOREIGN KEY (`language_id`)
21+
REFERENCES `language` (`id`)
22+
ON DELETE NO ACTION
23+
ON UPDATE NO ACTION)
24+
ENGINE = InnoDB;
4825

49-
-- -----------------------------------------------------
50-
-- Table `collectionfield`
51-
-- -----------------------------------------------------
52-
CREATE TABLE IF NOT EXISTS `collectionfield` (
53-
`collection_id` INT NOT NULL,
54-
`field_id` INT NOT NULL,
55-
`id` INT NOT NULL AUTO_INCREMENT,
56-
PRIMARY KEY (`id`, `collection_id`, `field_id`),
57-
INDEX `fk_collection_has_field_field1_idx` (`field_id` ASC),
58-
INDEX `fk_collection_has_field_collection1_idx` (`collection_id` ASC),
59-
CONSTRAINT `fk_collection_has_field_collection1`
26+
CREATE TABLE IF NOT EXISTS `field` (
27+
`id` INT NOT NULL AUTO_INCREMENT,
28+
`collection_id` INT NULL,
29+
`language_id` INT NULL,
30+
`name` VARCHAR(255) NOT NULL,
31+
`type` VARCHAR(255) NOT NULL,
32+
`value` TEXT NULL DEFAULT NULL,
33+
`label` VARCHAR(255) NOT NULL,
34+
PRIMARY KEY (`id`),
35+
INDEX `fk_field_collection1_idx` (`collection_id` ASC),
36+
INDEX `fk_field_language1_idx` (`language_id` ASC),
37+
CONSTRAINT `fk_field_collection1`
6038
FOREIGN KEY (`collection_id`)
6139
REFERENCES `collection` (`id`)
62-
ON DELETE NO ACTION
63-
ON UPDATE NO ACTION,
64-
CONSTRAINT `fk_collection_has_field_field1`
40+
ON DELETE NO ACTION
41+
ON UPDATE NO ACTION,
42+
CONSTRAINT `fk_field_language1`
43+
FOREIGN KEY (`language_id`)
44+
REFERENCES `language` (`id`)
45+
ON DELETE NO ACTION
46+
ON UPDATE NO ACTION)
47+
ENGINE = InnoDB;
48+
49+
CREATE TABLE IF NOT EXISTS `options` (
50+
`id` INT NOT NULL AUTO_INCREMENT,
51+
`text` TEXT NULL DEFAULT NULL,
52+
`field_id` INT NULL,
53+
`language_id` INT NULL,
54+
PRIMARY KEY (`id`),
55+
INDEX `fk_options_field_idx` (`field_id` ASC),
56+
INDEX `fk_options_language1_idx` (`language_id` ASC),
57+
CONSTRAINT `fk_options_field`
6558
FOREIGN KEY (`field_id`)
6659
REFERENCES `field` (`id`)
67-
ON DELETE NO ACTION
68-
ON UPDATE NO ACTION)
69-
ENGINE = InnoDB;
70-
60+
ON DELETE NO ACTION
61+
ON UPDATE NO ACTION,
62+
CONSTRAINT `fk_options_language1`
63+
FOREIGN KEY (`language_id`)
64+
REFERENCES `language` (`id`)
65+
ON DELETE NO ACTION
66+
ON UPDATE NO ACTION)
67+
ENGINE = InnoDB;
7168

7269
SET SQL_MODE=@OLD_SQL_MODE;
7370
SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS;

0 commit comments

Comments
 (0)