X-Git-Url: https://git.llucax.com/z.facultad/75.43/tp1.git/blobdiff_plain/6554fc774c6458cfb1fa451b260047dbcd7ec282..3cfdc427066ffa563f292c8267ecb8db8e1fd9d0:/src/lib/Info.php diff --git a/src/lib/Info.php b/src/lib/Info.php index 4579ed5..a6d2baa 100644 --- a/src/lib/Info.php +++ b/src/lib/Info.php @@ -1,15 +1,14 @@ infoCSVConst, array($this->id, $this->tema, $this->url, $this->autor, $this->comentario, $this->ranking, $this->fecha)); + } + + function saveExisting() { + if (($f = fopen($this->infoCSVConst, 'r+')) == false) return false; // error + $index = 0; + while (!feof($f)) + { + $index = ftell($f); + $d = fgetcsv($f, 4096); + if ($d[0] == $this->id) + { + fseek($f,$index); + fputcsv($f, array($this->id, $this->tema, $this->url, $this->autor, $this->comentario, $this->ranking, $this->fecha)); + fclose($f); + return true; + } + } + fclose($f); + return false; + } + + function saveLoadThis( $pId, $pTema, $pURL, $pAutor, $pComentario ) { $this->id = $pId; $this->tema = $pTema; $this->url = $pURL; $this->autor = $pAutor; - $this->comentario = $pComentario; + $this->comentario = preg_replace('[\n|\r\n]','
',$pComentario); $this->ranking = 0; $this->fecha = time(); $this->texto = ''; + } + function ingresar( $pId, $pTema, $pURL, $pAutor, $pComentario ) { + $this->saveLoadThis( $pId, $pTema, $pURL, $pAutor, $pComentario ); $resultado = ""; - if (!fappendcsv($this->infoCSVConst, array($this->id, $this->tema, $this->url, $this->autor, $this->comentario, $this->ranking, $this->fecha))) { + if (!$this->saveNew()) { $resultado = "ERROR al agregar la informacion. Revise que los parametros sean los adecuados"; - } + file_log_add($pAutor,$resultado); + } else { + file_log_add($pAutor,"Se agregó la información"); + } return $resultado; } @@ -89,32 +117,15 @@ class Info extends Item url;?> comentario;?> ranking;?> + Ver Comentarios getId(),"Se visitó una informacion (" . $this->url . ")"); $this->ranking = $this->ranking + 1; - if (($f = fopen($this->infoCSVConst, 'r')) == false) return false; // error - $index = 0; - $indexSave = 0; - while (!feof($f)) - { - $d = fgetcsv($f, 4096); - $index++; - if ($d[0] == $this->id) - { - $d[5] = $this->ranking; - fclose($f); - if (($f = fopen($this->infoCSVConst, 'r+')) == false) return false; // error - while ($indexSave!=($index-1)) { fgetcsv($f, 4096); $indexSave++; } - fputcsv($f, $d); - fclose($f); - return true; - } - } - fclose($f); - return false; + return $this->saveExisting(); } } ?>