Exemple #1
0
 public function action_create()
 {
     $project_input = Input::get('project');
     if ($project_input["project_type_id"] == "Other") {
         if (!Input::get('new_project_type_name')) {
             Session::flash('errors', array(__("r.flashes.new_project_no_project_type")));
             return Redirect::to_route('new_projects')->with_input();
         } elseif ($existing_project_type = ProjectType::where_name(Input::get('new_project_type_name'))->first()) {
             $project_input["project_type_id"] = $existing_project_type->id;
         } else {
             $project_type = new ProjectType(array('name' => Input::get('new_project_type_name')));
             $project_type->save();
             $project_input["project_type_id"] = $project_type->id;
         }
     }
     $project = new Project($project_input);
     $dt = new \DateTime($project_input["proposals_due_at"], new DateTimeZone('America/New_York'));
     // if user doesn't specify a date, set it to 1 month from now
     if (!$project_input["proposals_due_at"]) {
         $dt->modify('+1 month');
     }
     $dt->setTimeZone(new DateTimeZone('UTC'));
     $project->proposals_due_at = $dt;
     if ($project->validator()->passes()) {
         $project->save();
         $project->officers()->attach(Auth::officer()->id, array('owner' => true));
         return Redirect::to_route('project_template', array($project->id));
     } else {
         Session::flash('errors', $project->validator()->errors->all());
         return Redirect::to_route('new_projects')->with_input();
     }
 }