Example #1
0
 private function _map_posted_data()
 {
     $fund = new Fundraiser();
     $fund->set_fundraiser_type($_POST['fundraiser_type']);
     $fund->set_title($_POST['title']);
     $fund->set_amount($_POST['amount']);
     $fund->set_end_date($_POST['end_date']);
     $fund->set_description($_POST['description']);
     //embedding youtube url
     $string = $_POST['video_url'];
     $search = '#(.*?)(?:href="https?://)?(?:www\\.)?(?:youtu\\.be/|youtube\\.com(?:/embed/|/v/|/watch?.*?v=))([\\w\\-]{10,12}).*#x';
     $replace = 'http:/utube.com/embed/$2';
     $url = preg_replace($search, $replace, $string);
     $fund->set_video_url($url);
     //for file
     $filename = $_FILES['image']['name'];
     $path = ROOT_PATH . "/fundraiser/campaign_images/";
     move_uploaded_file($_FILES['image']['tmp_name'], $path . $filename);
     $savepath = BASE_URL . "/fundraiser/campaign_images/";
     $fund->set_image($savepath . $filename);
     $fund->set_details($_POST['details']);
     return $fund;
 }
 public function get_by_id($id)
 {
     $fund = null;
     //DATABASE CONNECTION
     $this->db->connect();
     //SELECT BY ID
     $sql = "SELECT * FROM fundraiser WHERE id=?";
     //PREPARE
     $stmt = $this->db->initialize($sql);
     //BIND
     $stmt->bind_param("i", $id);
     //EXECUTE
     $stmt->execute();
     //BIND RESULT
     $stmt->bind_result($id, $fundraiser_type, $title, $amount, $end_date, $description, $image, $video_url, $details, $u_id);
     while ($stmt->fetch()) {
         //instantiate object
         $fund = new Fundraiser();
         $fund->set_id($id);
         $fund->set_title($title);
         $fund->set_fundraiser_type($fundraiser_type);
         $fund->set_amount($amount);
         $fund->set_end_date($end_date);
         $fund->set_description($description);
         $fund->set_image($image);
         $fund->set_video_url($video_url);
         $fund->set_details($details);
         $fund->set_u_id($u_id);
     }
     //CLOSE CONNECTION
     $this->db->close();
     return $fund;
 }