Пример #1
0
 /**
  * Get a list of investments to be added or remove. Write the investments to the database.
  */
 public function GetInvestments()
 {
     //echo "start<br>";
     if (!$this->WS()) {
         return null;
     }
     try {
         if ($this->_sid == "") {
             return;
         }
         $params = array('sid' => $this->_sid);
         $result = $this->WS()->getSC()->__soapCall("GetInvestments", array($params));
         if ($result->GetInvestmentsResult->Status != 0) {
             return $result->GetInvestmentsResult->Message;
         }
         $buf = $result->GetInvestmentsResult->OffersZip;
         $f = fopen(self::TMP_ZIP_FILE, "w");
         fwrite($f, $buf);
         fclose($f);
         //unzip XML file with offers
         $zip = new ZipArchive();
         if ($zip->open(self::TMP_ZIP_FILE)) {
             $fp = $zip->getStream('xml.xml');
             if (!$fp) {
                 exit("failed reading xml file (" . getcwd() . ")\n");
             }
             $contents = '';
             while (!feof($fp)) {
                 $contents .= fread($fp, 2);
             }
             fclose($fp);
             $zip->close();
             file_put_contents(self::TMP_XML_INV_FILE, $contents);
             if (file_exists(self::TMP_ZIP_FILE)) {
                 unlink(self::TMP_ZIP_FILE);
             }
         }
         //open and read XML file
         $xml = simplexml_load_file(self::TMP_XML_INV_FILE);
         $investmentsNode = null;
         //read main nodes
         foreach ($xml->children() as $child) {
             //echo "<br />" . $child->getName() . ": " . $child;
             if ($child->getName() == "Inwestycje") {
                 $investmentsNode = $child;
             }
         }
         //read investments
         $importedInv = "";
         $count = 0;
         foreach ($investmentsNode->children() as $node) {
             $count++;
             $importedInv .= $node["ID"] . ",";
             //read major properties
             $garage = $node->Garaz == "True" ? 1 : 0;
             $pool = $node->Basen == "True" ? 1 : 0;
             $ter = $node->Taras == "True" ? 1 : 0;
             $ac = $node->Klimatyzacja == "True" ? 1 : 0;
             $spec = $node->Specjalna == "True" ? 1 : 0;
             $proj = $node->Projekt == "True" ? 1 : 0;
             $investment = new Investment($node["Jezyk"], $node["ID"], CheckNumeric($node["Lp"]), $node->Numer, $node->Nazwa, $node->Opis, $node->OpisSkrot, $node->DaneKontaktowe, $node->MapMar, $garage, $pool, $ter, $ac, $proj, $spec, $node->DataUtworzenia, $node->TerminOddania, CheckNumeric($node->PowierzchniaCalkowita), CheckNumeric($node->KubaturaBrutto), CheckNumeric($node->MetrazOd), CheckNumeric($node->MetrazDo), CheckNumeric($node->CenaOd), CheckNumeric($node->CenaDo), CheckNumeric($node->CenaM2Od), CheckNumeric($node->CenaM2Do), CheckNumeric($node->PietroOd), CheckNumeric($node->PietroDo), CheckNumeric($node->PokojeOd), CheckNumeric($node->PokojeDo), $node->Kraj == "" ? null : $node->Kraj, $node->Wojewodztwo == "" ? null : $node->Wojewodztwo, $node->Powiat == "" ? null : $node->Powiat, $node->Lokalizacja == "" ? null : $node->Lokalizacja, $node->Dzielnica == "" ? null : $node->Dzielnica, $node->Rejon == "" ? null : $node->Rejon, $node->Ulica, $node->Kategoria, $node["Oddzial"]);
             $photosNode = null;
             $lngsNode = null;
             $buildingsNode = null;
             $agentsNode = null;
             //read properties
             foreach ($node->children() as $propNode) {
                 if ($propNode->getName() == "Zdjecia") {
                     $photosNode = $propNode;
                 } else {
                     if ($propNode->getName() == "Jezyki") {
                         $lngsNode = $propNode;
                     } else {
                         if ($propNode->getName() == "Budynki") {
                             $buildingsNode = $propNode;
                         } else {
                             if ($propNode->getName() == "Agenci") {
                                 $agentsNode = $propNode;
                             } else {
                                 if ($propNode->getName() == "PolaDynamiczne") {
                                     //delete unuse properties from offer
                                     $addedProperties = array();
                                     foreach ($propNode->children() as $listNode) {
                                         $pname = (string) $listNode["Nazwa"];
                                         $investment->__set($pname, $listNode);
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
             //save investment object to database
             Investments::AddEditInvestment($investment);
             echo DataBase::GetDbInstance()->LastError();
             //delete unuse properties from offer
             $addedProperties = array();
             foreach ($node->children() as $propNode) {
                 $pname = $propNode->getName();
                 if ($pname == "PolaDynamiczne") {
                     foreach ($propNode->children() as $listNode) {
                         $pname = (string) $listNode["Nazwa"];
                         $prop = Properties::GetPropertyName($pname);
                         if ($prop != null) {
                             $addedProperties[count($addedProperties)] = $prop->GetID();
                         }
                     }
                 }
             }
             Investments::DeleteUnUseProperties($investment->GetId(), $investment->GetIdLng(), $addedProperties);
             //photos
             if ($photosNode != null) {
                 $addedPhotos = array();
                 foreach ($photosNode->children() as $photoNode) {
                     $intro = $photoNode->intro == "True" ? 1 : 0;
                     $photo = new OfferPhoto($photoNode['ID'], null, $investment->GetId(), $photoNode->plik, $photoNode->opis, $photoNode['lp'], $photoNode['typ'], $intro, null, (string) $photoNode->LinkFilmYouTube, (string) $photoNode->LinkMiniaturkaYouTube);
                     OfferPhotos::AddEditPhoto($photo);
                     echo DataBase::GetDbInstance()->LastError();
                     $addedPhotos[count($addedPhotos)] = $photo->GetId();
                 }
                 OfferPhotos::DeleteUnUsePhotos(0, $addedPhotos, $investment->GetId());
             }
             //buildings
             if ($buildingsNode != null) {
                 $importedBlds = "";
                 foreach ($buildingsNode->children() as $buildingNode) {
                     $importedBlds .= $buildingNode["ID"] . ",";
                     $building = new InvestmentBuilding(null, $buildingNode['ID'], $buildingNode->Nazwa, $buildingNode['Symbol'], $buildingNode->Opis, $investment->GetId(), CheckNumeric($buildingNode['Metraz']), $buildingNode->TerminOddania, CheckNumeric($buildingNode['LiczbaPieter']));
                     Investmentbuildings::AddEditInvestmentBuilding($building);
                     echo DataBase::GetDbInstance()->LastError();
                     //add offers to building
                     $offersNode = $buildingNode->Oferty;
                     Investmentbuildings::AddOffersToBuilding($offersNode, $building);
                 }
                 //delete buildings
                 $importedBlds = substr($importedBlds, 0, strlen($importedBlds) - 1);
                 if ($importedBlds != "") {
                     $result = DataBase::GetDbInstance()->ExecuteQuery("SELECT id FROM #S#investments_buildings WHERE investments_id=" . $investment->GetId() . " AND id NOT IN({$importedBlds})");
                     while ($row = DataBase::GetDbInstance()->FetchArray($result)) {
                         Investmentbuildings::DeleteInvestmentBuilding($row[0]);
                         echo DataBase::GetDbInstance()->LastError();
                     }
                 }
             }
             //agenci
             if ($agentsNode != null) {
                 foreach ($agentsNode->children() as $aNode) {
                     $a = Agents::GetAgent($aNode['wartosc']);
                     if ($a != null) {
                         Investments::AddInvestmentsAgent($investment, $a);
                     }
                 }
             }
         }
         //delete investments
         $importedInv = substr($importedInv, 0, strlen($importedInv) - 1);
         if ($importedInv == "") {
             $importedInv = "-1";
         }
         $result = DataBase::GetDbInstance()->ExecuteQuery("SELECT id FROM #S#investments WHERE id NOT IN({$importedInv})");
         while ($row = DataBase::GetDbInstance()->FetchArray($result)) {
             Investments::DeleteInvestment($row[0]);
             //delete agents_investments relation
             Investments::DelInvestmentsAgents($row[0]);
             echo DataBase::GetDbInstance()->LastError();
         }
         return $count;
     } catch (Exception $ex) {
         Errors::LogError("WebServiceVirgo:GetInvestments", $ex->getMessage() . "; " . $ex->getTraceAsString());
         return 0;
     }
 }
Пример #2
0
 /**
  * Return an array of Agents
  * @return Agents[]
  */
 public function GetAgents()
 {
     return Investments::GetInvestmentsAgents($this);
 }
Пример #3
0
 /**
  * Return investment as object.
  * @return Investment
  */
 public function GetInvestmentObj()
 {
     if ($this->_InvestmentObj == null) {
         $this->_InvestmentObj = Investments::GetInvestment($this->GetInvestmentId());
     }
     return $this->_InvestmentObj;
 }
Пример #4
0
 /**
  * Returns a unique list of categories used in investments.
  * @return string[]
  */
 public function GetInvestmentsCategories($idLng = 1045)
 {
     return Investments::GetCategories($idLng);
 }