forked from servergrove/TranslationEditorBundle
-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
274 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<?php | ||
|
||
namespace ServerGrove\Bundle\TranslationEditorBundle\Document; | ||
|
||
use ServerGrove\Bundle\TranslationEditorBundle\Model\Entry as AbstractEntry; | ||
|
||
/** | ||
* Entry entity for Doctrine MongoDB | ||
* | ||
* @author Ken Golovin <[email protected]> | ||
*/ | ||
class Entry extends AbstractEntry | ||
{ | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<?php | ||
|
||
namespace ServerGrove\Bundle\TranslationEditorBundle\Document; | ||
|
||
use ServerGrove\Bundle\TranslationEditorBundle\Model\Locale as AbstractLocale; | ||
|
||
/** | ||
* Locale entity for Doctrine MongoDB | ||
* | ||
* @author Ken Golovin <[email protected]> | ||
*/ | ||
class Locale extends AbstractLocale | ||
{ | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<?php | ||
|
||
namespace ServerGrove\Bundle\TranslationEditorBundle\Document; | ||
|
||
use ServerGrove\Bundle\TranslationEditorBundle\Model\Translation as AbstractTranslation; | ||
|
||
/** | ||
* Translation entity for Doctrine MongoDB | ||
* | ||
* @author Ken Golovin <[email protected]> | ||
*/ | ||
class Translation extends AbstractTranslation | ||
{ | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<doctrine-mongo-mapping xmlns="http://doctrine-project.org/schemas/odm/doctrine-mongo-mapping" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://doctrine-project.org/schemas/odm/doctrine-mongo-mapping | ||
http://doctrine-project.org/schemas/odm/doctrine-mongo-mapping.xsd"> | ||
|
||
<document name="ServerGrove\Bundle\TranslationEditorBundle\Document\Entry" | ||
table="sg_translation_entry"> | ||
|
||
<field fieldName="id" | ||
name="id" | ||
id="true" | ||
strategy="AUTO"> | ||
</field> | ||
|
||
<field fieldName="domain" | ||
name="domain" | ||
type="string"/> | ||
|
||
<field name="fileName" | ||
column="file_name" | ||
type="string"/> | ||
|
||
<field fieldName="format" | ||
name="format" | ||
type="string"/> | ||
|
||
<field fieldName="alias" | ||
name="alias" | ||
type="string"/> | ||
|
||
<reference-many target-document="ServerGrove\Bundle\TranslationEditorBundle\Document\Translation" | ||
field="translations" | ||
mapped-by="entry"> | ||
<cascade> | ||
<all /> | ||
</cascade> | ||
</reference-many> | ||
|
||
</document> | ||
|
||
</doctrine-mongo-mapping> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<doctrine-mongo-mapping xmlns="http://doctrine-project.org/schemas/odm/doctrine-mongo-mapping" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://doctrine-project.org/schemas/odm/doctrine-mongo-mapping | ||
http://doctrine-project.org/schemas/odm/doctrine-mongo-mapping.xsd"> | ||
|
||
<document name="ServerGrove\Bundle\TranslationEditorBundle\Document\Locale" | ||
table="sg_translation_entry"> | ||
|
||
<field fieldName="id" | ||
name="id" | ||
id="true" | ||
strategy="AUTO"> | ||
</field> | ||
|
||
|
||
<field fieldName="language" | ||
name="language" | ||
type="string"/> | ||
|
||
<field fieldName="country" | ||
name="country" | ||
type="string" | ||
nullable="true"/> | ||
|
||
<field fieldName="active" | ||
column="active" | ||
type="boolean"/> | ||
|
||
|
||
<reference-many target-document="ServerGrove\Bundle\TranslationEditorBundle\Document\Translation" | ||
field="translations" | ||
mapped-by="locale"> | ||
<cascade> | ||
<all /> | ||
</cascade> | ||
</reference-many> | ||
|
||
</document> | ||
|
||
</doctrine-mongo-mapping> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<doctrine-mongo-mapping xmlns="http://doctrine-project.org/schemas/odm/doctrine-mongo-mapping" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://doctrine-project.org/schemas/odm/doctrine-mongo-mapping | ||
http://doctrine-project.org/schemas/odm/doctrine-mongo-mapping.xsd"> | ||
|
||
<document name="ServerGrove\Bundle\TranslationEditorBundle\Document\Translation" | ||
table="sg_translation_entry"> | ||
|
||
<field fieldName="id" | ||
name="id" | ||
id="true" | ||
strategy="AUTO"> | ||
</field> | ||
|
||
<field fieldName="value" | ||
name="value" | ||
type="string"/> | ||
|
||
|
||
<reference-one target-document="ServerGrove\Bundle\TranslationEditorBundle\Document\Entry" | ||
field="entry"> | ||
<cascade> | ||
<persist /> | ||
<refresh /> | ||
</cascade> | ||
</reference-one> | ||
|
||
<reference-one target-document="ServerGrove\Bundle\TranslationEditorBundle\Document\Locale" | ||
field="locale"> | ||
<cascade> | ||
<persist /> | ||
<refresh /> | ||
</cascade> | ||
</reference-one> | ||
|
||
</document> | ||
|
||
</doctrine-mongo-mapping> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
<?php | ||
|
||
namespace ServerGrove\Bundle\TranslationEditorBundle\Storage; | ||
|
||
/** | ||
* Doctrine MongoDB Storage | ||
* | ||
* @author Ken Golovin <[email protected]> | ||
*/ | ||
class MongoDBStorage extends AbstractStorage implements StorageInterface | ||
{ | ||
const CLASS_LOCALE = 'ServerGrove\Bundle\TranslationEditorBundle\Document\Locale'; | ||
const CLASS_ENTRY = 'ServerGrove\Bundle\TranslationEditorBundle\Document\Entry'; | ||
const CLASS_TRANSLATION = 'ServerGrove\Bundle\TranslationEditorBundle\Document\Translation'; | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
protected function getLocaleClassName() | ||
{ | ||
return self::CLASS_LOCALE; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
protected function getEntryClassName() | ||
{ | ||
return self::CLASS_ENTRY; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
protected function getTranslationClassName() | ||
{ | ||
return self::CLASS_TRANSLATION; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function findLocaleList(array $criteria = array()) | ||
{ | ||
$builder = $this->manager->createQueryBuilder($this->getLocaleClassName()); | ||
|
||
$this->hydrateCriteria($builder, $criteria); | ||
|
||
return iterator_to_array($builder->getQuery()->execute()); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function findEntryList(array $criteria = array()) | ||
{ | ||
$builder = $this->manager->createQueryBuilder($this->getEntryClassName()); | ||
|
||
$this->hydrateCriteria($builder, $criteria); | ||
|
||
return iterator_to_array($builder->getQuery()->execute()); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function findTranslationList(array $criteria = array()) | ||
{ | ||
$builder = $this->manager->createQueryBuilder($this->getTranslationClassName()); | ||
|
||
if(isset($criteria['locale']) && $criteria['locale'] instanceof \ServerGrove\Bundle\TranslationEditorBundle\Document\Locale) { | ||
$criteria['locale'] = $criteria['locale']->getId(); | ||
} | ||
if(isset($criteria['entry']) && $criteria['entry'] instanceof \ServerGrove\Bundle\TranslationEditorBundle\Document\Entry) { | ||
$criteria['entry'] = $criteria['entry']->getId(); | ||
} | ||
|
||
$this->hydrateCriteria($builder, $criteria); | ||
|
||
return iterator_to_array($builder->getQuery()->execute()); | ||
} | ||
|
||
/** | ||
* Populate a criteria builder | ||
* | ||
* @param \Doctrine\ODM\MongoDB\Query\Builder $builder | ||
* @param array $criteria | ||
*/ | ||
protected function hydrateCriteria($builder, array $criteria = array()) | ||
{ | ||
foreach ($criteria as $fieldName => $fieldValue) { | ||
$builder->addOr($builder->expr()->field($fieldName)->equals($fieldValue)); | ||
} | ||
} | ||
} |