Adds a publication status on a Nos\Orm\Model. 2 modes are available:
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:
Required for date range mode. Column used to store the publication start date. Its data type must be datetime.
Required for date range mode. Column used to store the publication end date. Its data type must be datetime.
Returns: | true or false depending on whether the item is currently published or not. |
---|
Returns: | 0 (not published), 1 (published) or 2 (scheduled). |
---|
Returns: | the publication start date, MySQL format. |
---|
Returns: | the publication end date, MySQL format. |
---|
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).
<?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',
),
);
}