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())); } } }