function index($offset = 0, $limit = 800) { $estates = new Estate(); $estates->where('isFree', 0); $estates->order_by('id', 'desc'); $estates->get_paged($offset, $limit, TRUE); $xmlFile = "mitula_feed_" . $offset . "_" . $limit . ".xml"; $xmlFile = $_SERVER['DOCUMENT_ROOT'] . '/feeds/' . $xmlFile; //$f = fopen($xmlFile, 'w'); //create the xml document $xmlDoc = new DOMDocument('1.0', 'UTF-8'); $root = $xmlDoc->createElement('Mitula'); $xmlDoc->appendChild($root); foreach ($estates as $row) { $ad = $xmlDoc->createElement('ad'); // create id for ad $id = $xmlDoc->createElement('id'); $id->appendChild($xmlDoc->createCDATASection($row->code)); // create url for ad $url = $xmlDoc->createElement('name'); $url->appendChild($xmlDoc->createCDATASection(base_url() . $row->estatecatalogue->name_none . '/' . $row->estatecity->name_none . '/' . $row->title_none . '.html')); // create title for ad $title = $xmlDoc->createElement('title'); $title->appendChild($xmlDoc->createCDATASection($row->title)); // create type for ad $type = $xmlDoc->createElement('type'); $type->appendChild($xmlDoc->createCDATASection($row->estatetype->name)); // create content for ad $content = $xmlDoc->createElement('content'); $content->appendChild($xmlDoc->createCDATASection($row->description)); // create price for ad $price = $xmlDoc->createElement('price'); $period = $xmlDoc->createAttribute('period'); $period->value = 'monthly'; $price->appendChild($period); $price->appendChild($xmlDoc->createCDATASection($row->price_text . ' ' . getpricetype($row->price_type))); // create floor_area for ad $floor_area = $xmlDoc->createElement('floor_area'); $floor_area->appendChild($xmlDoc->createCDATASection($row->area_text . ' m2')); // create city for ad $city = $xmlDoc->createElement('city'); $city->appendChild($xmlDoc->createCDATASection($row->estatecity->name)); // create address for ad $address = $xmlDoc->createElement('address'); $address->appendChild($xmlDoc->createCDATASection($row->address)); $photos = new Estate_photo(); $photos->where('estate_id', $row->id); $photos->get(); if ($row->photo != null || $photos->result_count() > 0) { $pictures = $xmlDoc->createElement('pictures'); $picture = $xmlDoc->createElement('picture'); $pictureTitle = $xmlDoc->createElement('picture_title'); $pictureTitle->appendChild($xmlDoc->createCDATASection($row->title)); $pictureUrl = $xmlDoc->createElement('picture_url'); $pictureUrl->appendChild($xmlDoc->createCDATASection(image($row->photo, 'slide_580_380'))); $picture->appendChild($pictureUrl); $picture->appendChild($pictureTitle); if ($photos->result_count() > 0) { foreach ($photos as $photo) { $rowPhoto = new Estate_photo($photo->id); $picture = $xmlDoc->createElement('picture'); $pictureTitle = $xmlDoc->createElement('picture_title'); $pictureTitle->appendChild($xmlDoc->createCDATASection($row->title)); $pictureUrl = $xmlDoc->createElement('picture_url'); $pictureUrl->appendChild($xmlDoc->createCDATASection(image($rowPhoto->name, 'slide_580_380'))); $picture->appendChild($pictureUrl); $picture->appendChild($pictureTitle); $pictures->appendChild($picture); } } $pictures->appendChild($picture); } $ad->appendChild($id); $ad->appendChild($url); $ad->appendChild($title); $ad->appendChild($type); $ad->appendChild($content); $ad->appendChild($price); $ad->appendChild($floor_area); $ad->appendChild($city); $ad->appendChild($address); $ad->appendChild($pictures); $root->appendChild($ad); } //make the output pretty $xmlDoc->formatOutput = true; // Flush XML from memory to file in one go $result = file_put_contents($xmlFile, $xmlDoc->saveXML()) or print_r(error_get_last()); if ($result == false) { echo "Error"; } else { echo $xmlFile . " All good, {$result} bytes written"; } die; }
function postDetail($url) { $typeNameNone = $this->uri->segment(1, ""); $type = new Estatetype(); $type->where('name_none', $typeNameNone)->get(); if ($type->exists()) { show_404(); } $cate = new Estatecatalogue(); $cate->where('name_none', $this->uri->segment(1, ''))->get(); if (!$cate->exists()) { show_404(); } $dis['cate'] = $cate; $url = geturlfromuri($this->uri->segment(3)); $estate = new Estate(); $estate->where('title_none', $url); $estate->where_related_estatecatalogue('id', $cate->id); $estate->where('active', 0); $estate->get(); if (!$estate->exists()) { redirect(base_url() . $this->uri->segment(1, '') . '-' . $this->uri->segment(2, '')); die; } $dis['o'] = $estate; $photo = new Estate_photo(); $photo->where('estate_id', $estate->id); $photo->get_iterated(); $dis['photo'] = $photo; $tag = $estate->tag; $dis['tag'] = explode(',', $tag); $description = str_replace(array("\r", "\n"), '', strip_tags($estate->description)); $keyword = explode(' ', $estate->title); $this->page_title = $estate->title . ' | SotayNhadat.vn'; $this->page_description = cut_string($description, 180); $this->page_keyword = implode(', ', $keyword); /*Get estate related vip*/ $estates_vip = new Estate(); $estates_vip->where('id !=', $estate->id); $estates_vip->where('estatetype_id', $estate->estatetype_id); $estates_vip->where('estatecity_id', $estate->estatecity_id); $estates_vip->where('estateprice_id', $estate->estateprice_id); $estates_vip->where('isVip', 1); $estates_vip->where('active', 0); $estates_vip->order_by('created', 'desc'); $estates_vip->get(10); $count_vip = $estates_vip->result_count(); $dis['estates_vip'] = $estates_vip; /*Get estate related follow type, city and price*/ $estates_related_type_city_area = new Estate(); $estates_related_type_city_area->where('id !=', $estate->id); $estates_related_type_city_area->where('estatetype_id', $estate->estatetype_id); $estates_related_type_city_area->where('estatecity_id', $estate->estatecity_id); $estates_related_type_city_area->where('estateprice_id', $estate->estateprice_id); $estates_related_type_city_area->where('isVip', 0); $estates_related_type_city_area->where('active', 0); $estates_related_type_city_area->order_by('created', 'desc'); $estates_related_type_city_area->get(10 - $count_vip); $dis['estates_related_type_city_area'] = $estates_related_type_city_area; $count_type_city_area = $estates_related_type_city_area->result_count(); /*Get all id estate*/ $list_estates_id = array(0); foreach ($estates_related_type_city_area as $row) { array_push($list_estates_id, $row->id); } /*Get estate related follow type, city and area*/ if (10 - $count_vip - $count_type_city_area > 0) { /*If count more than 10*/ $estates_related_area_price = new Estate(); $estates_related_area_price->where('estatetype_id', $estate->estatetype_id); $estates_related_area_price->where('estatearea_id', $estate->estatearea_id); $estates_related_area_price->where('estatecity_id', $estate->estatecity_id); $estates_related_area_price->where_not_in('id', $list_estates_id); $estates_related_area_price->where('isVip', 0); $estates_related_area_price->where('active', 0); $estates_related_area_price->order_by('created', 'desc'); $estates_related_area_price->get(10 - $count_vip - $count_type_city_area); //$dis['estates_related_area_price'] = $estates_related_area_price; } //$limit_lv3 = $estates_related_area_price->result_count()==$limit_lv2?0:$limit_lv2-$estates_related_area_price->result_count(); foreach ($estates_related_area_price as $row) { array_push($list_estates_id, $row->id); } $estates_related_new = new Estate(); $estates_related_new->where('estatetype_id', $estate->estatetype_id); $estates_related_new->where('estatearea_id', $estate->estatearea_id); $estates_related_new->where('estatecity_id', $estate->estatecity_id); $estates_related_new->where('estateprice_id', $estate->estateprice_id); $estates_related_new->where_not_in('id', $list_estates_id); $estates_related_new->where('active', 0); $estates_related_new->order_by('created', 'desc'); $estates_related_new->get($limit_lv3); $dis['estates_related_new'] = $estates_related_new; $estates_related_price = new Estate(); $estates_related_price->where('estateprice_id', $estate->estateprice_id); $estates_related_price->where('estatecity_id', $estate->estatecity_id); $estates_related_price->where('id !=', $estate->id); $estates_related_price->where('active', 0); $estates_related_price->order_by('created', 'desc'); $estates_related_price->get(10); $dis['estates_related_price'] = $estates_related_price; $estatePrices = new Estateprice(); $estatePrices->where('estatecatalogue_id', $estate->estatecatalogue_id); $estatePrices->order_by('position', 'asc'); $estatePrices->get_iterated(); $dis['estatePrices'] = $estatePrices; $this->isRobotFollow = 3; $dis['base_url'] = base_url(); $dis['view'] = 'front/user/post-detail'; $this->viewfront($dis); }
function delete($id, $redirect, $param) { $id = $this->uri->segment(4); $estate = new Estate($id); // detele photo default $pathImageDefault = $_SERVER['DOCUMENT_ROOT'] . '/' . $estate->photo; unlink($pathImageDefault); // delete photo project $photos = new Estate_photo(); $photos->where('estate_id', $estate->id); $photos->get(); foreach ($photos as $row) { $pathImage = $_SERVER['DOCUMENT_ROOT'] . '/' . $row->name; unlink($pathImage); } $estate->delete(); flash_message('success', 'Xóa Tin bất động sản thành công'); if ($this->uri->segment(5) == 'user') { redirect($this->admin . 'estateusers/listEstates/' . $this->uri->segment(6)); } if ($this->uri->segment(5) == 'free') { redirect($this->admin . 'estates/listFree'); } else { redirect($this->admin . 'estates/list_all'); } }