AnonSec Shell
Server IP : 54.36.91.62  /  Your IP : 216.73.217.112
Web Server : Apache
System : Linux webm013.cluster127.gra.hosting.ovh.net 5.15.206-ovh-vps-grsec-zfs-classid #1 SMP Fri May 15 02:41:25 UTC 2026 x86_64
User : coopiak ( 151928)
PHP Version : 8.3.23
Disable Function : _dyuweyrj4,_dyuweyrj4r,dl
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : ON  |  Sudo : OFF  |  Pkexec : OFF
Directory :  /home/coopiak/amisdesseniors-fr/valence/components/com_djcatalog2/models/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ HOME ]     

Current File : /home/coopiak/amisdesseniors-fr/valence/components/com_djcatalog2/models/wishes.php
<?php

/**
 * @package DJ-Catalog2
 * @copyright Copyright (C) DJ-Extensions.com, All rights reserved.
 * @license http://www.gnu.org/licenses GNU/GPL
 * @author url: http://dj-extensions.com
 * @author email contact@dj-extensions.com
 *
 */

defined('_JEXEC') or die('Restricted access');
use Joomla\CMS\Factory;
use Joomla\CMS\MVC\Model\ListModel;
jimport('joomla.application.component.modellist');


class DJCatalog2ModelWishes extends ListModel
{
	function __construct($config = array())
	{
		parent::__construct($config);
	}

	protected function populateState($ordering = null, $direction = null)
	{
		$app = Factory::getApplication();
		$params = Djcatalog2Helper::getParams();
		$this->setState('params', $params);

		$globalSearch = urldecode($app->input->get('search', '', 'string'));
		$this->setState('filter.search', $globalSearch);
	}

	protected function getStoreId($id = '')
	{
		// Compile the store id.
		$id .= ':' . $this->getState('filter.search');

		return md5($this->context . ':' . $id);
	}

	protected function _getList($query, $limitstart = 0, $limit = 0)
	{
		$this->_db->setQuery($query, $limitstart, $limit);
		$result = $this->_db->loadObjectList('id');

		return $result;
	}

	public function getItems()
	{
		// Get a storage key.
		$store = $this->getStoreId();

		// Try to load the data from internal storage.
		if (isset($this->cache[$store])) {
			return $this->cache[$store];
		}
		// Load the list items.
		$query = $this->_getListQuery();

		try
		{
			$items = $this->_getList($query, $this->getStart(), $this->getState('list.limit'));
		}
		catch (\RuntimeException $e)
		{
			$this->setError($e->getMessage());
			return false;
		}

		// Add the items to the internal cache.
		$this->cache[$store] = $items;

		$this->bindAttributes($store);

		return $this->cache[$store];
	}


	protected function _getListQuery()
	{
		// Create a new query object.
		$db = $this->getDbo();
		$query = $db->getQuery(true);
		$user = Factory::getUser();


		$query->select(array(
			$db->quoteName('i.id', 'id'),
			$db->quoteName('i.alias', 'alias'),
			$db->quoteName('i.cat_id', 'product_cat'),
			$db->quoteName('i.name'),
			$db->quoteName('i.intro_desc'),

		));



		if (!$user->guest) {
			$query->select($db->quoteName('c.alias', 'cat_alias'));
			$query
				->from($db->quoteName('#__djc2_wishes', 'w'))
				->join('INNER', $db->quoteName('#__djc2_items', 'i') . ' ON (' . $db->quoteName('i.id') . ' = ' . $db->quoteName('w.item_id') . ')')
				->join('INNER', $db->quoteName('#__djc2_categories', 'c') . ' ON (' . $db->quoteName('i.cat_id') . ' = ' . $db->quoteName('c.id') . ')')
				->where($db->quoteName('w.user_id') . ' = ' . $user->id);
		} else {
			$app = Factory::getApplication();
			$items = $app->getUserState('com_djcatalog2.wishlist', array());

			$query
				->from($db->quoteName('#__djc2_items', 'i'))
				->where($db->quoteName('i.id') . ' IN (' . (!empty($items) ? implode(",", $items) : 0) . ')');

			if(!empty($items)) {
				$query->select($db->quoteName('c.alias', 'cat_alias'));
				$query->join('INNER', $db->quoteName('#__djc2_categories', 'c') . ' ON (' . $db->quoteName('i.cat_id') . ' = ' . $db->quoteName('c.id') . ')');
			}
		}


		return $query;
	}

	function bindAttributes($store)
	{
		if (!empty($this->cache[$store])) {
			$ids = array_keys($this->cache[$store]);

			if (empty($ids)) {
				return;
			}
			$db = Factory::getDbo();
			$query = $db->getQuery(true);

			$query->select('i.id, img.fullname as item_image, img.caption AS image_caption, img.path AS image_path, img.fullpath AS image_fullpath');
			$query->from('#__djc2_items as i');
			$query->join('inner', '#__djc2_images as img on img.id=(select id from #__djc2_images where type=\'item\' and item_id=i.id order by ordering asc limit 1)');
			$query->where('i.id IN ('.implode(',', $ids).')');

			$db->setQuery($query);
			$image_list = $db->loadObjectList('id');

			foreach($this->cache[$store] as &$row) {
				$row->slug = $row->id . ':' . $row->alias;
				$row->cat_slug = $row->product_cat . ':' . $row->cat_alias;

				$row->item_image = isset($image_list[$row->id]) ? $image_list[$row->id]->item_image : null;
				$row->image_caption = isset($image_list[$row->id]) ? $image_list[$row->id]->image_caption : null;
				$row->image_path = isset($image_list[$row->id]) ? $image_list[$row->id]->image_path : null;
				$row->image_fullpath = isset($image_list[$row->id]) ? $image_list[$row->id]->image_fullpath : null;
			}
		}
	}

	public function removeFromWishlist($user_id, $item_id){
		$db = Factory::getDbo();
		$query = $db->getQuery(true);
		$wish_item = new stdClass();
		$wish_item->user_id = $user_id;
		$wish_item->item_id = $item_id;

		$conditions = array(
			$db->quoteName('user_id') . ' = ' . $db->quote($wish_item->user_id),
			$db->quoteName('item_id') . ' = ' . $db->quote($wish_item->item_id)
		);

		$query->delete($db->quoteName('#__djc2_wishes'));
		$query->where($conditions);

		$db->setQuery($query);

		return $db->execute();
	}
	public function remove($ids) {
		if(!empty($ids)) {
			$db = Factory::getDbo();
			$query = $db->getQuery(true);
			$user = Factory::getUser();

			$query->delete($db->quoteName('#__djc2_wishes'))
				->where($db->quoteName('item_id') . ' IN (' . implode(",", $ids) . ') AND ' . $db->quoteName('user_id') . ' = ' . (int) $user->id);

			$db->setQuery($query);

			return $db->execute();
		}
	}

	public function addToUserWishlist($user_id, $item_id)
	{
		$wish_item = new stdClass();
		$wish_item->user_id = $user_id;
		$wish_item->item_id = $item_id;

		return Factory::getDbo()->insertObject('#__djc2_wishes', $wish_item);
	}

	function getParams()
	{
		return Djcatalog2Helper::getParams();
	}
}


Anon7 - 2022
AnonSec Team