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.

property Nos\Orm_Behaviour_Publishable::$options
allow_publish:Callback function or array of callback functions. If any returns false then the item will be restricted from publication.

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

CRUD form

If you’re using the standard_layout included in Novius OS, this behaviour will automatically prepend a field in the subtitle section to select publication status and/or dates (according to the behaviour configuration).

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',
                ),
        );
}