Beispiel #1
0
function __edit_post($uid, $post_id, $post_type, $property_type, $location, $num_rooms, $area, $price, $description)
{
    $post = Post::find($post_id);
    $user = User::find($uid);
    $user->viewedMatches()->detach($post->id);
    if ($post->post_type != $post_type) {
        SimilarPost::where('post_from', $post->id)->delete();
        // if post type had been changed, similar / matching relationship would have been broken.
        SimilarPost::where('post_to', $post->id)->delete();
        MatchingPost::where('post_from', $post->id)->delete();
        MatchingPost::where('post_to', $post->id)->delete();
    }
    $post->post_type = $post_type;
    $post->property_type = $property_type;
    $post->num_rooms = $num_rooms;
    $post->area = $area;
    $post->price = $price;
    $post->description = $description;
    if ($post->location != $location) {
        $post->location = $location;
        $r = getCoordinate($location);
        $post->lat = $r->results[0]->geometry->location->lat;
        $post->lng = $r->results[0]->geometry->location->lng;
    }
    $user->posts()->save($post);
    __process_post($post);
    // processes similar matches and finding matches
    return $post;
}
Beispiel #2
0
 function admin_update_post($f3, $params)
 {
     $token = $_SERVER['Authorization'];
     $admin = __get_auth_admin($token);
     $result = array();
     if ($admin == NULL) {
         $result['success'] = 'false';
         $result['message'] = 'You are not authorized';
     } else {
         $post_id = $params['id'];
         $post = Post::find($post_id);
         if ($post == NULL) {
             $result = array('success' => 'false', 'message' => 'No such post');
         } else {
             extract($_POST);
             if ($post->post_type != $post_type) {
                 SimilarPost::where('post_from', $post->id)->delete();
                 // if post type had been changed, similar / matching relationship would have been broken.
                 MatchingPost::where('post_from', $post->id)->delete();
             }
             $post->post_type = $post_type;
             $post->property_type = $property_type;
             $post->num_rooms = $num_rooms;
             $post->area = $area;
             $post->price = $price;
             $post->description = $description;
             if ($post->location != $location) {
                 $post->location = $location;
                 $r = getCoordinate($location);
                 $post->lat = $r->results[0]->geometry->location->lat;
                 $post->lng = $r->results[0]->geometry->location->lng;
             }
             $post->save();
             $result['success'] = 'true';
             $result['message'] = 'Updated';
             __process_post($post);
             // processes similar matches and finding matches
         }
     }
     echo json_encode($result);
 }