Source for file class.entities_advanced.php
Documentation is available at class.entities_advanced.php
* Logique des entités - avancée
* LODEL - Logiciel d'Edition ELectronique.
* Home page: http://www.lodel.org
* E-Mail: lodel@lodel.org
* This program 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.
* This program 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., 675 Mass Ave, Cambridge, MA 02139, USA.
* @author Ghislain Picard
* @copyright 2001-2002, Ghislain Picard, Marin Dacos
* @copyright 2003, Ghislain Picard, Marin Dacos, Luc Santeramo, Nicolas Nutten, Anne Gentil-Beccot
* @copyright 2004, Ghislain Picard, Marin Dacos, Luc Santeramo, Anne Gentil-Beccot, Bruno Cénou
* @copyright 2005, Ghislain Picard, Marin Dacos, Luc Santeramo, Gautier Poupeau, Jean Lamy, Bruno Cénou
* @copyright 2006, Marin Dacos, Luc Santeramo, Bruno Cénou, Jean Lamy, Mikaël Cixous, Sophie Malafosse
* @copyright 2007, Marin Dacos, Bruno Cénou, Sophie Malafosse, Pierre-Alain Mignot
* @licence http://www.gnu.org/copyleft/gpl.html
* @since Fichier ajouté depuis la version 0.8
* @version CVS:$Id: class.entities_advanced.php 4006 2007-10-05 11:53:41Z malafosse $
* Classe de logique des entités (gestion avancée)
* @author Ghislain Picard
* @copyright 2001-2002, Ghislain Picard, Marin Dacos
* @copyright 2003, Ghislain Picard, Marin Dacos, Luc Santeramo, Nicolas Nutten, Anne Gentil-Beccot
* @copyright 2004, Ghislain Picard, Marin Dacos, Luc Santeramo, Anne Gentil-Beccot, Bruno Cénou
* @copyright 2005, Ghislain Picard, Marin Dacos, Luc Santeramo, Gautier Poupeau, Jean Lamy, Bruno Cénou
* @copyright 2006, Marin Dacos, Luc Santeramo, Bruno Cénou, Jean Lamy, Mikaël Cixous, Sophie Malafosse
* @copyright 2007, Marin Dacos, Bruno Cénou, Sophie Malafosse, Pierre-Alain Mignot
* @licence http://www.gnu.org/copyleft/gpl.html
* @since Classe ajouté depuis la version 0.8
* Tableau des équivalents génériques
$this->Logic("entities");
* @param array &$context le contexte passé par référence
* @param array &$error le tableau des erreurs éventuelles passé par référence
die("ERROR: give the id ");
die("ERROR: you don't have the right to perform this operation");
$vo = $dao->getById($id);
die("ERROR: can't find object $id in the table ". $this->maintable);
$votype = $daotype->getById($vo->idtype);
// look for a multi-doc source ?
$context['multidocsourcefile'] = file_exists(SITEROOT. "lodel/sources/entite-multidoc". $vo->idparent. ".source");
* Changer le status d'une entité
* Modifie le status d'une entité en utilisant la valeur passée dans le context :
* @param array &$context le contexte passé par référence
* @param array &$error le tableau des erreurs éventuelles passé par référence
$status = intval($context['status']);
$vo = $dao->find("id='". $context['id']. "' AND status*$status>0 AND status<16", 'status,id');
die("ERROR: interface error in Entities_AdvancedLogic::changeStatusAction ");
// check if the entities have an history field defined
* Préparation du déplacement d'une entité.
* Cette méthode est appelée avant l'action move. Elle prépare le déplacement en vérifiant
* certaines conditions à celui-ci.
* @param array &$context le contexte passé par référence
* @param array &$error le tableau des erreurs éventuelles passé par référence
die("ERROR: you don't have the right to perform this operation");
* Boucle permettant de savoir si on a le droit de déplacer l'entité IDDOCUMENT (identifiée
* par son type IDTYPE) dans l'entité courante.
* On teste si le type de l'entité courante peut contenir le type de l'entité ID.
* On doit aussi tester si l'entité courante n'est pas un descendant de IDDOCUMENT
* @param array $context le context passé par référence
* @param string $funcname le nom de la fonction
function loop_move_right(&$context,$funcname)
//test1 : si le type de l'entité courante peut contenir ce type d'entité
if (!isset ($cache[$context['idtype']])) {
//mise en cache du type du document
$idtype = $idtypes[$context['iddocument']];
if (!$idtype) { // get the type, we don't have it!
$vo = $dao->getById($context['iddocument'],"idtype");
$idtype = $idtypes[$context['iddocument']]= $vo->idtype;
// récupère la condition sur les deux types testé.
$condition = $db->getOne(lq("SELECT cond FROM #_TP_entitytypes_entitytypes WHERE identitytype='". $idtype. "' AND identitytype2='". $context['idtype']. "'"));
$cache[$context['idtype']] = (boolean) $condition;
//test2 : si l'entité courante est une descendante de l'entité IDDOCUMENT
require_once 'entitiesfunc.php';
$boolchild = isChild($context['iddocument'], $context['id']);
if ($cache[$context['idtype']] && $boolchild) { //si c'est ok
* @param array &$context le contexte passé par référence
* @param array &$error le tableau des erreurs éventuelles passé par référence
die("ERROR: you don't have the right to perform this operation");
$id = $context['id']; // which entities
$idparent = intval($context['idparent']); // where to move it
require_once 'entitiesfunc.php';
die("ERROR: Can move the entities $id into $idparent. Check the editorial model.");
// yes we have the right, move the entities
$dao->instantiateObject($vo);
$vo->rank = 0; // recalculate
$vo->idparent = $idparent;
if ($db->affected_Rows()> 0) { // effective change
// get the new parent hierarchy
$result= $db->execute(lq("SELECT id1,degree FROM #_TP_relations WHERE id2='$idparent' AND nature='P'")) or dberror();
$id1 = $result->fields['id1'];
$degree = $result->fields['degree'];
$parents[$degree] = $id1;
$values.= "('". $id1. "','". $id. "','P','". ($degree+ 1). "'),";
// search for the children
$result= $db->execute(lq("SELECT id2,degree FROM #_TP_relations WHERE id1='$id' AND nature='P'")) or dberror();
$id2 = $result->fields['id2'];
$degree = $result->fields['degree'];
$delete.= " (id2='". $id2. "' AND degree>". $degree. ") OR "; // remove all the parent above $id.
for ($d= 0; $d<= $dmax; $d++ ) { // for each degree
$values.= "('". $parents[$d]. "','". $id2. "','P','". ($degree+ $d+ 1). "'),"; // add all the parent
$delete.= " id2='". $id. "' ";
$values.= "('". $idparent. "','". $id. "','P',1)";
// delete the relation to the parent
$db->execute(lq("DELETE FROM #_TP_relations WHERE (". $delete. ") AND nature='P'")) or dberror();
$db->execute(lq("REPLACE INTO #_TP_relations (id1,id2,nature,degree) VALUES ". $values)) or dberror();
* Récuperer le fichier source correspondant à une entité
* @param array &$context le contexte passé par référence
* @param array &$error le tableau des erreurs éventuelles passé par référence
switch($context['type']) {
$filename = "r2r-$id.xml";
$originalname = $filename;
$filename = $multidoc ? "entite-multidoc-$id.source" : "entite-$id.source";
$vo = $dao->getById($id,"creationmethod,creationinfo");
if ($vo->creationmethod!= ($multidoc ? "servoo;multidoc" : "servoo")) {
die("ERROR: error creationmethod is not compatible with download");
$originalname = $vo->creationinfo ? basename($vo->creationinfo) : basename($filename);
die ("ERROR: unknow type of download in downloadAction");
die ("ERROR: the filename $filename does not exists");
download ($dir. '/'. $filename, $originalname);
// begin{publicfields} automatic generation //
// end{publicfields} automatic generation //
// begin{uniquefields} automatic generation //
// end{uniquefields} automatic generation //
|