Advertisement
Guest User

Untitled

a guest
Aug 27th, 2014
190
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.62 KB | None | 0 0
  1. class SharedResourcesController extends BaseController {
  2. //Add a shared Resource to the DB
  3. //To do: Error checking and validation.
  4. public function handleResource(){
  5.  
  6. //Create Object
  7. $resource = new SharedResource;
  8. $resource->title = Input::get('title'); //Title of resource
  9. $resource->user_id = Input::get('user_id'); //User who uploads
  10. $resource->book_id = Input::get('book_id'); //Book it is associated with
  11. $resource->type_id = Input::get('type_id'); //Type of resource
  12.  
  13. //STORE LINKS
  14. //if type is link... 1
  15. if($resource->type_id == "1"){
  16. $resource->web_link = Input::get('link');
  17. }
  18. //if type is video...2
  19. if($resource->type_id == "2"){
  20. $resource->vid_link = Input::get('link');
  21. }
  22. //UPLOADING
  23. //If type is doc...3
  24. if($resource->type_id == "3"){
  25. if(Input::hasFile('file')){
  26. $destinationPath = '';
  27. $filename = '';
  28. $file = Input::file('file');
  29. $basename = Str::random(12);
  30. $extension = $file->getClientOriginalExtension();
  31. $destinationPath = public_path().'/file/';
  32. $filename = Str::slug($basename, '_').".".$extension;//Create the filename
  33. $file->move($destinationPath, $filename);
  34. $resource->doc_link = $filename;
  35. }
  36. }
  37. //if type is img...4
  38. if($resource->type_id == "4"){
  39. if(Input::hasFile('file')){
  40. $destinationPath = '';
  41. $filename = '';
  42. $file = Input::file('file');
  43. $basename = Str::random(12);
  44. $extension = $file->getClientOriginalExtension();
  45. $destinationPath = public_path().'/img/uploads/';
  46. $filename = Str::slug($basename, '_').".".$extension;//Create the filename
  47. $file->move($destinationPath, $filename);
  48. $resource->img_link = $filename;
  49. }
  50. }
  51.  
  52. //TAGS
  53. //Get the tags
  54. $tags = Array();
  55. $tags = explode(',', Input::get('tags'));
  56. foreach($tags as $tag){
  57. //Create a new Tag in DB - TO DO: Only Unique TAGS
  58. $newTag = new Tag;
  59. $newTag->name = $tag;
  60. $newTag->save();
  61. //Enter to resource tags
  62. }
  63.  
  64. //Entry to resouce_tags
  65.  
  66. //Save Object
  67. $resource->save();
  68. return Redirect::action('User_BaseController@getSharedResources')->with('success', 'Resouce Created!');
  69.  
  70. //Any errors return to Form...
  71. }
  72. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement