Skip to content

Commit

Permalink
Merge pull request #28 from williamespindola/feature/new-schema-multi…
Browse files Browse the repository at this point in the history
…language

Improve database schema, implement multi linguage and some fixes
  • Loading branch information
williamespindola committed Sep 23, 2015
2 parents 7dc86ad + 2faed9d commit 5ffbcf6
Show file tree
Hide file tree
Showing 24 changed files with 689 additions and 200 deletions.
18 changes: 13 additions & 5 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,27 @@

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

## NEXT - YYYY-MM-DD
## 2015-09-23

### Added
- Nothing
- Multi language support #24
- Refactoring cli Create class to work with language
- Add option via cli
- Add language via cli
- Update mysql schema with new schema without collection and field many to many relationship
- Improve readme

### Deprecated
- Nothing

### Fixed
- Nothing
- option word is reserved on mysql #18
- Config path on WilliamEspindola\Field\Console\Command\Database\DoctrineStorage
- getMapperInstance method on WilliamEspindola\Field\Console\Command\Database\DoctrineStorage must return instance of WilliamEspindola\Field\Storage\ORM\Doctrine not mapper


### Removed
- Nothing
- Remove collection and field n to n relationship #25

### Security
- Nothing
- Nothing
34 changes: 26 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,28 +7,46 @@
[![Quality Score][ico-code-quality]][link-code-quality]
[![Total Downloads][ico-downloads]][link-downloads]

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

## Features
- Mult language database schema
- Collection of fields
- Options of fields
- CLI interface
- Services, Repositories and Storage
- [Doctrine](https://github.com/doctrine/doctrine2) and [Relational](https://github.com/Respect/Relational) suport (cli only work with relational see issue #27)

### Example

Create some field, running this in your terminal
You can create Languages, Collections, Fields and Options. Here some examples:
```bash
php vendor/bin/field create Collection about "About page"
php vendor/bin/field create Field textfield "About text" text about
php vendor/bin/field create Field imagefield "About image" text about
php vendor/bin/field create Language en_EN English

php vendor/bin/field create Collection header Header en_EN

php vendor/bin/field create Field about "About text" en_EN html
php vendor/bin/field create Field meta-keys Metakeys en_EN text header
php vendor/bin/field create Field contact Contact en_EN text

php vendor/bin/field create Option Girl contact en_EN
php vendor/bin/field create Option Boy contact en_EN

```

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:
Now you can use some repository or services to consume, or implement the storage as you need and white you own repository and services.
Example!
```php
use WilliamEspindola\Field\Storage\ORM\Doctrine;
use WilliamEspindola\Field\Repository\CollectionFieldRepository;
use WilliamEspindola\Field\Repository\FieldRepository;

$doctrineStorage = new Doctrine(/** doctrine setup */); // you can uss orther ORM as you want
$repository = new CollectionFieldRepository($doctrineStorage);
$repository = new FieldRepository($doctrineStorage);

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

## Install

Expand Down
4 changes: 3 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@
],
"require": {
"php" : ">=5.4",
"ocramius/generated-hydrator": "1.1.0"
"ocramius/generated-hydrator": "1.1.0",
"doctrine/orm": "2.5.0",
"respect/relational": "^0.8"
},
"require-dev": {
"phpunit/phpunit" : "4.*",
Expand Down
2 changes: 2 additions & 0 deletions config/xml/WilliamEspindola.Field.Entity.Collection.dcm.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,7 @@

<field name="name" type="string" />
<field name="label" type="string" />

<one-to-one target-entity="WilliamEspindola\Field\Entity\Language" field="language" mapped-by="collection" />
</entity>
</doctrine-mapping>
2 changes: 2 additions & 0 deletions config/xml/WilliamEspindola.Field.Entity.Field.dcm.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,7 @@
<field name="type" type="string" />
<field name="value" type="text" />
<field name="label" type="string" />

<one-to-one target-entity="WilliamEspindola\Field\Entity\Language" field="language" mapped-by="collection" />
</entity>
</doctrine-mapping>
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
<!-- config/xml/CollectionField.dcm.xml -->
<!-- config/xml/Language.dcm.xml -->
<doctrine-mapping
xmlns="http://doctrine-project.org/schemas/orm/doctrine-mapping"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping http://raw.github.com/doctrine/doctrine2/master/doctrine-mapping.xsd">

<entity name="WilliamEspindola\Field\Entity\CollectionField" table="collectionfield">
<entity name="WilliamEspindola\Field\Entity\Language" table="language">
<id name="id" type="integer">
<generator strategy="AUTO" />
</id>

<many-to-one field="field" target-entity="WilliamEspindola\Field\Entity\Field" />
<many-to-one field="collection" target-entity="WilliamEspindola\Field\Entity\Collection" />
<field name="name" type="string" />
</entity>
</doctrine-mapping>
10 changes: 9 additions & 1 deletion config/xml/WilliamEspindola.Field.Entity.Options.dcm.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,14 @@

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

<many-to-one target-entity="WilliamEspindola\Field\Entity\Field" field="field" />
<one-to-many field="options" target-entity="WilliamEspindola\Field\Entity\Field" mapped-by="field">
<cascade>
<cascade-persist/>
</cascade>
<order-by>
<order-by-field name="text" direction="ASC" />
</order-by>
</one-to-many>
<one-to-one target-entity="WilliamEspindola\Field\Entity\Language" field="language" mapped-by="collection" />
</entity>
</doctrine-mapping>
Binary file added data/field.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
115 changes: 56 additions & 59 deletions data/mysql-schema.sql
Original file line number Diff line number Diff line change
@@ -1,73 +1,70 @@
-- MySQL Script generated by MySQL Workbench
-- Wed Jul 8 02:30:20 2015
-- Model: New Model Version: 1.0
SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0;
SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0;
SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='TRADITIONAL,ALLOW_INVALID_DATES';

-- -----------------------------------------------------
-- Table `field`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `field` (
`id` INT NOT NULL AUTO_INCREMENT,
`name` VARCHAR(255) NOT NULL,
`type` VARCHAR(255) NOT NULL,
`value` TEXT NULL,
`label` VARCHAR(255) NOT NULL,
PRIMARY KEY (`id`))
ENGINE = InnoDB;


-- -----------------------------------------------------
-- Table `option`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `option` (
`id` INT NOT NULL,
`option` TEXT NULL,
`field_id` INT NOT NULL,
PRIMARY KEY (`id`),
INDEX `fk_options_field_idx` (`field_id` ASC),
CONSTRAINT `fk_options_field`
FOREIGN KEY (`field_id`)
REFERENCES `field` (`id`)
ON DELETE NO ACTION
ON UPDATE NO ACTION)
ENGINE = InnoDB;
CREATE TABLE IF NOT EXISTS `language` (
`id` INT NOT NULL AUTO_INCREMENT,
`name` VARCHAR(50) NULL,
`label` VARCHAR(50) NULL,
PRIMARY KEY (`id`))
ENGINE = InnoDB;


-- -----------------------------------------------------
-- Table `collection`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `collection` (
`id` INT NOT NULL AUTO_INCREMENT,
`name` VARCHAR(255) NOT NULL,
`label` VARCHAR(255) NOT NULL,
PRIMARY KEY (`id`))
ENGINE = InnoDB;

`id` INT NOT NULL AUTO_INCREMENT,
`language_id` INT NULL,
`name` VARCHAR(255) NOT NULL,
`label` VARCHAR(255) NOT NULL,
PRIMARY KEY (`id`),
INDEX `fk_collection_language1_idx` (`language_id` ASC),
CONSTRAINT `fk_collection_language1`
FOREIGN KEY (`language_id`)
REFERENCES `language` (`id`)
ON DELETE NO ACTION
ON UPDATE NO ACTION)
ENGINE = InnoDB;

-- -----------------------------------------------------
-- Table `collectionfield`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `collectionfield` (
`collection_id` INT NOT NULL,
`field_id` INT NOT NULL,
`id` INT NOT NULL AUTO_INCREMENT,
PRIMARY KEY (`id`, `collection_id`, `field_id`),
INDEX `fk_collection_has_field_field1_idx` (`field_id` ASC),
INDEX `fk_collection_has_field_collection1_idx` (`collection_id` ASC),
CONSTRAINT `fk_collection_has_field_collection1`
CREATE TABLE IF NOT EXISTS `field` (
`id` INT NOT NULL AUTO_INCREMENT,
`collection_id` INT NULL,
`language_id` INT NULL,
`name` VARCHAR(255) NOT NULL,
`type` VARCHAR(255) NOT NULL,
`value` TEXT NULL DEFAULT NULL,
`label` VARCHAR(255) NOT NULL,
PRIMARY KEY (`id`),
INDEX `fk_field_collection1_idx` (`collection_id` ASC),
INDEX `fk_field_language1_idx` (`language_id` ASC),
CONSTRAINT `fk_field_collection1`
FOREIGN KEY (`collection_id`)
REFERENCES `collection` (`id`)
ON DELETE NO ACTION
ON UPDATE NO ACTION,
CONSTRAINT `fk_collection_has_field_field1`
ON DELETE NO ACTION
ON UPDATE NO ACTION,
CONSTRAINT `fk_field_language1`
FOREIGN KEY (`language_id`)
REFERENCES `language` (`id`)
ON DELETE NO ACTION
ON UPDATE NO ACTION)
ENGINE = InnoDB;

CREATE TABLE IF NOT EXISTS `options` (
`id` INT NOT NULL AUTO_INCREMENT,
`text` TEXT NULL DEFAULT NULL,
`field_id` INT NULL,
`language_id` INT NULL,
PRIMARY KEY (`id`),
INDEX `fk_options_field_idx` (`field_id` ASC),
INDEX `fk_options_language1_idx` (`language_id` ASC),
CONSTRAINT `fk_options_field`
FOREIGN KEY (`field_id`)
REFERENCES `field` (`id`)
ON DELETE NO ACTION
ON UPDATE NO ACTION)
ENGINE = InnoDB;

ON DELETE NO ACTION
ON UPDATE NO ACTION,
CONSTRAINT `fk_options_language1`
FOREIGN KEY (`language_id`)
REFERENCES `language` (`id`)
ON DELETE NO ACTION
ON UPDATE NO ACTION)
ENGINE = InnoDB;

SET SQL_MODE=@OLD_SQL_MODE;
SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS;
Expand Down
Loading

0 comments on commit 5ffbcf6

Please sign in to comment.