Exemplo n.º 1
0
 private function finalize($item_id, $mode, $value = 1)
 {
     if ($value) {
         wpl_property::finalize($item_id, $mode);
     } else {
         wpl_property::unfinalize($item_id);
     }
     $res = 1;
     $message = $res ? __('Saved.', WPL_TEXTDOMAIN) : __('Error Occured.', WPL_TEXTDOMAIN);
     $data = NULL;
     $response = array('success' => $res, 'message' => $message, 'data' => $data);
     echo json_encode($response);
     exit;
 }
Exemplo n.º 2
0
 /**
  * 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;
 }