Source for file CMS_CSSCLASS.phpclass

Documentation is available at CMS_CSSCLASS.phpclass

  1. <?php
  2. /**
  3.   * Class file CMS_CSSSTYLE.phpclass
  4.   *
  5.   * @project    Open CSP-Management
  6.   * @package    cms
  7.   * @categorie  css
  8.   *
  9.   * @author     Peter Krebs <pitlinz@users.sourceforge.net>
  10.   * @license    http://opensource.org/licenses/gpl-license.php GNU Public License
  11.   *
  12.   * @version pk-07-08-17
  13.   * @version $Id: CMS_CSSCLASS.phpclass,v 1.4 2008/06/20 15:29:53 pitlinz Exp $
  14.   * 
  15.   * @requires CMS_TABLEOBJ.phpclass
  16.   * @requires CMS_CSSSTYLE.phpclass
  17.   */
  18.  
  19. pcf_require_class('CMS_TABLEOBJ',__OCSP_PHPINCPATH__ "cms/CMS_TABLEOBJ.phpclass");
  20. pcf_require_class('CMS_CSSSTYLE',dirname(__FILE__)."/CMS_CSSSTYLE.phpclass");
  21.  
  22. /**
  23.   * handels CSS Class Files
  24.   *
  25.   * @project    Open CSP-Management
  26.   * @package    cms
  27.   * @categorie  css
  28.   *
  29.   * @author     Peter Krebs <pitlinz@users.sourceforge.net>
  30.   * @license    http://opensource.org/licenses/gpl-license.php GNU Public License
  31.   *
  32.   * @since      pk-06-09-07
  33.   * @version    pk-07-08-17
  34.   *
  35.   */
  36. class CMS_CSSCLASS  extends CMS_TABLEOBJ{
  37.     /**
  38.       * @staticvar string $myTable name of the db table
  39.       ***/
  40.     var $myTable="T_CMS_CSSCLASS";
  41.  
  42.     /**
  43.       * @staticvar string $myClassSrcFile if is set the DBMS_FORM get the class object
  44.       ***/
  45.     var $myClassSrcFile=__FILE__;
  46.  
  47.     /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
  48.  
  49.     /**
  50.       * @var CMS_CSSSTYLE $myStyleObj 
  51.       ***/
  52.     var $myStyleObj=NULL;
  53.  
  54.     /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
  55.     /*      cunstructor methods                                                     */
  56.     /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
  57.  
  58.     /**
  59.       * constructor
  60.       * if $aId <> null the object is populated
  61.       *
  62.       * @param int $aId 
  63.       * @param int $styId 
  64.       * @param boolean $debug 
  65.       *
  66.       * @return CMS_CSSCLASS 
  67.       *
  68.       * @version pk-07-08-17
  69.       ***/
  70.     function CMS_CSSCLASS($aId=0,$styId=0,$debug=FALSE{
  71.         if ($debugechoDebugMethod(__FILE__,get_class($this),"CMS_CSSCLASS::CMS_CSSCLASS()");
  72.  
  73.         $this->init($debug);
  74.         if (intval($aId)) {
  75.             $this->db_SetKey('CSS_ID',$aId);
  76.             $this->dbPopulate($debug);
  77.         else {
  78.             $this->setDefaults();
  79.             if (intval($styId)) {
  80.                 $this->setDBField("STY_ID",intval($styId));
  81.             }
  82.         }
  83.     }
  84.  
  85.     /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
  86.     /*      object var methods                                                      */
  87.     /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
  88.  
  89.     /**
  90.       * returns the id
  91.       * @returns int
  92.       ***/
  93.     function getId({
  94.         return intval($this->getDBField('CSS_ID'));
  95.     }
  96.  
  97.  
  98.     /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
  99.     /*      Database methods                                                        */
  100.     /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
  101.  
  102.     /**
  103.       * inserts a new row to the table
  104.       *
  105.       * @param string $gDBIDX Index of $GLOBALS to the db object
  106.       * @param bool   $debug  show debug info
  107.       *
  108.       * @returns int   returns the autoIncFld ID if exists or 1 on success
  109.       *
  110.       ***/
  111.     function dbInsert($debug=FALSE{
  112.         if ($debugechoDebugMethod(__FILE__,get_class($this),"CMS_CSSCLASS::dbInsert()");
  113.         $this->setDBField('CSS_OWNER',$GLOBALS['OCSP_OBJ']['USER']->getId());
  114.  
  115.         if (!$this->isConnected(TRUE,$debug))
  116.         {
  117.             ocsp_logError(__FILE__,__LINE__,"no database connection",E_ERROR);
  118.             die();
  119.         }
  120.  
  121.         if (!intval($this->getDBField('CSS_ORDERNR'))) {
  122.             $b_chkSort=FALSE;
  123.             $s_query ="SELECT IFNULL(MAX(CSS_ORDERNR),0)+1 FROM ".$this->myTable;
  124.             $s_query.=" WHERE PROJ_ID=".$this->getProjId();
  125.             $s_query.=" AND STY_ID=".$this->getStyleId();
  126.             if (!($i_orderNr=intval($this->myDBObj->quickQuery($s_query,0)))) {
  127.                 $i_orderNr=1;
  128.             }
  129.             $thihs->setDBField('CSS_ORDERNR',$i_orderNr);
  130.         else {
  131.             $b_chkSort=TRUE// move other classes down after insert
  132.         }
  133.         if (($a_id=parent::dbInsert($gDBIDX,$debug))) {
  134.             if ($b_chkSort{
  135.                 // move all other classes down if we have
  136.                 $s_cmd ="UPDATE ".$this->myTable." SET CSS_ORDERNR=CSS_ORDERNR+1";
  137.                 $s_cmd.=" WHERE STY_ID=".$this->getStyleId()." AND PROJ_ID=".$this->getProjId();
  138.                 $s_cmd.=" AND CSS_ORDERNR >= ".intval($this->getDBField('CSS_ORDERNR'));
  139.                 $s_cmd.=" AND CSS_ID <> ".$this->getId();
  140.                 $this->myDBObj->executeCmd($s_cmd);
  141.             }
  142.         }
  143.         CMS_CSSSTYLE::clearStyleCache($this->getStyleId(),$debug);
  144.         return $a_id;
  145.     }
  146.  
  147.     /**
  148.       * updates a row
  149.       *
  150.       * @param boolean $debug 
  151.       * @param boolean $ignorPopulated (if false the table MUST have been populated)
  152.       *
  153.       * @return boolean 
  154.       *
  155.       */
  156.     function dbReplace($debug=FALSE,$ignorPopulated=FALSE)
  157.     {
  158.         if ($debugechoDebugMethod(__FILE__,get_class($this),"CMS_CSSCLASS::dbReplace()");
  159.  
  160.         $this->setDBField('CSS_OWNER',$GLOBALS['OCSP_OBJ']['USER']->getId());
  161.         $this->setDBField('CSS_LASTCHANGE',NULL);
  162.         
  163.         CMS_CSSSTYLE::clearStyleCache($this->getStyleId(),$debug);
  164.  
  165.         return parent::dbReplace($debug,$ignorPopulated);
  166.     }
  167.  
  168.     /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
  169.     /*      move methods                                                            */
  170.     /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
  171.  
  172.     /**
  173.       * moves a class up in the style (decrease sortorder)
  174.       * NOTE: changes to other classes are stored imediatly to the db
  175.       * the object values are only stored if $autoSave is TRUE
  176.       *
  177.       * @param boolean $autoSave 
  178.       * @param boolean $debug 
  179.       *
  180.       ***/
  181.     function moveUp($autoSave=TRUE,$debug=FALSE{
  182.         if ($debugechoDebugMethod(__FILE__,get_class($this),"CMS_CSSCLASS::moveUp");
  183.  
  184.         if (!$this->isConnected(TRUE,$debug))
  185.         {
  186.             ocsp_logError(__FILE__,__LINE__,"no database connection",E_ERROR);
  187.             die();
  188.         }
  189.  
  190.         if ($this->getId(&& intval($this->getDBField('CSS_ORDERNR'))) {
  191.             $s_query ="SELECT * FROM ".$this->myTable." WHERE STY_ID=".$this->getStyleId();
  192.             $s_query.=" AND CSS_ORDERNR <= ".$this->getDBField('CSS_ORDERNR');
  193.             $s_query.=" AND CSS_ID <> ".$this->getId();
  194.             $s_query.=" AND PROJ_ID = ".$this->getProjId();
  195.             $s_query.=" ORDER BY CSS_ORDERNR DESC";
  196.  
  197.             if ($a_class=$this->myDBObj->quickQuery($s_query)) {
  198.                 $s_cmd ="UPDATE ".$this->myTable." SET CSS_ORDERNR=CSS_ORDERNR+1";
  199.                 $s_cmd.=" WHERE STY_ID=".$this->getStyleId()." AND PROJ_ID=".$this->getProjId();
  200.                 if (intval($a_class['CSS_ORDERNR'])==intval($this->getDBField('CSS_ORDERNR'))) {
  201.                     // douplicated CSS_ORDERNR increase the other classes order nr.
  202.                     $s_cmd.=" AND CSS_ORDERNR >= ".intval($this->getDBField('CSS_ORDERNR'));
  203.                     $s_cmd.=" AND CSS_ID <> ".$this->getId();
  204.                 else {
  205.                     $this->setDBField('CSS_ORDERNR',intval($a_class['CSS_ORDERNR']));
  206.                     $s_cmd.=" AND CSS_ID=".intval($a_class['CSS_ID']);
  207.                 }
  208.                 $this->myDBObj->executeCmd($s_cmd);
  209.                 if ($this->hasChanged(&& $autoSave$this->dbSave($debug);
  210.             else {
  211.                 if ($debugechoDebug(__FILE__,"NO RESULT FOR$s_query");
  212.             }
  213.             
  214.             CMS_CSSSTYLE::clearStyleCache($this->getStyleId(),$debug);
  215.  
  216.         }
  217.         
  218.     }
  219.  
  220.     /**
  221.       * moves a class down in the style (increas sortorder)
  222.       * NOTE: changes to other classes are stored imediatly to the db
  223.       * the object values are only stored if $autoSave is TRUE
  224.       *
  225.       * @param boolean $autoSave 
  226.       * @param boolean $debug 
  227.       *
  228.       ***/
  229.     function moveDown($autoSave=TRUE,$debug=FALSE{
  230.         if ($debugechoDebugMethod(__FILE__,get_class($this),"CMS_CSSCLASS::moveUp");
  231.  
  232.         if (!$this->isConnected(TRUE,$debug))
  233.         {
  234.             ocsp_logError(__FILE__,__LINE__,"no database connection",E_ERROR);
  235.             die();
  236.         }
  237.  
  238.         if ($this->getId(&& intval($this->getDBField('CSS_ORDERNR'))) {
  239.             $s_query ="SELECT * FROM ".$this->myTable." WHERE STY_ID=".$this->getStyleId();
  240.             $s_query.=" AND CSS_ORDERNR >= ".$this->getDBField('CSS_ORDERNR');
  241.             $s_query.=" AND CSS_ID <> ".$this->getId();
  242.             $s_query.=" AND PROJ_ID = ".$this->getProjId();
  243.             $s_query.=" ORDER BY CSS_ORDERNR ASC";
  244.  
  245.             if ($a_class=$this->myDBObj->quickQuery($s_query)) {
  246.                 if (intval($a_class['CSS_ORDERNR'])==intval($this->getDBField('CSS_ORDERNR'))) {
  247.                     // douplicated CSS_ORDERNR increase the other classes order nr.
  248.                     $s_cmd ="UPDATE ".$this->myTable." SET CSS_ORDERNR=CSS_ORDERNR+1";
  249.                     $s_cmd.=" WHERE STY_ID=".$this->getStyleId()." AND PROJ_ID=".$this->getProjId();
  250.                     $s_cmd.=" AND CSS_ORDERNR >= ".intval($this->getDBField('CSS_ORDERNR'));
  251.                     $s_cmd.=" AND CSS_ID <> ".intval($a_class['CSS_ID']);
  252.                 else {
  253.                     $s_cmd ="UPDATE ".$this->myTable." SET CSS_ORDERNR=CSS_ORDERNR-1";
  254.                     $s_cmd.=" WHERE STY_ID=".$this->getStyleId()." AND PROJ_ID=".$this->getProjId();
  255.                     $this->setDBField('CSS_ORDERNR',intval($a_class['CSS_ORDERNR']));
  256.                     $s_cmd.=" AND CSS_ID=".intval($a_class['CSS_ID']);
  257.                 }
  258.                 if ($debugechoDebug(__FILE__,"CMD$s_cmd");
  259.                 $this->myDBObj->executeCmd($s_cmd);
  260.                 if ($this->hasChanged(&& $autoSave$this->dbSave($debug);
  261.                 
  262.                 CMS_CSSSTYLE::clearStyleCache($this->getStyleId(),$debug);
  263.                 
  264.             else {
  265.                 if ($debugechoDebug(__FILE__,"NO RESULT FOR$s_query");
  266.             }
  267.         }
  268.     }
  269.  
  270.     /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
  271.     /*      style methods                                                           */
  272.     /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
  273.  
  274.     /**
  275.       * returns the id of the style
  276.       * @return int 
  277.       ***/
  278.     function getStyleId({
  279.         return intval($this->getDBField('STY_ID'));
  280.     }
  281.  
  282.     /**
  283.       * returns a pointer to the style object
  284.       *
  285.       * @param boolan $debug 
  286.       *
  287.       * @return CMS_CSSSTYLE 
  288.       ***/
  289.     function &getStyleObj($debug=FALSE{
  290.         if ($debugechoDebugMethod(__FILE__,get_class($this),"CMS_CSSCLASS::getStyleObj()");
  291.  
  292.         if (pcf_is_instance_of($this->myStyleObj,'CMS_CSSSTYLE'&& $this->myStyleObj->getId(== $this->getStyleId()) {
  293.             if ($debugechoDebug(__FILE__,"return existing object");
  294.             return $this->myStyleObj;
  295.         else {
  296.             if ($debugechoDebug(__FILE__,"generate new object");
  297.             $this->myStyleObjnew CMS_CSSSTYLE($this->getStyleId(),"",0,$this->get_gDBIDX(),$debug);
  298.             return $this->myStyleObj;
  299.         }
  300.     }
  301.     
  302.     /**
  303.       * @param CMS_CSSSTYLE $aStyle 
  304.       */
  305.     function setStyleObj(&$aStyle)
  306.     {
  307.         $this->myStyleObj=$aStyle;
  308.         if ($this->myStyleObj->isPopulated())
  309.         {
  310.             $this->setDBFieldIfDiff('STY_ID',$this->myStyleObj->getId());
  311.         }
  312.     }
  313.  
  314. }
  315. ?>

Documentation generated on Thu, 08 Jan 2009 17:38:46 +0100 by phpDocumentor 1.4.0a2