File manager - Edit - /home/capoccitel/www/components/com_tlpportfolio/models/portfolios.php
Back
<?php /** * @version 2.0 * @package com_tlpportfolio * @author TechLabPro <info@techlabpro.com> * @copyright Copyright (C) 2015. All rights reserved. * @license GNU General Public License version 2 or later; see LICENSE.txt */ defined('_JEXEC') or die; jimport('joomla.application.component.modellist'); /** * Methods supporting a list of Tlpportfolio records. * * @since 1.6 */ class TlpportfolioModelPortfolios extends JModelList { /** * Constructor. * * @param array $config An optional associative array of configuration settings. * * @see JController * @since 1.6 */ public function __construct($config = array()) { if (empty($config['filter_fields'])) { $config['filter_fields'] = array( 'id', 'a.id', 'title', 'a.title', 'alias', 'a.alias', 'category', 'a.category', 'short_description', 'a.short_description', 'tools_used', 'a.tools_used', 'project_url', 'a.project_url', 'client_name', 'a.client_name', 'description', 'a.description', 'portfolio_image', 'a.portfolio_image', 'completed_date', 'a.completed_date', 'tags', 'a.tags', 'related_projects', 'a.related_projects', 'language', 'a.language', 'access', 'a.access', 'ordering', 'a.ordering', 'state', 'a.state', 'created_by', 'a.created_by', ); } parent::__construct($config); } /** * Method to auto-populate the model state. * * Note. Calling getState in this method will result in recursion. * * @param string $ordering Elements order * @param string $direction Order direction * * @return void * * @throws Exception * * @since 1.6 */ protected function populateState($ordering = null, $direction = null) { // Initialise variables. $app = JFactory::getApplication(); // List state information $limit = $app->getUserStateFromRequest('global.list.limit', 'limit', $app->get('list_limit')); $this->setState('list.limit', $limit); $limitstart = $app->getUserStateFromRequest('limitstart', 'limitstart', 0); $this->setState('list.start', $limitstart); if ($list = $app->getUserStateFromRequest($this->context . '.list', 'list', array(), 'array')) { foreach ($list as $name => $value) { // Extra validations switch ($name) { case 'fullordering': $orderingParts = explode(' ', $value); if (count($orderingParts) >= 2) { // Latest part will be considered the direction $fullDirection = end($orderingParts); if (in_array(strtoupper($fullDirection), array('ASC', 'DESC', ''))) { $this->setState('list.direction', $fullDirection); } unset($orderingParts[count($orderingParts) - 1]); // The rest will be the ordering $fullOrdering = implode(' ', $orderingParts); if (in_array($fullOrdering, $this->filter_fields)) { $this->setState('list.ordering', $fullOrdering); } } else { $this->setState('list.ordering', $ordering); $this->setState('list.direction', $direction); } break; case 'ordering': if (!in_array($value, $this->filter_fields)) { $value = $ordering; } break; case 'direction': if (!in_array(strtoupper($value), array('ASC', 'DESC', ''))) { $value = $direction; } break; case 'limit': $limit = $value; break; // Just to keep the default case default: $value = $value; break; } $this->setState('list.' . $name, $value); } } // Receive & set filters if ($filters = $app->getUserStateFromRequest($this->context . '.filter', 'filter', array(), 'array')) { foreach ($filters as $name => $value) { $this->setState('filter.' . $name, $value); } } $ordering = $app->input->get('filter_order'); if (!empty($ordering)) { $list = $app->getUserState($this->context . '.list'); $list['ordering'] = $app->input->get('filter_order'); $app->setUserState($this->context . '.list', $list); } $orderingDirection = $app->input->get('filter_order_Dir'); if (!empty($orderingDirection)) { $list = $app->getUserState($this->context . '.list'); $list['direction'] = $app->input->get('filter_order_Dir'); $app->setUserState($this->context . '.list', $list); } $list = $app->getUserState($this->context . '.list'); if (empty($list['ordering'])) { $list['ordering'] = 'ordering'; } if (empty($list['direction'])) { $list['direction'] = 'asc'; } if (isset($list['ordering'])) { $this->setState('list.ordering', $list['ordering']); } if (isset($list['direction'])) { $this->setState('list.direction', $list['direction']); } } /** * Build an SQL query to load the list data. * * @return JDatabaseQuery * * @since 1.6 */ protected function getListQuery() { // Create a new query object. $db = $this->getDbo(); $query = $db->getQuery(true); $app = JFactory::getApplication(); $menu = $app->getMenu(); $active = $menu->getActive(); $itemId = $active->id; $menuparams = $menu->getParams($itemId); $category1 = $menuparams->get("category"); @$category = implode(",", $category1); JFactory::getLanguage()->getTag(); $multilang=JLanguageMultilang::isEnabled(); // Select the required fields from the table. $query ->select( $this->getState( 'list.select', 'DISTINCT a.*' ) ); $query->from('`#__tlpportfolio_portfolio` AS a'); // Join over the users for the checked out user. $query->select('uc.name AS editor'); $query->join('LEFT', '#__users AS uc ON uc.id=a.checked_out'); // Join over the category 'category' // $query->select('category.title AS category_title'); // $query->join('LEFT', '#__categories AS category ON category.id = a.category'); // Join over the foreign key 'tools_used' $query->select('#__tlpportfolio_tools_1712705.title AS tools_title_1712705'); $query->join('LEFT', '#__tlpportfolio_tools AS #__tlpportfolio_tools_1712705 ON #__tlpportfolio_tools_1712705.id = a.tools_used'); // Join over the foreign key 'related_projects' $query->select('#__tlpportfolio_portfolio_2156804.title AS portfolios_title_2156804'); $query->join('LEFT', '#__tlpportfolio_portfolio AS #__tlpportfolio_portfolio_2156804 ON #__tlpportfolio_portfolio_2156804.id = a.related_projects'); // Join over the created by field 'created_by' $query->join('LEFT', '#__users AS created_by ON created_by.id = a.created_by'); if (!JFactory::getUser()->authorise('core.edit.state', 'com_tlpportfolio')) { $query->where('a.state = 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->escape($search, true) . '%'); $query->where('( a.title LIKE '.$search.' OR a.client_name LIKE '.$search.' )'); } } //Filtering category $filter_category = $this->state->get("filter.category"); $q = array(); if (count($category1)>0) { foreach ($category1 as $cat) { $q[] = "(FIND_IN_SET('{$cat}',a.category))"; } } if(!empty($q)){ $string = implode(" OR ", $q); $query->where("( {$string} )"); } //Filtering tools_used $filter_tools_used = $this->state->get("filter.tools_used"); if ($filter_tools_used) { $query->where("FIND_IN_SET('" . $db->escape($filter_tools_used) . "',a.tools_used)"); } // Filter by language if ($multilang) { $query->where('a.language in (' . $db->quote(JFactory::getLanguage()->getTag()) . ',' . $db->quote('*') . ')'); } //Filtering language // $filter_language = $this->state->get("filter.language"); // if ($filter_language) { // $query->where("a.language = '".$db->escape($filter_language)."'"); // } // Add the list ordering clause. $orderCol = $this->state->get('list.ordering'); $orderDirn = $this->state->get('list.direction'); if ($orderCol && $orderDirn) { $query->order($db->escape($orderCol . ' ' . $orderDirn)); } //echo $query; return $query; } /** * Method to get an array of data items * * @return mixed An array of data on success, false on failure. */ public function getItems() { $items = parent::getItems(); foreach($items as $item){ // if ( isset($item->category) ) { // // Get the title of that particular template // $title = TlpportfolioFrontendHelper::getCategoryNameByCategoryId($item->category); // // Finally replace the data object with proper information // $item->category = !empty($title) ? $title : $item->category; // } if (isset($item->category) && $item->category != '') { $db = JFactory::getDbo(); $query = $db->getQuery(true); $query ->select($db->quoteName('title')) ->from($db->quoteName('#__categories')) ->where('FIND_IN_SET(' . $db->quoteName('id') . ', ' . $db->quote($item->category) . ')'); $db->setQuery($query); $result = $db->loadColumn(); $item->category_title = !empty($result) ? implode(', ', $result) : ''; } if (isset($item->tools_used) && $item->tools_used != '') { if(is_object($item->tools_used)){ $item->tools_used = JArrayHelper::fromObject($item->tools_used); } $values = (is_array($item->tools_used)) ? $item->tools_used : explode(',',$item->tools_used); $textValue = array(); foreach ($values as $value){ $db = JFactory::getDbo(); $query = $db->getQuery(true); $query ->select($db->quoteName('title')) ->from('`#__tlpportfolio_tools`') ->where($db->quoteName('id') . ' = ' . $db->quote($db->escape($value))); $db->setQuery($query); $results = $db->loadObject(); if ($results) { $textValue[] = $results->title; } } $item->tools_used = !empty($textValue) ? implode(', ', $textValue) : $item->tools_used; } if ( isset($item->tags) ) { // Catch the item tags (string with ',' coma glue) $tags = explode(",",$item->tags); $db = JFactory::getDbo(); $namedTags = array(); // Cleaning and initalization of named tags array // Get the tag names of each tag id foreach ($tags as $tag) { $query = $db->getQuery(true); $query->select("title"); $query->from('`#__tags`'); $query->where( "id=" . intval($tag) ); $db->setQuery($query); $row = $db->loadObjectList(); // Read the row and get the tag name (title) if (!is_null($row)) { foreach ($row as $value) { if ( $value && isset($value->title) ) { $namedTags[] = trim($value->title); } } } } // Finally replace the data object with proper information $item->tags = !empty($namedTags) ? implode(', ',$namedTags) : $item->tags; } if (isset($item->related_projects) && $item->related_projects != '') { if(is_object($item->related_projects)){ $item->related_projects = JArrayHelper::fromObject($item->related_projects); } $values = (is_array($item->related_projects)) ? $item->related_projects : explode(',',$item->related_projects); $textValue = array(); foreach ($values as $value){ $db = JFactory::getDbo(); $query = $db->getQuery(true); $query ->select($db->quoteName('title')) ->from('`#__tlpportfolio_portfolio`') ->where($db->quoteName('id') . ' = ' . $db->quote($db->escape($value))); $db->setQuery($query); $results = $db->loadObject(); if ($results) { $textValue[] = $results->title; } } $item->related_projects = !empty($textValue) ? implode(', ', $textValue) : $item->related_projects; } } return $items; } /** * Overrides the default function to check Date fields format, identified by * "_dateformat" suffix, and erases the field if it's not correct. * * @return void */ protected function loadFormData() { $app = JFactory::getApplication(); $filters = $app->getUserState($this->context . '.filter', array()); $error_dateformat = false; foreach ($filters as $key => $value) { if (strpos($key, '_dateformat') && !empty($value) && !$this->isValidDate($value)) { $filters[$key] = ''; $error_dateformat = true; } } if ($error_dateformat) { $app->enqueueMessage(JText::_("COM_TLPPORTFOLIO_SEARCH_FILTER_DATE_FORMAT"), "warning"); $app->setUserState($this->context . '.filter', $filters); } return parent::loadFormData(); } /** * Checks if a given date is valid and in a specified format (YYYY-MM-DD) * * @param string $date Date to be checked * * @return bool */ private function isValidDate($date) { return preg_match("/^(19|20)\d\d[-](0[1-9]|1[012])[-](0[1-9]|[12][0-9]|3[01])$/", $date) && date_create($date); } }
| ver. 1.6 |
Github
|
.
| PHP 7.4.33 | Generation time: 0 |
proxy
|
phpinfo
|
Settings