Current File : /home/pacjaorg/public_html/km/administrator/components/com_djclassifieds/models/region.php |
<?php
/**
* @package DJ-Classifieds
* @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;
class DJClassifiedsModelRegion extends DJClassifiedsAdminModel
{
protected $form_name = 'region';
public function __construct($config = array())
{
$config['event_after_save'] = 'onDJClassifiedsModelAdminAfterSave';
$config['event_after_delete'] = 'onDJClassifiedsModelAdminAfterDelete';
parent::__construct($config);
}
public function getTable($type = 'Regions', $prefix = 'DJClassifiedsTable', $config = array())
{
return JTable::getInstance($type, $prefix, $config);
}
public function getForm($data = array(), $loadData = true)
{
// Get the form.
$form = $this->loadForm('com_djclassifieds.'.$this->form_name, $this->form_name, array('control' => 'jform', 'load_data' => $loadData));
if (empty($form)) {
return false;
}
return $form;
}
protected function loadFormData()
{
$app = JFactory::getApplication();
$data = JFactory::getApplication()->getUserState('com_djclassifieds.edit.'.$this->form_name.'.data', array());
if (empty($data)) {
$data = $this->getItem();
// if(!$data->alias){
// $data->set('alias', DJClassifiedsSEO::getAliasName($data->name));
// }
if($data->country){
$data->set('type', 'country');
}elseif($data->city){
$data->set('type', 'city');
}else{
$data->set('type', 'other');
}
if(!$data->id){
$data->parent_id = $app->getUserState('djcf.last_reg_parent_id', 0);
}
}
return $data;
}
protected function prepareTable($table)
{
$app = JFactory::getApplication();
$db = JFactory::getDBO();
$par = JComponentHelper::getParams('com_djclassifieds');
$jform = $app->input->getArray()['jform'];
$app->triggerEvent('onBeforeAdminDJClassifiedsSaveRegion', array(&$table, &$par));
if($table->alias){
$table->alias = DJClassifiedsSEO::getAliasName($table->alias);
}else{
$table->alias = DJClassifiedsSEO::getAliasName($table->name);
}
if($jform['type'] == 'country'){
$table->country = 1;
$table->city = 0;
}elseif($jform['type'] == 'city'){
$table->country = 0;
$table->city = 1;
}else{
$table->country = 0;
$table->city = 0;
}
if(!$table->ordering && !$jform['id']){ // keep the ordering 0 for regions added before the ordering column
$query = "SELECT ordering FROM #__djcf_regions ORDER BY ordering DESC LIMIT 1";
$db->setQuery($query);
$ordering = $db->loadResult();
$table->ordering = $ordering + 1;
}
}
protected function getReorderConditions($table)
{
$condition = array();
$condition[] = 'parent_id = '.(int) $table->parent_id;
return $condition;
}
}