Exemplo n.º 1
0
 public function run()
 {
     $adminEmail = Config::get('madison.seeder.admin_email');
     $adminPassword = Config::get('madison.seeder.admin_password');
     // Login as admin to create docs
     $credentials = array('email' => $adminEmail, 'password' => $adminPassword);
     Auth::attempt($credentials);
     $admin = Auth::user();
     $group = Group::where('id', '=', 1)->first();
     // Create first doc
     $docSeedPath = app_path() . '/database/seeds/example.md';
     if (file_exists($docSeedPath)) {
         $content = file_get_contents($docSeedPath);
     } else {
         $content = "New Document Content";
     }
     $docOptions = array('title' => 'Example Document', 'content' => $content, 'sponsor' => $group->id, 'publish_state' => 'published', 'sponsorType' => Doc::SPONSOR_TYPE_GROUP);
     $document = Doc::createEmptyDocument($docOptions);
     //Set first doc as featured doc
     $featuredSetting = new Setting();
     $featuredSetting->meta_key = 'featured-doc';
     $featuredSetting->meta_value = $document->id;
     $featuredSetting->save();
     // Create second doc
     $docSeedPath = app_path() . '/database/seeds/example2.md';
     if (file_exists($docSeedPath)) {
         $content = file_get_contents($docSeedPath);
     } else {
         $content = "New Document Content";
     }
     $docOptions = array('title' => 'Second Example Document', 'sponsor' => $group->id, 'publish_state' => 'published', 'sponsorType' => Doc::SPONSOR_TYPE_GROUP);
     $document = Doc::createEmptyDocument($docOptions);
 }
Exemplo n.º 2
0
 public function createDocument()
 {
     if (!Auth::check()) {
         return Redirect::to('/')->with('error', 'You must be logged in');
     }
     $input = Input::all();
     $rules = array('title' => 'required');
     $validator = Validator::make($input, $rules);
     if ($validator->fails()) {
         return Redirect::to('documents')->withInput()->withErrors($validator);
     }
     try {
         $docOptions = array('title' => $input['title']);
         $user = Auth::user();
         $activeGroup = Session::get('activeGroupId');
         if ($activeGroup > 0) {
             $group = Group::where('id', '=', $activeGroup)->first();
             if (!$group) {
                 return Redirect::to('documents')->withInput()->with('error', 'Invalid Group');
             }
             if (!$group->userHasRole($user, Group::ROLE_EDITOR) && !$group->userHasRole($user, Group::ROLE_OWNER)) {
                 return Redirect::to('documents')->withInput()->with('error', 'You do not have permission to create a document for this group');
             }
             $docOptions['sponsor'] = $activeGroup;
             $docOptions['sponsorType'] = Doc::SPONSOR_TYPE_GROUP;
         } else {
             if (!$user->hasRole(Role::ROLE_INDEPENDENT_SPONSOR)) {
                 return Redirect::to('documents')->withInput()->with('error', 'You do not have permission to create a document as an individual');
             }
             $docOptions['sponsor'] = Auth::user()->id;
             $docOptions['sponsorType'] = Doc::SPONSOR_TYPE_INDIVIDUAL;
         }
         $document = Doc::createEmptyDocument($docOptions);
         if ($activeGroup > 0) {
             Event::fire(MadisonEvent::NEW_GROUP_DOCUMENT, array('document' => $document, 'group' => $group));
         }
         return Redirect::to("documents/edit/{$document->id}")->with('success_message', "Document Created Successfully");
     } catch (\Exception $e) {
         return Redirect::to("documents")->withInput()->with('error', "Sorry there was an error processing your request - {$e->getMessage()}");
     }
 }