phpDocumentor lodel
[ class tree: lodel ] [ index: lodel ] [ all elements ]

Source for file entitiesfunc.php

Documentation is available at entitiesfunc.php

  1. <?php
  2. /**
  3.  * Fichier utilitaire pour les entités
  4.  *
  5.  * PHP versions 4 et 5
  6.  *
  7.  * LODEL - Logiciel d'Edition ELectronique.
  8.  *
  9.  * Copyright (c) 2001-2002, Ghislain Picard, Marin Dacos
  10.  * Copyright (c) 2003, Ghislain Picard, Marin Dacos, Luc Santeramo, Nicolas Nutten, Anne Gentil-Beccot
  11.  * Copyright (c) 2004, Ghislain Picard, Marin Dacos, Luc Santeramo, Anne Gentil-Beccot, Bruno Cénou
  12.  * Copyright (c) 2005, Ghislain Picard, Marin Dacos, Luc Santeramo, Gautier Poupeau, Jean Lamy, Bruno Cénou
  13.  * Copyright (c) 2006, Marin Dacos, Luc Santeramo, Bruno Cénou, Jean Lamy, Mikaël Cixous, Sophie Malafosse
  14.  * Copyright (c) 2007, Marin Dacos, Bruno Cénou, Sophie Malafosse, Pierre-Alain Mignot
  15.  *
  16.  * Home page: http://www.lodel.org
  17.  *
  18.  * E-Mail: lodel@lodel.org
  19.  *
  20.  * All Rights Reserved
  21.  *
  22.  * This program is free software; you can redistribute it and/or modify
  23.  * it under the terms of the GNU General Public License as published by
  24.  * the Free Software Foundation; either version 2 of the License, or
  25.  * (at your option) any later version.
  26.  *
  27.  * This program is distributed in the hope that it will be useful,
  28.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  29.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  30.  * GNU General Public License for more details.
  31.  *
  32.  * You should have received a copy of the GNU General Public License
  33.  * along with this program; if not, write to the Free Software
  34.  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  35.  *
  36.  * @author Ghislain Picard
  37.  * @author Jean Lamy
  38.  * @author Sophie Malafosse
  39.  * @copyright 2005, Ghislain Picard, Marin Dacos, Luc Santeramo, Gautier Poupeau, Jean Lamy, Bruno Cénou
  40.  * @copyright 2006, Marin Dacos, Luc Santeramo, Bruno Cénou, Jean Lamy, Mikaël Cixous, Sophie Malafosse
  41.  * @copyright 2007, Marin Dacos, Bruno Cénou, Sophie Malafosse, Pierre-Alain Mignot
  42.  * @licence http://www.gnu.org/copyleft/gpl.html
  43.  * @version CVS:$Id:
  44.  * @package lodel
  45.  */
  46.  
  47. /**
  48.  * Vérifie que le type de $id peut être associé au type du parent $idparent
  49.  *
  50.  * Check that the type of $id can be in the type of $idparent.
  51.  * if $id=0 (creation of entites), use $idtype
  52.  *
  53.  * @param integer $id l'identifiant
  54.  * @param integer $idparent l'identifant du parent
  55.  * @param integer $idtype le type que l'on souhaite tester (utile si $id=0). Par défaut = 0
  56.  * @return la condition de compatibilité entre les deux types.
  57.  */
  58. function checkTypesCompatibility($id$idparent$idtype 0)
  59. {
  60.     global $db;
  61.     #echo "id=$id;idparent=$idparent;idtype=$idtype";
  62.     // check whether we have the right or not to put an entitie $id in the $idparent
  63.     if ($id 0{
  64.         $table "#_TP_entitytypes_entitytypes INNER JOIN #_TP_entities as son ON identitytype=son.idtype";
  65.         $criteria "son.id='"$id"'";
  66.     }    elseif ($idtype 0{
  67.         $table "#_TP_entitytypes_entitytypes";
  68.         $criteria "identitytype='"$idtype"'";
  69.     }    else {
  70.         die("ERROR: id=0 and idtype=0 in EntitiesLogic::_checkTypesCompatibility");
  71.     }
  72.     if ($idparent 0// there is a parent
  73.         $query "SELECT cond FROM "$table" INNER JOIN #_TP_entities as parent ON identitytype2=parent.idtype  WHERE parent.id='"$idparent"' AND "$criteria;
  74.     }    else // no parent, the base.
  75.         $query "SELECT cond FROM "$table" WHERE identitytype2=0 AND "$criteria;
  76.     }
  77.     #echo $query;
  78.     $condition $db->getOne(lq($query));
  79.     if ($db->errorno()) {
  80.         dberror();
  81.     }
  82.     return $condition;
  83. }
  84.  
  85. /**
  86.  * Teste si l'entité pointée par $idcurrent n'est pas une descendante de $idref
  87.  *
  88.  * @param integer $idref Identifiant de l'entité de référence
  89.  * @param integer $idcurrent Identifiant de l'entité courante
  90.  * @return boolean false si $idcurrent est une descendante de $idref
  91.  */
  92. function isChild($idref$idcurrent)
  93. {
  94.     global $db;
  95.     if(!isset($idcurrent|| !isset($idref)) {
  96.         return;
  97.     }
  98.     $sql lq("SELECT idrelation FROM #_TP_relations where id2='$idcurrentAND id1='$idref'");
  99.     $idrelation $db->getOne($sql);
  100.     if ($db->errorno()) {
  101.         dberror();
  102.     }
  103.     return $idrelation false true// si on a une relation (descendance) retourne false
  104. }
  105.  
  106.  
  107. /**
  108.  * Suppression des entités à -64 dont la dernière modification remonte à + de 12 h. Cette fonction est  appelée dans index.php (côté édition), lorsqu'il n'y a ni $do, ni $lo dans la requete (lorsque le controler n'est pas appelé).
  109.  *
  110.  * Cette fonction appelle l'action delete de la logique des entités.
  111.  *
  112.  * @see class.entities.php
  113.  */
  114.  
  115. function cleanEntities ()
  116. {
  117.         global $db;
  118.         $mysql lq('SELECT id FROM #_TP_entities WHERE status=-64 AND upd < DATE_SUB(NOW(), INTERVAL 12 HOUR)');
  119.         $result $db->execute($mysql);
  120.         $ids array();
  121.         while(!$result->EOF{
  122.             $ids[$result->fields['id'];
  123.             $result->MoveNext();
  124.         }
  125.         
  126.         if (is_array($ids)) {
  127.             require_once 'logic.php';
  128.             require_once 'func.php';
  129.             $logic &getLogic('entities');
  130.             foreach($ids as $id{
  131.                 $context['id'$id;
  132.                 $logic->deleteAction($context$error);
  133.                 }
  134.         }
  135. }
  136.  
  137.  
  138. ?>

Documentation generated on Thu, 10 Jul 2008 05:07:29 +0200 by phpDocumentor 1.4.0a2