app/Http/Controllers/AndroidController.php
//Nuoma nutraukiama ir isnuomotos patalpos vel patampa skelbimu ir taip pat istorijos objektu
Nuoma nutraukiama ir isnuomotos patalpos vel patampa skelbimu ir taip pat istorijos objektu
Nuoma nutraukiama ir isnuomotos patalpos vel patampa skelbimu ir taip pat istorijos objektu
public function postNutraukt(Request $request)
    {
        $user = User::where('email', $request->input('email'))->first();
        if (Hash::check($request->input('api_token'), $user->api_token)) {
            $postHist = Post::find(intval($request->input('post_id')));
            $postHist->statusas = 'istorija';
            $postHist->save();
            $post = new Post();
            $post->patalpuTipas = $postHist->patalpuTipas;
            $post->savivaldybe = $postHist->savivaldybe;
            $post->gyvenviete = $postHist->gyvenviete;
            $post->mikroRaj = $postHist->mikroRaj;
            $post->gatve = $postHist->gatve;
            $post->plotas = $postHist->plotas;
            $post->komentaras = $postHist->komentaras;
            $post->kaina = $postHist->kaina;
            $post->statusas = 'skelbimas';
            $post->ivertinimas = $postHist->ivertinimas;
            $post->nuomin_id = 0;
            $post->apsilankymas = "";
            $post->post_history_id = $postHist->id;
            $user->posts()->save($post);
            switch ($post->patalpuTipas) {
                case "Namas":
                    $namHist = Nam::where('post_id', $postHist->id)->first();
                    $namas = new Nam();
                    $namas->namoNr = $namHist->namoNr;
                    $namas->pastatoTip = $namHist->pastatoTip;
                    $namas->irengimoTip = $namHist->irengimoTip;
                    $namas->sildymoTip = $namHist->sildymoTip;
                    $namas->metai = $namHist->metai;
                    $namas->namoTip =  $namHist->namoTip;
                    $post->nam()->save($namas);
                    break;
                case "Butas":
                    $butHist = But::where('post_id', $postHist->id)->first();
                    $butas = new But();
                    $butas->namoNr = $butHist->namoNr;
                    $butas->butoNr = $butHist->butoNr;
                    $butas->aukstas =  $butHist->aukstas;
                    $butas->kambSk = $butHist->kambSk;
                    $butas->pastatoTip = $butHist->pastatoTip;
                    $butas->irengimoTip = $butHist->irengimoTip;
                    $butas->sildymoTip = $butHist->sildymoTip;
                    $butas->aukstuSk = $butHist->aukstuSk;
                    $butas->metai = $butHist->metai;
                    $post->but()->save($butas);
                    break;
            }
            $photos = Photo::where('post_id', $postHist->id)->get();
            if($photos->isNotEmpty()) {
                foreach($photos as $photo)
                {
                    $prefix = "http://marbar4.stud.if.ktu.lt/Nuoma2/storage/app/nuotraukos/";
                    $prefix2 = "http://marbar4.stud.if.ktu.lt/Nuoma2/storage/app/";
                    $orgPath = str_replace($prefix, "", $photo->path);
                    $newPath = 'nuotraukos/N'.$orgPath;
                    $orgPath = 'nuotraukos/'.$orgPath;
                    if (strcmp($photo->statusas, 'pagrindine') == 0) {
                        Storage::copy($orgPath, $newPath);
                        $photoz = new Photo();
                        $photoz->path = $prefix2.$newPath;
                        $photoz->statusas = 'pagrindine';
                        $photoz->post_id = $post->id;
                        $photoz->save();
                    } else if (strcmp($photo->statusas, 'paprasta') == 0){
                        Storage::copy($orgPath, $newPath);
                        $photoz = new Photo();
                        $photoz->path = $prefix2.$newPath;
                        $photoz->statusas = 'paprasta';
                        $photoz->post_id = $post->id;
                        $photoz->save();
                    }
                }
            }
            $reviews = Review::where('statusas', 'skelbimas')->where('rev_id', $postHist->id)->get();
            foreach ($reviews as $review)
            {
                $review->rev_id = $post->id;
                $review->save();
            }
            return "success";
        }
        return "no";
    }
public function postNutraukt ( Request $ request ) { $ user = User :: where ( 'email' , $ request -> input ( 'email' ) ) -> first ( ) ; if ( Hash :: check ( $ request -> input ( 'api_token' ) , $ user -> api_token ) ) { $ postHist = Post :: find ( intval ( $ request -> input ( 'post_id' ) ) ) ; $ postHist -> statusas = 'istorija' ; $ postHist -> save ( ) ; $ post = new Post ( ) ; $ post -> patalpuTipas = $ postHist -> patalpuTipas ; $ post -> savivaldybe = $ postHist -> savivaldybe ; $ post -> gyvenviete = $ postHist -> gyvenviete ; $ post -> mikroRaj = $ postHist -> mikroRaj ; $ post -> gatve = $ postHist -> gatve ; $ post -> plotas = $ postHist -> plotas ; $ post -> komentaras = $ postHist -> komentaras ; $ post -> kaina = $ postHist -> kaina ; $ post -> statusas = 'skelbimas' ; $ post -> ivertinimas = $ postHist -> ivertinimas ; $ post -> nuomin_id = 0 ; $ post -> apsilankymas = " " ; $ post -> post_history_id = $ postHist -> id ; $ user -> posts ( ) -> save ( $ post ) ; switch ( $ post -> patalpuTipas ) { case " Namas " : $ namHist = Nam :: where ( 'post_id' , $ postHist -> id ) -> first ( ) ; $ namas = new Nam ( ) ; $ namas -> namoNr = $ namHist -> namoNr ; $ namas -> pastatoTip = $ namHist -> pastatoTip ; $ namas -> irengimoTip = $ namHist -> irengimoTip ; $ namas -> sildymoTip = $ namHist -> sildymoTip ; $ namas -> metai = $ namHist -> metai ; $ namas -> namoTip = $ namHist -> namoTip ; $ post -> nam ( ) -> save ( $ namas ) ; break ; case " Butas " : $ butHist = But :: where ( 'post_id' , $ postHist -> id ) -> first ( ) ; $ butas = new But ( ) ; $ butas -> namoNr = $ butHist -> namoNr ; $ butas -> butoNr = $ butHist -> butoNr ; $ butas -> aukstas = $ butHist -> aukstas ; $ butas -> kambSk = $ butHist -> kambSk ; $ butas -> pastatoTip = $ butHist -> pastatoTip ; $ butas -> irengimoTip = $ butHist -> irengimoTip ; $ butas -> sildymoTip = $ butHist -> sildymoTip ; $ butas -> aukstuSk = $ butHist -> aukstuSk ; $ butas -> metai = $ butHist -> metai ; $ post -> but ( ) -> save ( $ butas ) ; break ; } $ photos = Photo :: where ( 'post_id' , $ postHist -> id ) -> get ( ) ; if ( $ photos -> isNotEmpty ( ) ) { foreach ( $ photos as $ photo ) { $ prefix = " http://marbar4.stud.if.ktu.lt/Nuoma2/storage/app/nuotraukos/ " ; $ prefix2 = " http://marbar4.stud.if.ktu.lt/Nuoma2/storage/app/ " ; $ orgPath = str_replace ( $ prefix , " " , $ photo -> path ) ; $ newPath = 'nuotraukos/N' . $ orgPath ; $ orgPath = 'nuotraukos/' . $ orgPath ; if ( strcmp ( $ photo -> statusas , 'pagrindine' ) == 0 ) { Storage :: copy ( $ orgPath , $ newPath ) ; $ photoz = new Photo ( ) ; $ photoz -> path = $ prefix2 . $ newPath ; $ photoz -> statusas = 'pagrindine' ; $ photoz -> post_id = $ post -> id ; $ photoz -> save ( ) ; } else if ( strcmp ( $ photo -> statusas , 'paprasta' ) == 0 ) { Storage :: copy ( $ orgPath , $ newPath ) ; $ photoz = new Photo ( ) ; $ photoz -> path = $ prefix2 . $ newPath ; $ photoz -> statusas = 'paprasta' ; $ photoz -> post_id = $ post -> id ; $ photoz -> save ( ) ; } } } $ reviews = Review :: where ( 'statusas' , 'skelbimas' ) -> where ( 'rev_id' , $ postHist -> id ) -> get ( ) ; foreach ( $ reviews as $ review ) { $ review -> rev_id = $ post -> id ; $ review -> save ( ) ; } return " success " ; } return " no " ; }
Nuoma nutraukiama ir isnuomotos patalpos vel patampa skelbimu ir taip pat istorijos objektu
Nuoma nutraukiama ir isnuomotos patalpos vel patampa skelbimu ir taip pat istorijos objektu
//Skelbimas issaugojamas kaip istorija bus skirta atsiliepimam ir vertinimam //Idedamas naujas skelbimas su tokiais pat duomenim //Perkopijuojamos nuotraukos i naujaji skelbima //statusas nustatomas ar pagrindine ar ne, ir per kopijuojamos tik pagrindines ir paprastos //Atsiliepimai prijungiami prie naujojo skelbimo