Example #1
0
 /**
  * Get a list of offers to be added or remove. Write the offers to the database.
  * @param string &$log
  * @return int
  */
 public function GetOffers(&$log)
 {
     if (!$this->WS()) {
         return null;
     }
     $log .= "START\n";
     $log .= "working dir=" . getcwd() . "\n";
     $time_start = microtime_float();
     $count_arr = array("suma" => 0, "dodane" => 0, "zmodyfikowane" => 0, "usuniete" => 0);
     $deleted_ids = $this->GetOffersPartial(false, $log, $count_arr);
     Errors::LogSynchroStep('WebServiceVirgo - GetOffers() - step 1');
     //delete offers
     foreach ($deleted_ids as $idd) {
         $ret = Offers::DeleteOffer($idd);
         if ($ret == "D") {
             $count_arr["suma"]++;
             $count_arr["usuniete"]++;
         }
         echo DataBase::GetDbInstance()->LastError();
     }
     Errors::LogSynchroStep('WebServiceVirgo - GetOffers() - step 4');
     Errors::LogError2File("Offers synchronization results: added=" . $count_arr["dodane"] . ", modified=" . $count_arr["zmodyfikowane"] . ", deleted=" . $count_arr["usuniete"]);
     $log .= "KONIEC\n";
     $time_end = microtime_float();
     $time = $time_end - $time_start;
     if ($this->_DEBUG) {
         echo "<b>Execution time: {$time} seconds</b><br>";
     }
     if ($this->_DEBUG) {
         echo "Queries count: " . DataBase::$QUERY_COUNT . "<br>";
     }
     OffersHelper::clearCache();
     return $count_arr["suma"];
 }
Example #2
0
 /**
  * Return unique list of used languages in offers.
  * @return Language[]
  */
 public static function GetAvailableLanguages()
 {
     if (!($lngs = OffersHelper::getMethodResultCache())) {
         $result = DataBase::GetDbInstance()->ExecuteQuery("SELECT DISTINCT(id_lng) FROM #S#offers ORDER BY id_lng ASC");
         $lngs = array();
         $ndx = 0;
         while ($row = DataBase::GetDbInstance()->FetchArray($result)) {
             $lngs[$ndx] = new Language($row[0]);
             $ndx++;
         }
         OffersHelper::setMethodResultCache($lngs);
     }
     return $lngs;
 }
Example #3
0
 /**
  * Creates query string from given params
  * @param string $select
  * @param string $sorting
  * @param mixed $filters
  * @return string
  */
 protected static function GetQuery($select = "SELECT * ", $sorting = "", $filters = null)
 {
     $query = $select . " FROM #S#investments AS i ";
     if (array_key_exists('properties', $filters)) {
         $i = 1;
         foreach ($filters['properties'] as $name => $values) {
             $query .= " INNER JOIN #S#investments_properties AS ip{$i} ON (i.id = ip{$i}.investments_id AND i.id_lng = ip{$i}.investments_id_lng) INNER JOIN #S#properties AS p{$i} ON (p{$i}.id = ip{$i}.properties_id AND p{$i}.id = " . OffersHelper::getProps($name) . ")";
             $i++;
         }
     }
     $query .= " WHERE 1=1 ";
     if ($filters != null) {
         foreach ($filters as $key => $value) {
             switch ($key) {
                 case "IdLng":
                     $query .= " AND i.id_lng=?";
                     break;
                 case "no":
                     $query .= " AND i.no LIKE ?";
                     break;
                 case "number":
                     $query .= " AND i.number LIKE ?";
                     break;
                 case "name":
                     $query .= " AND i.name LIKE ?";
                     break;
                 case "description":
                     $query .= " AND i.description LIKE ?";
                     break;
                 case "shortDescription":
                     $query .= " AND i.short_description LIKE ?";
                     break;
                 case "contact":
                     $query .= " AND i.contact LIKE ?";
                     break;
                 case "country":
                     $query .= " AND i.country LIKE ?";
                     break;
                 case "province":
                     $query .= " AND i.province LIKE ?";
                     break;
                 case "district":
                     $query .= " AND i.district LIKE ?";
                     break;
                 case "location":
                     $query .= " AND i.location LIKE ?";
                     break;
                 case "quarter":
                     $query .= " AND i.quarter LIKE ?";
                     break;
                 case "region":
                     $query .= " AND i.region LIKE ?";
                     break;
                 case "street":
                     $query .= " AND i.street LIKE ?";
                     break;
                 case "category":
                     $query .= " AND i.category LIKE ?";
                     break;
                 case "creationDateFrom":
                     $query .= " AND i.creation_date >= ?";
                     break;
                 case "creationDateTo":
                     $query .= " AND i.creation_date <= ?";
                     break;
                 case "dueDateFrom":
                     $query .= " AND i.due_date >= ?";
                     break;
                 case "dueDateTo":
                     $query .= " AND i.due_date <= ?";
                     break;
                 case "totalAreaFrom":
                     $query .= " AND i.total_area >= ?";
                     break;
                 case "totalAreaTo":
                     $query .= " AND i.total_area <= ?";
                     break;
                 case "grossVolumeFrom":
                     $query .= " AND i.gross_volume >= ?";
                     break;
                 case "grossVolumeTo":
                     $query .= " AND i.gross_volume <= ?";
                     break;
                 case "area":
                     $query .= " AND i.area_from <= ?" . " AND i.area_to >= ?";
                     break;
                 case "areaFrom":
                     $query .= " AND i.area_from >= ?";
                     break;
                 case "areaTo":
                     $query .= " AND i.area_to <= ?";
                     break;
                 case "price":
                     $query .= " AND i.price_from <= ?" . " AND i.price_to >= ?";
                     break;
                 case "priceFrom":
                     $query .= " AND i.price_from >= ?";
                     break;
                 case "priceTo":
                     $query .= " AND i.price_to <= ?";
                     break;
                 case "pricem2":
                     $query .= " AND i.pricem2_from <= ?" . " AND i.pricem2_to >= ?";
                     break;
                 case "floor":
                     $query .= " AND i.floor_from <= ?" . " AND i.floor_to >= ?";
                     break;
                 case "rooms":
                     $query .= " AND i.rooms_no_from <= ?" . " AND i.rooms_no_to >= ?";
                     break;
                 case "roomsNoFrom":
                     $query .= " AND i.rooms_no_from >= ?";
                     break;
                 case "roomsNoTo":
                     $query .= " AND i.rooms_no_to <= ?";
                     break;
                 case "districts":
                     $query .= " AND i.district IN (" . self::prepareStringToBind($value) . ")";
                     break;
                 case "locations":
                     $query .= " AND i.location IN (" . self::prepareStringToBind($value) . ")";
                     break;
                 case "quarters":
                     $query .= " AND i.quarter IN (" . self::prepareStringToBind($value) . ")";
                     break;
                 case "categories":
                     $query .= " AND i.category IN (" . self::prepareStringToBind($value) . ")";
                     break;
                 case "specjalne":
                     $query .= " AND i.special=1";
                     break;
                 case "department":
                     $query .= " AND i.departments_id = ?";
                     break;
                 case "departments":
                     $query .= " AND i.departments_id IN (" . self::prepareStringToBind($value) . ")";
                     break;
                 case "properties":
                     $query .= self::preparePropertiesToQuery($value);
                     break;
                 default:
                     $query .= " AND i.{$key}=?";
                     break;
             }
         }
     }
     if ($sorting != "") {
         $query .= " ORDER BY i." . self::prepareSort($sorting);
     }
     return $query;
 }