Source for file PRO_PART.phpclass

Documentation is available at PRO_PART.phpclass

  1. <?php
  2. /**
  3.   * openCSP class file PRO_PART.phpclass
  4.   *
  5.   * @project Open CSP-Management
  6.   * @package shop
  7.   *
  8.   * @author Peter Krebs <pitlinz@users.sourceforge.net>
  9.   * @license http://opensource.org/licenses/gpl-license.php GNU Public License
  10.   *
  11.   * @since pk-20.07.2008
  12.   * @version $Id: PRO_PART.phpclass,v 1.7 2008/10/16 02:21:48 pitlinz Exp $
  13.   */
  14.  
  15.     // ---------------------------------------------------------
  16.     // requirements
  17.     // ---------------------------------------------------------
  18.  
  19.     pcf_require_interface('INFA_PRO_PART',"products/");
  20.     
  21.     pcf_require_class('DBMS_TABLEOBJ',"db/");
  22.     pcf_require_class('PRO_PART_TYPE',dirname(__FILE__)."/");
  23.  
  24. /**
  25.   * openCSP class PRO_PART
  26.   *
  27.   * @project Open CSP-Management
  28.   * @package shop
  29.   *
  30.   * @author Peter Krebs <pitlinz@users.sourceforge.net>
  31.   * @license http://opensource.org/licenses/gpl-license.php GNU Public License
  32.   *
  33.   * @since pk-20.07.2008
  34.   * @version $Id: PRO_PART.phpclass,v 1.7 2008/10/16 02:21:48 pitlinz Exp $
  35.   */
  36. class PRO_PART extends DBMS_TABLEOBJ implements INFA_PRO_PART
  37. {
  38.     // ---------------------------------------------------------------------------
  39.     // constants
  40.     // ---------------------------------------------------------------------------
  41.     
  42.     /**
  43.      * @constant string CLASS_SRC_FILE
  44.      */
  45.     const CLASS_SRC_FILE = __FILE__;
  46.  
  47.     // ---------------------------------------------------------------------------
  48.     // class (static)
  49.     // ---------------------------------------------------------------------------
  50.     
  51.     /*** class vars ------------------------------------------------------ */
  52.     
  53.     private static $loadedParts array();
  54.     
  55.     /*** class methods --------------------------------------------------- */
  56.     
  57.     /**
  58.      * returns an instance of a part
  59.      *
  60.      * @param int $aId 
  61.      * @param boolean $debug 
  62.      * 
  63.      * @return PRO_PART 
  64.      */
  65.     public static function &getInstance($aId,$debug=False)
  66.     {
  67.         if ($debugechoDebugMethod(__FILE__,"static","PRO_PART::getInstance({$aId})");
  68.         
  69.         if (intval($aId))
  70.         {
  71.             if (!isset(self::$loadedParts[intval($aId)]))
  72.             {
  73.                 self::$loadedParts[intval($aId)self::factoryFromId($aId,$debug);
  74.             }
  75.             
  76.             return self::$loadedParts[intval($aId)];
  77.         else {
  78.             $obj_ret=Null;
  79.             return $obj_ret;
  80.         }
  81.     }
  82.     
  83.     /**
  84.      * adds an instance to self::$loadedParts
  85.      *
  86.      * @param PRO_PART $aPart 
  87.      * @param debug $debug 
  88.      * 
  89.      */
  90.     public static function setInstance(&$aPart,$debug=False)
  91.     {
  92.         if ($debugechoDebugMethod(__FILE__,"static","PRO_PART::setInstance()");
  93.         
  94.         if (method_exists($aPart,'getId'))
  95.         {
  96.             self::$loadedParts[intval($aPart->getId())$aPart;
  97.         }
  98.     }
  99.     
  100.     /**
  101.      * returns if a part has been added to the identity map
  102.      *
  103.      * @param int $aId 
  104.      * @return boolean 
  105.      */
  106.     public static function isInstanced($aId)
  107.     {
  108.         return isset(self::$loadedParts[intval($aId)]);
  109.     }
  110.     
  111.     // ---------------------------------------------------------------------------
  112.     // object vars
  113.     // ---------------------------------------------------------------------------
  114.     
  115.     /*** compostion --------------------------------------------------- */
  116.     
  117.     /**
  118.      * the product
  119.      *
  120.      * @var PRO_PRODUCT 
  121.      */
  122.     protected $myProduct = Null;
  123.     
  124.     /*** attributes  -------------------------------------------------- */
  125.     
  126.     /**
  127.       * @var string $myTable 
  128.       */
  129.     protected $myTable="T_PRO_PART";        
  130.         
  131.     // ---------------------------------------------------------------------------
  132.     // factory / construct
  133.     // ---------------------------------------------------------------------------
  134.     
  135.     /**
  136.      * factories a part
  137.      *
  138.      * @param int $aId 
  139.      * @param boolean $debug 
  140.      * 
  141.      * @return PRO_PART 
  142.      */
  143.     public static function &factoryFromId($aId,$debug=False)
  144.     {
  145.         if ($debugechoDebugMethod(__FILE__,"static","PRO_PART::factoryFromId");
  146.         
  147.         if ($arr_row OCSP_OBJ::defaultReadDBObj()->getRow('T_PRO_PART',array('PAR_ID'=>$aId)))
  148.         {
  149.             $obj_ret PRO_PART_TYPE::getInstance($arr_row['PAT_ID'])->factoryPartFromRow($arr_row);
  150.         else {
  151.             $obj_ret Null;
  152.         }
  153.         return $obj_ret;
  154.     }    
  155.     
  156.     // ---------------------------------------------------------------------------
  157.     // getter / setter
  158.     // ---------------------------------------------------------------------------    
  159.  
  160.     /**
  161.      * returns the product id
  162.      *
  163.      * @return int 
  164.      */
  165.     public function getId()
  166.     {
  167.         return $this->getDBField('PAR_ID');
  168.     }
  169.     
  170.     /**
  171.      * sets the product id
  172.      *
  173.      * @param int $aId 
  174.      */
  175.     public function setId($aId)
  176.     {
  177.         $this->setDBField('PAR_ID',intval($aId));
  178.     }
  179.     
  180.     /**
  181.      * returns the sort order number
  182.      *
  183.      * @return int 
  184.      */
  185.     public function getOrderNr()
  186.     {
  187.         return intval($this->getDBField('PAR_SORTORDER'));
  188.     }
  189.     
  190.     /**
  191.      * returns the available quantity of the part
  192.      *
  193.      * @return int 
  194.      */
  195.     public function getAvailable()
  196.     {
  197.         return intval($this->getDBField('PAR_AVAILQUANT'));
  198.     }
  199.     
  200.     /**
  201.      * sets the available quantity of the part
  202.      * 
  203.      * @param int $quant 
  204.      */
  205.     public function setAvailableQuant($quant)
  206.     {
  207.         $this->setDBFieldIfDiff('PAR_AVAILQUANT',intval($quant));    
  208.     }
  209.  
  210.     /**
  211.      * returns the price of the part
  212.      *
  213.      * @return float 
  214.      */
  215.     public function getPrice()
  216.     {
  217.         return floatval($this->getDBField('PAR_PRICE'));
  218.     }
  219.     
  220.     // -------------------------------------------------------
  221.     // db save methods (insert / replace (update) / delete)
  222.     // -------------------------------------------------------
  223.         
  224.     /**
  225.       * save the part to the database
  226.       *
  227.       * @param boolean   $debug  SHOW DEBUG INFO
  228.       *
  229.       * @returns mixed
  230.       *
  231.       */
  232.     public function dbSave($debug=False
  233.     {
  234.         if ($this->myProduct && method_exists($this->myProduct,'getId'))
  235.         {
  236.             $this->setDBField('PRO_ID',$this->myProduct->getId());
  237.                 
  238.         }
  239.         return parent::dbSave();
  240.     
  241.  
  242.     /**
  243.       * inserts a new row to the table
  244.       *
  245.       * @param boolean   $debug  show debug info
  246.       *
  247.       * @returns int   returns the autoIncFld ID if exists or 1 on success
  248.       *
  249.       */
  250.     function dbInsert($debug=False
  251.     {
  252.         if ($debugechoDebugMethod(__FILE__,get_class($this),"PRO_PART::dbInsert()");
  253.  
  254.         $this->setDBField('PAR_CREATION','#NOW');
  255.         if (!intval($this->getOrderNr()))
  256.         {
  257.             $str_query "SELECT MAX(PAR_SORTORDER) FROM T_PRO_PART";
  258.             $str_query.= " WHERE PRO_ID=" intval($this->getProductId());
  259.             $this->setDBField('PAR_SORTORDER',(intval(OCSP_OBJ::defaultReadDBObj()->getOne($str_query)) 1));
  260.         }
  261.         
  262.         return parent::dbInsert($debug);
  263.     }
  264.         
  265.     // -------------------------------------------------------
  266.     // product group methods
  267.     // -------------------------------------------------------
  268.     
  269.     /**
  270.      * returns the product group id
  271.      *
  272.      * @return int 
  273.      */
  274.     public function getProGroupId()
  275.     {
  276.         return intval($this->getDBField('PGP_ID'));
  277.     }
  278.     
  279.     /**
  280.      * retruns the product group
  281.      *
  282.      * @return PRO_GROUP 
  283.      */
  284.     public function getProGroup()
  285.     {
  286.            return PRO_GROUP::getInstance($this->getProGroupId());
  287.     }    
  288.     
  289.     // -------------------------------------------------------
  290.     // product methods
  291.     // -------------------------------------------------------
  292.     
  293.     
  294.     /**
  295.      * returns the product id
  296.      *
  297.      * @return int 
  298.      */
  299.     public function getProductId()
  300.     {
  301.         return $this->getDBField('PRO_ID');
  302.     }
  303.     
  304.     /**
  305.      * returns the product
  306.      *
  307.      * @return PRO_PRODUCT 
  308.      */
  309.     public function &getProduct()
  310.     {
  311.         if (!$this->myProduct
  312.         {
  313.             $this->myProduct = $this->getProGroup()->getProduct($this->getProductId());
  314.         }
  315.         return $this->myProduct;
  316.     }
  317.     
  318.     /**
  319.      * sets the product object
  320.      *
  321.      * @param PRO_PRODUCT $aProduct 
  322.      */
  323.     public function setProduct(&$aProduct)
  324.     {
  325.         $this->myProduct = $aProduct;
  326.         $this->setDBFieldIfDiff('PRO_ID',$aProduct->getId());
  327.         $this->setDBFieldIfDiff('PGP_ID',$aProduct->getProGroupId());
  328.     }
  329.     
  330.     // ---------------------------------------------------------------------------
  331.     // online state / rights
  332.     // ---------------------------------------------------------------------------
  333.     
  334.     /**
  335.      * returns if the part is online
  336.      *
  337.      * @param boolean $debug 
  338.      * 
  339.      * @return boolean 
  340.      */
  341.     public function isOnline($debug=False)
  342.     {
  343.         if ($debugechoDebugMethod(__FILE__,get_class($this),"PRO_PART::isOnline()");
  344.         
  345.         if (!intval($this->getDBField('PAR_SHOW')))
  346.         {
  347.             return False;
  348.         }        
  349.         
  350.         pcf_require_class('OCSP_DATE','common/');
  351.           $obj_date new OCSP_DATE();
  352.           $obj_date->setDbString($this->getDBField('PAR_SHOWFROM'));
  353.           if ($obj_date->isInFutur())
  354.           {
  355.               if ($debugechoDebugLine(__FILE__,__LINE__,"part will come in future");
  356.               return False;
  357.           }
  358.           $obj_date->setDbString($this->getDBField('PAR_SHOWTILL'));
  359.           if ($obj_date->isInPast())
  360.           {
  361.               if ($debugechoDebugLine(__FILE__,__LINE__,"part is out of date");
  362.               return False;
  363.           }        
  364.           
  365.           return True;
  366.     }
  367.     
  368.     /**
  369.      * returns if the part is in a campain
  370.      * 
  371.      * @return boolean 
  372.      */
  373.     public function isCampained()
  374.     {
  375.         return (intval($this->getDBField('PAR_CAMPAINED')) True False);
  376.     }
  377.     
  378. }
  379.  
  380. ?>

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