Your IP : 216.73.216.240


Current Path : /home/juvelize/www/administrator/components/com_ffgate/models/
Upload File :
Current File : /home/juvelize/www/administrator/components/com_ffgate/models/settings.php

<?php
/**
 * @package    FFGate
 * @author     Yves Hoppe <yves@compojoom.com>
 * @date       26.11.13
 *
 * @copyright  Copyright (C) 2008 - 2013 compojoom.com - Yves Hoppe. All rights reserved.
 * @license    GNU General Public License version 2 or later; see LICENSE
 * @since      1.0.0
 */
defined('_JEXEC') or die();

jimport('joomla.application.component.model');

/**
 * Class FFGateModelSettings
 *
 * @since  1.0.0
 */
class FFGateModelSettings extends JModelLegacy
{
	var $_data = null;

	var $_id = null;

	/**
	 * The constructor
	 */
	public function __construct()
	{
		parent::__construct();
	}

	/**
	 * Gets the data
	 *
	 * @return  array|null
	 */
	public function getData()
	{
		if (empty($this->_data))
		{
			$query = $this->_buildQuery();
			$this->_data = $this->_getList($query);
		}

		return $this->_data;
	}

	/**
	 * Checks if an item is checked out
	 *
	 * @param   int  $uid  - The uid
	 *
	 * @return  bool
	 */
	public function isCheckedOut($uid = 0)
	{
		if ($this->_loadData())
		{
			if ($uid)
			{
				return ($this->_data->checked_out && $this->_data->checked_out != $uid);
			}
			else
			{
				return $this->_data->checked_out;
			}
		}
	}

	/**
	 * Checks the table in
	 *
	 * @return  bool
	 */
	public function checkin()
	{
		if ($this->_id)
		{
			$hotspots = & $this->getTable();

			if (!$hotspots->checkin($this->_id))
			{
				$this->setError($this->_db->getErrorMsg());

				return false;
			}
		}

		return false;
	}

	/**
	 * Checkout
	 *
	 * @param   int  $uid  - The uid
	 *
	 * @return bool
	 */
	public function checkout($uid = null)
	{
		if ($this->_id)
		{
			if (is_null($uid))
			{
				$user =& JFactory::getUser();
				$uid = $user->get('id');
			}

			$hotspots = & $this->getTable();

			if (!$hotspots->checkout($uid, $this->_id))
			{
				$this->setError($this->_db->getErrorMsg());

				return false;
			}

			return true;
		}

		return false;
	}

	/**
	 * Saves the settings
	 *
	 * @param   array  $dataArray  - The data array
	 *
	 * @return  bool
	 */
	public function store($dataArray)
	{
		$row =& $this->getTable('Settings', 'Table');

		if (!empty($dataArray))
		{
			foreach ($dataArray as $key => $value)
			{
				$data['id'] = $key;
				$data['value'] = $value;

				if (!$row->bind($data))
				{
					$this->setError($this->_db->getErrorMsg());

					return false;
				}

				if (!$row->check())
				{
					$this->setError($this->_db->getErrorMsg());

					return false;
				}

				if (!$row->store())
				{
					$this->setError($this->_db->getErrorMsg());

					return false;
				}
			}
		}

		return true;
	}

	/**
	 * Builds the query
	 *
	 * @return  string
	 */
	public function _buildQuery()
	{
		$query = ' SELECT st.*'
			. ' FROM #__ffgate_settings AS st'
			. ' ORDER BY st.id';

		return $query;
	}
}