Skip to content

Commit

Permalink
Merge pull request #33 from mugoweb/extend-ezsite-data
Browse files Browse the repository at this point in the history
Adding function "createNew" to simplify the creation of a ezsitedata entry
  • Loading branch information
pkamps authored Jan 11, 2017
2 parents 37960de + 41ba067 commit b222c1f
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 17 deletions.
60 changes: 43 additions & 17 deletions kernel/classes/ezsitedata.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,38 +8,64 @@
* @package kernel
*/

/**
* eZPersistentObject implementation for ezsite_data table.
* Enables you to store and fetch key/value pairs
*
* Class eZSiteData
*/
class eZSiteData extends eZPersistentObject
{
/**
* Schema definition
* eZPersistentObject implementation for ezsite_data table
* @see kernel/classes/ezpersistentobject.php
* @return array
*/
public static function definition()
{
return array( 'fields' => array( 'name' => array( 'name' => 'name',
'datatype' => 'string',
'default' => null,
'required' => true ),

'value' => array( 'name' => 'value',
'datatype' => 'string',
'default' => null,
'required' => true ),

),

'keys' => array( 'name' ),
'class_name' => 'eZSiteData',
'name' => 'ezsite_data',
'function_attributes' => array()
return array(
'fields' => array(
'name' => array(
'name' => 'name',
'datatype' => 'string',
'default' => null,
'required' => true
),
'value' => array(
'name' => 'value',
'datatype' => 'string',
'default' => null,
'required' => true
),
),
'keys' => array( 'name' ),
'class_name' => 'eZSiteData',
'name' => 'ezsite_data',
'function_attributes' => array()
);
}

/**
* Constructs a new eZSiteData instance. You need to call 'store()'
* in order to store it into the DB.
*
* @param string $key
* @param string $value
* @return eZSiteData
*/
public static function create( $name, $value )
{
return new eZSiteData( array(
'name' => $name,
'value' => $value
) );
}

/**
* Fetches a site data by name
*
* @param string $name
* @return eZPersistentObject
*/
public static function fetchByName( $name )
{
Expand Down
16 changes: 16 additions & 0 deletions tests/tests/kernel/classes/ezsitedata_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,22 @@ public function testFetchByName()

$res->remove();
}

/**
* Unit test for testCreate() method
*/
public function testCreate()
{
$obj = eZSiteData::create( 'foo', 'bar' );
$obj->store();
unset( $obj );

$res = eZSiteData::fetchByName( 'foo' );
$this->assertInstanceOf( 'eZSiteData', $res );

$res->remove();
}

}

?>

0 comments on commit b222c1f

Please sign in to comment.