function getPachetServicii($entryID, $mandatory) { return PacheteServicii::where('EntryID', $entryID)->where('Mandatory', $mandatory)->distinct('ServID')->get(['ServID', 'Name']); }
public function XmlFiles($operator) { $files = File::files("CatalogFiles/{$operator}"); Pachete::truncate(); PacheteCamere::truncate(); PacheteOcupare::truncate(); PacheteServicii::truncate(); PacheteIntrari::truncate(); PacheteOcupare::truncate(); foreach ($files as $file) { $xml = new SimpleXMLElement($file, null, TRUE); $pachete = $xml->Packages; //----parcurg pachetele din $pachete---// foreach ($pachete as $pachet) { // dd($pachet); //---parcurg nodurile pachetului-----// foreach ($pachet as $xml_pachet) { $atribute_pachet = $xml_pachet->attributes(); //---definim array_pachet---// $array_pachet = ['PackID' => $atribute_pachet->ID, 'ProjectID' => $xml_pachet->Project->attributes()->ID, 'ProjectName' => $xml_pachet->Project->attributes()->Name, 'HomeCateg' => '', 'Type' => $atribute_pachet->Type, 'Name' => $atribute_pachet->Name, 'Currency' => $atribute_pachet->Currency, 'Code' => $atribute_pachet->Code, 'Description' => $xml_pachet->Description, 'Operator' => $operator]; Pachete::create($array_pachet); //-------------de testat cu extradetalii suplimentare $extradescrieri = $xml_pachet->ExtraDescription->Description; if ($extradescrieri) { foreach ($extradescrieri as $xml_extradescrieri) { $atribute_extradescrieri = $xml_extradescrieri->attributes(); $array_extradescrieri = ['PackID' => $atribute_pachet->ID, 'Title' => $atribute_extradescrieri->Title, 'Description' => $xml_extradescrieri, 'Operator' => $operator]; } } $intrari_pachet = $xml_pachet->PackEntries->PackEntry; //----Parcurg nodul de intrari pachete-----// foreach ($intrari_pachet as $xml_intrari_pachet) { $atribute_intrare_pachet = $xml_intrari_pachet->attributes(); //-----definim array_intrari_pachet----// $array_intrare_pachet = ['PackID' => $atribute_pachet->ID, 'EntryID' => $atribute_intrare_pachet->ID, 'DateEnd' => $atribute_intrare_pachet->DateEnd, 'DateStart' => $atribute_intrare_pachet->DateStart, 'Duration' => $xml_intrari_pachet->Duration, 'TimeUnit' => $xml_intrari_pachet->Duration->attributes()->TimeUnit, 'Operator' => $operator]; PacheteIntrari::create($array_intrare_pachet); //-----definesc nodurile copil din intrari pachete-----// $extrservicii = $xml_intrari_pachet->ExtraServices->ExtraService; //-----parcurg extraserviciile----// if (!is_null(@$extrservicii)) { foreach ($extrservicii as $xml_extraservicii) { $atribute_extraservicii = $xml_extraservicii->attributes(); //-- definim array_extraservicii--// $array_extraservicii = ['EntryID' => $atribute_intrare_pachet->ID, 'ServID' => $atribute_extraservicii->ID, 'Name' => $atribute_extraservicii->Name, 'Type' => $atribute_extraservicii->Type, 'Mandatory' => $atribute_extraservicii->Mandatory, 'PriceSetID' => @$xml_extraservicii->PriceSet->attributes()->ID, 'Operator' => $operator]; PacheteServicii::create($array_extraservicii); } } //----------parcurg packconfigurarion--------// $configurari_pachete = $xml_intrari_pachet->PackConfigurations; foreach ($configurari_pachete as $configurare_pachet) { //---------parcurg configurarile-----------// foreach ($configurare_pachet as $xml_configurare_pachet) { //------definesc nodurile copil din configurari $ocupare_camere = $xml_configurare_pachet->Occupancy->GuestCount; $date_camere_unitate = $xml_configurare_pachet->Accommodation; //----parcurg nodul unitate----// $array_adults = []; $array_childs = []; $array_infants = []; $nrAdults = 0; $nrChilds = 0; $nrInfants = 0; foreach ($date_camere_unitate as $xml_unitate_camere) { $atribute_unitate = $xml_unitate_camere->attributes(); //----definesc array_unitate_camere-----// $array_unitate_camere = ['PackID' => $atribute_pachet->ID, 'EntryID' => $atribute_intrare_pachet->ID, 'UnitID' => $atribute_unitate->UnitID, 'RoomID' => $atribute_unitate->RoomID, 'Name' => $atribute_unitate->Name, 'Stars' => $atribute_unitate->Stars, 'RoomName' => $atribute_unitate->RoomName, 'RoomType' => $xml_unitate_camere->RoomType, 'RoomFeature' => $xml_unitate_camere->RoomFeature, 'CityID' => $xml_unitate_camere->City->attributes()->ID, 'CityName' => $xml_unitate_camere->City->attributes()->Name, 'Price' => $xml_configurare_pachet->Price->attributes()->Ammount, 'Currency' => $xml_configurare_pachet->Price->attributes()->CurrencyCode, 'Operator' => $operator]; $pachete_camera = PacheteCamere::create($array_unitate_camere); Pachete::where('PackID', $atribute_pachet->ID)->update(['CityID' => $xml_unitate_camere->City->attributes()->ID]); Pachete::where('PackID', $atribute_pachet->ID)->update(['UnitID' => $atribute_unitate->UnitID]); } //------parcurg nodurile ocupare camere------// foreach ($ocupare_camere as $xml_ocupare_camere) { $atribute_ocupare_camere = $xml_ocupare_camere->attributes(); //----definim array_ocupare camere-----// $array_ocupare_camere = ['IDCamera' => $pachete_camera->id, 'Count' => $atribute_ocupare_camere->Count, 'AgeQualifyingCode' => $atribute_ocupare_camere->AgeQualifyingCode, 'MinAge' => $atribute_ocupare_camere->MinAge, 'MaxAge' => $atribute_ocupare_camere->MaxAge, 'RoomID' => $atribute_unitate->RoomID, 'UnitID' => $atribute_unitate->UnitID, 'PackID' => $atribute_pachet->ID, 'EntryID' => $atribute_intrare_pachet->ID, 'Operator' => $operator]; PacheteOcupare::create($array_ocupare_camere); //--------creez coloanele de max adulti si max copii din pachete camare------------// if ((string) $atribute_ocupare_camere->AgeQualifyingCode == 'a') { $nrAdults += $atribute_ocupare_camere->Count; // array_push($array_adults, (string) $atribute_ocupare_camere->AgeQualifyingCode . '|' . (string) $atribute_ocupare_camere->Count); } else { if ((string) $atribute_ocupare_camere->AgeQualifyingCode == 'c' && (string) $atribute_ocupare_camere->MinAge >= 2) { $nrChilds += $atribute_ocupare_camere->Count; // array_push($array_childs, (string) $atribute_ocupare_camere->AgeQualifyingCode . '|' . (string) $atribute_ocupare_camere->Count); } else { if ((string) $atribute_ocupare_camere->AgeQualifyingCode == 'c' && (string) $atribute_ocupare_camere->MinAge < 2) { $nrInfants += $atribute_ocupare_camere->Count; // array_push($array_infants, (string) $atribute_ocupare_camere->AgeQualifyingCode . '|' . (string) $atribute_ocupare_camere->Count); } } } //array_push($array_age, (string) $atribute_ocupare_camere->AgeQualifyingCode . "|" . $atribute_ocupare_camere->Count); } // $pachete_camera->update(['Adults' => serialize($array_adults), 'Childs' => serialize($array_childs), 'Infants' => serialize($array_infants)]); $pachete_camera->update(['Adults' => $nrAdults, 'Childs' => $nrChilds, 'Infants' => $nrInfants]); // dd($pachete_camera); } } } } } // Files::delete($file); } }