-
Notifications
You must be signed in to change notification settings - Fork 1
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
0 parents
commit 37b95c0
Showing
14 changed files
with
1,148 additions
and
0 deletions.
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,44 @@ | ||
<?php | ||
/** | ||
* This file is part of the EzMatrixBundle package | ||
* | ||
* See README.md file distributed with this source code for further information. | ||
* | ||
* @copyright Copyright (C) eZ Systems AS. All rights reserved. | ||
* @license For full copyright and license information view LICENSE file distributed with this source code. | ||
* @author For list of contributors see link in composer.json file distributed with this source code. | ||
*/ | ||
|
||
namespace xrow\MatrixBundle\DependencyInjection; | ||
|
||
use Symfony\Component\DependencyInjection\ContainerBuilder; | ||
use Symfony\Component\Config\FileLocator; | ||
use Symfony\Component\DependencyInjection\Extension\PrependExtensionInterface; | ||
use Symfony\Component\HttpKernel\DependencyInjection\Extension; | ||
use Symfony\Component\DependencyInjection\Loader; | ||
use Symfony\Component\Yaml\Yaml; | ||
|
||
/** | ||
* This is the class that loads and manages your bundle configuration | ||
* | ||
* To learn more see {@link http://symfony.com/doc/current/cookbook/bundles/extension.html} | ||
*/ | ||
class xrowMatrixExtension extends Extension implements PrependExtensionInterface | ||
{ | ||
/** | ||
* {@inheritDoc} | ||
*/ | ||
public function load( array $configs, ContainerBuilder $container ) | ||
{ | ||
$loader = new Loader\YamlFileLoader( $container, new FileLocator( __DIR__ . '/../Resources/config' ) ); | ||
$loader->load( 'services.yml' ); | ||
} | ||
|
||
public function prepend( ContainerBuilder $container ) | ||
{ | ||
$config = Yaml::parse( __DIR__ . '/../Resources/config/field_templates.yml' ); | ||
|
||
$container->prependExtensionConfig( 'ezpublish', $config ); | ||
|
||
} | ||
} |
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,59 @@ | ||
<?php | ||
/** | ||
* This file is part of the EzMatrixBundle package | ||
* | ||
* See README.md file distributed with this source code for further information. | ||
* | ||
* @copyright Copyright (C) eZ Systems AS. All rights reserved. | ||
* @license For full copyright and license information view LICENSE file distributed with this source code. | ||
* @author For list of contributors see link in composer.json file distributed with this source code. | ||
*/ | ||
|
||
namespace xrow\MatrixBundle\FieldType\Matrix; | ||
|
||
use eZ\Publish\SPI\Persistence\ValueObject; | ||
|
||
/** | ||
* Class Column | ||
* Column represents a single configured Column for a Matrix | ||
* | ||
* @package xrow\MatrixBundle\FieldType\Matrix | ||
*/ | ||
class Column extends ValueObject | ||
{ | ||
/** | ||
* Identifier value of the column | ||
* @var string | ||
*/ | ||
public $id; | ||
|
||
/** | ||
* User-friendly name for the column | ||
* @var string | ||
*/ | ||
public $name; | ||
|
||
/** | ||
* Integer position of the column | ||
* @var int | ||
*/ | ||
public $num; | ||
|
||
public function __toString() | ||
{ | ||
return (string)$this->name; | ||
} | ||
|
||
/** | ||
* Convert the column to an array compatible with the Matrix hash format | ||
* @return array | ||
*/ | ||
public function toArray() | ||
{ | ||
return array( | ||
'id' => $this->id, | ||
'name' => $this->name, | ||
'num' => $this->num | ||
); | ||
} | ||
} |
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,133 @@ | ||
<?php | ||
/** | ||
* This file is part of the EzMatrixBundle package | ||
* | ||
* See README.md file distributed with this source code for further information. | ||
* | ||
* @copyright Copyright (C) eZ Systems AS. All rights reserved. | ||
* @license For full copyright and license information view LICENSE file distributed with this source code. | ||
* @author For list of contributors see link in composer.json file distributed with this source code. | ||
*/ | ||
|
||
namespace xrow\MatrixBundle\FieldType\Matrix; | ||
|
||
use eZ\Publish\Core\Base\Exceptions\InvalidArgumentType; | ||
|
||
/** | ||
* Class ColumnCollection | ||
* Collection of Column values for Matrix | ||
* | ||
* @package xrow\MatrixBundle\FieldType\Matrix | ||
*/ | ||
class ColumnCollection extends \ArrayObject | ||
{ | ||
|
||
/** | ||
* @param \xrow\MatrixBundle\FieldType\Matrix\Column[] $elements | ||
*/ | ||
public function __construct( array $elements = array() ) | ||
{ | ||
// Call parent constructor without $elements because all column elements | ||
// must be given an id by $this->offsetSet() | ||
parent::__construct(); | ||
foreach ( $elements as $i => $author ) | ||
{ | ||
if ( is_array( $author ) ) | ||
{ | ||
$author = new Column( $author ); | ||
} | ||
$this->offsetSet( $i, $author ); | ||
} | ||
} | ||
|
||
/** | ||
* Create a ColumnCollection from an array of field names. | ||
* The ids will be auto-generated based on the names. | ||
* @param array $names | ||
* | ||
* @return ColumnCollection | ||
*/ | ||
public static function createFromNames( array $names = array() ) | ||
{ | ||
$columns = array(); | ||
$i = 1; | ||
|
||
foreach ( $names as $name ) | ||
{ | ||
$id = strtolower( | ||
preg_replace( | ||
array( '/\s+/', '/[^a-z0-9_]/i' ), | ||
array( '_', '' ), | ||
$name | ||
) | ||
); | ||
|
||
$columns[] = new Column( array( 'id' => $id, 'name' => $name, 'num' => $i ) ); | ||
$i++; | ||
} | ||
|
||
return new self( $columns ); | ||
} | ||
|
||
/** | ||
* Adds a new author to the collection | ||
* | ||
* @throws InvalidArgumentType When $value is not of type Column | ||
* @param int $offset | ||
* @param \xrow\MatrixBundle\FieldType\Matrix\Column $value | ||
*/ | ||
public function offsetSet( $offset, $value ) | ||
{ | ||
if ( !$value instanceof Column ) | ||
{ | ||
throw new InvalidArgumentType( | ||
'$value', | ||
'xrow\\MatrixBundle\\FieldType\\Matrix\\Column', | ||
$value | ||
); | ||
} | ||
|
||
$aColumns = $this->getArrayCopy(); | ||
parent::offsetSet( $offset, $value ); | ||
if ( !isset( $value->id ) || $value->id == -1 ) | ||
{ | ||
if ( !empty( $aColumns ) ) | ||
{ | ||
$value->id = end( $aColumns )->id + 1; | ||
} | ||
else | ||
{ | ||
$value->id = 1; | ||
} | ||
} | ||
} | ||
|
||
/* | ||
* Returns a comma-separated list of the column names. | ||
* @return string | ||
*/ | ||
public function getColumnNames() | ||
{ | ||
return implode( ', ', $this->getArrayCopy() ); | ||
} | ||
|
||
public function __toString() | ||
{ | ||
return implode( "\t", $this->getArrayCopy() ); | ||
} | ||
|
||
/** | ||
* Returns an array compatible with the 'columns' portion of the Matrix hash format. | ||
* @return array | ||
*/ | ||
public function toArray() | ||
{ | ||
$columns = array(); | ||
foreach ( $this->getArrayCopy() as $column ) | ||
{ | ||
$columns[] = $column->toArray(); | ||
} | ||
|
||
return $columns; | ||
} | ||
} |
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,27 @@ | ||
<?php | ||
/** | ||
* This file is part of the EzMatrixBundle package | ||
* | ||
* See README.md file distributed with this source code for further information. | ||
* | ||
* @copyright Copyright (C) eZ Systems AS. All rights reserved. | ||
* @license For full copyright and license information view LICENSE file distributed with this source code. | ||
* @author For list of contributors see link in composer.json file distributed with this source code. | ||
*/ | ||
|
||
namespace xrow\MatrixBundle\FieldType\Matrix; | ||
|
||
use eZ\Publish\SPI\Persistence\ValueObject; | ||
|
||
/** | ||
* Class Matrix | ||
* Value object for the Matrix FieldType | ||
* | ||
* @package xrow\MatrixBundle\FieldType\Matrix | ||
*/ | ||
class Matrix extends ValueObject | ||
{ | ||
public $id; | ||
public $columns; | ||
public $rows; | ||
} |
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,59 @@ | ||
<?php | ||
/** | ||
* This file is part of the EzMatrixBundle package | ||
* | ||
* See README.md file distributed with this source code for further information. | ||
* | ||
* @copyright Copyright (C) eZ Systems AS. All rights reserved. | ||
* @license For full copyright and license information view LICENSE file distributed with this source code. | ||
* @author For list of contributors see link in composer.json file distributed with this source code. | ||
*/ | ||
|
||
namespace xrow\MatrixBundle\FieldType\Matrix; | ||
|
||
use eZ\Publish\SPI\Persistence\ValueObject; | ||
|
||
/** | ||
* Class Row | ||
* Represents a Row in a Matrix | ||
* | ||
* @package xrow\MatrixBundle\FieldType\Matrix | ||
*/ | ||
class Row extends ValueObject | ||
{ | ||
|
||
/** | ||
* Row's index within the row collection. | ||
* | ||
* @var int | ||
*/ | ||
public $id; | ||
|
||
/** | ||
* Associative array of column values | ||
* | ||
* @var array | ||
*/ | ||
public $columns; | ||
|
||
public function __construct( array $columns ) | ||
{ | ||
$this->columns = $columns; | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function __toString() | ||
{ | ||
return implode( "\t", $this->columns ); | ||
} | ||
|
||
/** | ||
* @return array | ||
*/ | ||
public function toArray() | ||
{ | ||
return $this->columns; | ||
} | ||
} |
Oops, something went wrong.