/** * Creates a new model. * If creation is successful, the browser will be redirected to the 'view' page. */ public function actionCreate() { $model = new Youtube(); // Uncomment the following line if AJAX validation is needed // $this->performAjaxValidation($model); if (isset($_POST['Youtube'])) { $model->attributes = $_POST['Youtube']; if ($model->save()) { $this->redirect(array('view', 'id' => $model->id)); } } $this->render('create', array('model' => $model)); }
/** * Creates a new model. * If creation is successful, the browser will be redirected to the 'view' page. */ public function actionCreate() { $model = new Youtube(); // Uncomment the following line if AJAX validation is needed // $this->performAjaxValidation($model); if (isset($_POST['Youtube'])) { $model->attributes = $_POST['Youtube']; $model->created_on = new CDbExpression('NOW()'); $model->created_by = Yii::app()->user->id; if ($model->save()) { Yii::app()->user->setFlash('success', 'Youtube vidio created successfully'); $this->redirect(array('view', 'id' => $model->id)); } } $this->render('create', array('model' => $model)); }
public function postAdd() { if (!$this->checkRoute()) { return Redirect::route('index'); } $title = 'Add A Youtube Video / Playlist - ' . $this->site_name; $input = Input::only('url', 'category', 'modpack', 'mod'); $validator = Validator::make($input, ['url' => 'required']); if ($validator->fails()) { return Redirect::action('YoutubeController@getadd')->withErrors($validator)->withInput(); } $youtube = new Youtube(); $processed_url = $this->processURL($input['url']); if (!$processed_url['type']) { return Redirect::action('YoutubeController@getadd')->withErrors(['message' => 'Unable to process URL.'])->withInput(); } $youtube_information = $youtube->getVideoInfo($processed_url['id'], $processed_url['type']); if (!$youtube_information) { return Redirect::action('YoutubeController@getadd')->withErrors(['message' => 'Unable to process Youtube API.'])->withInput(); } $youtube_information = $youtube_information->items[0]; $youtube->type = $processed_url['type']; $youtube->title = $youtube_information->snippet->title; $youtube->youtube_id = $youtube_information->id; $youtube->channel_title = $youtube_information->snippet->channelTitle; $youtube->channel_id = $youtube_information->snippet->channelId; $youtube->thumbnail = $youtube_information->snippet->thumbnails->medium->url; $youtube->category_id = $input['category']; if ($input['modpack']) { $youtube->modpack_id = $input['modpack']; } elseif ($input['mod']) { $youtube->mod_id = $input['mod']; } $youtube->last_ip = Request::getClientIp(); $success = $youtube->save(); if ($success) { Cache::tags('modpacks')->flush(); Cache::tags('mods')->flush(); Queue::push('BuildCache'); return View::make('youtube.add', ['title' => $title, 'success' => true, 'categories' => $this->categories]); } return Redirect::action('YoutubeController@getadd')->withErrors(['message' => 'Unable to add modpack code.'])->withInput(); }