Publishable

class Nos\Orm_Behaviour_Publishable

Adds a publication status on a Nos\Orm\Model. 2 modes are available:

  • Yes / No state ;
  • Publication depending on start / end dates (yes / no choice remains).

Configuration

property Nos\Orm_Behaviour_Publishable::$publication_state_property

Always required, both for the yes/no and the date range modes.

Column used to store the publication state. Its data type must be int:

  • 0 means not published;
  • 1 means always published;
  • 2 means publication depends on a date range (when combining the 2 modes).
property Nos\Orm_Behaviour_Publishable::$publication_start_property

Required for date range mode. Column used to store the publication start date. Its data type must be datetime.

property Nos\Orm_Behaviour_Publishable::$publication_end_property

Required for date range mode. Column used to store the publication end date. Its data type must be datetime.

Methods

Nos\Orm_Behaviour_Publishable::published()
Returns:true or false depending on whether the item is currently published or not.
Nos\Orm_Behaviour_Publishable::planificationStatus()
Returns:0 (not published), 1 (published) or 2 (scheduled).
Nos\Orm_Behaviour_Publishable::publicationStart()
Returns:the publication start date, MySQL format.
Nos\Orm_Behaviour_Publishable::publicationEnd()
Returns:the publication end date, MySQL format.

Other

This behaviour extends Model->find().

You can use the published key in the where array. Appropriate conditions will be added, according to the configuration of the behaviour. Especially useful with the date range mode (and start / end dates).

Example

<?php

// Yes/No state
class Model_Page extends \Nos\Orm\Model
{
        protected static $_behaviours = array(
                'Nos\Orm_Behaviour_Publishable' => array(
                        'publication_state_property' => 'page_published',
                ),
        );
}

$page = Model_Page::find(1);

if ($page->published()) {
        // Do something
}
<?php

// Date range mode (combined with Yes/No state)
class Model_Page extends \Nos\Orm\Model
{
        protected static $_behaviours = array(
                'Nos\Orm_Behaviour_Publishable' => array(
                        'publication_state_property' => 'page_published',
                        'publication_start_property' => 'page_publication_start',
                        'publication_end_property'   => 'page_publication_end',
                ),
        );
}
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.