public function actionManage() { $file = new MediaFile('search', 'youTube'); $model = $file->getApi(); if (isset($_GET[get_class($model)])) { $model->setAttributes($_GET[get_class($model)], false); } $this->render('manage', ["model" => $model]); }
public function run() { $file = new MediaFile('search', 'local'); $file->getDbCriteria()->mergeWith(['condition' => 'target_api IS NOT NULL AND status=:status', 'params' => ['status' => MediaFile::STATUS_ACTIVE]]); $files = $file->findAll(); foreach ($files as $file) { $local_api = $file->getApi(); if ($local_api instanceof LocalApi) { $file->setApi($file->target_api); $file->convertFromLocal($local_api); $file->target_api = null; $file->save(); } } }
protected function saveGallery($gallery) { $user = User::model()->findByAttributes(['email' => '*****@*****.**']); $album = new MediaAlbum(); $album->title = $gallery['title']; $album->model_id = get_class($user); $album->object_id = $user->id; $album->source = 'sherdog.com'; $album->source_id = $gallery['id']; $album->status = MediaAlbum::STATUS_ACTIVE; if (!$album->save()) { throw new CException(json_encode($album->getErrors())); } $order = 0; foreach ($gallery['imgs'] as $img) { if (!$img['path']) { continue; } $file = new MediaFile('insert', 'local'); $file->model_id = get_class($album); $file->object_id = $album->id; $file->tag = 'files'; $file->title = $img['title']; $file->remote_id = $img['path']; $file->order = ++$order; $file->getApi()->need_upload = false; if (!$file->save()) { throw new CException(json_encode($file->getErrors())); } } }
public static function parse($source) { $model = null; foreach (self::getConfiguration() as $api => $conf) { $model = new MediaFile('create', $api); if ($id = $model->getApi()->parse($source)) { $model->remote_id = $id; $model->api_name = $api; $model->type = $model->getApi()->getType(); return $model; } } return false; }