Twinnable

class Nos\Orm_Behaviour_Twinnable
It adds the ability to twin together different items with different contexts.

See also

Multi-Contexts.

See also

Nos\Orm_Behaviour_Contextable for configuration and methods.

Configuration

property Nos\Orm_Behaviour_Twinnable::$common_id_property

Required. Column used to store the common ID between twinned items. Data type must be int.

property 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.

Methods

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:
  • $context (mixed) –

    Can be

    • Array of contexts ID.
    • all, to receive all contexts.
    • Context ID.
    • main, to receive main twin item.
Returns:

A twinned item, or an array of twinned items, null or array() if none.

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:
  • $filter (array) – Array of contexts ID. If set, return only twin items which the context belongs to array $filter.
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:
  • $filter (array) – Array of contexts ID. If set, return only twinned contexts which belongs to array $filter.
Returns:

Array of all twinned contexts ID, excluding the one of the current item.

Example

<?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',
                        'invariant_fields'   => array(),
                ),
        );
}
Read the Docs v: chiba.1
Versions
latest
chiba.2
chiba.1
0.2
Downloads
PDF
HTML
Epub
On Read the Docs
Project Home
Builds

Free document hosting provided by Read the Docs.