/** * 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; }
public function display($instance = array()) { /** do cronjobs **/ _wpl_import('libraries.events'); wpl_events::do_cronjobs(); /** check access **/ if (!wpl_users::check_access('propertyshow')) { /** import message tpl **/ $this->message = __("You don't have access to this part!", WPL_TEXTDOMAIN); return parent::render($this->tpl_path, 'message', false, true); } $this->tpl = wpl_request::getVar('tpl', 'default'); /** property listing model **/ $this->model = new wpl_property(); $this->pid = wpl_request::getVar('pid', 0); $listing_id = wpl_request::getVar('mls_id', 0); if (trim($listing_id)) { $this->pid = wpl_property::pid($listing_id); wpl_request::setVar('pid', $this->pid); } $property = $this->model->get_property_raw_data($this->pid); /** no property found **/ if (!$property or $property['finalized'] == 0 or $property['confirmed'] == 0 or $property['deleted'] == 1 or $property['expired'] >= 1) { /** import message tpl **/ $this->message = __("No property found or it's not available now!", WPL_TEXTDOMAIN); return parent::render($this->tpl_path, 'message', false, true); } $this->pshow_fields = $this->model->get_pshow_fields('', $property['kind']); $this->pshow_categories = wpl_flex::get_categories('', '', " AND `enabled`>='1' AND `kind`='" . $property['kind'] . "' AND `pshow`='1'"); $wpl_properties = array(); /** define current index **/ $wpl_properties['current']['data'] = (array) $property; $wpl_properties['current']['raw'] = (array) $property; $find_files = array(); $rendered_fields = $this->model->render_property($property, $this->pshow_fields, $find_files, true); $wpl_properties['current']['rendered_raw'] = $rendered_fields['ids']; $wpl_properties['current']['materials'] = $rendered_fields['columns']; foreach ($this->pshow_categories as $pshow_category) { $pshow_cat_fields = $this->model->get_pshow_fields($pshow_category->id, $property['kind']); $wpl_properties['current']['rendered'][$pshow_category->id]['self'] = (array) $pshow_category; $wpl_properties['current']['rendered'][$pshow_category->id]['data'] = $this->model->render_property($property, $pshow_cat_fields); } $wpl_properties['current']['items'] = wpl_items::get_items($this->pid, '', $property['kind'], '', 1); /** property location text **/ $wpl_properties['current']['location_text'] = $this->model->generate_location_text((array) $property); /** property full link **/ $wpl_properties['current']['property_link'] = $this->model->get_property_link((array) $property); /** property page title **/ $wpl_properties['current']['property_page_title'] = $this->model->update_property_page_title($property); /** property title **/ $wpl_properties['current']['property_title'] = $this->model->update_property_title($property); /** apply filters (This filter must place after all proccess) **/ _wpl_import('libraries.filters'); @extract(wpl_filters::apply('property_listing_after_render', array('wpl_properties' => $wpl_properties))); $this->wpl_properties = $wpl_properties; $this->kind = $property['kind']; $this->property = $wpl_properties['current']; /** updating the visited times and etc **/ wpl_property::property_visited($this->pid); /** trigger event **/ wpl_global::event_handler('property_show', array('id' => $this->pid)); /** import tpl **/ $this->tpl = wpl_flex::get_kind_tpl($this->tpl_path, $this->tpl, $this->kind); return parent::render($this->tpl_path, $this->tpl, false, true); }
$value = rtrim($value, ','); if ($value != '') { $query .= " AND `" . $table_column . "` IN (" . $value . ")"; } } $done_this = true; } elseif ($format == 'notselect' and !$done_this) { if ($value != '-1' and trim($value) != '') { $query .= " AND `" . $table_column . "` != '" . $value . "'"; } $done_this = true; } elseif ($format == 'parent' and !$done_this) { if ($value != '-1' and trim($value) != '') { /** converts listing id to property id **/ if ($value) { $value = wpl_property::pid($value); } $query .= " AND `parent` = '" . $value . "'"; } $done_this = true; } elseif ($format == 'textsearch' and !$done_this) { if (trim($value) != '') { $query .= " AND `" . $table_column . "` LIKE '%" . $value . "%'"; } $done_this = true; } elseif ($format == 'text' and !$done_this) { if (trim($value) != '') { $query .= " AND `" . $table_column . "` LIKE '%" . $value . "%'"; } $done_this = true; } elseif ($format == 'unit' and !$done_this) {