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

Source for file class.optiongroups.php

Documentation is available at class.optiongroups.php

  1. <?php
  2. /**    
  3.  * Logique des groupes d'options
  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.optiongroups.php 4006 2007-10-05 11:53:41Z malafosse $
  40.  */
  41.  
  42.  
  43.  
  44. /**
  45.  * Classe de logique des groupes d'options
  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 OptiongroupsLogic extends Logic {
  61.  
  62.     /**
  63.      * Constructor
  64.      */
  65.     function OptiongroupsLogic(
  66.     {
  67.         $this->Logic("optiongroups");
  68.     }
  69.  
  70.     /**
  71.      * Construction des balises select HTML pour cet objet
  72.      *
  73.      * @param array &$context le contexte, tableau passé par référence
  74.      * @param string $var le nom de la variable du select
  75.      */
  76.     function makeSelect(&$context$var)
  77.     {
  78.         global $db;
  79.  
  80.         switch($var{
  81.         case 'idparent':
  82.             $arr=array();
  83.             $rank=array();
  84.             $parent=array();
  85.             $ids=array(0);
  86.             $l=1;
  87.             do {
  88.                 $result=$db->execute(lq("SELECT * FROM #_TP_optiongroups WHERE idparent ".sql_in_array($ids)." ORDER BY rank")) or dberror();
  89.                 $ids=array();
  90.                 $i=1;
  91.                 while(!$result->EOF{
  92.                     $id=$result->fields['id'];
  93.                     if ($id!=$context['id']{
  94.                         $ids[]=$id;     
  95.                         $fullname=$result->fields['title'];
  96.                         $idparent=$result->fields['idparent'];
  97.                         if ($idparent$fullname=$parent[$idparent]." / ".$fullname;       
  98.                         $d=$rank[$id]=$rank[$idparent]+($i*1.0)/$l;
  99.                         //echo $d," ";
  100.                         $arr["p$d"]=array($id,$fullname);
  101.                         $parent[$id]=$fullname;
  102.                         $i++;
  103.                     }
  104.                     $result->MoveNext();
  105.                 }
  106.                 $l*=100;
  107.             while ($ids);
  108.             ksort($arr);
  109.             $arr2=array('0' => '--')// reorganize the array $arr
  110.             foreach($arr as $row{
  111.                 $arr2[$row[0]] $row[1];
  112.             }
  113.             renderOptions($arr2$context[$var]);
  114.             break;
  115.         }
  116.     }
  117.     
  118.     
  119.     /**
  120.      * Changement du rang d'un objet
  121.      *
  122.      * @param array &$context le contexte passé par référence
  123.      * @param array &$error le tableau des erreurs éventuelles passé par référence
  124.      */
  125.     function changeRankAction(&$context&$error)
  126.     {
  127.         return Logic::changeRankAction(&$context&$error'idparent''');
  128.     }
  129.  
  130.     /**
  131.     *  Indique si un objet est protégé en suppression
  132.     *
  133.     * Cette méthode indique si un objet, identifié par son identifiant numérique et
  134.     * éventuellement son status, ne peut pas être supprimé. Dans le cas où un objet ne serait
  135.     * pas supprimable un message est retourné indiquant la cause. Sinon la méthode renvoit le
  136.     * booleen false.
  137.     *
  138.     * @param integer $id identifiant de l'objet
  139.     * @param integer $status status de l'objet
  140.     * @return false si l'objet n'est pas protégé en suppression, un message sinon
  141.     */
  142.     function isdeletelocked($id$status 0)
  143.     {
  144.         global $db;
  145.         $count $db->getOne(lq("SELECT count(*) FROM #_TP_options WHERE idgroup='$idAND status>-64"));
  146.         $countgroups $db->getOne(lq("SELECT count(*) FROM #_TP_optiongroups WHERE idparent='$idAND status>-64"));
  147.         $count $count $countgroups;
  148.         if ($db->errorno())  dberror();
  149.         if ($count==0{
  150.             return false;
  151.         else {
  152.             return sprintf(getlodeltextcontents("cannot_delete_hasoptions","admin"),$count);
  153.         }
  154.     }
  155.     
  156.     
  157.     /**
  158.     * Préparation de l'action Edit
  159.     *
  160.     * @access private
  161.     * @param object $dao la DAO utilisée
  162.     * @param array &$context le context passé par référence
  163.     */
  164.     function _prepareEdit($dao,&$context)
  165.     {
  166.         // gather information for the following
  167.         if ($context['id']//it is an edition
  168.         {
  169.             $this->oldvo=$dao->getById($context['id']);
  170.             if (!$this->oldvo)
  171.                 die("ERROR: internal error in OptionGroups::_prepareEdit");
  172.             if($context['idparent'!= $this->oldvo->idparent//can't change the parent of an optiongroup !
  173.                 die("ERROR : Changing the parent of a group is forbidden");
  174.             
  175.         }
  176.         else //it is an add
  177.         {
  178.             //if it is an add - the optiongroup inherit the exportpolicy
  179.             if($context['idparent'])
  180.             {
  181.                     $voparent $dao->getById($context['idparent'],"id,exportpolicy");
  182.                     $context['exportpolicy'$voparent->exportpolicy;
  183.             }
  184.         }
  185.     }
  186.     
  187.     
  188.     /**
  189.      * Ajout d'un nouvel objet ou Edition d'un objet existant
  190.      *
  191.      * Ajout d'un groupe d'option
  192.      *
  193.      * @param array &$context le contexte passé par référence
  194.      * @param array &$error le tableau des erreurs éventuelles passé par référence
  195.      */
  196.     function editAction(&$context&$error$clean false)
  197.     {
  198.         $ret Logic::editAction($context$error);
  199.         if (!$error$this->clearCache();
  200.                 return $ret;
  201.     }
  202.     
  203.     /**
  204.     * Sauve des données dans des tables liées éventuellement
  205.     *
  206.     * Appelé par editAction pour effectuer des opérations supplémentaires de sauvegarde.
  207.     *
  208.     * @param object $vo l'objet qui a été créé
  209.     * @param array $context le contexte
  210.     */
  211.     function _saveRelatedTables($vo,&$context
  212.     {
  213.         global $db;
  214.         //if the exportpolicy has been changed update the optiongroups children    
  215.         $dao=$this->_getMainTableDAO();
  216.         $newpolicy $vo->exportpolicy;
  217.         $oldpolicy $context['exportpolicy'== 'on' 0;
  218.         if($newpolicy != $oldpolicy)    
  219.         {
  220.             $ids array($vo->id);
  221.             do
  222.             {
  223.                 $vos $dao->findMany("exportpolicy <> '$newpolicyAND idparent ".sql_in_array($ids),"rank DESC","id,idparent,exportpolicy");
  224.                 $sqlquery lq("UPDATE #_TP_optiongroups SET exportpolicy='$newpolicyWHERE exportpolicy <> '$newpolicyAND idparent ".sql_in_array($ids));
  225.                 $ret $db->execute($sqlquery);
  226.                 $ids array();
  227.                 if($ret!==false//
  228.                     foreach($vos as $vo)
  229.                         $ids[$vo->id;
  230.             }
  231.             while($ids);
  232.         }
  233.     }
  234.     
  235.     /**
  236.      * Suppression d'un objet
  237.      *
  238.      * @param array &$context le contexte passé par référence
  239.      * @param array &$error le tableau des erreurs éventuelles passé par référence
  240.      */
  241.     function deleteAction(&$context,&$error)
  242.  
  243.     {
  244.         $ret=Logic::deleteAction($context,$error);
  245.         if (!$error$this->clearCache();
  246.         return $ret;
  247.  
  248.     }
  249.     /**
  250.      * Effacement du cache
  251.      */
  252.     function clearCache()
  253.     {
  254.         @unlink(SITEROOT"CACHE/options_cache.php");
  255.     }
  256.  
  257.     // begin{publicfields} automatic generation  //
  258.  
  259.     /**
  260.      * Retourne la liste des champs publics
  261.      * @access private
  262.      */
  263.     function _publicfields(
  264.     {
  265.         return array('idparent' => array('select''+'),
  266.                                     'name' => array('text''+'),
  267.                                     'title' => array('text''+'),
  268.                                     'altertitle' => array('mltext'''),
  269.                                     'logic' => array('text'''),
  270.                                     'exportpolicy' => array('boolean''+'),
  271.                                     'comment' => array('longtext'''));
  272.     }
  273.     // end{publicfields} automatic generation  //
  274.  
  275.     // begin{uniquefields} automatic generation  //
  276.  
  277.     /**
  278.      * Retourne la liste des champs uniques
  279.      * @access private
  280.      */
  281.     function _uniqueFields(
  282.     
  283.         return array(array('name'));
  284.     }
  285.     // end{uniquefields} automatic generation  //
  286.         
  287.  
  288. // class 
  289.  
  290. ?>

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