public function newversion($prop_id) { // $obj=DB::transaction(function($connection) { $var = INPUT::all(); $user = Auth::user()->user(); /*$mod=new Proposal; $mod=$mod::find($prop_id); $mod->field=$var['fieldName']; $mod->title>$var['title_g']; $mod->team_members=$var['teamMembers']; $mod->research_place=$var['researchPlace']; $mod->end_date_of_proposal=$var['duration']; $mod->proposed_amount=$var['grantNeeded']; $mod->description=$var['propDescription']; $mod->userid=$user['id']; $mod->save();*/ $ver = \App\proposal_version::where('proposal_id', '=', $prop_id)->first(); $ver_num = $ver->version_number; $ver_num += 1; $a = \App\Proposal::find($prop_id); $filename = $user['id'] . '_' . $a->title . '_' . $ver_num . '.'; $filename .= $var['grantProposal']->getClientOriginalExtension(); $var['grantProposal']->move(storage_path('uploads/grant_proposals'), $filename); $obj = new \App\proposal_version(); $obj::create(['version_number' => $ver_num, 'version_path' => $filename, 'proposal_id' => $prop_id]); $ver->destroy($ver->id); // }); return $this->allgrants(); }
/** * Like a comment. * * @return Response */ public function like() { // Get Proposal $proposal = Proposal::find($id); // Returns true if the current user is logged in, false otherwise. // if (Auth::check()) { // $user = Auth::user(); // $uuid = Uuid::uuid4(); // } // else { // $user = null; // $uuid = Uuid::uuid4(); // } if (isset($_POST['post_like'])) { // Retrieve user IP address $ip = $_SERVER['REMOTE_ADDR']; $proposal_id = $_POST['proposal_id']; // $voted_IP = array(); // // Get voters'IPs for the current proposal // $meta_IP = get_proposal_meta($proposal_id, "voted_IP"); // // if (!empty($meta_IP[0])) // $voted_IP = $meta_IP[0]; // Get votes count for the current proposal $like_count = get_proposal_like($proposal_id, 'votes_count', true); // Use has already voted ? if (!user_has_already_voted($proposal_id)) { $voted_IP[$ip] = time(); // Save IP and increase votes count update_proposal_like($proposal_id, 'voted_IP', $voted_IP); update_proposal_like($proposal_id, 'votes_count', ++$like_count); // Display count (ie jQuery return value) echo $like_count; } else { echo 'already'; } } exit; }
/** * Get proposal by ID. * * @param int $proposalId * * @return Collection */ public function byId($proposalId) { return Proposal::find($proposalId); }