<?php
/*
* Free IT Foundation
* Free Technology Serving Knowledge
* http://www.free-it-foundation.org
*
* This file is part of Knowledge Box.
*
* Knowledge Box 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 3 of the License, or
* (at your option) any later version.
*
* Knowledge Box 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 Knowledge Box. If not, see <http://www.gnu.org/licenses/>.
*/
/*
* class
* KBModuleBase
*/
class KBModuleBase extends CDpObject
{
var $id = 0;
var $name;
/*
* constructor
*/
function KBModuleBase ()
{
$primaryKey = 'id';
$this->CDpObject (KB_TABLE_BASES, $primaryKey);
}
/*
* getId ()
*/
function getId ()
{
return $this->id;
}
/*
* setId ()
*/
function setId ($id)
{
$this->id = (int) $id;
}
/*
* getName ()
*/
function getName ()
{
return $this->name;
}
/*
* setName ()
*/
function setName ($name)
{
$this->name = $name;
}
/*
* store ()
*/
function store ()
{
// insert
if ((int) $this->id == 0)
{
// execute
$this->storeRecord ();
// config
$config = new KBModuleConfig ();
$config->setBaseId ($this->getId ());
$config->setProperty (KB_CONFIG_PROPERTY_RESULTS);
$config->setIntValue (KB_CONFIG_DEFAULT_RESULTS);
$config->store ();
// config
$config = new KBModuleConfig ();
$config->setBaseId ($this->getId ());
$config->setProperty (KB_CONFIG_PROPERTY_LASTENTRIES);
$config->setIntValue (KB_CONFIG_DEFAULT_LASTENTRIES);
$config->store ();
// config
$config = new KBModuleConfig ();
$config->setBaseId ($this->getId ());
$config->setProperty (KB_CONFIG_PROPERTY_DATEFORMAT);
$config->setStringValue (KB_CONFIG_DEFAULT_DATEFORMAT);
$config->store ();
// config
$config = new KBModuleConfig ();
$config->setBaseId ($this->getId ());
$config->setProperty (KB_CONFIG_PROPERTY_DATESEPARATOR);
$config->setStringValue (KB_CONFIG_DEFAULT_DATESEPARATOR);
$config->store ();
// config
$config = new KBModuleConfig ();
$config->setBaseId ($this->getId ());
$config->setProperty (KB_CONFIG_PROPERTY_WYSIWYG);
$config->setStringValue (KB_CONFIG_DEFAULT_WYSIWYG);
$config->store ();
// update
} else {
// execute
$this->storeRecord ();
}
}
/*
* storeRecord ()
*/
function storeRecord ()
{
parent::store ();
}
/*
* delete ()
*/
function delete ()
{
// recursive
$configs = KBModuleConfig::getConfigsByBase ($this->id);
foreach ($configs as $config)
$config->delete (true);
// recursive
$entries = KBModuleEntry::getEntriesByBase ($this->id);
foreach ($entries as $entry)
$entry->delete (true);
// recursive
$fields = KBModuleField::getFieldsByBase ($this->id);
foreach ($fields as $field)
$field->delete (true);
// recursive
$elements = KBModuleElement::getElementsByBase ($this->id);
foreach ($elements as $element)
$element->delete (true);
// recursive
$elements = KBModuleElement::getElementsByBaseAsRelations ($this->id);
foreach ($elements as $element)
$element->delete (true);
// recursive
$groups = KBModuleGroup::getGroupsByBase ($this->id);
foreach ($groups as $group)
$group->delete (true);
// get config
$configs = KBModuleConfig::getConfigsByBase (KB_BASE_UNDEFINED);
// recursive reset
foreach ($configs as $config)
{
// username
if ($config->getProperty () == KB_CONFIG_PROPERTY_AUTHENTICATION_USERNAME)
{
// base is negative id
if ($config->getIntValue () < KB_CONFIG_DEFAULT_AUTHENTICATION_UNDEFINED && abs ($config->getIntValue ()) == $this->id)
{
$config->setIntValue (KB_CONFIG_DEFAULT_AUTHENTICATION_UNDEFINED);
$config->store ();
}
}
}
// sql
$sql = "DELETE FROM " . KB_TABLE_BASES . " WHERE id = " . $this->id;
// execute
return !db_exec ($sql) ? db_error () : null;
}
/*
* getBases ()
*/
function getBases ()
{
$r = array ();
// sql
$sql = "SELECT * FROM " . KB_TABLE_BASES . " ORDER BY name";
// load
$hash = db_loadList ($sql);
// bind
foreach ($hash as $row)
{
$obj = new KBModuleBase ();
bindHashToObject ($row, $obj);
$r [] = $obj;
}
// return
return $r;
}
/*
* isAuthenticationBase ()
*/
function isAuthenticationBase ()
{
// config
$password = KBModuleConfig::getConfig (KB_BASE_UNDEFINED, KB_CONFIG_PROPERTY_AUTHENTICATION_PASSWORD);
// field
$field = new KBModuleField ();
$field->load ($password->getIntValue ());
// compare base ids
return $field->getBaseId () == $this->id;
}
}
?>