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

Source for file class.persons.php

Documentation is available at class.persons.php

  1. <?php
  2. /**    
  3.  * Logique des personnes
  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.  * @author Sophie Malafosse
  32.  * @copyright 2001-2002, Ghislain Picard, Marin Dacos
  33.  * @copyright 2003, Ghislain Picard, Marin Dacos, Luc Santeramo, Nicolas Nutten, Anne Gentil-Beccot
  34.  * @copyright 2004, Ghislain Picard, Marin Dacos, Luc Santeramo, Anne Gentil-Beccot, Bruno Cénou
  35.  * @copyright 2005, Ghislain Picard, Marin Dacos, Luc Santeramo, Gautier Poupeau, Jean Lamy, Bruno Cénou
  36.  * @copyright 2006, Marin Dacos, Luc Santeramo, Bruno Cénou, Jean Lamy, Mikaël Cixous, Sophie Malafosse
  37.  * @copyright 2007, Marin Dacos, Bruno Cénou, Sophie Malafosse, Pierre-Alain Mignot
  38.  * @licence http://www.gnu.org/copyleft/gpl.html
  39.  * @since Fichier ajouté depuis la version 0.8
  40.  * @version CVS:$Id: class.persons.php 4006 2007-10-05 11:53:41Z malafosse $
  41.  */
  42.  
  43. require_once("class.entries.php");
  44.  
  45. /**
  46.  * Classe de logique des personnes
  47.  * 
  48.  * @package lodel/logic
  49.  * @author Ghislain Picard
  50.  * @author Jean Lamy
  51.  * @copyright 2001-2002, Ghislain Picard, Marin Dacos
  52.  * @copyright 2003, Ghislain Picard, Marin Dacos, Luc Santeramo, Nicolas Nutten, Anne Gentil-Beccot
  53.  * @copyright 2004, Ghislain Picard, Marin Dacos, Luc Santeramo, Anne Gentil-Beccot, Bruno Cénou
  54.  * @copyright 2005, Ghislain Picard, Marin Dacos, Luc Santeramo, Gautier Poupeau, Jean Lamy, Bruno Cénou
  55.  * @copyright 2006, Marin Dacos, Luc Santeramo, Bruno Cénou, Jean Lamy, Mikaël Cixous, Sophie Malafosse
  56.  * @copyright 2007, Marin Dacos, Bruno Cénou, Sophie Malafosse, Pierre-Alain Mignot
  57.  * @licence http://www.gnu.org/copyleft/gpl.html
  58.  * @since Classe ajoutée depuis la version 0.8
  59.  * @see logic.php
  60.  */
  61. class PersonsLogic extends EntriesLogic
  62. {
  63.  
  64.     /** Constructor
  65.      */
  66.     function PersonsLogic ({
  67.         $this->EntriesLogic('persons');
  68.         $this->daoname 'persontypes';
  69.         $this->idtype 'idperson';
  70.     }
  71.  
  72.         
  73.     /**
  74.      * Ajout d'un nouvel objet ou Edition d'un objet existant
  75.      *
  76.      * Ajout d'un nouvel objet persons
  77.      *
  78.      * @param array &$context le contexte passé par référence
  79.      * @param array &$error le tableau des erreurs éventuelles passé par référence
  80.      */
  81.     function editAction (&$context&$error$clean=false
  82.     {
  83.         global $lodeluser$home;
  84.         $id=$context['id'];
  85.         $idtype=$context['idtype'];
  86.         if (!$idtypedie ("ERROR: internal error in PersonsLogic::editAction");
  87.         $status=$context['status'];
  88. #echo "status=$status"; print_r ($context);
  89.         // get the class 
  90.         $daotype=&getDAO ("persontypes");
  91.         $votype=$daotype->getById ($idtype"class");
  92.         $class=$context['class']=$votype->class;
  93.         #print_r($context);
  94.         if ($clean!=CLEAN{
  95.             if (!$this->validateFields ($context$error)) {
  96.             // error.
  97.             // if the entity is imported and will be checked
  98.             // that's fine, let's continue, if not return an error
  99.                 if ($status>-64return "_error";
  100.             }
  101.         }
  102.         foreach (array ("firstname""familyname"as $g{
  103.             $equiv[$g]=$this->getGenericEquivalent($class,$g);
  104.             if (!$equiv[$g]trigger_error ("ERRORThe generic field $g is requiredPlease edit your editorial model.",E_USER_ERROR);
  105.             $$g=trim($context['data'][$equiv[$g]]);
  106.         }
  107.  
  108.         if (!$familyname && !$firstname$error[$equiv['familyname']]="+"return "_error"}
  109.         // get the dao for working with the object
  110.         $dao=$this->_getMainTableDAO();
  111.  
  112.         if (!$id && ($familyname || $firstname)) {
  113.             // search if the person exists
  114.             // ajout de slashes pour le SELECT dans la base 
  115.             $tmpfirstname $firstname;
  116.             $tmpfamilyname $familyname;
  117.             myaddslashes($tmpfirstname);
  118.             myaddslashes($tmpfamilyname);
  119.             $vo=$dao->find ("g_familyname='"$tmpfamilyname"' AND g_firstname='"$tmpfirstname"'  AND idtype='".$idtype."' AND status>-64","id,status");
  120.             //$vo=$dao->find ("g_familyname='". $familyname. "' AND g_firstname='". $firstname. "'  AND idtype='".$idtype."' AND status>-64","id,status");
  121.             ifabs($vo->status== 32$context['protected'1//if protected
  122.             $new=false;
  123.         }
  124.  
  125.         if (!$vo{
  126.             if ($id//edit
  127.                 $new=false;
  128.                 $dao->instantiateObject($vo);
  129.                 $vo->id=$id;
  130.             else //create
  131.                 $new=true;
  132.                 $vo=$dao->createObject();
  133.                 $vo->status=$status $status : -1;
  134.             }
  135.         }
  136.         // populate the persons table
  137.         if ($dao->rights['protect']$vo->protect=$context ['protected'0;
  138.         if ($idtype$vo->idtype=$idtype;
  139.         $vo->g_firstname=$firstname;
  140.         $vo->g_familyname=$familyname;
  141.         $vo->sortkey=makeSortKey ($familyname." ".$firstname);
  142.         $id=$context['id']=$dao->save($vo);
  143.         // change the group recursively
  144.         //if ($context['usergrouprec'] && $lodeluser['admin']) change_usergroup_rec($id,$usergroup);
  145.  
  146.         // save the class table
  147.         $gdao=&getGenericDAO ($class,"idperson");
  148.         $gdao->instantiateObject ($gvo);
  149.         $context['data']['id']=$context['id'];
  150.         $this->_populateObject ($gvo,$context['data']);
  151.         $gvo->idperson=$id;
  152.         $this->_moveFiles ($id$this->files_to_move$gvo);
  153.         $gdao->save ($gvo,$new);  // save the related table
  154.         // save the entities_class table
  155.         if ($context['identity']{
  156.             $dao=&getDAO ("relations");
  157.             $vo=$dao->find ("id1='".intval ($context['identity'])"' AND id2='"$id"' AND nature='G' AND degree='".intval ($context['degree'])"'""idrelation");
  158.             if (!$vo{
  159.                 $dao->instantiateObject ($vo);
  160.                 $vo->id1=intval ($context['identity']);
  161.                 $vo->id2=$id;
  162.                 $vo->degree=intval ($context['degree']);
  163.                 $vo->nature='G';
  164.                 $idrelation=$context['idrelation'$dao->save($vo);
  165.             else {
  166.                 $idrelation=$context['idrelation'$vo->idrelation;
  167.             }
  168.  
  169.             $gdao=&getGenericDAO("entities_".$class,"idrelation");
  170.             $gdao->instantiateObject($gvo);
  171.             $this->_populateObject($gvo,$context['data']);
  172.             $gvo->idrelation=$idrelation;
  173.             $gdao->save($gvo,true);  // save the related table
  174.         }
  175.  
  176.         update();
  177.         return "_back";
  178.     }
  179.  
  180. }// class 
  181.  
  182. /*------------------------------------*/
  183. /* special function                   */
  184.  
  185.  
  186.  
  187. /*-----------------------------------*/
  188. /* loops                             */
  189. ?>

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