File manager - Edit - /home/capoccitel/www/components/com_tlpportfolio/models/portfolio.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 */ // No direct access. defined('_JEXEC') or die; jimport('joomla.application.component.modelitem'); jimport('joomla.event.dispatcher'); use Joomla\Utilities\ArrayHelper; /** * Tlpportfolio model. * * @since 1.6 */ class TlpportfolioModelPortfolio extends JModelItem { /** * Method to auto-populate the model state. * * Note. Calling getState in this method will result in recursion. * * @return void * * @since 1.6 * */ protected function populateState() { $app = JFactory::getApplication('com_tlpportfolio'); // Load state from the request userState on edit or from the passed variable on default if (JFactory::getApplication()->input->get('layout') == 'edit') { $id = JFactory::getApplication()->getUserState('com_tlpportfolio.edit.portfolio.id'); } else { $id = JFactory::getApplication()->input->get('id'); JFactory::getApplication()->setUserState('com_tlpportfolio.edit.portfolio.id', $id); } $this->setState('portfolio.id', $id); // Load the parameters. $params = $app->getParams(); $params_array = $params->toArray(); if (isset($params_array['item_id'])) { $this->setState('portfolio.id', $params_array['item_id']); } $this->setState('params', $params); } /** * Method to get an object. * * @param integer $id The id of the object to get. * * @return mixed Object on success, false on failure. */ public function &getData($id = null) { if ($this->_item === null) { $this->_item = false; if (empty($id)) { $id = $this->getState('portfolio.id'); } // Get a level row instance. $table = $this->getTable(); // Attempt to load the row. if ($table->load($id)) { // Check published state. if ($published = $this->getState('filter.published')) { if ($table->state != $published) { return $this->_item; } } // Convert the JTable to a clean JObject. $properties = $table->getProperties(1); $this->_item = ArrayHelper::toObject($properties, 'JObject'); } } if (isset($this->_item->tools_used) && $this->_item->tools_used != '') { if(is_object($this->_item->tools_used)){ $this->_item->tools_used = JArrayHelper::fromObject($this->_item->tools_used); } $values = (is_array($this->_item->tools_used)) ? $this->_item->tools_used : explode(',',$this->_item->tools_used); $textValue = array(); foreach ($values as $value){ $db = JFactory::getDbo(); $query = $db->getQuery(true); $query ->select('title') ->from('`#__tlpportfolio_tools`') ->where('id = ' . $db->quote($db->escape($value))); $db->setQuery($query); $results = $db->loadObject(); if ($results) { $textValue[] = $results->title; } } $this->_item->tools_used = !empty($textValue) ? implode(', ', $textValue) : $this->_item->tools_used; } if ( isset($this->_item->tags) ) { // Catch the item tags (string with ',' coma glue) $tags = explode(",",$this->_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 if (!empty($namedTags)) { $this->_item->tags = implode(', ',$namedTags); } else { $this->_item->tags = !empty($this->_item->my_tags) ? ($this->_item->my_tags) : (""); } } if (isset($this->_item->related_projects) && $this->_item->related_projects != '') { if(is_object($this->_item->related_projects)){ $this->_item->related_projects = JArrayHelper::fromObject($this->_item->related_projects); } $values = (is_array($this->_item->related_projects)) ? $this->_item->related_projects : explode(',',$this->_item->related_projects); $textValue = array(); foreach ($values as $value){ $db = JFactory::getDbo(); $query = $db->getQuery(true); $query ->select('id,title,portfolio_image') ->from('`#__tlpportfolio_portfolio`') ->where('id = ' . $db->quote($db->escape($value))); $db->setQuery($query); $results = $db->loadObject(); if ($results) { $textValue[] = $results; } } $this->_item->related_projects = $textValue; }if (isset($this->_item->created_by) ) { $this->_item->created_by_name = JFactory::getUser($this->_item->created_by)->name; } return $this->_item; } /** * Get an instance of JTable class * * @param string $type Name of the JTable class to get an instance of. * @param string $prefix Prefix for the table class name. Optional. * @param array $config Array of configuration values for the JTable object. Optional. * * @return JTable|bool JTable if success, false on failure. */ public function getTable($type = 'Portfolio', $prefix = 'TlpportfolioTable', $config = array()) { $this->addTablePath(JPATH_ADMINISTRATOR . '/components/com_tlpportfolio/tables'); return JTable::getInstance($type, $prefix, $config); } /** * Get the id of an item by alias * * @param string $alias Item alias * * @return mixed */ public function getItemIdByAlias($alias) { $table = $this->getTable(); $table->load(array('alias' => $alias)); return $table->id; } /** * Method to check in an item. * * @param integer $id The id of the row to check out. * * @return boolean True on success, false on failure. * * @since 1.6 */ public function checkin($id = null) { // Get the id. $id = (!empty($id)) ? $id : (int) $this->getState('portfolio.id'); if ($id) { // Initialise the table $table = $this->getTable(); // Attempt to check the row in. if (method_exists($table, 'checkin')) { if (!$table->checkin($id)) { return false; } } } return true; } /** * Method to check out an item for editing. * * @param integer $id The id of the row to check out. * * @return boolean True on success, false on failure. * * @since 1.6 */ public function checkout($id = null) { // Get the user id. $id = (!empty($id)) ? $id : (int) $this->getState('portfolio.id'); if ($id) { // Initialise the table $table = $this->getTable(); // Get the current user object. $user = JFactory::getUser(); // Attempt to check the row out. if (method_exists($table, 'checkout')) { if (!$table->checkout($user->get('id'), $id)) { return false; } } } return true; } /** * Get the name of a category by id * * @param int $id Category id * * @return Object|null Object if success, null in case of failure */ public function getCategoryName($id) { $db = JFactory::getDbo(); $query = $db->getQuery(true); $query ->select('title') ->from('#__categories') ->where('id = ' . $id); $db->setQuery($query); return $db->loadObject(); } /** * Publish the element * * @param int $id Item id * @param int $state Publish state * * @return boolean */ public function publish($id, $state) { $table = $this->getTable(); $table->load($id); $table->state = $state; return $table->store(); } /** * Method to delete an item * * @param int $id Element id * * @return bool */ public function delete($id) { $table = $this->getTable(); return $table->delete($id); } public function getAliasFieldNameByView($view) { switch ($view) { case 'portfolio': case 'portfolioform': return 'alias'; break; } } }
| ver. 1.6 |
Github
|
.
| PHP 7.4.33 | Generation time: 0 |
proxy
|
phpinfo
|
Settings