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

Source for file class.tablefields.php

Documentation is available at class.tablefields.php

  1. <?php
  2. /**    
  3.  * Logique des champs
  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.tablefields.php 4006 2007-10-05 11:53:41Z malafosse $
  40.  */
  41.  
  42.  
  43. /**
  44.  * Classe de logique des champs
  45.  * 
  46.  * @package lodel/logic
  47.  * @author Ghislain Picard
  48.  * @author Jean Lamy
  49.  * @copyright 2001-2002, Ghislain Picard, Marin Dacos
  50.  * @copyright 2003, Ghislain Picard, Marin Dacos, Luc Santeramo, Nicolas Nutten, Anne Gentil-Beccot
  51.  * @copyright 2004, Ghislain Picard, Marin Dacos, Luc Santeramo, Anne Gentil-Beccot, Bruno Cénou
  52.  * @copyright 2005, Ghislain Picard, Marin Dacos, Luc Santeramo, Gautier Poupeau, Jean Lamy, Bruno Cénou
  53.  * @copyright 2006, Marin Dacos, Luc Santeramo, Bruno Cénou, Jean Lamy, Mikaël Cixous, Sophie Malafosse
  54.  * @copyright 2007, Marin Dacos, Bruno Cénou, Sophie Malafosse, Pierre-Alain Mignot
  55.  * @licence http://www.gnu.org/copyleft/gpl.html
  56.  * @since Classe ajouté depuis la version 0.8
  57.  * @see logic.php
  58.  */
  59. class TableFieldsLogic extends Logic 
  60. {
  61.  
  62.     /**
  63.      * Constructeur
  64.      */
  65.     function TableFieldsLogic()
  66.     {
  67.         $this->Logic('tablefields');
  68.     }
  69.  
  70.     /**
  71.      * Affichage d'un objet
  72.      *
  73.      * @param array &$context le contexte passé par référence
  74.      * @param array &$error le tableau des erreurs éventuelles passé par référence
  75.      */
  76.     function viewAction(&$context,&$error)
  77.  
  78.     {
  79.         global $db;
  80.  
  81.         $ret=Logic::viewAction($context,$error);
  82.         $this->_getClass($context);
  83.         return $ret;
  84.     }
  85.  
  86.     /**
  87.      * Ajout d'un nouvel objet ou Edition d'un objet existant
  88.      *
  89.      * Ajout d'un nouveau champ
  90.      *
  91.      * @param array &$context le contexte passé par référence
  92.      * @param array &$error le tableau des erreurs éventuelles passé par référence
  93.      */
  94.     function editAction(&$context&$error)
  95.     {
  96.         $this->_getClass($context);
  97.         // must be done before the validation
  98.         return Logic::editAction($context$error);
  99.     }
  100.  
  101.  
  102.     /**
  103.      * Changement du rang d'un objet
  104.      *
  105.      * @param array &$context le contexte passé par référence
  106.      * @param array &$error le tableau des erreurs éventuelles passé par référence
  107.      */
  108.     function changeRankAction(&$context&$error)
  109.     {
  110.         return Logic::changeRankAction(&$context&$error'idgroup,class');
  111.     }
  112.  
  113.  
  114.     /**
  115.      * Construction des balises select HTML pour cet objet
  116.      *
  117.      * @param array &$context le contexte, tableau passé par référence
  118.      * @param string $var le nom de la variable du select
  119.      */
  120.     function makeSelect(&$context$var)
  121.     {
  122.         switch($var{
  123.         case 'type':
  124.             require_once 'commonselect.php';
  125.             makeSelectFieldTypes($context['type']);
  126.             break;
  127.         case 'gui_user_complexity' :
  128.             require_once 'commonselect.php';
  129.             makeSelectGuiUserComplexity($context['gui_user_complexity']);
  130.             break;
  131.         case 'cond':
  132.             $arr array(
  133.             '*' => getlodeltextcontents('nocondition''admin'),
  134.             '+' => getlodeltextcontents('fieldrequired''admin'),
  135.             'defaultnew' => getlodeltextcontents('use_default_at_creation only''admin'),
  136.             'permanent' => getlodeltextcontents('permanent''admin'),
  137.             'unique' => getlodeltextcontents('single''admin'),
  138.             );
  139.         renderOptions($arr,$context['cond']);
  140.             break;
  141.         case 'edition':
  142.             require_once 'commonselect.php';
  143.             makeSelectEdition($context['edition']);
  144.             break;
  145.         case 'allowedtags':
  146.             require_once 'balises.php';
  147.             $groups array_keys($GLOBALS['xhtmlgroups']);
  148.             $arr2 array();
  149.             foreach($groups as $k{
  150.                 if ($k && !is_numeric($k)) $arr2[$k]=$k;
  151.             }
  152.             renderOptions($arr2,$context['allowedtags']);
  153.             break;
  154.         case 'idgroup':
  155.             $arr array();
  156.             // get the groups having of the same class as idgroup
  157.             $result $GLOBALS['db']->execute(lq("SELECT #_TP_tablefieldgroups.id,#_TP_tablefieldgroups.title FROM #_tablefieldgroupsandclassesjoin_ INNER JOIN #_TP_tablefieldgroups as tfg2 ON tfg2.class=#_TP_classes.class WHERE tfg2.id='".$context['idgroup']."'")) or die($GLOBALS['db']->errormsg());
  158.             while(!$result->EOF{
  159.                 $arr[$result->fields['id']]=$result->fields['title'];
  160.                 $result->MoveNext();
  161.             }
  162.             renderOptions($arr$context['idgroup']);
  163.             break;
  164.     case 'g_name':
  165.         require_once 'fieldfunc.php';
  166.         if (!$context['classtype']$this->_getClass($context);
  167.         switch ($context['classtype']{
  168.         case 'entities':
  169.             $g_namefields $GLOBALS['g_entities_fields'];/*array('DC.Title', 'DC.Description',
  170.                     'DC.Publisher', 'DC.Date',
  171.                     'DC.Format', 'DC.Identifier',
  172.                     'DC.Source', 'DC.Language',
  173.                     'DC.Relation', 'DC.Coverage',
  174.                     'DC.Rights','generic_icon');*/
  175.             break;
  176.         case 'persons':
  177.             $g_namefields $GLOBALS['g_persons_fields'];#array('Firstname', 'Familyname', 'Title');
  178.             break;
  179.         case 'entities_persons':
  180.             $g_namefields $GLOBALS['g_entities_persons_fields'];# array('Title');
  181.             break;
  182.         case 'entries':
  183.             $g_namefields array('Index key');
  184.             break;
  185.         default:
  186.             trigger_error("class type ?",E_USER_ERROR);
  187.         }
  188.  
  189.         $dao $this->_getMainTableDAO();
  190.         $tablefields $dao->findMany("class='".$context['class']."'","","g_name,title");     
  191.         foreach($tablefields as $tablefield$arr[$tablefield->g_name]=$tablefield->title}
  192.  
  193.         $arr2 array(''=>'--');
  194.         foreach($g_namefields as $g_name{
  195.             $lg_name=strtolower($g_name);
  196.             if ($arr[$lg_name]{
  197.                 $arr2[$lg_name]=$g_name." &rarr; ".$arr[$lg_name];
  198.             else {
  199.                 $arr2[$lg_name]=$g_name;
  200.             }
  201.         }
  202.         renderOptions($arr2$context['g_name']);
  203.         break;
  204.         case 'weight':
  205.             $arr array('0' => getlodeltextcontents('not_indexed''admin'),
  206.             '1' => '1''2' => '2''4' => '4''8' => '8');
  207.             renderOptions($arr$context['weight']);
  208.             break;
  209.         }
  210.     }
  211.  
  212.     /*** In 0.7 we check the field is not moved in another class... it's not 100% required in fact
  213.         function validateFields(&$context,&$error) {
  214.         if (!Logic::validateFields($context,$error)) return false;
  215.         // check the group does not change 
  216.         if ($oldidgroup!=$idgroup) {
  217.     $set['rank']=get_rank_max("fields","idgroup='$idgroup'");      
  218.     // check the new group has the same class (extra security)
  219.     $result=mysql_query("SELECT 1 FROM $GLOBALS[tp]tablefieldgroups WHERE id='$idgroup' AND class='".$context['class']."'") or dberror();
  220.     if (mysql_num_rows($result)!=1) die("ERROR: the new and the old group of the field are not in the same class");
  221.             }**/
  222.  
  223.     /**
  224.     * Préparation de l'action Edit
  225.     *
  226.     * @access private
  227.     * @param object $dao la DAO utilisée
  228.     * @param array &$context le context passé par référence
  229.     */
  230.     function _prepareEdit($dao,&$context)
  231.  
  232.     {
  233.         // gather information for the following
  234.         if ($context['id']{
  235.             $this->oldvo=$dao->getById($context['id']);
  236.             if (!$this->oldvodie("ERROR: internal error in TableFields::_prepareEdit");
  237.         }
  238.     }
  239.     /**
  240.     * Sauve des données dans des tables liées éventuellement
  241.     *
  242.     * Appelé par editAction pour effectuer des opérations supplémentaires de sauvegarde.
  243.     *
  244.     * @param object $vo l'objet qui a été créé
  245.     * @param array $context le contexte
  246.     */
  247.     function _saveRelatedTables($vo,$context
  248.  
  249.     {
  250.         global $home,$lodelfieldtypes,$db;
  251.         require_once("fieldfunc.php");
  252.  
  253.         // remove the dc for all the other fields
  254.         if ($vo->g_name{
  255.             $db->execute(lq("UPDATE #_TP_tablefields SET g_name='' WHERE g_name='".$vo->g_name."' AND id!='".$vo->id."' AND class='".$vo->class."'")) or dberror();
  256.         }
  257.  
  258.         // manage the physical field 
  259.         if ($vo->class && $this->oldvo->class && 
  260.     $this->oldvo->class!=$vo->classdie("ERROR: field change of class is not implemented yet");
  261.  
  262.         if ($vo->type!="entities"{
  263.             if (!$this->oldvo{
  264.     $alter="ADD";
  265.             elseif ($this->oldvo->name!=$vo->name{
  266.     $alter="CHANGE ".$this->oldvo->name;
  267.             elseif ($lodelfieldtypes[$this->oldvo->type]['sql']=$lodelfieldtypes[$vo->type]['sql']{
  268.     $alter="MODIFY";
  269.             }
  270.  
  271.             if ($alter// modify or add or rename the field
  272.     if (!$lodelfieldtypes[$vo->type]['sql']die("ERROR: internal error in TableFields:: _saveRelatedTables ".$vo->type);
  273.     $db->execute(lq("ALTER TABLE #_TP_".$context['class']." $alter ".$vo->name." ".$lodelfieldtypes[$vo->type]['sql'])) or dberror();
  274.             }
  275.             if ($alter || $vo->filtering!=$this->oldvo->filtering{
  276.     // should be in view ??
  277.     require_once("cachefunc.php");
  278.     clearcache();
  279.             }
  280.         }
  281.         unset($this->oldvo);
  282.     }
  283.  
  284.     /**
  285.     * Appelé avant l'action delete
  286.     *
  287.     * Cette méthode est appelée avant l'action delete pour effectuer des vérifications
  288.     * préliminaires à une suppression.
  289.     *
  290.     * @param object $dao la DAO utilisée
  291.     * @param array &$context le contexte passé par référénce
  292.     */
  293.     function _prepareDelete($dao,&$context)
  294.  
  295.     {     
  296.         // gather information for the following
  297.         $this->vo=$dao->getById($context['id']);
  298.         if (!$this->vodie("ERROR: internal error in TableFields::deleteAction");
  299.     }
  300.     
  301.     /**
  302.      * Suppression dans les tables liées
  303.      *
  304.      * @param integer $id identifiant numérique de l'objet supprimé
  305.      */
  306.     function _deleteRelatedTables($id)
  307.     {
  308.         global $db$home;
  309.  
  310.         if (!$this->vo{
  311.             die("ERROR: internal error in TableFields::deleteAction");
  312.         }
  313.         if ($this->vo->type!="entities"{
  314.             $db->execute(lq("ALTER TABLE #_TP_".$this->vo->class." DROP ".$this->vo->name)) or dberror();
  315.         }
  316.         unset($this->vo);
  317.  
  318.         // should be in the view....
  319.         require_once 'cachefunc.php';
  320.         clearcache();
  321.         //
  322.  
  323.         return '_back';
  324.     }
  325.  
  326.     /**
  327.      * Récupère la classe d'un groupe de champ
  328.      *
  329.      * @param array &$context le contexte, tableau passé par référence
  330.      */
  331.     function _getClass(&$context)
  332.     {
  333.         global $db;
  334.         if ($context['idgroup']{
  335.             $row $db->getRow(lq("SELECT #_TP_classes.class,classtype FROM #_tablefieldgroupsandclassesjoin_ WHERE #_TP_tablefieldgroups.id='"$context['idgroup']"'")) or dberror();
  336.             if ($context['class'&& $context['class'!= $row['class']{
  337.                 die("ERROR: idgroup and class are incompatible in TableFieldsLogic::editAction");
  338.             }
  339.             $context['class']     $row['class'];
  340.             $context['classtype'$row['classtype'];
  341.         else {
  342.             if (substr($context['class'],0,9== 'entities_'{
  343.                 $class substr($context['class'],9);
  344.                 $classtype 'entities_';
  345.             else {
  346.                 $class $context['class'];
  347.             }
  348.             $classtype.= $db->getOne(lq("SELECT classtype FROM #_TP_classes WHERE class='"$class"'"));
  349.             $context['classtype'$classtype;
  350.         }
  351.     }
  352.  
  353.     /**
  354.         *
  355.         * Special treatment for allowedtags, from/to the context
  356.         */
  357.     function _populateContext(&$vo,&$context)
  358.     {
  359.         Logic::_populateContext($vo$context);
  360.         $context['allowedtags'explode(';'$vo->allowedtags);
  361.     }
  362.  
  363.     function _populateObject(&$vo&$context)
  364.     {
  365.         Logic::_populateObject($vo,$context);
  366.         $vo->class $context['class']// it is safe, we now that !
  367.         $vo->allowedtags is_array($context['allowedtags']join(';'$context['allowedtags']'';
  368.     }
  369.  
  370.     // begin{publicfields} automatic generation  //
  371.  
  372.     /**
  373.      * Retourne la liste des champs publics
  374.      * @access private
  375.      */
  376.     function _publicfields(
  377.     {
  378.         return array('name' => array('tablefield''+'),
  379.                                     'class' => array('class''+'),
  380.                                     'title' => array('text''+'),
  381.                                     'altertitle' => array('mltext'''),
  382.                                     'gui_user_complexity' => array('select''+'),
  383.                                     'idgroup' => array('select''+'),
  384.                                     'type' => array('select''+'),
  385.                                     'g_name' => array('select'''),
  386.                                     'style' => array('mlstyle'''),
  387.                                     'cond' => array('select''+'),
  388.                                     'defaultvalue' => array('text'''),
  389.                                     'processing' => array('text'''),
  390.                                     'allowedtags' => array('multipleselect'''),
  391.                                     'edition' => array('select'''),
  392.                                     'editionparams' => array('text'''),
  393.                                     'weight' => array('select'''),
  394.                                     'filtering' => array('text'''),
  395.                                     'comment' => array('longtext'''));
  396.     }
  397.     // end{publicfields} automatic generation  //
  398.  
  399.     // begin{uniquefields} automatic generation  //
  400.  
  401.     /**
  402.      * Retourne la liste des champs uniques
  403.      * @access private
  404.      */
  405.     function _uniqueFields(
  406.     
  407.         return array(array('name''class'));
  408.     }
  409.     // end{uniquefields} automatic generation  //
  410.  
  411.  
  412. // class 
  413.  
  414. /*-----------------------------------*/
  415. /* loops                             */
  416. function loop_allowedtags_documentation(&$context,$funcname)
  417.  
  418. {
  419.     ##$groups=array_merge(array_keys($GLOBALS['xhtmlgroups']),array_keys($GLOBALS['multiplelevel']));
  420.     require_once("balises.php");
  421.     foreach($GLOBALS['xhtmlgroups'as $groupname => $tags{
  422.         $localcontext=$context;
  423.         $localcontext['count']=$count;
  424.         $count++;
  425.         $localcontext['groupname']=$groupname;
  426.         $localcontext['allowedtags']="";
  427.         foreach ($tags as $k=>$vif (!is_numeric($k)) unset($tags[$k])}
  428.         if (!$tagscontinue;
  429.         $localcontext['allowedtags']=join(", ",$tags);
  430.         call_user_func("code_do_$funcname",$localcontext);
  431.     }
  432. }
  433.  
  434. ?>

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