<?php
/* This file is part of testMaker.
testMaker is free software; you can redistribute it and/or modify
it under the terms of version 2 of the GNU General Public License as
published by the Free Software Foundation.
testMaker 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, see <http://www.gnu.org/licenses/>. */
/**
* @package Core
*/
/**
* Include the InfoBlock class
*/
require_once(dirname(__FILE__).'/InfoBlock.php');
/**
* Include the Block class
*/
require_once(dirname(__FILE__).'/TreeNode.php');
/**
* InfoPage class
*
* @package Core
*/
libLoad("utilities::shortenString");
class InfoPage extends TreeNode
{
var $id;
var $content;
function InfoPage($id)
{
$this->db = &$GLOBALS['dao']->getConnection();
$this->table = DB_PREFIX.'info_pages';
$this->sequence = DB_PREFIX.'info_pages';
$this->parentConnector = 'block_id';
$this->TreeNode($id);
}
/**
* returns parent node with given id
* @return InfoBlock
*/
function _returnParent($id)
{
return $GLOBALS["BLOCK_LIST"]->getBlockById($id, BLOCK_TYPE_INFO);
}
/**
* returns owner of upper block
* @return User
*/
function getOwner()
{
$parent = $this->getParent();
return $parent->getOwner();
}
/**
* returns the title of current info page or if not set a short part of the content
* @return String
*/
function getTitle($shorten = true)
{
$query = 'SELECT title FROM '.$this->table.' WHERE id = ?';
$field = $this->db->getOne($query, array($this->id));
if($this->db->isError($field)) {
return false;
}
if($shorten && (strlen(trim($field)) == 0)) {
$field = shortenString(strip_tags($this->getContent()), 25);
}
return $field;
}
/**
* returns the content of the current page
* @return String
*/
function getContent()
{
return $this->_getField('content');
}
/**
* returns the media connect id
* @return int
*/
function getMediaConnectId()
{
$parent = $this->getParent();
return $parent->getMediaConnectId();
}
/**
* Returns a copy of the current node
* @param integer target parent node id
* @param mixed[] 2-dimensional array of changed ids. First dimension containing node type as name and seconde dimension assigns old id to new id.
* @param integer predefined new node id
* @return Node
*/
function copyNode($parentId, &$changedIds, $newNodeId = NULL)
{
$node = parent::copyNode($parentId, $changedIds, $newNodeId = NULL);
//modify media pathes
if(isset($node)) {
$content = $this->getContent();
$fileHandling = new FileHandling();
$mediaPath = str_replace(ROOT, '', $fileHandling->getFileDirectory()).'media/';
$newParent = new InfoBlock($parentId);
$content = preg_replace('/'.preg_quote($mediaPath, '/').'[0-9]+_/', $mediaPath.$newParent->getMediaConnectId().'_', $content);
$node->modify(array('content' => $content));
}
return $node;
}
/**
* modify the given informations in the current page
* @param mixed[] $modification values to be modified
* @return bool
*/
function modify($modifications)
{
if(!is_array($modifications)) {
trigger_error('<b>InfoPage::modify</b>: $modifications is no valid array');
}
$avalues = array();
if(array_key_exists('content', $modifications)) {
$avalues['content'] = $modifications['content'];
}
if(array_key_exists('title', $modifications)) {
$avalues['title'] = $modifications['title'];
}
if(array_key_exists('pos', $modifications)) {
$avalues['pos'] = $modifications['pos'];
}
if(array_key_exists('media_connect_id', $modifications)) {
$avalues['media_connect_id'] = $modifications['media_connect_id'];
}
if(array_key_exists('disabled', $modifications)) {
$avalues['disabled'] = $modifications['disabled'] ? 1 : 0;
}
return $this->_modify($avalues);
}
}
?>