Nos\
Orm_Behaviour_Twinnable
¶Nos\Orm_Behaviour_Contextable
.Nos\Orm_Behaviour_Contextable
for configuration and methods.Nos\Orm_Behaviour_Twinnable::$
common_id_property
¶Required.
Column used to store the common ID between twinned items. Data type must be int
.
Nos\Orm_Behaviour_Twinnable::$
is_main_property
¶Required.
Column used to store if the item is the main item among twin items. Data type must be boolean
.
Nos\Orm_Behaviour_Twinnable::$
common_fields
¶Array of fields which are common to all context twins.
This behaviour adds 2 providers to link WYSIWYGs and medias to context twins.
Provider for Nos\Media\Model_Link
linked to context twins.
<?php
$item->shared_medias_context->avatar; // Get a Model_Link named 'avatar'
$item->shared_medias_context->avatar->media; // Get Model_Media named 'avatar'
$item->shared_medias_context->cv = $Model_Media; // Attach a Model_Media named 'cv'
$item->shared_medias_context->cv = null; // Detach a media from items context twins
// or
unset($item->shared_medias_context->cv);
Provider for Nos\Model_Wysiwyg
linked to context twins.
<?php
$item->shared_wysiwygs_context->content; // Get a Model_Wysiwyg named 'content'
$item->shared_wysiwygs_context->content->wysiwyg_text; // Get content of Model_Wysiwyg named 'content'
$item->shared_wysiwygs_context->summary = 'foo'; // Set a Model_Wysiwyg named 'content', with content 'foo'.
$item->shared_wysiwygs_context->summary = null; // Remove a wysiwyg from items context twins
// or
unset($item->shared_wysiwygs_context->summary);
Nos\Orm_Behaviour_Twinnable::
hasCommonFields
¶Returns: | True if model has common fields, medias or WYSIWYGs. |
---|
Nos\Orm_Behaviour_Twinnable::
isCommonField
($name)¶Parameters: |
|
---|---|
Returns: |
|
Nos\Orm_Behaviour_Twinnable::
delete_all_context
()¶Removes all items twinned to the current item, including the current item itself.
Nos\Orm_Behaviour_Twinnable::
is_main_context
()¶Returns: | True if item is the main among twin items. |
---|
Nos\Orm_Behaviour_Twinnable::
find_context
($context)¶Parameters: |
|
---|---|
Returns: | A twinned item, or an array of twinned items, |
Nos\Orm_Behaviour_Twinnable::
find_main_context
()¶Returns: | The main item among the twins. |
---|
Alias for ->find_context('main')
.
Nos\Orm_Behaviour_Twinnable::
find_other_context
($filter = array())¶Parameters: |
|
---|---|
Returns: | Array of twin items, current item exclude. |
Nos\Orm_Behaviour_Twinnable::
get_all_context
()¶Returns: | Array of all twinned contexts, including the one of the current item. |
---|
Nos\Orm_Behaviour_Twinnable::
get_other_context
($filter = array())¶Parameters: |
|
---|---|
Returns: | Array of all twinned contexts ID, excluding the one of the current item. |
Nos\Orm_Behaviour_Twinnable::
get_possible_context
()¶Returns: | Array of possible contexts ID for current item. |
---|
Nos\Orm_Behaviour_Twinnable::
findMainOrContext
($context, array $options = array())¶Parameters: |
|
---|---|
Returns: | Array of items, like |
See also
<?php
class Model_Page extends \Nos\Orm\Model
{
protected static $_behaviours = array(
'Nos\Orm_Behaviour_Twinnable' => array(
'events' => array('before_insert', 'after_insert', 'before_save', 'after_delete', 'change_parent'),
'context_property' => 'page_context',
'common_id_property' => 'page_context_common_id',
'is_main_property' => 'page_context_is_main',
'common_fields' => array(),
),
);
}