<?php
/**
 * @package DJ-Events
 * @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
 * @developer Szymon Woronowski - szymon.woronowski@design-joomla.eu
 *
 */

defined('_JEXEC') or die('Restricted access');

class DJEventsTableCities extends JTable
{
	public function __construct(&$db)
	{
		parent::__construct('#__djev_cities', 'id', $db);
	}
	function bind($array, $ignore = '')
	{
		if(empty($array['alias'])) {
			$array['alias'] = $array['name'];
		}
		$array['alias'] = JFilterOutput::stringURLSafe($array['alias']);
		if(trim(str_replace('-','',$array['alias'])) == '') {
			$array['alias'] = JFactory::getDate()->format("Y-m-d-H-i-s");
		}
		
		return parent::bind($array, $ignore);
	}

    public function store($updateNulls = false)
    {
        $date	= JFactory::getDate();
        $user	= JFactory::getUser();
        $app = JFactory::getApplication();
        $db = JFactory::getDbo();

        if (!$this->id) {
            if (!intval($this->created)) {
                $this->created = $date->toSql();
            }
            if (empty($this->created_by)) {
                $this->created_by = $user->get('id');
            }
        }


        return parent::store($updateNulls);
    }
}