Best Atoum code snippet using adapter.__set
PostController.php
Source:PostController.php
...24 public function crear(){25 if(isset($_SESSION['id'])){26 $post=new Post($this->adapter);27 $user=new Usuario($this->adapter);28 $user->__set("id",$_SESSION['id']);29 $privacidad=(int)$_POST["privacidad"]==0||(int)$_POST["privacidad"]==0?(int)$_POST["privacidad"]:1;30 $titulo=isset($_POST["titulo"])?$_POST['titulo']:NULL;31 $cuerpo=isset($_POST["cuerpo"])?$_POST['cuerpo']:NULL;32 $palabras=isset($_POST["palabras"])?$_POST["palabras"]:NULL;33 $palabras=substr($palabras,1);34 $si=explode("#",$palabras);35 $fotos=array($_FILES['img1'],$_FILES['img2'],$_FILES['img3']);36 if(!$titulo||!$cuerpo){37 $_SESSION['error']="El post debe tener al menos un titulo y una descripción";38 $this->redirect("post","");39 }else{40 $post->__set('user',$user);41 $post->__set('privacidad',$privacidad);42 $post->__set('cuerpo',$cuerpo);43 $post->__set("titulo",$titulo);44 $i=1;45 foreach($si as $palabra){46 47 $post->__set("palabra".$i,$palabra);48 $i++;49 }50 $i=1;51 foreach($fotos as $foto){52 53 $rec="img".$i;54 $fileName=$foto['name'];55 $tmpName=$foto['tmp_name'];56 $fileSize=$foto['size'];57 $fileType=$foto['type'];58 if($fileType=="image/jpeg" || $fileType=="image/jpg" || $fileType=="image/png" || $fileType=="image/gif")59 {60 $imagenes=$_SERVER['DOCUMENT_ROOT']."/LABII/public/img/post/";61 $extension=explode("/",$fileType);62 $fileName=bin2hex(random_bytes(8)).'.'.$extension[1];63 $filePath=$imagenes.$fileName;64 $serverName="http://localhost/LABII/public/img/post/".$fileName;65 if($result=move_uploaded_file($tmpName, $filePath)){66 $post->__set($rec,$serverName);67 }else{68 $_SESSION['error']="No se pudo cargar la imagen ".$fileName;69 $this->redirect("post","");70 }}71 $i++;72 }73 $save=$post->save();74 $this->redirect("usuario","verMuro");75 }76 }77 }78 public function actualizar(){79 $pd=new Post($this->adapter);80 $post=$pd->getById($_GET['id']);81 $ud=new Usuario($this->adapter);82 $usuario=$ud->getById($_SESSION['id']);83 if($ud->getUnseen($_SESSION['id'])==!NULL){84 $notificaciones=sizeof($ud->getUnseen($_SESSION["id"]));}else{$notificaciones=0;}85 $this->view("EditarPost",array(86 "notis"=>$notificaciones,87 "post"=>$post,88 "usuario"=>$usuario89 ));90 }91 public function enviar(){92 $post=new Post($this->adapter);93 $user=new Usuario($this->adapter);94 $user->__set("id",$_SESSION['id']);95 $id=$_POST['id'];96 $post->__set("id",$id);97 if(isset($_POST['eliminar'])){98 $post->__set("status",0);99 $post->__set("porMi","si");100 $post->save();101 $this->redirect("usuario","verMuro");102 } else {103 $privacidad=(int)$_POST["privacidad"]==1||(int)$_POST["privacidad"]==0?(int)$_POST["privacidad"]:1;104 $titulo=isset($_POST["titulo"])?$_POST['titulo']:NULL;105 $cuerpo=isset($_POST["cuerpo"])?$_POST['cuerpo']:NULL;106 $palabra1=isset($_POST["palabra1"])?substr($_POST["palabra1"],1):NULL;107 $palabra2=isset($_POST["palabra2"])?substr($_POST["palabra2"],1):NULL;108 $palabra3=isset($_POST["palabra3"])?substr($_POST["palabra3"],1):NULL;109 if(!$cuerpo||!$titulo){110 $_SESSION['error']="No se pudo actualizar el post";111 $this->redirect("usuario","verMuro");112 } else {113 $post->__set("user",$user);114 $post->__set("privacidad",$privacidad);115 $post->__set("titulo",$titulo);116 $post->__set("palabra1",$palabra1);117 $post->__set("palabra2",$palabra2);118 $post->__set("palabra3",$palabra3);119 $post->__set("cuerpo",$cuerpo);120 $save=$post->save();121 $this->redirect("usuario","verMuro");122 }123 }124 }125 public function comentar(){126 $com=new Comentario($this->adapter);127 $usuario=new Usuario($this->adapter);128 $post=new Post($this->adapter);129 $cuerpo=isset($_POST['txt'])?$_POST['txt']:"";130 $usuario->__set("id",$_SESSION['id']);131 $com->__set("user",$usuario);132 $com->__set("cuerpo",$cuerpo);133 $post->__set("id",$_GET['idPost']);134 $com->__set("post",$post);135 $save=$com->save();136 $allComentarios=$com->getComentarios($_GET['idPost']);137 $_SESSION['unico']=$_GET['idPost'];138 $_SESSION['nCom']=$save;139 $this->redirect('notificaciones','crear');140 }141}142?>...
DenunciaController.php
Source:DenunciaController.php
...13 }14 public function denunciarPost(){15 $dPost= new DenunciaPost($this->adapter);16 $post=new Post($this->adapter);17 $post->__set("id",$_GET['id']);18 $dPost->__set("post",$post);19 $usuario=new Usuario($this->adapter);20 $usuario->__set("id",$_SESSION['id']);21 $dPost->__set("user",$usuario);22 $dPost->__set("motivo",$_POST['motivo']);23 $save=$dPost->save();24 $this->redirect("usuario","index");25 }26 public function denunciarCom(){27 $dCom= new DenunciaCom($this->adapter);28 $com=new Comentario($this->adapter);29 $com->__set("id",$_GET['id']);30 $dCom->__set("comentario",$com);31 $usuario=new Usuario($this->adapter);32 $usuario->__set("id",$_SESSION['id']);33 $dCom->__set("user",$usuario);34 $save=$dCom->save();35 $_SESSION['unico']=$_GET['unico'];36 $this->redirect("usuario","verPost");37 }38 public function moderador(){39 if(isset($_SESSION["id"])){40 $ad=new Moderador($this->adapter);41 $posts=$ad->getPostsDenunciados();42 $coms=$ad->getComDenunciados();43 $ud=new Usuario($this->adapter);44 $usuarios=$ud->getAll();45 $cant=0;$t=0;46 if(isset($coms)){47 $cant+=sizeof($coms);48 }49 if(isset($posts)){50 $t+=sizeof($posts);51 }52 $this->view("Moderar",array(53 "usuarios"=>$usuarios,54 "cant"=>$cant,55 "t"=>$t,56 "posts"=>$posts,57 "coms"=>$coms58 ));59 }else{60 $this->view("Bienvenida","");61 }62 }63 public function moderar(){64 if(isset($_SESSION['c'])){65 $c=(int)$_SESSION['c'];66 for($i=1;$i<=$c;$i++){67 $si="s".$i; $no="x".$i;68 $idCom="n".$i;$denCom="d".$i;$fecCom="f".$i;69 if(isset($_POST["$si"])){70 $this->denegarC($_POST["$idCom"],$_POST["$denCom"],$_POST["$fecCom"],1);71 }72 if(isset($_POST["$no"])){73 $this->denegarC($_POST["$idCom"],$_POST["$denCom"],$_POST["$fecCom"],0);74 }75 }76 }77 if(isset($_SESSION['t'])){78 $t=(int)$_SESSION['t'];79 for($i=1;$i<=$t;$i++){80 $este="si".$i; $otro="nono".$i;81 $idPos="p".$i;$denPos="r".$i;$fecPos="fec".$i;82 if(isset($_POST["$este"])){83 $this->permitirP($_POST["$idPos"],$_POST["$denPos"],$_POST["$fecPos"]);84 }85 if(isset($_POST["$otro"])){86 $this->denegarP($_POST["$idPos"],$_POST["$denPos"],$_POST["$fecPos"],$_POST["$idPos"]);87 }88 }89 }90 }91 public function permitirP($idP,$denP,$fecP){92 //actualizar denuncia con idModerador y dFecha93 unset($_SESSION['t']);94 $dd=new DenunciaPost($this->adapter);95 $moderador=new Moderador($this->adapter);96 $moderador->__set("id",$_SESSION['id']);97 $us=new Usuario($this->adapter);98 $us->__set("id",$denP);99 $pd=new Post($this->adapter);100 $pd->__set("id",$idP);101 $dd->__set("post",$pd);102 $dd->__set("user",$us);103 $dd->__set("dFecha",$fecP);104 $dd->__set("moderador",$moderador);105 $dd->save();106 $this->moderador();107 }108 public function denegarP($idP,$denP,$fecP){109 //save post con status 0110 //actualizar denuncia con id moderador111 unset($_SESSION['t']);112 $pd=new Post($this->adapter);113 $pd->__set("id",$idP);114 $pd->__set("status",0);115 $pd->save();116 $this->permitirP($idP,$denP,$fecP);117 }118 public function actualizar($idC,$denC,$fecC){119 $dd=new DenunciaCom($this->adapter);120 $moderador=new Moderador($this->adapter);121 $moderador->__set("id",$_SESSION['id']);122 $us=new Usuario($this->adapter);123 $us->__set("id",$denC);124 $pd=new Comentario($this->adapter);125 $pd->__set("id",$idC);126 $dd->__set("comentario",$pd);127 $dd->__set("user",$us);128 $dd->__set("dFecha",$fecC);129 $dd->__set("moderador",$moderador);130 $save=$dd->save();131 $_SESSION['aca']="vengo de comentario, habilitame el js";132 $this->moderador();133 }134 public function denegarC($idC,$denC,$fecC,$x){135 unset($_SESSION['c']);136 $cd=new Comentario($this->adapter);137 $cd->__set("id",$idC);138 $cd->__set("status",$x);139 $cd->save();140 $this->actualizar($idC,$denC,$fecC);141 }142}143?>...
AdminController.php
Source:AdminController.php
...42 //hacer cartelito43 if($ud->getById($_POST['id'])==!NULL){44 if(!$mod->yaExiste($_POST['id'])){45 $usuario=$ud->getById($_POST['id']);46 $obj=$ad->__set("id",$_SESSION['id']);47 $md=new Moderador($this->adapter);48 $md->__set("username",$usuario->mail);49 $md->__set("salt",NULL);50 $md->__set("pass","12345");51 $md->__set("adminUltMod",$obj);52 $md->__set("mail",$usuario->mail);53 $save=$md->save();54 } else {55 $moderador=$mod->getModByUser($_POST['id']);56 $ad->__set("id",$_SESSION['id']);57 if($moderador->status==1){58 $mod->__set("id",$moderador->id);59 $mod->__set("adminUltMod",$ad);60 $mod->__set("status",0);61 $mod->save();62 } else {63 $mod->__set("id",$moderador->id);64 $mod->__set("adminUltMod",$ad);65 $mod->__set("status",1);66 $mod->save();67 }68 }69 }70 $this->index();71 }72 public function habilitar(){73 //actualizar estado de usuario 174 $ud=new Usuario($this->adapter);75 $usu=$ud->getById($_POST['id']);76 $ad=new Admin($this->adapter);77 $obj=$ad->__set("id",$_SESSION['id']);78 $usuario=new Usuario($this->adapter);79 $usuario->__set("id",$_POST['id']);80 if($usu->status==0){81 $usuario->__set("status",1);82 $usuario->save();83 } else {84 $usuario->__set("status",0);85 $usuario->save();86 }87 $this->index();88 }89 public function todo(){90 $this->view("Full","");91 }92}...
__set
Using AI Code Generation
1$adapter = new Adapter();2$adapter->name = 'John';3$adapter->age = 25;4$adapter = new Adapter();5echo $adapter->name;6echo $adapter->age;
__set
Using AI Code Generation
1$adapter = new Adapter();2$adapter->title = "The title";3$adapter->author = "The author";4$adapter->content = "The content";5$adapter = new Adapter();6echo $adapter->title;7echo $adapter->author;8echo $adapter->content;9Related posts: How to use __get() and __set() methods in PHP How to use __call() and __callStatic() methods in PHP How to use __isset() and __unset() methods in PHP How to use __sleep() and __wakeup() methods in PHP How to use __toString() method in PHP
__set
Using AI Code Generation
1$adapter = new Adapter();2$adapter->set('name', 'John');3$adapter->set('job', 'programmer');4$adapter->set('age', 25);5$adapter = new Adapter();6echo $adapter->get('name');7echo $adapter->get('job');8echo $adapter->get('age');
__set
Using AI Code Generation
1$obj = new adapter();2$obj->name = "John";3$obj->age = 18;4$obj->address = "New York";5$obj->phone = "1234567890";6echo $obj->name;7echo $obj->age;8echo $obj->address;9echo $obj->phone;10Adapter Design Pattern | Set 2 (Multiple Adapters)11Adapter Design Pattern | Set 3 (Multiple Adapters)12Adapter Design Pattern | Set 4 (Multiple Adapters)13Adapter Design Pattern | Set 5 (Multiple Adapters)14Adapter Design Pattern | Set 6 (Multiple Adapters)15Adapter Design Pattern | Set 7 (Multiple Adapters)16Adapter Design Pattern | Set 8 (Multiple Adapters)17Adapter Design Pattern | Set 9 (Multiple Adapters)18Adapter Design Pattern | Set 10 (Multiple Adapters)19Adapter Design Pattern | Set 11 (Multiple Adapters)20Adapter Design Pattern | Set 12 (Multiple Adapters)21Adapter Design Pattern | Set 13 (Multiple Adapters)22Adapter Design Pattern | Set 14 (Multiple Adapters)23Adapter Design Pattern | Set 15 (Multiple Adapters)24Adapter Design Pattern | Set 16 (Multiple Adapters)25Adapter Design Pattern | Set 17 (Multiple Adapters)26Adapter Design Pattern | Set 18 (Multiple Adapters)27Adapter Design Pattern | Set 19 (Multiple Adapters)
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Execute automation tests with __set on a cloud-based Grid of 3000+ real browsers and operating systems for both web and mobile applications.
Test now for FreeGet 100 minutes of automation test minutes FREE!!