public function wizard($instance = array()) { /** load assets **/ $this->load_assets(); /** check access **/ if (!wpl_users::check_access('propertywizard')) { /** import message tpl **/ $this->message = __("You don't have access to this part!", WPL_TEXTDOMAIN); return parent::render($this->tpl_path, 'message'); } $this->kind = trim(wpl_request::getVar('kind')) != '' ? wpl_request::getVar('kind') : 0; $this->property_id = trim(wpl_request::getVar('pid')) != '' ? wpl_request::getVar('pid') : 0; $this->mode = $this->property_id ? 'edit' : 'add'; if ($this->mode == 'add') { /** checking access **/ if (!wpl_users::check_access($this->mode)) { $this->message = __("Limit reached. You can not add more property!", WPL_TEXTDOMAIN); return parent::render($this->tpl_path, 'message'); } /** generate new property **/ $this->property_id = wpl_property::create_property_default('', $this->kind); } $this->values = wpl_property::get_property_raw_data($this->property_id); $this->finalized = isset($this->values['finalized']) ? $this->values['finalized'] : 0; $this->kind = isset($this->values['kind']) ? $this->values['kind'] : 0; $this->field_categories = wpl_flex::get_categories(0, $this->kind); $this->kind_label = wpl_flex::get_kind_label($this->kind); if ($this->mode == 'edit') { if (!$this->values) { $this->message = __("Property does not exist!", WPL_TEXTDOMAIN); return parent::render($this->tpl_path, 'message'); } /** checking access **/ if (!wpl_users::check_access($this->mode, $this->values['user_id'])) { $this->message = __("You can not edit this property.", WPL_TEXTDOMAIN); return parent::render($this->tpl_path, 'message'); } } /** import tpl **/ $this->tpl = wpl_flex::get_kind_tpl($this->tpl_path, 'wizard', $this->kind); parent::render($this->tpl_path, $this->tpl); }
/** * This function is for importing/updating properties into the WPL. It uses WPL standard format for importing * This function must call in everywhere that we need to import properties like MLS and IMPORTER Addons. * @author Howard <*****@*****.**> * @static * @param array $properties_to_import * @param string $wpl_unique_field * @param int $user_id * @param string $source * @param boolean $finalize * @param array $log_params * @return array property IDs */ public static function import($properties_to_import, $wpl_unique_field = 'mls_id', $user_id = '', $source = 'mls', $finalize = true, $log_params = array()) { if (!$user_id) { $user_id = wpl_users::get_cur_user_id(); } $pids = array(); $added = array(); // Used for logging results $updated = array(); // Used for logging results /** model **/ $model = new wpl_property(); $possible_columns = wpl_db::columns('wpl_properties'); foreach ($properties_to_import as $property_to_import) { $q = ''; $unique_value = ''; foreach ($property_to_import as $key => $row) { $wpl_field = $row['wpl_table_column'] ? $row['wpl_table_column'] : $key; $wpl_value = $row['wpl_value'] ? $row['wpl_value'] : ''; /** validation table column **/ if (!in_array($wpl_field, $possible_columns)) { continue; } /** set unique value **/ if ($wpl_field == $wpl_unique_field) { $unique_value = $wpl_value; } /** set user id value **/ if ($wpl_field == 'user_id') { $user_id = $wpl_value; } $q .= "`{$wpl_field}`='" . wpl_db::escape($wpl_value) . "',"; } $exists = $model->get_properties_count(" AND `{$wpl_unique_field}`='{$unique_value}'"); if (!$exists) { $pid = $model->create_property_default($user_id); } else { $pid = $model->pid($unique_value, $wpl_unique_field); } /** add property id to return **/ $pids[] = $pid; /** Add source and last sync date **/ if (in_array('source', $possible_columns) and in_array('last_sync_date', $possible_columns)) { $q .= "`source`='{$source}',"; $q .= "`last_sync_date`='" . date('Y-m-d H:i:s') . "',"; } $q = trim($q, ', '); $query = "UPDATE `#__wpl_properties` SET " . $q . " WHERE `id`='" . $pid . "'"; wpl_db::q($query); if ($finalize) { $mode = $exists ? 'edit' : 'add'; $model->finalize($pid, $mode, $user_id); } if ($exists) { $added[] = $unique_value; } else { $updated[] = $unique_value; } } /** Creating Log **/ if ($source == 'mls' and wpl_global::check_addon('mls')) { _wpl_import('libraries.addon_mls'); if (method_exists('wpl_addon_mls', 'log')) { wpl_addon_mls::log($added, $updated, $log_params); } } return $pids; }