Location: PHPKode > projects > v-creator > v-creator_1.3-pre3/modules/content.php
<?php
	/*
	 * Copyright (c) 2003 gencon Ltd, all rights reserved.
	 *
	 * This file is part of v-creator.
	 *
   * v-creator is free software; you can redistribute it and/or modify
   * it under the terms of the GNU General Public License as published by
   * the Free Software Foundation; either version 2 of the License, or
   * (at your option) any later version.
	 *
   * v-creator is distributed in the hope that it will be useful,
   * but WITHOUT ANY WARRANTY; without even the implied warranty of
   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   * GNU General Public License for more details.
	 *
   * You should have received a copy of the GNU General Public License
   * along with this program; if not, write to the Free Software
   * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
	 */

		require_once(VC_ROOT.'/classes/VCMaintenance.php');

	/**
	 * @brief Class for processing content table functionality.
	 *
	 * $Revision: 1.4 $  $Date: 2006-03-02 12:35:26 $
	 *
	 * @author Initial Generation by v-creator's genDBModule.
	 *
	 * This module is used to maintain and access the content table.
	 * To preserve customisation changes should be made BELOW the point
	 * indicated in the source. This then allows the module to be
	 * re-generated without customisations being lost.
	 *
	 **/
	class content extends VCMaintenance {

		/**
		 * @brief Callback hook for VCMaintenance.
		 *
		 * This function implements the callback function required
		 * by VCMaintenance. If this class is extended the subclass should
		 * override this function to call process relative to the subclass
		 * and not this class.
		 *
		 * @static
		 **/
		function process() {
			VCMaintenance::process(new content);
		}

		/**
		 * @brief Function to delete a row from the content table.
		 *
		 * This function is used to delete a content row based on the unique id.
		 * The following values from VC_data will be used if available:
		 *
		 * <dl>
		 *	<dt>content_id</dt>
		 *	<dd>This should be set to the unique id of the row to be deleted.</dd>
		 * </dl>
		 *
		 * @static
		 */
		function delete() {
			global $VC_data;

			$content_id = VCPage::getSafeVC_data('content_id');

			$sql = 'DELETE FROM content where content_id='.$content_id;
			$VC_data['VC_link']->run($sql);

		}

		/**
		 * @brief Function to add a row to the content table.
		 *
		 * This function is used to add a content row. The following values
		 * from VC_data will be used if available:
		 *
		 * <dl>
		 *  <dt>content_ref</dt>
		 *  <dd>This is a reference to a group of related content items. For example it maybe the URL for the page the content is intented for.</dd>
		 *  <dt>content_sequence</dt>
		 *  <dd>This is the display sequence for content items with the same content_ref.</dd>
		 *  <dt>content_title</dt>
		 *  <dd>An optional main title for a content item.</dd>
		 *  <dt>content_subtitle</dt>
		 *  <dd>An optional subtitle for a content item.</dd>
		 *  <dt>content_text</dt>
		 *  <dd>The actual text for the content item.</dd>
		 *  <dt>content_image</dt>
		 *  <dd>An option reference to an image associated with the content item, usually a URL.</dd>
		 *  <dt>content_image_alignment</dt>
		 *  <dd>A flag that can be used to specify the alignment of the image.</dd>
		 * </dl>
		 *
		 * The following VC_data values will be set:
		 *
		 * <dl>
		 *  <dt>content_last_insert_id</dt>
		 *	<dd>This is set to the content_id of the last row to be added.</dd>
		 * </dl>
		 *
		 * @static
		 */
		function add() {
			global $VC_data;

			$content_ref = VCPage::getSafeVC_data('content_ref');
			$content_title = VCPage::getSafeVC_data('content_title');
			$content_subtitle = VCPage::getSafeVC_data('content_subtitle');
			$content_text = VCPage::getSafeVC_data('content_text');
			$content_image = VCPage::getSafeVC_data('content_image');
			$content_image_alignment = VCPage::getSafeVC_data('content_image_alignment');
			$audit_user_id = VCSession::get('VCSession_user_id');

			$sql = "SELECT MAX(content_sequence) as next_content_sequence FROM content WHERE content_ref='".$content_ref."'";
			$row = $VC_data['VC_link']->getOneRow($sql);
			$content_sequence = $row['next_content_sequence'];
			if ($content_sequence) {
				$content_sequence ++;
			} else {
				$content_sequence = 1;
			}

			$sql = "INSERT INTO content (content_ref, content_sequence, content_title, content_subtitle, content_text, content_image, content_image_alignment, audit_user_id, audit_timestamp) values ('$content_ref', '$content_sequence', '$content_title', '$content_subtitle', '$content_text', '$content_image', '$content_image_alignment', '$audit_user_id', now() )";
			$VC_data['VC_link']->run($sql);
			$VC_data['content_last_insert_id'] = $VC_data['VC_link']->getInsertId();
		}

		/**
		 * @brief Function to update a content row.
		 *
		 * This function is used to update a content row based on it's unique id.
		 * The following values from VC_data will be used if available:
		 *
		 * <dl>
		 *  <dt>content_id</dt>
		 *  <dd>The unique id of the content item.</dd>
		 *  <dt>content_ref</dt>
		 *  <dd>This is a reference to a group of related content items. For example it maybe the URL for the page the content is intented for.</dd>
		 *  <dt>content_sequence</dt>
		 *  <dd>This is the display sequence for content items with the same content_ref.</dd>
		 *  <dt>content_title</dt>
		 *  <dd>An optional main title for a content item.</dd>
		 *  <dt>content_subtitle</dt>
		 *  <dd>An optional subtitle for a content item.</dd>
		 *  <dt>content_text</dt>
		 *  <dd>The actual text for the content item.</dd>
		 *  <dt>content_image</dt>
		 *  <dd>An option reference to an image associated with the content item, usually a URL.</dd>
		 *  <dt>content_image_alignment</dt>
		 *  <dd>A flag that can be used to specify the alignment of the image.</dd>
		 * </dl>
		 *
		 * @static
		 */
		function update() {
			global $VC_data;

			$content_id = VCPage::getSafeVC_data('content_id');
			$content_ref = VCPage::getSafeVC_data('content_ref');
			$content_sequence = VCPage::getSafeVC_data('content_sequence');
			$content_title = VCPage::getSafeVC_data('content_title');
			$content_subtitle = VCPage::getSafeVC_data('content_subtitle');
			$content_text = VCPage::getSafeVC_data('content_text');
			$content_image = VCPage::getSafeVC_data('content_image');
			$content_image_alignment = VCPage::getSafeVC_data('content_image_alignment');
			$audit_user_id = VCSession::get('VCSession_user_id');

			$sql = "UPDATE content SET content_ref='$content_ref', content_sequence='$content_sequence', content_title='$content_title', content_subtitle='$content_subtitle', content_text='$content_text', content_image='$content_image', content_image_alignment='$content_image_alignment', audit_user_id='$audit_user_id', audit_timestamp=now()  WHERE content_id='$content_id'";
			$VC_data['VC_link']->run($sql);

		}

		/**
		 * @brief Function to retrieve user data.
		 *
		 * This function is used to retrieve data from the content table. The
		 * dataSet values returned are:
		 *
		 * <dl>
		 *  <dt>content_id</dt>
		 *  <dd>The unique id of the content item.</dd>
		 *  <dt>content_ref</dt>
		 *  <dd>This is a reference to a group of related content items. For example it maybe the URL for the page the content is intented for.</dd>
		 *  <dt>content_sequence</dt>
		 *  <dd>This is the display sequence for content items with the same content_ref.</dd>
		 *  <dt>content_title</dt>
		 *  <dd>An optional main title for a content item.</dd>
		 *  <dt>content_subtitle</dt>
		 *  <dd>An optional subtitle for a content item.</dd>
		 *  <dt>content_text</dt>
		 *  <dd>The actual text for the content item.</dd>
		 *  <dt>content_image</dt>
		 *  <dd>An option reference to an image associated with the content item, usually a URL.</dd>
		 *  <dt>content_image_alignment</dt>
		 *  <dd>A flag that can be used to specify the alignment of the image.</dd>
		 *  <dt>audit_user_id</dt>
		 *  <dd>The last user to update the content item.</dd>
		 *  <dt>audit_timestamp</dt>
		 *  <dd>Date and time content item was last updated.</dd>
		 *  <dt>current</dt>
		 *  <dd>If content_current_id is set and content_id in the row is
		 *      set then this value for the row will be true indicating that
		 *      the value of content_id is the current value.</dd>
		 * </dl>
		 *
		 * The following values from VC_data will be used if available:
		 *
		 * <dl>
		 *	<dt>content_current_id</dt>
		 *	<dd>If set this value is used to identify and flag the row matching the
		 *			specified content_id value.</dd>
		 *	<dt>content_id</dt>
		 *	<dd>If set only records where content_id matches are retrieved.</dd>
		 * </dl>
		 *
		 * @static
		 */
		function getDataSet() {
			global $VC_data;

			$content_current_id = VCPage::getSafeVC_data('content_current_id');
			$content_id = VCPage::getSafeVC_data('content_id');

			$dataSet = array(array('content_id', 'content_ref', 'content_sequence', 'content_title', 'content_subtitle', 'content_text', 'content_image', 'content_image_alignment', 'audit_user_id', 'audit_timestamp', 'current'));

			$where = '';
			$group = '';
			$order = '';
			$limit = '';

			if ($content_id) {
				$where .= " content_id = '" . $content_id . "' ";
			}

			content::modifyDataSet($where, $group, $order, $limit);

			if ($where) $where = ' WHERE '.$where;
			if ($group) $group = ' GROUP BY '.$group;
			if ($order) $order = ' ORDER BY '.$order;
			if ($limit) $limit = ' LIMIT '.$limit;

			$sql = 'SELECT content_id, content_ref, content_sequence, content_title, content_subtitle, content_text, content_image, content_image_alignment, audit_user_id, UNIX_TIMESTAMP(audit_timestamp) as audit_timestamp FROM content '.$where.' '.$group.' '.$order.' '.$limit;
			$result = $VC_data['VC_link']->execute($sql);

			while ($row = $VC_data['VC_link']->getNextRow($result)) {
				$current = $content_current_id == $row['content_id']?VC_TRUE:VC_FALSE;
				$dataSet[] = array($row['content_id'], stripslashes($row['content_ref']), $row['content_sequence'], stripslashes($row['content_title']), stripslashes($row['content_subtitle']), stripslashes($row['content_text']), stripslashes($row['content_image']), $row['content_image_alignment'], $row['audit_user_id'], $row['audit_timestamp'], $current);
			}

			return $dataSet;
		}

		/* ==================================================================== */
		/* === DO NOT EDIT THIS LINE: CODE BELOW IT WILL NOT BE REGENERATED === */
		/* ==================================================================== */

		/**
		 * @brief Function to setup defines.
		 *
		 * When called this function sets up defines for use with the content module.
		 *
		 * @static
		 **/
		function defines() {
			if (!defined('CONTENT_DEFINES')) {
				define('CONTENT_DEFINES','CONTENT_DEFINES');

				// This define can be used with the dataSetList module to build dropdowns and check 'modes' for alignment.
				define('CONTENT_ALIGNMENT', 'NONE,LEFT,CENTER,RIGHT');
			}
		}

		/**
		 * @brief Function to customise SQL for content::getDataSet.
		 *
		 * This function is used to customise the SQL used by the content::getDataSet
		 * function.
		 *
		 * @param where The where clause for the SQL without the leading WHERE keyword,
		 * may already contain data if content_id has been set in VC_data.
		 * @param group The group by clause for the SQL without the leading GROUP BY keywords.
		 * @param order The order by clause for the SQL without the leading ORDER BY keywords.
		 * @param limit The limit clause for the SQL without the leading LIMIT keyword.
		 *
		 * @static
		 */
		function modifyDataSet(&$where, &$group, &$order, &$limit) {

			$content_ref = VCPage::getSafeVC_data('content_ref');
			if ($content_ref) {
				if ($where) $where = $where.' AND ';
				$where .= ' content_ref = \''.$content_ref.'\'';
			}

			$order .= 'content_sequence';
		}
	}

?>
Return current item: v-creator