newsItem.class.inc.php

The NewsItem class is a variant on the Post class.It illustrates the use of the $docFields array to specify built-in fields to be associated with the PubKit item. Here, the description field can be linked to a form input for an "editor's notes" feature. As of PubKit E1.0, you can also add more fields using the &docFields parameter in the snippet call.

<?php
class NewsItem extends Resource
{
    public $defaultDate; // set using function in constructor

    public $tvs = array(
        'pkDate'=>NULL,
        'pkDateTo'=>NULL
        );

    public $validate = array(
        'pagetitle'=>'string||Req||title',
        'longtitle'=>'string||Req||postHeadline',
        'section'=>'string||Req||tags',
        'tvpkRichContent'=>'string||Req||postContent',
        'displayDate'=>'date||Req||displayDate',
        'displayFrom'=>'date||Opt||fromDate',
        'displayTo'=>'date||Opt||toDate'
        );

    public $docFields = array('description');

function __construct($pid, $fields, $lang) {
    $this->defaultDate = strftime($lang['dateFormat']);
    $this->tvs['pkPreviewFlag'] = (isset($fields['preview'])) ? 1:0;
    parent::__construct($pid, $fields, $lang);
}

function CustomFields($fields, $doc) {
    $customFields = array();

    $customFields['displayDate'] = strftime($this->lang['dateFormat'], strtotime($fields['pkDate']));
    $customFields['displayTo']   = ($fields['pkDateTo'] > 0) ?
        strftime($this->lang['dateFormat'], strtotime($fields['pkDateTo'])) : "";
    $customFields['displayFrom'] = ($doc->Get('pub_date') > 0) ?
        strftime($this->lang['dateFormat'], $doc->Get('pub_date')) : "";

    return $customFields;
}

}
?>