Exemplo n.º 1
0
 public function executeGetTodaysPostings(sfWebRequest $request)
 {
     try {
         $start = $request->getParameter('start');
         $start = empty($start) ? 0 : $start;
         $Postings = new Postings();
         list($result, $total) = $Postings->getTodaysPostings($_SESSION['userId'], $start);
         //hangouts that responded to user's posting
         if ($result->count() == 5) {
             $current_total = $start;
         } else {
             $current_total = $start + $result->count();
         }
         $hideLoadMorePostDiv = false;
         if ($total == $current_total) {
             $hideLoadMorePostDiv = true;
         }
         $postingData = array();
         foreach ($result as $val) {
             $photo = $val->getMember()->getPhoto();
             $path = $photo[0]->getPath();
             $postingData[] = array('photo' => $path, 'username' => $val->getMember()->getUsername(), 'gender' => $val->getGenderType(), 'date_to_hangout' => $val->getDateToHangout(), 'enddate_hangout' => $val->getEnddateHangout(), 'num_ppl' => $val->getNumPpl(), 'posting_enddt' => $val->getPostingEnddt(), 'starttime' => $val->getStarttime(), 'endtime' => $val->getEndtime(), 'posting_title' => $val->getPostingTitle(), 'posting_desc' => $val->getPostingDesc(), 'date_created' => $val->getDateCreated(), 'no_of_respondents' => $val->getRequester()->count());
         }
         $postingHtml = "<ul class='list-group'>";
         foreach ($postingData as $id => $val) {
             $remaining = CustomHangout::calculateRemainingDays(strtotime($val['posting_enddt']), 'till posting end time');
             $postingHtml .= '<li class="list-group-item">';
             $postingHtml .= "<div style='padding-bottom:5px;'>";
             $postingHtml .= "<div class='row'>";
             $postingHtml .= "<div class='col-xs-2' style='width:10.667%!important;'>";
             $postingHtml .= "<img height='80' width = '80' style='border:3px solid #DFF0D8;' src='/{$val['photo']}'/>";
             $postingHtml .= "</div>";
             $postingHtml .= "<div class='col-xs-10'>";
             $postingHtml .= "<div class='row'>";
             $postingHtml .= '<div class="col-xs-6"><span style="color:#008000;">' . strtoupper($val['username']) . '</div>';
             $postingHtml .= '<div class="col-xs-6 hangout-date">' . $val['posting_title'] . '</div>';
             $postingHtml .= "</div>";
             $postingHtml .= "<div class='row'>";
             $postingHtml .= '<div class="col-xs-12"><span style="color:#3E505C;">Start Time: </span>' . date("l, F j, Y", strtotime($val['date_to_hangout'])) . ' ' . date("h:i A", strtotime($val['starttime'])) . '</div>';
             $postingHtml .= "</div>";
             $postingHtml .= "<div class='row'>";
             $postingHtml .= '<div class="col-xs-12"><span style="color:#3E505C;">End Time: </span>' . date("l, F j, Y", strtotime($val['enddate_hangout'])) . ' ' . date("h:i A", strtotime($val['endtime'])) . '</div>';
             $postingHtml .= "</div>";
             $postingHtml .= "</div>";
             $postingHtml .= "<div class='row'>";
             $postingHtml .= '<div class="col-xs-12 remaining-hrs"><span class="label label-primary">' . strtoupper($remaining) . '</span></div>';
             $postingHtml .= "</div>";
             $postingHtml .= "</div>";
             $postingHtml .= "</div>";
             $postingHtml .= "</li>";
         }
         $postingHtml .= "</ul>";
         sleep(2);
         $data = array('data' => $postingHtml, 'start' => $start + 5, 'hideLoadMorePostDiv' => $hideLoadMorePostDiv);
         die(json_encode($data));
     } catch (Exception $e) {
         die($e->getMessage());
     }
 }
Exemplo n.º 2
0
 public function executeSearch(sfWebRequest $request)
 {
     $sortBy = $_REQUEST['sortBy'];
     $userId = $_SESSION['userId'];
     $post_id = $_REQUEST['id'];
     $page = $_GET['page'];
     $subSQL = "";
     $subSQL_4 = "";
     $orderBy = "ORDER BY cast(p.posting_enddt as datetime), p.date_to_hangout desc";
     $start = empty($_REQUEST['start']) ? 0 : (isset($_REQUEST['page']) ? $_REQUEST['page'] : $_REQUEST['start']);
     $limit = empty($_REQUEST['limit']) ? 5 : $_REQUEST['limit'];
     switch ($sortBy) {
         case 1:
             $subSQL_4 = '';
             //"WHERE (SELECT age FROM member WHERE id = $userId) BETWEEN p.age_range_1 AND p.age_range_2";
             break;
         case 2:
             $subSQL_4 = "WHERE (SELECT age FROM member WHERE id = {$userId}) BETWEEN p.age_range_1 AND p.age_range_2";
             break;
         case 3:
             $subSQL_4 = "WHERE \n                            (SELECT age FROM member where id = {$userId}) BETWEEN p.age_range_1 AND p.age_range_2\n                            AND m.gender = 'm'";
             break;
         case 4:
             $subSQL_4 = "WHERE \n                            (SELECT age FROM member where id = {$userId}) BETWEEN p.age_range_1 AND p.age_range_2\n                            AND m.gender = 'f'";
             break;
         case 5:
             $subSQL_4 = "WHERE m.gender in ('m')";
             break;
         case 6:
             $subSQL_4 = "WHERE m.gender in ('f')";
             break;
     }
     if (!empty($subSQL_4)) {
         $subSQL = $subSQL_4;
         if (isset($_REQUEST['country'])) {
             // $subSQL .= " AND m.country LIKE '%".addslashes($_GET['country'])."%'";
             if (isset($_REQUEST['city'])) {
                 $subSQL .= " AND lower(m.city) LIKE '%" . addslashes(strtolower($_REQUEST['city'])) . "%'";
             }
         }
         if (isset($_REQUEST['zipcode'])) {
             $subSQL .= " AND m.zip_code = '" . addslashes($_REQUEST['zipcode']) . "'";
         }
         if (isset($_REQUEST['state'])) {
             $subSQL .= " AND m.state = '" . addslashes($_REQUEST['state']) . "'";
         }
     } else {
         $tmp = array();
         if (isset($_REQUEST['city'])) {
             $tmp[] = " lower(m.city) LIKE '%" . addslashes(strtolower($_REQUEST['city'])) . "%'";
         }
         if (isset($_REQUEST['zipcode'])) {
             $tmp[] = " m.zip_code = '" . addslashes($_REQUEST['zipcode']) . "'";
         }
         if (isset($_REQUEST['state'])) {
             $tmp[] = " m.state = '" . addslashes($_REQUEST['state']) . "'";
         }
         $subSQL .= count($tmp) > 0 ? ' WHERE ' . implode(" AND ", $tmp) : '';
     }
     if (empty($subSQL)) {
         $subSQL = " WHERE p.status = 1 AND posting_enddt >= CURRENT_TIMESTAMP \n              AND p.num_ppl > (SELECT count(*) FROM requester WHERE posting_id = p.id AND request_status_id = 4)";
     } else {
         $subSQL .= " AND p.status = 1 AND posting_enddt >= CURRENT_TIMESTAMP \n              AND p.num_ppl > (SELECT count(*) FROM requester WHERE posting_id = p.id AND request_status_id = 4)";
     }
     //retrieve all postings based on search criteria
     $sql = "SELECT \n                    m.username, \n                    CASE\n                        WHEN p.gender_type = 'm' THEN 'Male'\n                        WHEN p.gender_type = 'f' THEN 'Female'\n                    ELSE 'Any'\n                    END AS gender, \n                    date_to_hangout, \n                    num_ppl,\n                    age_range_1, \n                    age_range_2, \n                    starttime, \n                    p.id as posting_id,\n                    endtime, \n                    posting_title, \n                    posting_desc, \n                    ph.path, \n                    posting_enddt,\n                    m.zip_code,\n                    (SELECT count(*) FROM requester WHERE posting_id = p.id AND request_status_id = 4) as total_requesters,\n                    ( SELECT latitude FROM zipcodes WHERE zipcode = m.zip_code limit 1) as latitude,\n                    ( SELECT longitude FROM zipcodes WHERE zipcode = m.zip_code limit 1) as longitude,\n                    ( SELECT city FROM zipcodes WHERE zipcode = m.zip_code limit 1) as city,\n                    ( SELECT state FROM zipcodes WHERE zipcode = m.zip_code limit 1) as state\n                FROM `postings` p\n                JOIN member m ON p.member_id = m.id\n                LEFT JOIN photo ph ON m.profile_picture_id = ph.id {$subSQL} {$orderBy}";
     try {
         $st = $this->conn->execute($sql);
         $result = $st->fetchAll();
         $total_count = count($result);
         $total_page = $total_count / $limit;
         $total_page = is_int($total_page) ? $total_page : (int) $total_page + 1;
         $sliced_data = array_slice($result, $start, $limit);
         $q = "SELECT \n                zip_code,  \n                (SELECT latitude FROM zipcodes WHERE zipcode = zip_code limit 1) AS latitude,\n                (SELECT longitude FROM zipcodes WHERE zipcode = zip_code limit 1) AS longitude\n              FROM member WHERE id = {$_SESSION['userId']}";
         $user_result = $this->conn->fetchAll($q);
     } catch (Exception $e) {
         die($e->getMessage());
     }
     $postings = array();
     $postings_nonzero_dist = array();
     $postings_zero_dist = array();
     foreach ($sliced_data as $val) {
         $distance = $this->calculateDistance($user_result[0]['latitude'], $user_result[0]['longitude'], $val['latitude'], $val['longitude'], 'M');
         if (isset($_REQUEST['miles']) && is_numeric($_REQUEST['miles']) && $distance > $_REQUEST['miles']) {
             continue;
         }
         if ($distance == 0) {
             $postings_zero_dist[$val['posting_id']] = $distance;
         } else {
             $postings_nonzero_dist[$val['posting_id']] = $distance;
         }
         $postings[$val['posting_id']] = $distance;
     }
     if ($sortBy == 1 || isset($_REQUEST['miles']) && !empty($_REQUEST['miles'])) {
         asort($postings_nonzero_dist);
         //sort starting from nearest distance in miles
         $postings = array();
         $tmpArray = array();
         $tmpArray[] = $postings_zero_dist;
         $tmpArray[] = $postings_nonzero_dist;
         foreach ($tmpArray as $postings_arr) {
             foreach ($postings_arr as $i => $val) {
                 $postings[$i] = $val;
             }
         }
     }
     if (empty($postings)) {
         $element = "<h5> No results found.</h5>";
         sleep(3);
         die($element);
     }
     foreach ($sliced_data as $x => $val) {
         if (!array_key_exists($val['posting_id'], $postings)) {
             continue;
         }
         $val['distance'] = $postings[$val['posting_id']];
         $postings[$val['posting_id']] = $val;
     }
     if ($sortBy == 1 || isset($_REQUEST['miles']) && !empty($_REQUEST['miles'])) {
         $tmpArray = array();
         foreach ($postings as $posting_id => $val) {
             $tmpArray[$val['distance']][$val['posting_enddt']][] = $val;
             ksort($tmpArray[$val['distance']]);
         }
         $postings = array();
         foreach ($tmpArray as $distance => $val) {
             foreach ($val as $posting_enddt => $v) {
                 foreach ($v as $x) {
                     $postings[$x['posting_id']] = $x;
                 }
             }
         }
     }
     //        $element = '<ul id="portfolio">';
     //        foreach($postings as $val)
     //        {
     //            $date = strtotime($val['posting_enddt']);
     //            $remaining = CustomHangout::calculateRemainingDays($date, 'left');
     //
     //            $element .= '<li class="cms integration portfolio_one_column grid_12 alpha tabProfileBox" >';
     //            $element .= '<div class="featured-image image-fade grid_5 alpha" style="width:200px!important;">
     //                            <a class="portfolio" href="/'.$val['path'].'">
     //                            <img height=155 width = "211" alt="'.$val['username'].'" src="/'.$val['path'].'" />
     //                            </a>
     //                        </div>';
     //            $element .= '<div class="portfolio-page-meta grid_4" style="width:435px!important;height:152px;border:0px solid;">';
     //            $element .= '<h5 class="portfolio-title"><div id="post_'.$val['posting_id'].'" style="font-weight:bold;">'.$val['posting_title'].'</div></h5>'. '<span style="color:red;font-weight:bold;">*</span>'.$remaining;
     //            $element .= '<div class="hr-pattern" ></div>';
     //
     //            $element .= '<div class="portfolio-excerpt" style="font-weight:bold;" id="post-blockquote">';
     //            //$element .= '<blockquote>'.substr($val['posting_desc'],0,200).'<a class="read-more" href="/index.php/postings/post?id='.$val['posting_id'].'&sort_by='.$sortBy.'&page='.($start).'" >&nbsp; View Posting &rarr;</a> </blockquote>';
     //            $element .= '<blockquote>'.substr($val['posting_desc'],0,200).'<a class="read-more" href="/index.php/postings/post/id/'.$val['posting_id'].'/sort_by/'.$sortBy.'/page/'.($start).'" >&nbsp; View Posting &rarr;</a> </blockquote>';
     //            $element .= '</div>';
     //            $element .= '</div>';
     //
     //            $element .= '<div class="grid_3 omega" style="float:right;width:265px!important;">';
     //            $element .= '<div style="margin-top:29px;font-weight:bold;"> More Details </div>';
     //            $element .= '<div class="hr-pattern" ></div>';
     //
     //            $element .= '<div class=""> <b> HangOut Date: </b> '.date('l, F j, Y', strtotime($val['date_to_hangout'])).' </div>';
     //            $element .= '<div class=""> <b> Start & End Time: </b> '.$val['starttime'].' - '.$val['endtime'].' </div>';
     //            $element .= '<div class=""> <b> Posting End Date: </b> '.date('l, F j, Y',  strtotime($val['posting_enddt'])).'</div>';
     //            $element .= '<div class=""> <b> Posting End Time: </b> '.date('h:i A',  strtotime($val['posting_enddt'])).' </div>';
     //            $element .= '<div class=""> <b> Distance in Miles: </b> '.number_format($val['distance'],2).' Miles</div>';
     //            $element .= '<div class=""> <b> Address: </b> '.$val['city'].', '.$val['state'].'</div>';
     //            $element .= '</div>';
     //
     //            $element .= '<div class="clear"></div>';
     //            $element .= '</li>';
     //        }
     //
     //        $element .= '</ul>';
     $element = "";
     foreach ($postings as $val) {
         $date = strtotime($val['posting_enddt']);
         $remaining = CustomHangout::calculateRemainingDays($date, '');
         $element .= '<div class="well" style="background-color:#FFF;">';
         $element .= '<div class="media">';
         $element .= '<div class="media-body">';
         #post title
         $element .= '<h4 class="media-heading">' . $val['posting_title'] . '</h4>';
         #picture of the owner's post
         $element .= '<a class="pull-left" href="#">';
         $element .= '<img class="img-thumbnail" style="height: 100px; width: 100px; margin-right: 5px;" src="/' . $val['path'] . '">';
         $element .= '</a>';
         #owner's username
         $element .= '<p class="text-right">By: ' . $val['username'] . '</p>';
         #post description
         $element .= '<p>' . $val['posting_desc'] . '</p>';
         #other details
         $element .= '<ul class="list-inline list-unstyled" style="font-size:11px;">';
         $element .= '<li><span style="font-weight: bold;">Expires in: </span>' . $remaining . '</li>';
         $element .= '<li>|</li>';
         $element .= '<li><span style="font-weight: bold;">Slots Left: </span>' . ($val['num_ppl'] - $val['total_requesters']) . '</li>';
         $element .= '<li>|</li>';
         $element .= '<li><span style="font-weight: bold;">When: </span>' . date('l, F j, Y', strtotime($val['date_to_hangout'])) . " " . $val['starttime'] . ' - ' . $val['endtime'] . '</li>';
         $element .= '<li>|</li>';
         $element .= '<li><span style="font-weight: bold;">Where: </span>' . $val['city'] . ', ' . $val['state'] . '</li>';
         $element .= '<li>|</li>';
         $element .= '<li><span style="font-weight: bold;">Distance in Miles: </span>' . number_format($val['distance'], 2) . ' Miles</li>';
         $element .= '<li>|</li>';
         $element .= '<li><a href="#" style="font-weight: bold;">View Post</a></li>';
         $element .= '</ul>';
         #end of other details
         $element .= '</div></div></div>';
     }
     $data = array('data' => $element, 'total_count' => $total_count, 'total_page' => $total_page, 'post_id' => $post_id);
     die(json_encode($data));
 }