[Agora-commits] agora/ecrire/include/bd inc_mapping_factory.php,
NONE, 1.1 mapping.php, NONE, 1.1
lpoinsignon at adullact1.hosting.cri74.org
lpoinsignon at adullact1.hosting.cri74.org
Jeu 15 Sep 15:50:43 CEST 2005
Update of /cvsroot/agora/agora/ecrire/include/bd
In directory adullact1:/tmp/cvs-serv17486/ecrire/include/bd
Added Files:
inc_mapping_factory.php mapping.php
Log Message:
Fonctionnalite de mapping (indexer un article dans plusieurs rubriques)
--- NEW FILE: inc_mapping_factory.php ---
<?php
// fichier ajoute pour le mapping
function &recuperer_instance_mapping() {
global $bd_params;
global $bd_options;
require_once(dirname(__FILE__)."/mapping.php");
$mapping = &BD_mapping::factory($bd_params);
if (PEAR::isError($mapping)) {
die($mapping->getMessage());
}
$mapping->setDbOptions($bd_options);
return $mapping;
}
?>
--- NEW FILE: mapping.php ---
<?php
require_once dirname(__FILE__)."/metier.php";
require_once dirname(__FILE__)."/../../inc_meta.php3";
/**
* BD_mapping is a base class for mapping and article relation managements.
* @package BD
* @author Guillaume Grason <guillaume.grason at diplomatie.gouv.fr>
* @access public
*/
class BD_mapping {
// {{{ properties
/**
* Parameters instance used for PEAR::DB factory and
* Metier subclasses factories.
*
* @access private
*/
var $_dbParameters;
/**
* DB options array used for PEAR::DB options.
*
* @access private
*/
var $_dbOptions = false;
/**
* Article ID.
* @var int
* @access private
*/
var $_articleId;
/**
* Mapping ID.
* @var String
* @access private
*/
var $_mappingId;
// {{{ factory()
/**
* This method is a factory static method. It should be used to get any
* specific implementation instace of Article business data type.
* @param BD_parameters DB connection parameters
* @access public
*/
function &factory($dbParameters, $dbOptions = null) {
if(file_exists(dirname(__FILE__)."/".$dbParameters->_dbEngine."/mapping_".$dbParameters->_dbEngine.".php") == false) {
include_once(dirname(__FILE__)."/common/mapping_common.php");
$classname = "BD_mapping_common";
}
else {
include_once(dirname(__FILE__)."/".$dbParameters->_dbEngine."/mapping_".$dbParameters->_dbEngine.".php");
$classname = "BD_mapping_".$dbParameters->_dbEngine;
}
if (!class_exists($classname)) {
return PEAR::raiseError("Cannot instanciate class $classname", null,
null, null, null, null, false);
}
$obj =& new $classname;
$result = $obj->setDbParameters($dbParameters);
if ($dbOptions != null) {
$obj->setDbOptions($dbOptions);
}
if (PEAR::isError($result)) {
return $result;
} else {
return $obj;
}
}
// }}}
// {{{ constructor
/**
* DB_article constructor.
*
* @access public
*/
function BD_mapping() {
}
// }}}
// {{{ getDbParameters()
/**
* Getter method to retreive the instance Parameters object
*
* @return DB parameters
* @access public
*/
function getDbParameters() {
return $this->_dbParameters;
}
// }}}
// {{{ setDbParameters()
/**
* Setter method to set the instance Parameters object
*
* @param $dbParameters new DB parameters
*/
function setDbParameters($dbParameters) {
if (strtolower(get_class($dbParameters)) == "bd_parameters") {
$this->_dbParameters = $dbParameters;
} else {
return PEAR::raiseError("Erreur! le parametre de la methode setDbParameters doit etre un objet de la hierarchie DB_parameters !",
null, null, null, null, null, false);
}
}
// }}}
// {{{ getDbOptions()
/**
* Getter method to retreive the instance Options array
*
* @return array
* @access public
*/
function getDbOptions() {
return $this->_dbOptions;
}
// }}}
// {{{ setDbOptions()
/**
* Setter method to set the instance Parameters object
*
* @param array array of PEAR::DB options
*/
function setDbOptions($dbOptions) {
$this->_dbOptions = $dbOptions;
}
// }}}
// {{{ _getDB()
/**
* Protected method used to get an PEAR::DB instance
* using the parameters stored in the _dbParameters field
*
* @return Newly creating PEAR::DB object
* according to the instance parameters
* @access private
*/
function &_getDB($dbParameters = null) {
require_once "PEAR.php";
if($dbParameters == null) {
$DBManager = &DBManager::getDBManager($this->_dbParameters->getDSN(), $this->_dbOptions);
$db = $DBManager->getDB($this->_dbParameters->getDSN(), $this->_dbOptions);
} else {
$DBManager = &DBManager::getDBManager($dbParameters->getDSN(), $this->_dbOptions);
$db = $DBManager->getDB($dbParameters->getDSN(), $this->_dbOptions);
}
return $db;
}
// }}}
// {{{ getArticleId()
function getArticleId() {
return $this->_articleId;
}
// }}}
// {{{ setArticleId()
function setArticleId($articleId) {
$this->_articleId = $articleId;
}
// }}}
// {{{ getMappingId()
function getMappingId() {
return $this->_mappingId;
}
// }}}
// {{{ setMappingId()
function setMappingId($mappingId) {
$this->_mappingId = $mappingId;
}
// }}}
// {{{ _fetchData()
/**
* This method is used to fetch result set fields into the object fields
* @access private
* @param int $idArticle id of article to load
*/
function _fetchData($row) {
$this->setArticleId($row['id_article']);
$this->setMappingId($row['id_map']);
}
// }}}
// {{{ createEntry()
/**
* This method is used to create an entry in the database
* @access public
*/
function createEntry($articleId, $mappingId) {
$db = &$this->_getDB();
if (DB::isError($db)) {
return PEAR::raiseError("[".get_class($this)." DB_mapping : createEntry()] ".$db->getMessage()."", null,
null, null, null, null, false);
}
$query = "INSERT INTO ".$GLOBALS['table_prefix']."_articles_mapping (id, id_map, id_article) VALUES ('', '$mappingId', '$articleId')";
$result = $db->query($query);
if (DB::isError($result)) {
return PEAR::raiseError("[".get_class($this)." DB_mapping : createEntry()] ".$result->getMessage()."", null,
null, null, null, null, false);
}
}
// }}}
// {{{ deleteEntryByArticleIdAndMappingId()
/**
* This method is used to delete an entry from the database
* @access public
*/
function deleteEntryByArticleIdAndMappingId($articleId, $mappingId) {
$db = &$this->_getDB();
if (DB::isError($db)) {
return PEAR::raiseError("[".get_class($this)." DB_mapping : deleteEntryByArticleIdAndMappingId()] ".$db->getMessage()."", null,
null, null, null, null, false);
}
$query = "DELETE FROM ".$GLOBALS['table_prefix']."_articles_mapping WHERE id_map = '$mappingId' AND id_article = '$articleId'";
$result = $db->query($query);
if (DB::isError($result)) {
return PEAR::raiseError("[".get_class($this)." DB_mapping : deleteEntryByArticleIdAndMappingId()] ".$result->getMessage()."", null,
null, null, null, null, false);
}
}
// }}}
// {{{ deleteEntryByArticleId()
/**
* This method is used to delete multiples entries from the database
* @access public
*/
function deleteEntryByArticleId($articleId) {
$db = &$this->_getDB();
if (DB::isError($db)) {
return PEAR::raiseError("[".get_class($this)." DB_mapping : deleteEntryByArticleId()] ".$db->getMessage()."", null,
null, null, null, null, false);
}
$query = "DELETE FROM ".$GLOBALS['table_prefix']."_articles_mapping id_article = '$articleId'";
$result = $db->query($query);
if (DB::isError($result)) {
return PEAR::raiseError("[".get_class($this)." DB_mapping : deleteEntryByArticleId()] ".$result->getMessage()."", null,
null, null, null, null, false);
}
}
// }}}
// {{{ getMappings()
/**
* This method is used to list entries from the database corresponding to an article ID
* @access public
*/
function getMappings($articleId) {
$mappings = array();
$db = &$this->_getDB();
if (DB::isError($db)) {
return PEAR::raiseError("[".get_class($this)." DB_mapping : getMappings()] ".$db->getMessage()."", null,
null, null, null, null, false);
}
$query = "SELECT id_map, id_article FROM ".$GLOBALS['table_prefix']."_articles_mapping WHERE id_article=".$articleId;
$queryResult = $db->query($query);
if (DB::isError($queryResult)) {
return PEAR::raiseError("[".get_class($this)." DB_mapping : getMappings()] ".$queryResult->getMessage()."", null,
null, null, null, null, false);
}
while ($row = $queryResult->fetchRow()) {
$this->_fetchData($row);
$mappings[] = $this->getMappingId();
}
$queryResult->free();
return $mappings;
}
// }}}
// {{{ loadArticle()
/**
* This method is used to find the parent of a mapping from the database
* @access public
*/
function loadArticle($mappingId) {
$db = &$this->_getDB();
if (DB::isError($db)) {
return PEAR::raiseError("[".get_class($this)." DB_mapping : loadArticle()] ".$db->getMessage()."", null,
null, null, null, null, false);
}
$query = "SELECT id_map, id_article FROM ".$GLOBALS['table_prefix']."_articles_mapping WHERE id_map=".$mappingId;
$queryResult = $db->query($query);
if (DB::isError($queryResult)) {
return PEAR::raiseError("[".get_class($this)." DB_mapping : loadArticle()] ".$queryResult->getMessage()."", null,
null, null, null, null, false);
}
$row = $queryResult->fetchRow();
$this->_fetchData($row);
return $this->getArticleId();
}
// }}}
}
?>
Plus d'informations sur la liste de diffusion Agora-commits