Support Joomla!

Joomla! 1.5 Documentation

Packages

Package: Joomla-Framework

Developer Network License

The Joomla! Developer Network content is © copyright 2006 by the individual contributors and can be used in accordance with the Creative Commons License, Attribution- NonCommercial- ShareAlike 2.5
Source code for file /joomla/database/table.php

Documentation is available at table.php

  1. <?php
  2. /**
  3.  * @version        $Id: table.php 6761 2007-03-03 07:09:23Z tcp $
  4.  * @package        Joomla.Framework
  5.  * @subpackage    Table
  6.  * @copyright    Copyright (C) 2005 - 2007 Open Source Matters. All rights reserved.
  7.  * @license        GNU/GPL, see LICENSE.php
  8.  *  Joomla! is free software. This version may have been modified pursuant
  9.  *  to the GNU General Public License, and as distributed it includes or
  10.  *  is derivative of works licensed under the GNU General Public License or
  11.  *  other free or open source software licenses.
  12.  *  See COPYRIGHT.php for copyright notices and details.
  13.  */
  14.  
  15. // Check to ensure this file is within the rest of the framework
  16. defined('JPATH_BASE'or die();
  17.  
  18. /**
  19.  * Abstract Table class
  20.  *
  21.  * Parent classes to all tables.
  22.  *
  23.  * @abstract
  24.  * @author        Andrew Eddie <[email protected]>
  25.  * @package     Joomla.Framework
  26.  * @subpackage    Table
  27.  * @since        1.0
  28.  * @tutorial    Joomla.Framework/jtable.cls
  29.  */
  30. class JTable extends JObject
  31. {
  32.     /**
  33.      * Name of the table in the db schema relating to child class
  34.      *
  35.      * @var     string 
  36.      * @access    protected
  37.      */
  38.     var $_tbl        = '';
  39.  
  40.     /**
  41.      * Name of the primary key field in the table
  42.      *
  43.      * @var        string 
  44.      * @access    protected
  45.      */
  46.     var $_tbl_key    = '';
  47.  
  48.     /**
  49.      * Error message
  50.      *
  51.      * @var        string 
  52.      * @access    protected
  53.      */
  54.     var $_error        = '';
  55.  
  56.     /**
  57.      * Error number
  58.      *
  59.      * @var        int 
  60.      * @access    protected
  61.      */
  62.     var $_errorNum = 0;
  63.  
  64.     /**
  65.      * Database connector
  66.      *
  67.      * @var        JDatabase 
  68.      * @access    protected
  69.      */
  70.     var $_db        = null;
  71.  
  72.     /**
  73.      * Object constructor to set table and key field
  74.      *
  75.      * Can be overloaded/supplemented by the child class
  76.      *
  77.      * @access protected
  78.      * @param string $table name of the table in the db schema relating to child class
  79.      * @param string $key name of the primary key field in the table
  80.      * @param object $db JDatabase object
  81.      */
  82.     function __construct$table$key&$db )
  83.     {
  84.         $this->_tbl        = $table;
  85.         $this->_tbl_key    = $key;
  86.         $this->_db        =$db;
  87.     }
  88.  
  89.     /**
  90.      * Returns a reference to the a Table object, always creating it
  91.      *
  92.      * @param type $type The table type to instantiate
  93.      * @param string A prefix for the table class name
  94.      * @return database A database object
  95.      * @since 1.5
  96.     */
  97.     function &getInstance$type$prefix='JTable' )
  98.     {
  99.         $false false;
  100.  
  101.         $tableClass $prefix.ucfirst($type);
  102.  
  103.         if (!class_exists$tableClass ))
  104.         {
  105.             jimport('joomla.filesystem.path');
  106.             if($path JPath::find(JTable::addIncludePath()strtolower($type).'.php'))
  107.             {
  108.                 require_once $path;
  109.  
  110.                 if (!class_exists$tableClass ))
  111.                 {
  112.                     JError::raiseWarning0'Table class ' $tableClass ' not found in file.' );
  113.                     return $false;
  114.                 }
  115.             }
  116.             else
  117.             {
  118.                 JError::raiseWarning0'Table ' $type ' not supported. File not found.' );
  119.                 return $false;
  120.             }
  121.         }
  122.  
  123.         $db =JFactory::getDBO();
  124.         $instance new $tableClass($db);
  125.         $instance->setDBO($db);
  126.  
  127.         return $instance;
  128.     }
  129.  
  130.     /**
  131.      * Get the internal database object
  132.      *
  133.      * @return object JDatabase based object
  134.      */
  135.     function &getDBO()
  136.     {
  137.         return $this->_db;
  138.     }
  139.  
  140.     /**
  141.      * Set the internal database object
  142.      *
  143.      * @param    object    $db    A JDatabase based object
  144.      * @return    void 
  145.      */
  146.     function setDBO(&$db)
  147.     {
  148.         $this->_db =$db;
  149.     }
  150.  
  151.     /**
  152.      * Gets the internal table name for the object
  153.      *
  154.      * @return string 
  155.      * @since 1.5
  156.      */
  157.     function getTableName()
  158.     {
  159.         return $this->_tbl;
  160.     }
  161.  
  162.     /**
  163.      * Gets the internal primary key name
  164.      *
  165.      * @return string 
  166.      * @since 1.5
  167.      */
  168.     function getKeyName()
  169.     {
  170.         return $this->_tbl_key;
  171.     }
  172.  
  173.  
  174.     /**
  175.      * Returns the error message
  176.      *
  177.      * @return string 
  178.      */
  179.     function getError()
  180.     {
  181.         return $this->_error;
  182.     }
  183.  
  184.     /**
  185.      * Returns the error number
  186.      *
  187.      * @return int The error number
  188.      */
  189.     function getErrorNum()
  190.     {
  191.         return $this->_errorNum;
  192.     }
  193.  
  194.     /**
  195.      * Resets the default properties
  196.      * @return    void 
  197.      */
  198.     function reset()
  199.     {
  200.         $k $this->_tbl_key;
  201.         foreach (get_class_varsget_class$this ) ) as $name => $value)
  202.         {
  203.             if (($name != $kand ($name != '_db'and ($name != '_tbl'and ($name != '_tbl_key')) {
  204.                 $this->$name    $value;
  205.             }
  206.         }
  207.     }
  208.  
  209.     /**
  210.      * Binds a named array/hash to this object
  211.      *
  212.      * Can be overloaded/supplemented by the child class
  213.      *
  214.      * @access    public
  215.      * @param    $from    mixed    An associative array or object
  216.      * @param    $ignore    mixed    An array or space separated list of fields not to bind
  217.      * @return    boolean 
  218.      */
  219.     function bind$from$ignore=array() )
  220.     {
  221.         $fromArray    is_array$from );
  222.         $fromObject    is_object$from );
  223.  
  224.         if (!$fromArray && !$fromObject)
  225.         {
  226.             $this->setErrorget_class$this ).'::bind failed. Invalid from argument' );
  227.             $this->setErrorNum(20);
  228.             return false;
  229.         }
  230.         if (!is_array$ignore )) {
  231.             $ignore explode' '$ignore );
  232.         }
  233.         foreach ($this->getPublicProperties(as $k)
  234.         {
  235.             // internal attributes of an object are ignored
  236.             if (!in_array$k$ignore ))
  237.             {
  238.                 if ($fromArray && isset$from[$k)) {
  239.                     $this->$k $from[$k];
  240.                 else if ($fromObject && isset$from->$k )) {
  241.                     $this->$k $from->$k;
  242.                 }
  243.             }
  244.         }
  245.         return true;
  246.     }
  247.  
  248.     /**
  249.      * Loads a row from the database and binds the fields to the object properties
  250.      *
  251.      * @access    public
  252.      * @param    mixed    Optional primary key.  If not specifed, the value of current key is used
  253.      * @return    boolean    True if successful
  254.      */
  255.     function load$oid=null )
  256.     {
  257.         $k $this->_tbl_key;
  258.  
  259.         if ($oid !== null{
  260.             $this->$k $oid;
  261.         }
  262.  
  263.         $oid $this->$k;
  264.  
  265.         if ($oid === null{
  266.             return false;
  267.         }
  268.         $this->reset();
  269.  
  270.         $db =$this->getDBO();
  271.  
  272.         $query 'SELECT *'
  273.         . ' FROM '.$this->_tbl
  274.         . ' WHERE '.$this->_tbl_key.' = '.$db->Quote($oid);
  275.         $db->setQuery$query );
  276.  
  277.         if ($result $db->loadAssoc)) {
  278.             return $this->bind($result);
  279.         }
  280.         else
  281.         {
  282.             $this->setError$db->getErrorMsg() );
  283.             return false;
  284.         }
  285.     }
  286.  
  287.     /**
  288.      * Generic check method
  289.      *
  290.      * Can be overloaded/supplemented by the child class
  291.      *
  292.      * @access public
  293.      * @return boolean True if the object is ok
  294.      */
  295.     function check()
  296.     {
  297.         return true;
  298.     }
  299.  
  300.     /**
  301.      * Inserts a new row if id is zero or updates an existing row in the database table
  302.      *
  303.      * Can be overloaded/supplemented by the child class
  304.      *
  305.      * @access public
  306.      * @param boolean If false, null object variables are not updated
  307.      * @return null|stringnull if successful otherwise returns and error message
  308.      */
  309.     function store$updateNulls=false )
  310.     {
  311.         $k $this->_tbl_key;
  312.  
  313.         if$this->$k)
  314.         {
  315.             $ret $this->_db->updateObject$this->_tbl$this$this->_tbl_key$updateNulls );
  316.         }
  317.         else
  318.         {
  319.             $ret $this->_db->insertObject$this->_tbl$this$this->_tbl_key );
  320.         }
  321.         if!$ret )
  322.         {
  323.             $this->setError(get_class$this ).'::store failed - '.$this->_db->getErrorMsg());
  324.             $this->setErrorNum($this->_db->getErrorNum());
  325.             return false;
  326.         }
  327.         else
  328.         {
  329.             return true;
  330.         }
  331.     }
  332.  
  333.     /**
  334.      * Description
  335.      *
  336.      * @access public
  337.      * @param $dirn 
  338.      * @param $where 
  339.      */
  340.     function move$dirn$where='' )
  341.     {
  342.         $k $this->_tbl_key;
  343.  
  344.         $sql "SELECT $this->_tbl_keyordering FROM $this->_tbl";
  345.  
  346.         if ($dirn 0)
  347.         {
  348.             $sql .= ' WHERE ordering < '.$this->ordering;
  349.             $sql .= ($where '    AND '.$where '');
  350.             $sql .= ' ORDER BY ordering DESC';
  351.         }
  352.         else if ($dirn 0)
  353.         {
  354.             $sql .= ' WHERE ordering > '.$this->ordering;
  355.             $sql .= ($where '    AND '$where '');
  356.             $sql .= ' ORDER BY ordering';
  357.         }
  358.         else
  359.         {
  360.             $sql .= 'WHERE ordering = '$this->ordering;
  361.             $sql .= ($where ' AND '.$where '');
  362.             $sql .= ' ORDER BY ordering';
  363.         }
  364.  
  365.         $this->_db->setQuery$sql0);
  366.  
  367.  
  368.         $row null;
  369.         $row $this->_db->loadObject();
  370.         if (isset($row))
  371.         {
  372.             $query 'UPDATE '$this->_tbl
  373.             . ' SET ordering = "'$row->ordering'"'
  374.             . ' WHERE '$this->_tbl_key .' = "'$this->$k '"'
  375.             ;
  376.             $this->_db->setQuery$query );
  377.  
  378.             if (!$this->_db->query())
  379.             {
  380.                 $err $this->_db->getErrorMsg();
  381.                 die$err );
  382.             }
  383.  
  384.             $query 'UPDATE '.$this->_tbl
  385.             . ' SET ordering = "'.$this->ordering.'"'
  386.             . ' WHERE '.$this->_tbl_key.' = \''.$row->$k.'\''
  387.             ;
  388.             $this->_db->setQuery$query );
  389.  
  390.             if (!$this->_db->query())
  391.             {
  392.                 $err $this->_db->getErrorMsg();
  393.                 die$err );
  394.             }
  395.  
  396.             $this->ordering $row->ordering;
  397.         }
  398.         else
  399.         {
  400.             $query 'UPDATE '$this->_tbl
  401.             . ' SET ordering = "'.$this->ordering.'"'
  402.             . ' WHERE '$this->_tbl_key .' = "'$this->$k .'"'
  403.             ;
  404.             $this->_db->setQuery$query );
  405.  
  406.             if (!$this->_db->query())
  407.             {
  408.                 $err $this->_db->getErrorMsg();
  409.                 die$err );
  410.             }
  411.         }
  412.     }
  413.  
  414.     /**
  415.      * Returns the ordering value to place a new item last in its group
  416.      *
  417.      * @access public
  418.      * @param string query WHERE clause for selecting MAX(ordering).
  419.      */
  420.     function getNextOrder $where='' )
  421.     {
  422.         if (!in_array'ordering'$this->getPublicProperties() ))
  423.         {
  424.             $this->setErrorget_class$this ).' does not support ordering' );
  425.             $this->setErrorNum(21);
  426.             return false;
  427.         }
  428.  
  429.         $query 'SELECT MAX(ordering)' .
  430.                 ' FROM ' $this->_tbl .
  431.                 ($where ' WHERE '.$where '');
  432.  
  433.         $this->_db->setQuery$query );
  434.         $maxord $this->_db->loadResult();
  435.  
  436.         if ($this->_db->getErrorNum())
  437.         {
  438.             $this->setError($this->_db->getErrorMsg());
  439.             $this->setErrorNum($this->_db->getErrorNum());
  440.             return false;
  441.         }
  442.         return $maxord 1;
  443.     }
  444.  
  445.     /**
  446.      * Compacts the ordering sequence of the selected records
  447.      *
  448.      * @access public
  449.      * @param string Additional where query to limit ordering to a particular subset of records
  450.      */
  451.     function reorder$where='' )
  452.     {
  453.         $k $this->_tbl_key;
  454.  
  455.         if (!in_array'ordering'$this->getPublicProperties() ))
  456.         {
  457.             $this->setErrorget_class$this ).' does not support ordering');
  458.             $this->setErrorNum(21);
  459.             return false;
  460.         }
  461.  
  462.         if ($this->_tbl == '#__content_frontpage')
  463.         {
  464.             $order2 ", content_id DESC";
  465.         }
  466.         else
  467.         {
  468.             $order2 "";
  469.         }
  470.  
  471.         $query 'SELECT '.$this->_tbl_key.', ordering'
  472.         . ' FROM '$this->_tbl
  473.         . $where ' WHERE '$where '' )
  474.         . ' ORDER BY ordering'.$order2
  475.         ;
  476.         $this->_db->setQuery$query );
  477.         if (!($orders $this->_db->loadObjectList()))
  478.         {
  479.             $this->setError($this->_db->getErrorMsg());
  480.             $this->setErrorNum($this->_db->getErrorNum());
  481.             return false;
  482.         }
  483.         // compact the ordering numbers
  484.         for ($i=0$n=count$orders )$i $n$i++)
  485.         {
  486.             if ($orders[$i]->ordering >= 0)
  487.             {
  488.                 if ($orders[$i]->ordering != $i+1)
  489.                 {
  490.                     $orders[$i]->ordering $i+1;
  491.                     $query 'UPDATE '.$this->_tbl
  492.                     . ' SET ordering = "'$orders[$i]->ordering .'"'
  493.                     . ' WHERE '$k .' = "'$orders[$i]->$k .'"'
  494.                     ;
  495.                     $this->_db->setQuery$query);
  496.                     $this->_db->query();
  497.                 }
  498.             }
  499.         }
  500.  
  501.     return true;
  502.  
  503.  
  504. //        $shift = 0;
  505. //        $n=count( $orders );
  506. //        for ($i=0; $i < $n; $i++)
  507. //        {
  508. //            //echo "i=$i id=".$orders[$i]->$k." order=".$orders[$i]->ordering;
  509. //            if ($orders[$i]->$k == $this->$k)
  510. //            {
  511. //                // place 'this' record in the desired location
  512. //                $orders[$i]->ordering = min( $this->ordering, $n );
  513. //                $shift = 1;
  514. //            }
  515. //            else if ($orders[$i]->ordering >= $this->ordering && $this->ordering > 0)
  516. //            {
  517. //                $orders[$i]->ordering++;
  518. //            }
  519. //        }
  520. //    //echo '<pre>';print_r($orders);echo '</pre>';
  521. //        // compact once more until I can find a better algorithm
  522. //        for ($i=0, $n=count( $orders ); $i < $n; $i++)
  523. //        {
  524. //            if ($orders[$i]->ordering >= 0)
  525. //            {
  526. //                $orders[$i]->ordering = $i+1;
  527. //                $query = "UPDATE $this->_tbl"
  528. //                . "\n SET ordering = '". $orders[$i]->ordering ."'"
  529. //                . "\n WHERE $k = '". $orders[$i]->$k ."'"
  530. //                ;
  531. //                $this->_db->setQuery( $query);
  532. //                $this->_db->query();
  533. //    //echo '<br />'.$this->_db->getQuery();
  534. //            }
  535. //        }
  536. //
  537. //        // if we didn't reorder the current record, make it last
  538. //        if ($shift == 0)
  539. //        {
  540. //            $order = $n+1;
  541. //            $query = "UPDATE $this->_tbl"
  542. //            . "\n SET ordering = '$order'"
  543. //            . "\n WHERE $k = '". $this->$k ."'"
  544. //            ;
  545. //            $this->_db->setQuery( $query );
  546. //            $this->_db->query();
  547. //    //echo '<br />'.$this->_db->getQuery();
  548. //        }
  549. //        return true;
  550.     }
  551.  
  552.     /**
  553.      * Generic check for whether dependancies exist for this object in the db schema
  554.      *
  555.      * can be overloaded/supplemented by the child class
  556.      *
  557.      * @access public
  558.      * @param string $msg Error message returned
  559.      * @param int Optional key index
  560.      * @param array Optional array to compiles standard joins: format [label=>'Label',name=>'table name',idfield=>'field',joinfield=>'field']
  561.      * @return true|false
  562.      */
  563.     function canDelete$oid=null$joins=null )
  564.     {
  565.         $k $this->_tbl_key;
  566.         if ($oid)
  567.         {
  568.             $this->$k intval$oid );
  569.         }
  570.         if (is_array$joins ))
  571.         {
  572.             $select "$k";
  573.             $join "";
  574.             foreach$joins as $table )
  575.             {
  576.                 $select .= ', COUNT(DISTINCT '.$table['idfield'].') AS '.$table['idfield'];
  577.                 $join .= ' LEFT JOIN '.$table['name'].' ON '.$table['joinfield'].' = '.$k;
  578.             }
  579.  
  580.             $query 'SELECT '$select
  581.             . ' FROM '$this->_tbl
  582.             . $join
  583.             . ' WHERE '$k .' = "'$this->$k .'"'
  584.             . ' GROUP BY '$k
  585.             ;
  586.             $this->_db->setQuery$query );
  587.  
  588.             if ($obj $this->_db->loadObject())
  589.             {
  590.                 $this->setError($this->_db->getErrorMsg());
  591.                 $this->setErrorNum($this->_db->getErrorNum());
  592.                 return false;
  593.             }
  594.             $msg array();
  595.             foreach$joins as $table )
  596.             {
  597.                 $k $table['idfield'];
  598.                 if ($obj->$k)
  599.                 {
  600.                     $msg[JText::_$table['label');
  601.                 }
  602.             }
  603.  
  604.             if (count$msg ))
  605.             {
  606.                 $this->setError("noDeleteRecord" ": " implode', '$msg ));
  607.                 $this->setErrorNum(22);
  608.                 return false;
  609.             }
  610.             else
  611.             {
  612.                 return true;
  613.             }
  614.         }
  615.  
  616.         return true;
  617.     }
  618.  
  619.     /**
  620.      * Default delete method
  621.      *
  622.      * can be overloaded/supplemented by the child class
  623.      *
  624.      * @access public
  625.      * @return true if successful otherwise returns and error message
  626.      */
  627.     function delete$oid=null )
  628.     {
  629.         //if (!$this->canDelete( $msg ))
  630.         //{
  631.         //    return $msg;
  632.         //}
  633.  
  634.         $k $this->_tbl_key;
  635.         if ($oid)
  636.         {
  637.             $this->$k intval$oid );
  638.         }
  639.  
  640.         $query 'DELETE FROM '.$this->_db->nameQuote$this->_tbl ).
  641.                 ' WHERE '.$this->_tbl_key.' = '$this->_db->Quote($this->$k);
  642.         $this->_db->setQuery$query );
  643.  
  644.         if ($this->_db->query())
  645.         {
  646.             return true;
  647.         }
  648.         else
  649.         {
  650.             $this->setError($this->_db->getErrorMsg());
  651.             $this->setErrorNum($this->_db->getErrorNum());
  652.             return false;
  653.         }
  654.     }
  655.  
  656.     /**
  657.      * Checks out a row
  658.      *
  659.      * @access public
  660.      * @param    integer    The id of the user
  661.      * @param     mixed    The primary key value for the row
  662.      * @return    boolean    True if successful, or if checkout is not supported
  663.      */
  664.     function checkout$who$oid null )
  665.     {
  666.         if (!in_array'checked_out'$this->getPublicProperties() )) {
  667.             return true;
  668.         }
  669.  
  670.         $k $this->_tbl_key;
  671.         if ($oid !== null{
  672.             $this->$k $oid;
  673.         }
  674.         $time date'Y-m-d H:i:s' );
  675.  
  676.         $query 'UPDATE '.$this->_db->nameQuote$this->_tbl .
  677.             ' SET checked_out = '.(int)$who.', checked_out_time = '.$this->_db->Quote($time.
  678.             ' WHERE '.$this->_tbl_key.' = '$this->_db->Quote($this->$k);
  679.         $this->_db->setQuery$query );
  680.  
  681.         $this->checked_out $who;
  682.         $this->checked_out_time $time;
  683.  
  684.         return $this->_db->query();
  685.     }
  686.  
  687.     /**
  688.      * Checks in a row
  689.      *
  690.      * @access    public
  691.      * @param    mixed    The primary key value for the row
  692.      * @return    boolean    True if successful, or if checkout is not supported
  693.      */
  694.     function checkin$oid=null )
  695.     {
  696.         if (!in_array'checked_out'$this->getPublicProperties() )) {
  697.             return true;
  698.         }
  699.         $k $this->_tbl_key;
  700.  
  701.         if ($oid !== null{
  702.             $this->$k $oid;
  703.         }
  704.  
  705.         if ($this->$k == NULL{
  706.             return false;
  707.         }
  708.  
  709.         $query 'UPDATE '.$this->_db->nameQuote$this->_tbl ).
  710.                 ' SET checked_out = 0, checked_out_time = '.$this->_db->Quote($this->_db->_nullDate.
  711.                 ' WHERE '.$this->_tbl_key.' = '$this->_db->Quote($this->$k);
  712.         $this->_db->setQuery$query );
  713.  
  714.         $this->checked_out 0;
  715.         $this->checked_out_time '';
  716.  
  717.         return $this->_db->query();
  718.     }
  719.  
  720.     /**
  721.      * Description
  722.      *
  723.      * @access public
  724.      * @param $oid 
  725.      * @param $log 
  726.      */
  727.     function hit$oid=null$log=false )
  728.     {
  729.         $k $this->_tbl_key;
  730.  
  731.         if ($oid !== null{
  732.             $this->$k intval$oid );
  733.         }
  734.  
  735.         $query 'UPDATE '$this->_tbl
  736.         . ' SET hits = ( hits + 1 )'
  737.         . ' WHERE '$this->_tbl_key .'='$this->_db->Quote($this->$k);
  738.         $this->_db->setQuery$query );
  739.         $this->_db->query();
  740.     }
  741.  
  742.     /**
  743.      * Check if an item is checked out
  744.      *
  745.      * This function can be used as a static function too, when you do so you need to also provide the
  746.      * a value for the $against parameter.
  747.      *
  748.      * @static
  749.      * @access public
  750.      * @param integer  $with      The userid to preform the match with, if an item is checked out
  751.      *                                by this user the function will return false
  752.      * @param integer  $against     The userid to perform the match against when the function is used as
  753.      *                              a static function.
  754.      * @return boolean 
  755.      */
  756.     function isCheckedOut$with 0$against null)
  757.     {
  758.         if(is_null($against)) {
  759.             $against $this->get'checked_out' );
  760.         }
  761.  
  762.         //item is not checked out, or being checked out by the same user
  763.         if (!$against || $against == $with{
  764.             return  false;
  765.         }
  766.  
  767.         return true;
  768.  
  769.         $session =JTable::getInstance('session');
  770.         return $session->exists($against);
  771.     }
  772.  
  773.     /**
  774.      * Generic save function
  775.      *
  776.      * @access public
  777.      * @param array Source array for binding to class vars
  778.      * @param string Filter for the order updating
  779.      * @returns TRUE if completely successful, FALSE if partially or not succesful.
  780.      */
  781.     function save$source$order_filter='' )
  782.     {
  783.         if (!$this->bind$source ))
  784.         {
  785.             return false;
  786.         }
  787.         if (!$this->check())
  788.         {
  789.             return false;
  790.         }
  791.         if (!$this->store())
  792.         {
  793.             return false;
  794.         }
  795.         if (!$this->checkin())
  796.         {
  797.             return false;
  798.         }
  799.         if ($order_filter)
  800.         {
  801.             $filter_value $this->$order_filter;
  802.             $this->reorder$order_filter $this->_db->nameQuote$order_filter ).' = '.$this->_db->Quote$filter_value '' );
  803.         }
  804.         $this->setError('');
  805.         $this->setErrorNum(0);
  806.         return true;
  807.     }
  808.  
  809.     /**
  810.      * Sets the internal error message
  811.      * @param string The error message
  812.      * @since 1.5
  813.      */
  814.     function setError$value )
  815.     {
  816.         $this->_error = $value;
  817.     }
  818.  
  819.     /**
  820.      * Sets the internal error number
  821.      *
  822.      * @param int Set the error number with this value
  823.      */
  824.     function setErrorNum$value )
  825.     {
  826.         $this->_errorNum = $value;
  827.     }
  828.  
  829.     /**
  830.      * Generic Publish/Unpublish function
  831.      *
  832.      * @access public
  833.      * @param array An array of id numbers
  834.      * @param integer 0 if unpublishing, 1 if publishing
  835.      * @param integer The id of the user performnig the operation
  836.      * @since 1.0.4
  837.      */
  838.     function publish$cid=null$publish=1$user_id=)
  839.     {
  840.         JArrayHelper::toInteger$cidarray() );
  841.         $user_id    = (int) $user_id;
  842.         $publish    = (int) $publish;
  843.         $k            $this->_tbl_key;
  844.  
  845.         if (count$cid 1)
  846.         {
  847.             $this->setError("No items selected.");
  848.             $this->setErrorNum(24);
  849.             return false;
  850.         }
  851.  
  852.         $cids $k '=' implode' OR ' $k '='$cid );
  853.  
  854.         $query 'UPDATE '$this->_tbl
  855.         . ' SET published = ' . (int) $publish
  856.         . ' WHERE ('.$cids.')'
  857.         ;
  858.  
  859.         $checkin in_array'checked_out'$this->getPublicProperties() );
  860.         if ($checkin)
  861.         {
  862.             $query .= ' AND (checked_out = 0 OR checked_out = '.$user_id.')';
  863.         }
  864.  
  865.         $this->_db->setQuery$query );
  866.         if (!$this->_db->query())
  867.         {
  868.             $this->setError($this->_db->getErrorMsg());
  869.             $this->setErrorNum($this->_db->getErrorNum());
  870.             return false;
  871.         }
  872.  
  873.         if (count$cid == && $checkin)
  874.         {
  875.             $this->checkin$cid[0);
  876.         }
  877.         $this->setError('');
  878.         $this->setErrorNum(0);
  879.         return true;
  880.     }
  881.  
  882.     /**
  883.      * Export item list to xml
  884.      *
  885.      * @access public
  886.      * @param boolean Map foreign keys to text values
  887.      */
  888.     function toXML$mapKeysToText=false )
  889.     {
  890.         $xml '<record table="' $this->_tbl . '"';
  891.  
  892.         if ($mapKeysToText)
  893.         {
  894.             $xml .= ' mapkeystotext="true"';
  895.         }
  896.         $xml .= '>';
  897.         foreach (get_object_vars$this as $k => $v)
  898.         {
  899.             if (is_array($vor is_object($vor $v === NULL)
  900.             {
  901.                 continue;
  902.             }
  903.             if ($k[0== '_')
  904.             // internal field
  905.                 continue;
  906.             }
  907.             $xml .= '<' $k '><![CDATA[' $v ']]></' $k '>';
  908.         }
  909.         $xml .= '</record>';
  910.  
  911.         return $xml;
  912.     }
  913.  
  914.     /**
  915.      * Add a directory where JTable should search for table types. You may
  916.      * either pass a string or an array of directories.
  917.      *
  918.      * @access    public
  919.      * @param    string    A path to search.
  920.      * @return    array    An array with directory elements
  921.      * @since 1.5
  922.      */
  923.     function addIncludePath$path=null )
  924.     {
  925.         static $paths;
  926.  
  927.         if (!isset($paths)) {
  928.             $paths arrayJPATH_LIBRARIES.DS.'joomla'.DS.'database'.DS.'table' );
  929.         }
  930.  
  931.         // just force path to array
  932.         settype($path'array');
  933.  
  934.         if (!empty$path && !in_array$path$paths ))
  935.         {
  936.             // loop through the path directories
  937.             foreach ($path as $dir)
  938.             {
  939.                 // no surrounding spaces allowed!
  940.                 $dir trim($dir);
  941.  
  942.                 // add to the top of the search dirs
  943.                 //array_unshift($paths, $dir);
  944.                 $paths[$dir;
  945.             }
  946.  
  947.  
  948.         }
  949.         return $paths;
  950.  
  951.     }
  952. }

Documentation generated on Mon, 05 Mar 2007 21:27:40 +0000 by phpDocumentor 1.3.1