public function getSearchInfo() { return ['video' => ['sql' => ' SELECT media_files.id, media_files.id as object_id, "MediaFile" as model_id, media_files.title, media_files.descr FROM ' . MediaFile::model()->tableName() . ' WHERE media_files.type="video" '], 'audio' => ['sql' => ' SELECT media_files.id, media_files.id as object_id, "MediaFile" as model_id, media_files.title, media_files.descr FROM ' . MediaFile::model()->tableName() . ' WHERE media_files.type="audio" '], 'albums' => ['sql' => ' SELECT media_albums.id, media_albums.id as object_id, "MediaAlbum" as model_id, media_albums.title, media_albums.descr FROM ' . MediaAlbum::model()->tableName() . ' ']]; }
public function actionManage($user_id = null, $q = null) { if ($user_id) { $this->user = User::model()->throw404IfNull()->findByPk($user_id); $this->page_title = 'Альбомы пользователя: ' . $this->user->getLink(); } else { $this->user = new User(); $this->page_title = 'Альбомы'; } $this->render('manage', ['dp' => MediaAlbum::model()->search($this->user, $q), 'is_my' => Yii::app()->user->id && Yii::app()->user->id == $user_id]); }
public function parse() { libxml_use_internal_errors(true); $doc = new DOMDocument(); /** @var $row DOMElement */ /** @var $attr DOMAttr */ while ($this->next_url) { $doc->loadHTML(file_get_contents($this->base_url . $this->next_url)); $xpath = new DOMXPath($doc); foreach ($xpath->query("//div[@class='content']//li/h3[@class='title']/a") as $row) { $id = end(explode('-', $row->getAttribute('href'))); //checko on existing if (MediaAlbum::model()->parent('sherdog.com', $id)->find()) { return true; } $gallery = ['title' => $row->textContent, 'id' => $id, 'imgs' => $this->parseGalleryPage($row->getAttribute('href'))]; $this->saveGallery($gallery); } $row = $xpath->query("//div[@class='col_left']//a[@rel='next']")->item(0); $this->next_url = $row ? $row->getAttribute('href') : false; } libxml_clear_errors(); }
protected function parseAlbum($db) { $collection = $db->sherdog_gallery; foreach ($collection->find() as $gallery) { if (isset($gallery['status']) && $gallery['status'] == 'parsed') { continue; } $model = MediaAlbum::model()->findByAttributes(['source' => 'sherdog.com', 'source_id' => $gallery['id']]); if ($model) { continue; } $transaction = Yii::app()->db->beginTransaction(); try { $this->saveGallery($gallery); $transaction->commit(); $gallery['status'] = 'parsed'; $collection->update(['id' => $gallery['id']], $gallery); } catch (Exception $e) { $transaction->rollback(); $collection->remove(['id' => $gallery['id']]); Yii::log($e, CLogger::LEVEL_ERROR); } } }