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

Source for file class.entities_advanced.php

Documentation is available at class.entities_advanced.php

  1. <?php
  2. /**    
  3.  * Logique des entités - avancée
  4.  *
  5.  * PHP versions 4 et 5
  6.  *
  7.  * LODEL - Logiciel d'Edition ELectronique.
  8.  *
  9.  * Home page: http://www.lodel.org
  10.  * E-Mail: lodel@lodel.org
  11.  *
  12.  * All Rights Reserved
  13.  *
  14.  * This program is free software; you can redistribute it and/or modify
  15.  * it under the terms of the GNU General Public License as published by
  16.  * the Free Software Foundation; either version 2 of the License, or
  17.  * (at your option) any later version.
  18.  *
  19.  * This program is distributed in the hope that it will be useful,
  20.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  21.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  22.  * GNU General Public License for more details.
  23.  *
  24.  * You should have received a copy of the GNU General Public License
  25.  * along with this program; if not, write to the Free Software
  26.  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  27.  *
  28.  * @package lodel/logic
  29.  * @author Ghislain Picard
  30.  * @author Jean Lamy
  31.  * @copyright 2001-2002, Ghislain Picard, Marin Dacos
  32.  * @copyright 2003, Ghislain Picard, Marin Dacos, Luc Santeramo, Nicolas Nutten, Anne Gentil-Beccot
  33.  * @copyright 2004, Ghislain Picard, Marin Dacos, Luc Santeramo, Anne Gentil-Beccot, Bruno Cénou
  34.  * @copyright 2005, Ghislain Picard, Marin Dacos, Luc Santeramo, Gautier Poupeau, Jean Lamy, Bruno Cénou
  35.  * @copyright 2006, Marin Dacos, Luc Santeramo, Bruno Cénou, Jean Lamy, Mikaël Cixous, Sophie Malafosse
  36.  * @copyright 2007, Marin Dacos, Bruno Cénou, Sophie Malafosse, Pierre-Alain Mignot
  37.  * @licence http://www.gnu.org/copyleft/gpl.html
  38.  * @since Fichier ajouté depuis la version 0.8
  39.  * @version CVS:$Id: class.entities_advanced.php 4006 2007-10-05 11:53:41Z malafosse $
  40.  */
  41.  
  42.  
  43.  
  44. /**
  45.  * Classe de logique des entités (gestion avancée)
  46.  * 
  47.  * @package lodel/logic
  48.  * @author Ghislain Picard
  49.  * @author Jean Lamy
  50.  * @copyright 2001-2002, Ghislain Picard, Marin Dacos
  51.  * @copyright 2003, Ghislain Picard, Marin Dacos, Luc Santeramo, Nicolas Nutten, Anne Gentil-Beccot
  52.  * @copyright 2004, Ghislain Picard, Marin Dacos, Luc Santeramo, Anne Gentil-Beccot, Bruno Cénou
  53.  * @copyright 2005, Ghislain Picard, Marin Dacos, Luc Santeramo, Gautier Poupeau, Jean Lamy, Bruno Cénou
  54.  * @copyright 2006, Marin Dacos, Luc Santeramo, Bruno Cénou, Jean Lamy, Mikaël Cixous, Sophie Malafosse
  55.  * @copyright 2007, Marin Dacos, Bruno Cénou, Sophie Malafosse, Pierre-Alain Mignot
  56.  * @licence http://www.gnu.org/copyleft/gpl.html
  57.  * @since Classe ajouté depuis la version 0.8
  58.  * @see logic.php
  59.  */
  60. class Entities_AdvancedLogic extends Logic
  61. {
  62.  
  63.     /**
  64.      * Tableau des équivalents génériques
  65.      *
  66.      * @var array 
  67.      */
  68.     var $g_name;
  69.  
  70.     /**
  71.      * Constructeur
  72.      */
  73.     function Entities_AdvancedLogic()
  74.     {
  75.         $this->Logic("entities");
  76.     }
  77.  
  78.  
  79.     /**
  80.      * Affichage d'un objet
  81.      *
  82.      * @param array &$context le contexte passé par référence
  83.      * @param array &$error le tableau des erreurs éventuelles passé par référence
  84.      */
  85.     function viewAction(&$context&$error)
  86.     {
  87.         if ($error{
  88.             return;
  89.         }
  90.         recordurl();
  91.  
  92.         $id $context['id'];
  93.         if (!$id{
  94.             die("ERROR: give the id ");
  95.         }
  96.         if (!rightonentity('advanced'$context)) {
  97.             die("ERROR: you don't have the right to perform this operation");
  98.         }
  99.  
  100.         $dao $this->_getMainTableDAO();
  101.         $vo  $dao->getById($id);
  102.         if (!$vo{
  103.             die("ERRORcan't find object $id in the table "$this->maintable);
  104.         }
  105.         $this->_populateContext($vo$context);
  106.  
  107.         $daotype &getDAO('types');
  108.         $votype  $daotype->getById($vo->idtype);
  109.         $this->_populateContext($votype$context['type']);
  110.  
  111.         // look for the source
  112.         $context['sourcefile'file_exists(SITEROOT."lodel/sources/entite-".$id.".source");
  113.  
  114.         // look for a multi-doc source ?
  115.         $context['multidocsourcefile'file_exists(SITEROOT"lodel/sources/entite-multidoc"$vo->idparent".source");
  116.  
  117.         return '_ok';
  118.     }
  119.  
  120.     /**
  121.      * Changer le status d'une entité
  122.      *
  123.      * Modifie le status d'une entité en utilisant la valeur passée dans le context :
  124.      * $context['status'].
  125.      *
  126.      * @param array &$context le contexte passé par référence
  127.      * @param array &$error le tableau des erreurs éventuelles passé par référence
  128.      */
  129.     function changeStatusAction(&$context&$error)
  130.     {
  131.         global $db;
  132.         $status intval($context['status']);
  133.         $this->_isAuthorizedStatus($status);
  134.         $dao $this->_getMainTableDAO();
  135.         $vo  $dao->find("id='"$context['id']"AND status*$status>0 AND status<16"'status,id');
  136.         if (!$vo{
  137.             die("ERROR: interface error in Entities_AdvancedLogic::changeStatusAction ");
  138.         }
  139.         $vo->status $status;
  140.         $dao->save($vo);
  141.     
  142.         // check if the entities have an history field defined
  143.         $this->_processSpecialFields('history'$context$status);
  144.     
  145.         update();
  146.         return '_back';
  147.     }
  148.  
  149.     /**
  150.      * Préparation du déplacement  d'une entité.
  151.      *
  152.      * Cette méthode est appelée avant l'action move. Elle prépare le déplacement en vérifiant
  153.      * certaines conditions à celui-ci.
  154.      *
  155.      * @param array &$context le contexte passé par référence
  156.      * @param array &$error le tableau des erreurs éventuelles passé par référence
  157.      */
  158.     function prepareMoveAction(&$context&$error)
  159.     {
  160.         if (!rightonentity('move'$context)) {
  161.             die("ERROR: you don't have the right to perform this operation");
  162.         }
  163.         /**
  164.          * Boucle permettant de savoir si on a le droit de déplacer l'entité IDDOCUMENT (identifiée
  165.          * par son type IDTYPE) dans l'entité courante.
  166.          * On teste si le type de l'entité courante peut contenir le type de l'entité ID.
  167.          * On doit aussi tester si l'entité courante n'est pas un descendant de IDDOCUMENT
  168.          *
  169.          * @param array $context le context passé par référence
  170.          * @param string $funcname le nom de la fonction
  171.          */
  172.         function loop_move_right(&$context,$funcname)
  173.         {
  174.             static $cache,$idtypes;
  175.             global $db,$home;
  176.  
  177.             //test1 : si le type de l'entité courante peut contenir ce type d'entité
  178.             if (!isset($cache[$context['idtype']])) {
  179.                 //mise en cache du type du document
  180.                 $idtype $idtypes[$context['iddocument']];
  181.                 if (!$idtype// get the type, we don't have it!
  182.                     $dao &getDAO("entities");
  183.                     $vo $dao->getById($context['iddocument'],"idtype");
  184.                     $idtype $idtypes[$context['iddocument']]=$vo->idtype;
  185.                 }
  186.                 // récupère la condition sur les deux types testé.
  187.                 $condition $db->getOne(lq("SELECT cond FROM #_TP_entitytypes_entitytypes WHERE identitytype='"$idtype"' AND identitytype2='"$context['idtype']"'"));
  188.                 $cache[$context['idtype']] = (boolean)$condition;
  189.                 if ($db->errorno()) {
  190.                     dberror();
  191.                 }
  192.             }
  193.             //test2 : si l'entité courante est une descendante de l'entité IDDOCUMENT
  194.             require_once 'entitiesfunc.php';
  195.             $boolchild isChild($context['iddocument']$context['id']);
  196.             if ($cache[$context['idtype']] && $boolchild//si c'est ok
  197.                 if (function_exists("code_do_$funcname")) {
  198.                     call_user_func("code_do_$funcname"$context);
  199.                 }
  200.             else {
  201.                 if (function_exists("code_alter_$funcname")) {
  202.                     call_user_func("code_alter_$funcname"$context);
  203.                 }
  204.             }
  205.         }
  206.         return 'move';
  207.     }
  208.  
  209.     /**
  210.      * Déplacer une entité
  211.      *
  212.      * @param array &$context le contexte passé par référence
  213.      * @param array &$error le tableau des erreurs éventuelles passé par référence
  214.      */
  215.     function moveAction(&$context&$error)
  216.     {
  217.         global $db,$home;
  218.         if (!rightonentity('move'$context)) {
  219.             die("ERROR: you don't have the right to perform this operation");
  220.         }
  221.  
  222.         $id $context['id']// which entities
  223.         $idparent intval($context['idparent'])// where to move it
  224.  
  225.         require_once 'entitiesfunc.php';
  226.         if (!checkTypesCompatibility($id$idparent)) {
  227.             die("ERRORCan move the entities $id into $idparentCheck the editorial model.");
  228.         }
  229.  
  230.         // yes we have the right, move the entities
  231.         $dao $this->_getMainTableDAO();
  232.         $dao->instantiateObject($vo);
  233.         $vo->id       $id;
  234.         $vo->rank     0// recalculate
  235.         $vo->idparent $idparent;
  236.         $dao->save($vo);
  237.  
  238.         if ($db->affected_Rows()>0// effective change
  239.             // get the new parent hierarchy
  240.             $result=$db->execute(lq("SELECT id1,degree FROM #_TP_relations WHERE id2='$idparentAND nature='P'")) or dberror();
  241.     
  242.             $values '';
  243.             $dmax   0;
  244.             while (!$result->EOF{
  245.                 $id1 $result->fields['id1'];
  246.                 $degree $result->fields['degree'];
  247.                 $parents[$degree$id1;
  248.                 if ($degree>$dmax{
  249.                     $dmax $degree;
  250.                 }
  251.                 $values.= "('"$id1"','"$id"','P','"($degree+1)"'),";
  252.                 $result->MoveNext();
  253.             }
  254.             $parents[0$idparent;
  255.             // search for the children
  256.             $result=$db->execute(lq("SELECT id2,degree FROM #_TP_relations WHERE id1='$idAND nature='P'")) or dberror();
  257.  
  258.             $delete '';
  259.             while (!$result->EOF{
  260.                 $id2 $result->fields['id2'];
  261.                 $degree $result->fields['degree'];
  262.         
  263.                 $delete.= " (id2='".$id2."' AND degree>".$degree.") OR "// remove all the parent above $id.
  264.                 for ($d=0$d<=$dmax$d++// for each degree
  265.                     $values.= "('".$parents[$d]."','".$id2."','P','".($degree+$d+1)."'),"// add all the parent
  266.                 }
  267.                 $result->MoveNext();
  268.             }
  269.     
  270.             $delete.= " id2='".$id."' ";
  271.             $values.= "('".$idparent."','".$id."','P',1)";
  272.     
  273.             // delete the relation to the parent 
  274.             if ($delete{
  275.                 $db->execute(lq("DELETE FROM #_TP_relations WHERE (".$delete.") AND nature='P'")) or dberror();
  276.             }
  277.             if ($values{
  278.                 $db->execute(lq("REPLACE INTO #_TP_relations (id1,id2,nature,degree) VALUES ".$values)) or dberror();
  279.             }
  280.         }
  281.  
  282.         update();
  283.         return '_back';
  284.     }
  285.  
  286.     /**
  287.      * Récuperer le fichier source correspondant à une entité
  288.      *
  289.      * @param array &$context le contexte passé par référence
  290.      * @param array &$error le tableau des erreurs éventuelles passé par référence
  291.      */
  292.     function downloadAction(&$context&$error)
  293.     {
  294.         $id $context['id'];
  295.         switch($context['type']{
  296.         case 'xml':
  297.             die('a implementer');
  298.             $filename "r2r-$id.xml";
  299.             $originalname $filename;
  300.             $dir '../txt';
  301.             break;
  302.         case 'multidocsource' :
  303.             $multidoc true;
  304.         case 'source' :
  305.             $filename $multidoc "entite-multidoc-$id.source"entite-$id.source";
  306.             $dir "../sources";
  307.             // get the official name 
  308.             $dao $this->_getMainTableDAO();
  309.             $vo  $dao->getById($id,"creationmethod,creationinfo");
  310.             if ($vo->creationmethod!=($multidoc "servoo;multidoc" "servoo")) {
  311.                 die("ERROR: error creationmethod is not compatible with download");
  312.             }
  313.             $originalname $vo->creationinfo basename($vo->creationinfobasename($filename);
  314.             break;
  315.         default:
  316.             die ("ERROR: unknow type of download in downloadAction");
  317.         }
  318.         
  319.         if (!file_exists($dir."/".$filename)) {
  320.             die ("ERRORthe filename $filename does not exists");
  321.         }
  322.         require_once 'func.php';
  323.         download ($dir'/'$filename$originalname);
  324.         exit;
  325.     }
  326.  
  327.     // begin{publicfields} automatic generation  //
  328.     /**
  329.      * @access private
  330.      */
  331.     function _publicfields({
  332.         return array();
  333.     }
  334.     // end{publicfields} automatic generation  //
  335.  
  336.     // begin{uniquefields} automatic generation  //
  337.  
  338.     // end{uniquefields} automatic generation  //
  339.  
  340.  
  341. // class 
  342.  
  343. ?>

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