Source for file checkin.php

Documentation is available at checkin.php

  1. <?php
  2. /**
  3.  * @package     Joomla.Administrator
  4.  * @subpackage  com_checkin
  5.  *
  6.  * @copyright   Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
  7.  * @license     GNU General Public License version 2 or later; see LICENSE.txt
  8.  */
  9.  
  10. defined('_JEXEC'or die;
  11.  
  12. /**
  13.  * Checkin Model
  14.  *
  15.  * @package     Joomla.Administrator
  16.  * @subpackage  com_checkin
  17.  * @since       1.6
  18.  */
  19. {
  20.     protected $total;
  21.  
  22.     protected $tables;
  23.  
  24.     /**
  25.      * Method to auto-populate the model state.
  26.      *
  27.      * @Note. Calling getState in this method will result in recursion.
  28.      * @param   string  $ordering   An optional ordering field.
  29.      * @param   string  $direction  An optional direction (asc|desc).
  30.      *
  31.      * @return  void 
  32.      *
  33.      * @since   1.6
  34.      */
  35.     protected function populateState($ordering null$direction null)
  36.     {
  37.         $search $this->getUserStateFromRequest($this->context . '.filter.search''filter_search');
  38.         $this->setState('filter.search'$search);
  39.  
  40.         // List state information.
  41.         parent::populateState('table''asc');
  42.     }
  43.  
  44.     /**
  45.      * Checks in requested tables
  46.      *
  47.      * @param   array    $ids  An array of table names. Optional.
  48.      *
  49.      * @return  integer  Checked in item count
  50.      *
  51.      * @since   1.6
  52.      */
  53.     public function checkin($ids array())
  54.     {
  55.         $app JFactory::getApplication();
  56.         $db $this->_db;
  57.         $nullDate $db->getNullDate();
  58.  
  59.         if (!is_array($ids))
  60.         {
  61.             return;
  62.         }
  63.  
  64.         // this int will hold the checked item count
  65.         $results 0;
  66.  
  67.         foreach ($ids as $tn)
  68.         {
  69.             // make sure we get the right tables based on prefix
  70.             if (stripos($tn$app->getCfg('dbprefix')) !== 0)
  71.             {
  72.                 continue;
  73.             }
  74.  
  75.             $fields $db->getTableColumns($tn);
  76.  
  77.             if (!(isset($fields['checked_out']&& isset($fields['checked_out_time'])))
  78.             {
  79.                 continue;
  80.             }
  81.  
  82.             $query $db->getQuery(true)
  83.                 ->update($db->quoteName($tn))
  84.                 ->set('checked_out = 0')
  85.                 ->set('checked_out_time = ' $db->quote($nullDate))
  86.                 ->where('checked_out > 0');
  87.  
  88.             $db->setQuery($query);
  89.             if ($db->execute())
  90.             {
  91.                 $results $results $db->getAffectedRows();
  92.             }
  93.         }
  94.         return $results;
  95.     }
  96.  
  97.     /**
  98.      * Get total of tables
  99.      *
  100.      * @return  int    Total to check-in tables
  101.      *
  102.      * @since   1.6
  103.      */
  104.     public function getTotal()
  105.     {
  106.         if (!isset($this->total))
  107.         {
  108.             $this->getItems();
  109.         }
  110.         return $this->total;
  111.     }
  112.  
  113.     /**
  114.      * Get tables
  115.      *
  116.      * @return  array  Checked in table names as keys and checked in item count as values
  117.      *
  118.      * @since   1.6
  119.      */
  120.     public function getItems()
  121.     {
  122.         if (!isset($this->items))
  123.         {
  124.             $app JFactory::getApplication();
  125.             $db $this->_db;
  126.             $tables $db->getTableList();
  127.  
  128.             // this array will hold table name as key and checked in item count as value
  129.             $results array();
  130.  
  131.             foreach ($tables as $i => $tn)
  132.             {
  133.                 // make sure we get the right tables based on prefix
  134.                 if (stripos($tn$app->getCfg('dbprefix')) !== 0)
  135.                 {
  136.                     unset($tables[$i]);
  137.                     continue;
  138.                 }
  139.  
  140.                 if ($this->getState('filter.search'&& stripos($tn$this->getState('filter.search')) === false)
  141.                 {
  142.                     unset($tables[$i]);
  143.                     continue;
  144.                 }
  145.  
  146.                 $fields $db->getTableColumns($tn);
  147.  
  148.                 if (!(isset($fields['checked_out']&& isset($fields['checked_out_time'])))
  149.                 {
  150.                     unset($tables[$i]);
  151.                     continue;
  152.                 }
  153.             }
  154.             foreach ($tables as $tn)
  155.             {
  156.                 $query $db->getQuery(true)
  157.                     ->select('COUNT(*)')
  158.                     ->from($db->quoteName($tn))
  159.                     ->where('checked_out > 0');
  160.  
  161.                 $db->setQuery($query);
  162.                 if ($db->execute())
  163.                 {
  164.                     $results[$tn$db->loadResult();
  165.                 }
  166.                 else
  167.                 {
  168.                     continue;
  169.                 }
  170.             }
  171.             $this->total = count($results);
  172.             if ($this->getState('list.ordering'== 'table')
  173.             {
  174.                 if ($this->getState('list.direction'== 'asc')
  175.                 {
  176.                     ksort($results);
  177.                 }
  178.                 else
  179.                 {
  180.                     krsort($results);
  181.                 }
  182.             }
  183.             else
  184.             {
  185.                 if ($this->getState('list.direction'== 'asc')
  186.                 {
  187.                     asort($results);
  188.                 }
  189.                 else
  190.                 {
  191.                     arsort($results);
  192.                 }
  193.             }
  194.             $results array_slice($results$this->getState('list.start')$this->getState('list.limit'$this->getState('list.limit'null);
  195.             $this->items $results;
  196.         }
  197.         return $this->items;
  198.     }
  199. }

Documentation generated on Tue, 19 Nov 2013 14:55:42 +0100 by phpDocumentor 1.4.3