public function save() { $edit = array(); $edit['expire'] = time() + $this->_duration; $edit['session_name'] = $this->_sessionName; $edit['session_key'] = $this->_key; $edit['data'] = $this->_session->getData(); $id = parent::edit('thinsession', $this->_session->getId(), $edit); $this->_session = parent::getById('thinsession', $id); $data = $this->_session->getData(); return $data; }
public static function save($id) { $res = Data::query('movie', 'id_ac = ' . $id); if (!count($res)) { $info = static::getInfosMovie($id); $info['id_ac'] = $id; $info['id_video'] = null; $info['plateforme'] = null; $movie = Data::getById('movie', Data::add('movie', $info)); } else { $movie = Data::getObject(current($res)); } return $movie; }
public function getAds($maxPages = 0) { set_time_limit(0); $first = dwn('http://m.duproprio.com/resultats?hash=/s-pmin=0/s-pmax=99999999/p-ord=date/p-dir=DESC/pa-ge=1/s-filter=forsale/s-build=1/p-con=main/g-pr=1/s-bmin=0'); $nbPages = 0 == $maxPages ? Utils::cut('Page 1 de ', ' ', $first) : $maxPages; $ids = array(); $infos = array(); $pageIds = array(); $tab = explode('<a id=', $first); for ($i = 1; $i < count($tab); $i++) { $seg = trim($tab[$i]); $id = Utils::cut('"', '"', $seg); if (!Arrays::in($id, $ids)) { array_push($ids, $id); array_push($pageIds, $id); } } foreach ($pageIds as $id) { $seg = $this->tag('<div class="thumbnail" data-listing-code="' . $id . '">', '<a id="', $first); if (!empty($seg)) { $tmp = $this->tag('<img src="', '"', $seg); $picId = $this->tag('-big-', '.', $tmp); $infos[$id]['thumb'] = $picId; $type = $this->tag('<span class="listing-type">', '</span>', $seg); $type = html_entity_decode(repl(array("\n", "\r", "\t"), '', strip_tags($type))); if (contain(',', $type)) { list($type, $bedroom) = explode(',', $type, 2); } else { $type = $type; $bedroom = 0; } $infos[$id]['type'] = $this->clean($type); $infos[$id]['bedroom'] = repl(' ch.', '', $this->clean($bedroom)); $address = $this->tag('<span class="listing-address">', '</span>', $seg); $address = html_entity_decode(repl(array("\n", "\r", "\t"), '', strip_tags($address))); $address = $this->clean($address); $tabAddress = explode(', ', $address); if (count($tabAddress)) { $city = Arrays::last($tabAddress); $address = repl(', ' . $city, '', $address); } else { $city = ''; } $infos[$id]['address'] = $address; $infos[$id]['city'] = $city; $price = $this->tag('<span class="listing-price">', '</span>', $seg); $price = html_entity_decode(repl(array("\n", "\r", "\t"), '', strip_tags($price))); $infos[$id]['price'] = $this->clean(repl(array(' ', '$'), '', $price)); $infos[$id]['partner'] = 'duproprio'; $infos[$id]['partner_id'] = $id; } } foreach ($infos as $id => $property) { Data::getById('property', Data::add('propriete', $property)); } for ($j = 2; $j <= (int) $nbPages; $j++) { $page = dwn('http://m.duproprio.com/resultats?page=' . $j . '&hash=%2Fs-pmin%3D0%2Fs-pmax%3D99999999%2Fp-ord%3Ddate%2Fp-dir%3DDESC%2Fpa-ge%3D2%2Fs-filter%3Dforsale%2Fs-build%3D1%2Fp-con%3Dmain%2Fg-pr%3D1%2Fs-bmin%3D0'); $infos = array(); $pageIds = array(); $tab = explode('<a id=', $page); for ($i = 1; $i < count($tab); $i++) { $seg = trim($tab[$i]); $id = Utils::cut('"', '"', $seg); if (!Arrays::in($id, $ids)) { array_push($ids, $id); array_push($pageIds, $id); } } foreach ($pageIds as $id) { $seg = $this->tag('<div class="thumbnail" data-listing-code="' . $id . '">', '<a id="', $page); if (!empty($seg)) { $tmp = $this->tag('<img src="', '"', $seg); $picId = $this->tag('-big-', '.', $tmp); $infos[$id]['thumb'] = $picId; $type = $this->tag('<span class="listing-type">', '</span>', $seg); $type = html_entity_decode(repl(array("\n", "\r", "\t"), '', strip_tags($type))); if (contain(',', $type)) { list($type, $bedroom) = explode(',', $type, 2); } else { $type = $type; $bedroom = 0; } $infos[$id]['type'] = $this->clean($type); $infos[$id]['bedroom'] = repl(' ch.', '', $this->clean($bedroom)); $address = $this->tag('<span class="listing-address">', '</span>', $seg); $address = html_entity_decode(repl(array("\n", "\r", "\t"), '', strip_tags($address))); $address = $this->clean($address); $tabAddress = explode(', ', $address); if (count($tabAddress)) { $city = Arrays::last($tabAddress); $address = repl(', ' . $city, '', $address); } else { $city = ''; } $infos[$id]['address'] = $address; $infos[$id]['city'] = $city; $price = $this->tag('<span class="listing-price">', '</span>', $seg); $price = html_entity_decode(repl(array("\n", "\r", "\t"), '', strip_tags($price))); $infos[$id]['price'] = $this->clean(repl(array(' ', '$'), '', $price)); $infos[$id]['partner'] = 'duproprio'; $infos[$id]['partner_id'] = $id; } } foreach ($infos as $id => $property) { Data::getById('property', Data::add('propriete', $property)); } } return $this; }
public function get($results = null) { $resultsGet = null !== $results ? $results : $this->results; $queryKey = sha1(serialize($this->wheres) . serialize($resultsGet)); $cache = Data::cache($this->type, $queryKey); if (!empty($cache) && true === $this->cache) { return $cache; } if (count($resultsGet)) { if (null !== $this->groupBy) { $groupBys = array(); $ever = array(); foreach ($resultsGet as $key => $id) { $object = Data::getById($this->type, $id); $getter = getter($this->groupBy); $obj = $object->{$getter}(); if ($obj instanceof Container) { $obj = $obj->getId(); } if (!Arrays::in($obj, $ever)) { $groupBys[$key] = $id; $ever[] = $obj; } } $this->results = $groupBys; $this->order($this->groupBy); $resultsGet = $this->results; } if (0 < $this->limit) { $max = count($resultsGet); $number = $this->limit - $this->offset; if ($number > $max) { $this->offset = $max - $this->limit; if (0 > $this->offset) { $this->offset = 0; } $this->limit = $max; } $resultsGet = array_slice($resultsGet, $this->offset, $this->limit); } } $collection = array(); if (count($resultsGet)) { $_sum = 0; $_avg = 0; $_min = 0; $_max = 0; $first = true; foreach ($resultsGet as $key => $id) { $object = Data::getById($this->type, $id); if (null !== $this->sum) { $getter = getter($this->sum); $_sum += $object->{$getter}(); } if (null !== $this->avg) { $getter = getter($this->avg); $_avg += $object->{$getter}(); } if (null !== $this->min) { $getter = getter($this->min); if (true === $first) { $_min = $object->{$getter}(); } else { $_min = $object->{$getter}() < $_min ? $object->{$getter}() : $_min; } } if (null !== $this->max) { $getter = getter($this->max); if (true === $first) { $_max = $object->{$getter}(); } else { $_max = $object->{$getter}() > $_max ? $object->{$getter}() : $_max; } } $collection[] = $object; $first = false; } } if (null !== $this->min) { $collection = $_min; } if (null !== $this->max) { $collection = $_max; } if (null !== $this->sum) { $collection = $_sum; } if (null !== $this->avg) { $collection = $_avg / count($collection); } $cache = Data::cache($this->type, $queryKey, $collection); return $collection; }