[ Index ]
 

Code source de SPIP Agora 1.4

Accédez au Source d'autres logiciels libresSoutenez Angelica Josefina !

title

Body

[fermer]

/Agora1-4/ecrire/ -> inc_contraintes.php (source)

   1  <?php
   2  /*****************************************************
   3  * This file is part of Agora, web based content management system.
   4  *
   5  * Agora is free software; you can redistribute it and/or modify
   6  * it under the terms of the GNU General Public License as published by
   7  * the Free Software Foundation; version 2 of the License.
   8  *
   9  * Agora is distributed in the hope that it will be useful,
  10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12  * GNU General Public License for more details (file "COPYING").
  13  *
  14  * Copyright © Arnaud Martin, Antoine Pitrou et Philippe Rivière.
  15  * List of authors detailed in "copyright_fr.html" file.
  16  * E-mail : agora@sig.premier-ministre.gouv.fr
  17  * Web site : http://www.agora.gouv.fr
  18  *****************************************************/
  19  //$Id$
  20  
  21  require_once dirname(__FILE__). "/include/bd/inc_article_factory.php";
  22  
  23  require_once dirname(__FILE__). "/include/bd/inc_rubrique_factory.php";
  24  require_once dirname(__FILE__). "/include/typologie/inc_rule_factory.php";
  25  
  26  // Le scripts essaye de charger le fichier de contraintes.
  27  // Utile pour ne pas perdre les modifications/création de contraintes lors des MAJ de SPIP AGORA
  28  //require_once dirname(__FILE__)."/include/typologie/mes_contraintes.php";
  29  if (file_exists(dirname(__FILE__). "/include/typologie/mes_contraintes.php")) {
  30      require_once dirname(__FILE__). "/include/typologie/mes_contraintes.php";
  31  }
  32  else {
  33      $GLOBALS['aConstraints'] = array();
  34  }
  35  
  36  // {{{ getErrorMsg
  37  
  38  /**
  39   * This function apply constraints rules on the content type $sType
  40   * @param   $sContentType String ie : articles, rubriques
  41   * @access public
  42   */
  43  function getErrorMsg ($sContentType, $Object) {
  44      $isExtra = false;
  45      $articleId = false;
  46      $rubriqueId = false;
  47  
  48      if ($sContentType == "article") {
  49          $aRules = loadConstraintRules($sContentType, $Object->getRubriqueId());
  50          $articleId = $Object->getArticleId();
  51          $extra = $Object->getExtra();
  52          if ($extra) {
  53              $extra = unserialize($extra);
  54          }
  55      }
  56      else if ($sContentType == "rubrique") {
  57          $rubriqueId = $Object->getRubriqueId();
  58          $aRules = loadConstraintRules($sContentType, $Object->getParentId());
  59      }
  60  
  61      if (count($aRules) <= 0) {
  62          // Si aucune regle n'est définie
  63          return false;
  64      }
  65  
  66      $aErrorMsg = array();
  67  
  68      while (list($sField, $aRulesList) = each($aRules)) {
  69          // Vérification du type (extra ou non)
  70          if (is_array($extra)) {
  71              if (in_array($sField, array_keys($extra))) {
  72                  $isExtra = true;
  73              }
  74              else {
  75                  $isExtra = false;
  76              }
  77          }
  78  
  79          $aErrorMsg[$sField] = array();
  80  
  81          if (!$isExtra) {
  82              /**
  83               * Ici on vérifie si la personne en créant les contraintes
  84               * n'a pas fait d'erreur dans les noms des extras.
  85               */
  86  
  87              $aClassMethods = get_class_methods($Object);
  88              $methodName = 'get' . $sField;
  89              if (!in_array(strtolower($methodName), $aClassMethods)) {
  90                  trigger_error
  91                      (" Il y a un problème au niveau de la configuration des contraintes : le champs extra " . $sField . " ne semble pas exister");
  92                  $aErrorMsg[$sField][] = "Le champs extra " . $sField . " ne semble pas exister";
  93                  return $aErrorMsg;
  94              }
  95              else {
  96                  eval ('$sFieldContent = $Object->get' . $sField . '();');
  97              }
  98          }
  99          else {
 100              eval ('$sFieldContent = $extra["' . $sField . '"];');
 101              $sFieldProps = $GLOBALS['champs_extra'][$sContentType . "s"][$sField];
 102              $aFieldProps = split("[|]", $sFieldProps);
 103              if (count($aFieldProps) > 0) {
 104                  $sField = $aFieldProps[2];
 105              }
 106          }
 107          while (list($sRuleName, $sRuleValue) = each($aRulesList)) {
 108              $rule = &recuperer_instance_rule($sRuleName);
 109              $rule->setArticleId($articleId);
 110              $rule->setRuleValue($sRuleValue);
 111              $rule->setFieldContent($sFieldContent);
 112              $rule->setFieldName($sField);
 113              $ruleResult = $rule->validate();
 114              if (is_string($ruleResult)) {
 115                  $aErrorMsg[$sField][] = $ruleResult;
 116              }
 117          }
 118      }
 119  
 120      return $aErrorMsg;
 121  }
 122  
 123  function displayErrorMsg ($aErrorMsg) {
 124      if (!$aErrorMsg) {
 125          return false;
 126      }
 127  
 128      $bErr = false;
 129      $strErr = _T('err_common'). '<br>';
 130  
 131      while (list(, $aFieldMsg) = each($aErrorMsg)) {
 132          if (count($aFieldMsg) > 0) {
 133              $bErr = true;
 134          }
 135          while (list(, $msg) = each($aFieldMsg)) {
 136              $strErr .= $msg . "<br>";
 137          }
 138      }
 139  
 140      if ($bErr) {
 141          return $strErr;
 142      }
 143      else {
 144          return $bErr;
 145      }
 146  }
 147  
 148  // }}}
 149  
 150  // {{{ loadConstraintRules
 151  
 152  /**
 153   * This function load rules for the $sContentType
 154   * @param $sContentType String
 155   * @param $aConstraints Array
 156   * @access public
 157   */
 158  function loadConstraintRules ($sContentType, $aContrainst) {
 159      global $GLOBALS;
 160      $context = 'all';
 161      $ensemble = $aContrainst;
 162      $id_rubrique = $ensemble;
 163      $rubriqueMetier = &recuperer_instance_rubrique();
 164  
 165      while ($id_rubrique > 0) {
 166          if (isset($GLOBALS['aConstraints'][$sContentType]['=' . $id_rubrique])) {
 167              $context = '=' . $id_rubrique;
 168              return $GLOBALS["aConstraints"][$sContentType][$context];
 169          }
 170  
 171          $currentRubrique = false;
 172          $loadOK = $rubriqueMetier->load($id_rubrique);
 173          $id_rubrique = $rubriqueMetier->getParentId();
 174          if (!PEAR::isError($loadOK)) {
 175              if (isset($GLOBALS['aConstraints'][$sContentType]['-' . $id_rubrique])) {
 176                  $context = '-' . $id_rubrique;
 177                  $id_rubrique = 0;
 178                  $heritage = true;
 179              }
 180          }
 181      }
 182  
 183      return $GLOBALS["aConstraints"][$sContentType][$context];
 184  }
 185  
 186  // }}}
 187  ?>


Généré le : Sat Feb 24 14:40:03 2007 par Balluche grâce à PHPXref 0.7