Location: PHPKode > projects > Blandware AtLeap Lite - CMS on PHP > atleaplite/include/dataobject/Page.php
<?php
/*
 *  Copyright 2008 Blandware (http://www.blandware.com)
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 */

/**
 * Table Definition for page
 *
 * @package     AtleapLite
 * @author      Roman Puchkovskiy
 * @license     http://www.apache.org/licenses/LICENSE-2.0  Apache License, Version 2.0
 */

/**
 */
require_once 'dbdo_ext.php';

/**
 * Represents a page; has title, keywords, description, identifier. Page
 * always belongs to some layout which controls its display. Page also may
 * belong to some menu.
 *
 * @package     AtleapLite
 */
class DataObjects_Page extends DB_DataObject_Base 
{
    ###START_AUTOCODE
    /* the code below is auto generated do not remove the above tag */

    var $__table = 'page';                            // table name
    var $id;                              // int(11)  not_null primary_key auto_increment
    var $title;                           // string(765)  not_null
    var $keywords;                        // string(765)  
    var $description;                     // string(765)  
    var $identifier;                      // string(120)  not_null multiple_key
    var $language;                        // string(765)  not_null
    var $layout;                          // string(120)  not_null
    var $fixed;                           // int(1)  not_null
    var $menu;                            // string(120)  
    var $menu_index;                      // int(11)  
    var $published;                       // int(1)  not_null
    var $modification_date;               // datetime(19)  binary
    var $publication_date;                // date(10)  binary
    var $expiration_date;                 // date(10)  binary

    /* ZE2 compatibility trick*/
    function __clone() { return $this;}

    /* Static get */
    function staticGet($k,$v=NULL) { return DB_DataObject::staticGet('DataObjects_Page',$k,$v); }

    /* the code above is auto generated do not remove the tag below */
    ###END_AUTOCODE

    /**
     * Returns title of layout to which this page belongs.
     *
     * @return string layout title
     */
    function getLayoutTitle() {
        return getLayoutTitle($this->layout);
    }

    /**
     * Returns title of menu to which this page belongs.
     *
     * @return string menu title
     */
    function getMenuTitle() {
        return getMenuTitle($this->layout, $this->menu);
    }

    /**
     * Returns fields owned by this page.
     *
     * @return array fields
     */
    function getFields() {
        $dao =& getDao('field');
        $dao->page_id = $this->id;
        return $dao->fetchAll();
    }

    /**
     * Returns whether this page is fixed (and cannot be deleted).
     *
     * @return bool true if fixed
     */
    function isFixed() {
        return $this->fixed == 1;
    }

    /**
     * Returns human-readable status which says whether this page is fixed
     * or not.
     *
     * @return string yes or no (localized)
     */
    function isFixedYesno() {
        return yesnoDescr($this->isFixed());
    }

    /**
     * Returns whether this page is published.
     *
     * @return bool true if published
     */
    function isPublished() {
        return $this->published == 1;
    }

    /**
     * Returns human-readable status which says whether this is published.
     *
     * @return string yes or no (localized)
     */
    function isPublishedYesno() {
        return yesnoDescr($this->isPublished());
    }

    /**
     * Returns true if page is published and the current date is between its
     * publication and expiration dates.
     *
     * @return true if active
     */
    function isActive() {
        return $this->isPublished() && isNowBetween($this->publication_date, $this->expiration_date);
    }

    /**
     * Returns human-readable status which says whether this is active.
     *
     * @return string yes or no (localized)
     */
    function isActiveYesno() {
        return yesnoDescr($this->isActive());
    }

    /**
     * Finds a page by its identifier and language.
     *
     * @param string $identifier    page identifier
     * @param string $language      page language
     * @return page
     */
    function findByIdentifierAndLanguage($identifier, $language) {
        $this->identifier = $identifier;
        $this->language = $language;
        return $this->find(true);
    }

    /**
     * Returns active pages.
     *
     * @param string $language  language
     * @param bool $noNewsItems if true, no news items will be returned
     * @return array pages
     */
    function findActiveByLanguage($language, $noNewsItems) {
        $dao =& getDao('page');
        $dao->language = $language;
        if ($noNewsItems) {
            $dao->whereAdd("(layout <> 'newsItem')");
        }
        $dao->published = 1;
        $dao->whereAdd("('" . getNowDate() . "' BETWEEN publication_date AND expiration_date)");
        $dao->orderBy('id');
        return $dao->fetchAll();
    }

    /**
     * Returns active pages which are assigned a given menu.
     *
     * @param string $menuId    menu identifier
     * @param string $language  language
     * @return array pages
     */
    function findActiveByMenuAndLanguage($menuId, $language) {
        $dao =& getDao('page');
        $dao->menu = $menuId;
        $dao->language = $language;
        $dao->published = 1;
        $dao->whereAdd("('" . getNowDate() . "' BETWEEN publication_date AND expiration_date)");
        $dao->orderBy('menu_index');
        return $dao->fetchAll();
    }

    /**
     * Deletes all subobjects owned by this page (fields).
     *
     * @return boolean true
     */
    function deleteSubObjects() {
        $fields = $this->getFields();
        foreach ($fields as $field) {
            $field->delete();
        }

        return true;
    }
}
Return current item: Blandware AtLeap Lite - CMS on PHP