/** * Creates a new model. * If creation is successful, the browser will be redirected to the 'view' page. */ public function actionCreate($id = '') { if ($id) { $model = $this->loadModel($id); } else { $model = new Ads(); } // Uncomment the following line if AJAX validation is needed // $this->performAjaxValidation($model); if (isset($_POST['Ads'])) { $model->attributes = $_POST['Ads']; if ($model->save()) { $this->redirect(array('view', 'id' => $model->id)); } } $this->render('create', array('model' => $model)); }
public function option($name, $type) { global $db; $res = $db->selectCol("SELECT id_{$name} AS ARRAY_KEY, {$name}_name FROM " . $type); return $res; } } if ($_SERVER['REQUEST_METHOD'] == 'POST' && empty($_GET['id'])) { if ($_POST['id_type'] == 1) { $ad = new PrivatePersonAds($_POST); $ad->save(); } else { $ad = new CompanyAds($_POST); $ad->save(); } } elseif (isset($_GET['action']) && $_GET['action'] == 'delete') { $ad = new Ads($_POST); $ad->delete(); } elseif ($_SERVER['REQUEST_METHOD'] == 'POST' && isset($_POST['change'])) { $_POST['ad_id'] = $_GET['id']; $change = new Ads($_POST); $change->save(); header("Location: HW15.php?id={$_GET['id']}"); } elseif (isset($_GET['id'])) { $full = new Ads($_POST); $smarty->assign('selected_ads', $full->fullAd()); } $main = AdsStore::instance(); $main->getAllAdsFromDb(); $main->writeOut(); $smarty->display('HW15.tpl');
global $db; $all = $db->select('select * from ads'); foreach ($all as $value) { $ad = new Ads($value); self::addAds($ad); //помещаем объекты в хранилище } return self::$instance; } public function prepareForOut() { global $smarty; $row = ''; foreach ($this->ads as $value) { $smarty->assign('ad', $value); $row .= $smarty->fetch('table_row.tpl.html'); } $smarty->assign('ads_rows', $row); return self::$instance; } public function display() { global $smarty; $smarty->display('oop.tpl'); } } if (isset($_POST['name']) && isset($_POST['desc'])) { $ad = new Ads($_POST); $ad->save(); } AdsStore::instance()->getAllAdsFromDb()->prepareForOut()->display();
/** * This is the default 'index' action that is invoked * when an action is not explicitly requested by users. */ public function actionIndex() { $allsite = file_get_html('http://dnepropetrovsk.dnp.olx.ua/nedvizhimost/arenda-kvartir/dolgosrochnaya-arenda-kvartir/'); $allads = $allsite->find('table[id="offers_table"]/table'); $all_tr = array_reverse($allads); foreach ($all_tr as $index => $article) { $title = $article->find('strong', 0)->plaintext; $link = $article->find('a', 0)->href; if (!empty($link) && $link !== "#") { $add = file_get_html($link); /*price*/ $price = $add->find('div[id=offeractions]/div[1]/div[1]/strong', 0)->plaintext; /*phone*/ $isclasses = $add->find('ul[id=contact_methods]/li', 0)->class; $isclasses_explode = explode(' ', $isclasses); $phone_id = ''; foreach ($isclasses_explode as $index => $lasses) { if (strpos($lasses, "'id':") !== false) { $lasses_explode = explode(':', $lasses); $phone_id = str_replace("'", '', $lasses_explode[count($lasses_explode) - 1]); $phone_id = str_replace(",", '', $phone_id); } } /*get contact - get to http://dnepropetrovsk.dnp.olx.ua/ajax/misc/contact/phone/{ID}/*/ $ch = curl_init(); // //GET запрос указывается в строке URL curl_setopt($ch, CURLOPT_URL, 'http://dnepropetrovsk.dnp.olx.ua/ajax/misc/contact/phone/' . $phone_id . '/'); curl_setopt($ch, CURLOPT_HEADER, false); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30); curl_setopt($ch, CURLOPT_USERAGENT, 'Olx getter'); $data = curl_exec($ch); curl_close($ch); $phone = json_decode($data)->value; /*description*/ $description = $add->find('div[id=textContent]/p[class=pding10 lheight20 large]', 0)->plaintext; /*author name */ $author = $add->find('div[id=offeractions]/span[class=block color-5 brkword xx-large]', 0)->plaintext; $search_by_link = Ads::model()->findByAttributes(array('link' => $link)); if (!$search_by_link) { $ads = new Ads(); $ads->title = $title; $ads->description = $description; $ads->link = $link; $ads->author = $author; $ads->phone = $phone; $ads->price = $price; $ads->time_create = time(); $ads->read_status = 0; if ($ads->save()) { foreach ($add->find('div[id=offerdescription]/img') as $index => $im) { $images = new Images(); $images->ads_id = $ads->id; $images->link = $im->src; $images->save(); } } } // else break; } } }