/pdf/code/trunk/administrator/components/com_artofpdf/models/pdfs.php
PHP | 170 lines | 87 code | 21 blank | 62 comment | 13 complexity | 55bdd92fc46e1454e0828b78280d531d MD5 | raw file
- <?php
- /**
- * @version $Id: pdfs.php 288 2010-09-27 21:45:36Z eddieajau $
- * @package NewLifeInIT
- * @subpackage com_artofpdf
- * @copyright Copyright 2010 New Life in IT Pty Ltd. All rights reserved.
- * @license GNU General Public License version 2 or later.
- * @link http://www.theartofjoomla.com
- */
- // No direct access
- defined('_JEXEC') or die;
- juimport('joomla.application.component.modellist');
- juimport('joomla.database.databasequery');
- /**
- * Pdfs model.
- *
- * @package NewLifeInIT
- * @subpackage com_artofpdf
- * @since 1.0
- */
- class ArtofPdfModelPdfs extends JModelList
- {
- /**
- * Method to get an array of data items.
- *
- * @return mixed An array of data items on success, false on failure.
- * @since 1.6
- */
- public function getItems()
- {
- $items = parent::getItems();
- // Add path and PDF information.
- foreach ($items as $item)
- {
- // TODO configure PDF name.
- $path = JPATH_SITE.'/tmp/'.$item->title.'.pdf';
- if (file_exists($path)) {
- $item->file_path = $path;
- $item->file_url = JUri::root().'tmp/'.$item->title.'.pdf';
- $item->file_size = filesize($path);
- $item->file_name = basename($path);
- }
- else {
- $item->file_path = null;
- $item->file_url = null;
- $item->file_size = null;
- }
- }
- return $items;
- }
- /**
- * Build an SQL query to load the list data.
- *
- * @return JDatabaseQuery
- * @since 1.0
- */
- protected function getListQuery()
- {
- // Initialise variables.
- $db = $this->getDbo();
- $query = new JDatabaseQuery;
- // Select the required fields from the table.
- $query->select(
- $this->getState(
- 'list.select',
- 'a.id, a.title, a.published, a.build_time'
- )
- );
- $query->from('#__artof_pdfs AS a');
- // Join on the access name.
- $query->select('g.name AS access_name');
- $query->innerJoin('#__groups AS g ON g.id = a.access');
- // Filter by access level.
- $access = $this->getState('filter.access');
- if (is_numeric($access)) {
- $query->where('a.access = '.(int) $access);
- }
- // Filter by published state.
- $published = $this->getState('filter.state');
- if (is_numeric($published)) {
- $query->where('a.published = '.(int) $published);
- }
- else if (empty($published)) {
- $query->where('(a.published IN (0, 1))');
- }
- // Filter by search in title
- $search = $this->getState('filter.search');
- if (!empty($search)) {
- if (stripos($search, 'id:') === 0) {
- $query->where('a.id = '.(int) substr($search, 3));
- }
- else {
- $search = $db->Quote('%'.$db->getEscaped($search, true).'%');
- $query->where('(a.title LIKE '.$search.')');
- }
- }
- // Add the list ordering clause.
- $orderCol = $this->state->get('list.ordering');
- $orderDirn = $this->state->get('list.direction');
- if ($orderCol == 'a.ordering' || $orderCol == 'category_title') {
- $orderCol = 'category_title '.$orderDirn.', a.ordering';
- }
- $query->order($db->getEscaped($orderCol.' '.$orderDirn));
- //echo nl2br(str_replace('#__','jos_',$query));
- return $query;
- }
- /**
- * Method to get a store id based on model configuration state.
- *
- * This is necessary because the model is used by the component and
- * different modules that might need different sets of data or different
- * ordering requirements.
- *
- * @param string A prefix for the store id.
- *
- * @return string A store id.
- * @since 1.0
- */
- protected function getStoreId($id = '')
- {
- // Compile the store id.
- $id .= ':'.$this->getState('filter.search');
- $id .= ':'.$this->getState('filter.access');
- $id .= ':'.$this->getState('filter.state');
- return parent::getStoreId($id);
- }
- /**
- * Method to auto-populate the model state.
- *
- * Note. Calling getState in this method will result in recursion.
- *
- * @return void
- * @since 1.0
- */
- protected function populateState()
- {
- // Initialise variables.
- $app = JFactory::getApplication('administrator');
- // Load the filter state.
- $value = $app->getUserStateFromRequest($this->context.'.filter.search', 'filter_search');
- $this->setState('filter.search', $value);
- $value = $app->getUserStateFromRequest($this->context.'.filter.access', 'filter_access');
- $this->setState('filter.access', $value);
- $state = $app->getUserStateFromRequest($this->context.'.filter.state', 'filter_published');
- $this->setState('filter.state', $state);
- // Set list state ordering defaults.
- parent::populateState('a.title', 'asc');
- }
- }