app/Http/Controllers/AndroidController.php
//Paliekamas atsiliepimas ir ivertinimas apie patalpas ir/arba vartotoja
Paliekamas atsiliepimas ir ivertinimas apie patalpas ir/arba vartotoja
Paliekamas atsiliepimas ir ivertinimas apie patalpas ir / arba vartotoja
public function paliktAtsIvert(Request $request)
    {
        $user = User::where('email', $request->input('email'))->first();
        if(Hash::check($request->input('api_token'), $user->api_token)) {
            $review = Review::where('user_id', $user->id)->where('statusas', (string)$request->input('statusas'));
            if(strcmp((string)$request->input('statusas'), 'skelbimas') == 0) {
                $post = Post::where('post_history_id', intval($request->input('rev_id')))->first();
                $rev_id = $post->id;
            }else
            {
                $rev_id = intval($request->input('rev_id'));
            }
               $review = $review->where('rev_id', $rev_id);
            if($review->get()->isNotEmpty())
            {
                return "exists";
            }else {
                $review = new Review();
                $review->statusas = (string)$request->input('statusas'); 
                $review->atsiliepimas = (string)$request->input('atsiliepimas');
                $review->ivertinimas = doubleval($request->input('ivertinimas'));
                $review->user_id = $user->id;
                if(strcmp((string)$request->input('statusas'), 'skelbimas') == 0)
                {
                    $post = Post::where('post_history_id', intval($request->input('rev_id')))->first();
                    $review->rev_id = $post->id;
                    $review->save();
                    $reviews = Review::where('rev_id', intval($request->input('rev_id')))->where('statusas', 'skelbimas');
                    $count = $reviews->count();
                    $ivertinimas = 0;
                    foreach ($reviews->get()->toArray() as $review)
                    {
                        $ivertinimas = $ivertinimas + $review['ivertinimas'];
                    }
                    $ivertinimas =  $ivertinimas + doubleval($request->input('ivertinimas'));
                    $count = $count + 1;
                    $ivertinimas = $ivertinimas/$count;
                    $post->ivertinimas = $ivertinimas;
                    $post->save();
                }else
                {
                    $user = User::find(intval($request->input('rev_id')));
                    $review->rev_id = $user->id;
                    $review->save();
                    $reviews = Review::where('rev_id', intval($request->input('rev_id')))->where('statusas', 'vartotojas');
                    $count = $reviews->count();
                    $ivertinimas = 0;
                    foreach ($reviews->get()->toArray() as $review)
                    {
                        $ivertinimas = $ivertinimas + $review['ivertinimas'];
                    }
                    $ivertinimas =  $ivertinimas + doubleval($request->input('ivertinimas'));
                    $count = $count + 1;
                    $ivertinimas = $ivertinimas/$count;
                    $user->ivertinimas = $ivertinimas;
                    $user->save();
                }
                return "success";
            }
        }
        return "no";
    }
public function paliktAtsIvert ( Request $ request ) { $ user = User :: where ( 'email' , $ request -> input ( 'email' ) ) -> first ( ) ; if ( Hash :: check ( $ request -> input ( 'api_token' ) , $ user -> api_token ) ) { $ review = Review :: where ( 'user_id' , $ user -> id ) -> where ( 'statusas' , ( string ) $ request -> input ( 'statusas' ) ) ; if ( strcmp ( ( string ) $ request -> input ( 'statusas' ) , 'skelbimas' ) == 0 ) { $ post = Post :: where ( 'post_history_id' , intval ( $ request -> input ( 'rev_id' ) ) ) -> first ( ) ; $ rev_id = $ post -> id ; } else { $ rev_id = intval ( $ request -> input ( 'rev_id' ) ) ; } $ review = $ review -> where ( 'rev_id' , $ rev_id ) ; if ( $ review -> get ( ) -> isNotEmpty ( ) ) { return " exists " ; } else { $ review = new Review ( ) ; $ review -> statusas = ( string ) $ request -> input ( 'statusas' ) ; $ review -> atsiliepimas = ( string ) $ request -> input ( 'atsiliepimas' ) ; $ review -> ivertinimas = doubleval ( $ request -> input ( 'ivertinimas' ) ) ; $ review -> user_id = $ user -> id ; if ( strcmp ( ( string ) $ request -> input ( 'statusas' ) , 'skelbimas' ) == 0 ) { $ post = Post :: where ( 'post_history_id' , intval ( $ request -> input ( 'rev_id' ) ) ) -> first ( ) ; $ review -> rev_id = $ post -> id ; $ review -> save ( ) ; $ reviews = Review :: where ( 'rev_id' , intval ( $ request -> input ( 'rev_id' ) ) ) -> where ( 'statusas' , 'skelbimas' ) ; $ count = $ reviews -> count ( ) ; $ ivertinimas = 0 ; foreach ( $ reviews -> get ( ) -> toArray ( ) as $ review ) { $ ivertinimas = $ ivertinimas + $ review [ 'ivertinimas' ] ; } $ ivertinimas = $ ivertinimas + doubleval ( $ request -> input ( 'ivertinimas' ) ) ; $ count = $ count + 1 ; $ ivertinimas = $ ivertinimas / $ count ; $ post -> ivertinimas = $ ivertinimas ; $ post -> save ( ) ; } else { $ user = User :: find ( intval ( $ request -> input ( 'rev_id' ) ) ) ; $ review -> rev_id = $ user -> id ; $ review -> save ( ) ; $ reviews = Review :: where ( 'rev_id' , intval ( $ request -> input ( 'rev_id' ) ) ) -> where ( 'statusas' , 'vartotojas' ) ; $ count = $ reviews -> count ( ) ; $ ivertinimas = 0 ; foreach ( $ reviews -> get ( ) -> toArray ( ) as $ review ) { $ ivertinimas = $ ivertinimas + $ review [ 'ivertinimas' ] ; } $ ivertinimas = $ ivertinimas + doubleval ( $ request -> input ( 'ivertinimas' ) ) ; $ count = $ count + 1 ; $ ivertinimas = $ ivertinimas / $ count ; $ user -> ivertinimas = $ ivertinimas ; $ user -> save ( ) ; } return " success " ; } } return " no " ; }
Paliekamas atsiliepimas ir ivertinimas apie patalpas ir/arba vartotoja
Paliekamas atsiliepimas ir ivertinimas apie patalpas ir / arba vartotoja
//Visada daromas tikrinimas ar useris is appso prisijunges //Jei is appso viskas ok //Ar atsiliepimas apie skelbima ar apie vartotoja //Ivertinimo dalis //Atrandamas skelbimas kuriam turetu priklausyti ivertinimas ir atsiliepimas //Skaiciuojamas ivertinimas ir issaugojamas tam paciam postui //CIA SITO REIKIA KADANGI NAUJAS REVIEW DAR PILNAI NEISSISAUGOJO! //Atrandamas vartotojas kuriam turetu priklausyti ivertinimas ir atsiliepimas //Skaiciuojamas ivertinimas ir issaugojamas tam paciam postui //CIA SITO REIKIA KADANGI NAUJAS REVIEW DAR PILNAI NEISSISAUGOJO!