Location: PHPKode > projects > Blandware AtLeap Lite - CMS on PHP > atleaplite/include/dataobject/Resource.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 resource
 *
 * @package     AtleapLite
 * @author      Roman Puchkovskiy
 * @license     http://www.apache.org/licenses/LICENSE-2.0  Apache License, Version 2.0
 */

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

/**
 * Resource which was uploaded by user and further may be downloaded by another
 * user.
 *
 * @package     AtleapLite
 */
class DataObjects_Resource extends DB_DataObject_Base 
{
    ###START_AUTOCODE
    /* the code below is auto generated do not remove the above tag */

    var $__table = 'resource';                        // table name
    var $id;                              // int(11)  not_null primary_key auto_increment
    var $title;                           // string(765)  not_null
    var $size;                            // int(11)  not_null
    var $download;                        // int(1)  not_null
    var $data;                            // blob(16777215)  blob binary
    var $file_name;                       // string(765)  not_null
    var $published;                       // int(1)  not_null
    var $modification_date;               // datetime(19)  binary
    var $publication_date;                // date(10)  binary
    var $expiration_date;                 // date(10)  binary
    var $type;                            // int(6)  not_null

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

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

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

    /**
     * Returns whether this resource is for download, not for view.
     *
     * @return bool true if for download
     */
    function isDownload() {
        return $this->download == 1;
    }

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

    /**
     * Returns whether this resource 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 resource 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());
    }

    /**
     * Detects whether this is image. This is done by file name extension, file
     * content is not examined.
     *
     * @return bool true if this is image
     */
    function isImage() {
        return isResourceImage($this->file_name);
    }

    /**
     * Returns a MIME type detected by this resource extension.
     *
     * @return string|null mime-type or null if not detected
     */
    function getMimeType() {
        return detectMimeType($this->file_name);
    }

    /**
     * Finds a resource by its file name.
     *
     * @param string $fileName  file name
     */
    function findByFileName($fileName) {
        $this->file_name = $fileName;
        $this->find(true);
    }

    /**
     * Returns active resources which are files. Data is not returned.
     *
     * @return array resources
     */
    function findActiveFiles() {
        $dao =& getDao('resource');
        $dao->type = RESOURCE_TYPE_FILE;
        $dao->published = 1;
        $dao->whereAdd("('" . getNowDate() . "' BETWEEN publication_date AND expiration_date)");
        $dao->orderBy('id');
        $dao->selectAdd();
        $dao->selectAdd('id');
        $dao->selectAdd('title');
        $dao->selectAdd('size');
        $dao->selectAdd('download');
        $dao->selectAdd('file_name');
        return $dao->fetchAll();
    }
}
Return current item: Blandware AtLeap Lite - CMS on PHP