post.class.inc.php

The default class for a resource-based item.

The date field (pkDate) is automatically set to today's date.

The template variables to be loaded and saved with the item are listed in the tvs array. This array can be extended (as of PubKit E1.0) using the &tvs parameter to list extra text-type MODx template variables. The &tags parameter can also specify extra template variables for checkboxes, radio buttons and selection lists.

The fields to be validated are listed in the validate array, specifying the type of validation, whether the field may be empty, and the error message to extract from the language file's array. An alternative set of validation rules can be specified with the &validate parameter.

<?php
class Post 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',
        'tvpkRichContent'=>'string||Req||postContent',
        'displayDate'=>'date||Req||displayDate',
        'displayFrom'=>'date||Opt||fromDate',
        'displayTo'=>'date||Opt||toDate'
        );

    public $docFields = array();

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;
}

}
?>