/** * Store a newly created resource in storage. * * @return Response */ public function store($story) { $input = $request->all(); $story_id = $story; $chapter = new chapter(); $part->story_id = $story_id; $part->title = $input['title']; $part->description = $input['description']; //place of part $position = 0; $current_position = Part::where('story_id', $story)->pluck('position'); if (empty($current_positioncount)) { $current_position = 0; } else { $current_position; } //current_position = 1 if ($position <= $current_position) { $position = $current_position + 1; //expect position to go to 2 } else { $position = $current_position; } $part->position = $position; //setting position 2 $part->save(); //image $destinatonPath = ''; $filename = ''; $file = Input::file('image'); $destinationPath = public_path() . '/images/parts'; $filename = $part->id . '_' . $file->getClientOriginalName(); $uploadSuccess = $file->move($destinationPath, $filename); $addimage = Part::find($part->id); $addimage->image = $filename; $addimage->save(); return redirect('story/' . $story . '/edit'); }
private function getpart($type) { $items = Part::find(array("type=:type:", "bind" => array("type" => $type))); $parts = array(); foreach ($items as $index => $item) { $parts[$index] = $item; } return $parts; }
function get_undo_parts() { $results = array(); $count_sum = 0; /* 生产数量合计 */ $feeding_price_sum = 0; /* 投料金额合计 */ $parts = Part::find('all', array('conditions' => array('is_done = ?', 0), 'order' => 'id asc')); // foreach ($parts as $part) { $results['parts'][] = array('part_num' => $part->num, 'part_name' => $part->name, 'part_count' => $part->count, 'part_feeding_price' => $part->feeding_price, 'prod_type' => get_prod_type($part->production->type), 'prod_graphic_src' => get_prod_graphic_src($part->production->graphic_src)); $count_sum += $part->count; $feeding_price_sum += $part->feeding_price; } $results['count_sum'] = $count_sum; $results['feeding_price_sum'] = $feeding_price_sum; return $results; }
public function addTest($school) { $test = new Test(); $test->people = 2; $test->school_id = $school->school_id; $test->begin_time = '2014-12-5 00:00:00'; $test->end_time = '2014-12-15 23:59:59'; $parts = Part::find(); $test->exam_num = $parts->Count(); $test->description = '2014心理健康测评'; if (!$test->save()) { foreach ($school->getMessages() as $message) { throw new PDOException($message); } } foreach ($parts as $part) { $tprel = new Tprel(); $tprel->test_id = $test->t_id; $tprel->part_id = $part->p_id; $tprel->save(); } return $test; }