Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class SharedResourcesController extends BaseController {
- //Add a shared Resource to the DB
- //To do: Error checking and validation.
- public function handleResource(){
- //Create Object
- $resource = new SharedResource;
- $resource->title = Input::get('title'); //Title of resource
- $resource->user_id = Input::get('user_id'); //User who uploads
- $resource->book_id = Input::get('book_id'); //Book it is associated with
- $resource->type_id = Input::get('type_id'); //Type of resource
- //STORE LINKS
- //if type is link... 1
- if($resource->type_id == "1"){
- $resource->web_link = Input::get('link');
- }
- //if type is video...2
- if($resource->type_id == "2"){
- $resource->vid_link = Input::get('link');
- }
- //UPLOADING
- //If type is doc...3
- if($resource->type_id == "3"){
- if(Input::hasFile('file')){
- $destinationPath = '';
- $filename = '';
- $file = Input::file('file');
- $basename = Str::random(12);
- $extension = $file->getClientOriginalExtension();
- $destinationPath = public_path().'/file/';
- $filename = Str::slug($basename, '_').".".$extension;//Create the filename
- $file->move($destinationPath, $filename);
- $resource->doc_link = $filename;
- }
- }
- //if type is img...4
- if($resource->type_id == "4"){
- if(Input::hasFile('file')){
- $destinationPath = '';
- $filename = '';
- $file = Input::file('file');
- $basename = Str::random(12);
- $extension = $file->getClientOriginalExtension();
- $destinationPath = public_path().'/img/uploads/';
- $filename = Str::slug($basename, '_').".".$extension;//Create the filename
- $file->move($destinationPath, $filename);
- $resource->img_link = $filename;
- }
- }
- //TAGS
- //Get the tags
- $tags = Array();
- $tags = explode(',', Input::get('tags'));
- foreach($tags as $tag){
- //Create a new Tag in DB - TO DO: Only Unique TAGS
- $newTag = new Tag;
- $newTag->name = $tag;
- $newTag->save();
- //Enter to resource tags
- }
- //Entry to resouce_tags
- //Save Object
- $resource->save();
- return Redirect::action('User_BaseController@getSharedResources')->with('success', 'Resouce Created!');
- //Any errors return to Form...
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement