Esempio n. 1
0
File: admin.php Progetto: ajb/rfpez
 public function action_project_sections_toggle_source($id)
 {
     $section = ProjectSection::find($id);
     $section->source = $section->source == 1 ? 0 : 1;
     $section->save();
     return Redirect::back();
 }
Esempio n. 2
0
 public static function change_times_used($section_ids_or_array, $direction)
 {
     if (!is_array($section_ids_or_array)) {
         $section_ids_or_array = array($section_ids_or_array);
     }
     foreach ($section_ids_or_array as $section_id) {
         $section = ProjectSection::find($section_id);
         if ($section) {
             $new_times_used = $section->times_used + $direction;
             if ($new_times_used >= 0) {
                 $section->times_used = $new_times_used;
             }
             $section->save();
         }
     }
 }
Esempio n. 3
0
 public function action_sections_post()
 {
     $project = Config::get('project');
     $section_id = Input::get('section_id');
     $section_input = Input::get('project_section');
     if ($section_id) {
         // we're editing an existing section
         $section = ProjectSection::find($section_id);
         if ($section->can_edit_without_forking()) {
             $section->fill($section_input);
             $section->body = htmLawed($section->body, array('safe' => true));
             $section->times_used = 1;
             $section->created_by_project_id = $project->id;
             $section->save();
             if (trim($section_input["title"]) == "" && trim($section_input["body"]) == "") {
                 $project->remove_section($section->id);
             }
         } else {
             $new_section = $section->fork($project->id, $section_input);
             $new_section->body = htmLawed($new_section->body, array('safe' => true));
             $new_section->save();
             $project->replace_section($section->id, $new_section->id);
             if (trim($section_input["title"]) == "" && trim($section_input["body"]) == "") {
                 $project->remove_section($new_section->id);
             }
         }
     } elseif (trim($section_input["title"]) != "" && trim($section_input["body"]) != "") {
         // we're adding a new sction
         $section = new ProjectSection($section_input);
         $section->body = htmLawed($section->body, array('safe' => true));
         $section->created_by_project_id = $project->id;
         $section->save();
         $section->project_types()->attach($project->project_type_id);
         $project->add_section($section->id);
     }
     return Response::json(array('status' => 'success', 'sections_for_editing_html' => View::make('projects.partials.sections_for_editing')->with('project', $project)->render()));
 }