X-Git-Url: https://git.llucax.com/z.facultad/75.43/tp1.git/blobdiff_plain/0f8291748d189597a52452a196aeacbc247ee450..cca05437f65a5e90c1822e0ed3a2439e3c0d98c8:/src/lib/Comentario.php
diff --git a/src/lib/Comentario.php b/src/lib/Comentario.php
index d0406a9..9a412ef 100644
--- a/src/lib/Comentario.php
+++ b/src/lib/Comentario.php
@@ -1,19 +1,129 @@
comentarioCSVConst = $this->comentarioCSVBaseConst . "." . $pInfo_ID . ".csv";
+ if (!$loadFromRecord) {
+ if ($param) {
+ $this->id = $param;
+ $this->reload();
+ }
+ } else {
+ $this->id = $param[0];
+ $this->autor = $param[1];
+ $this->texto = $param[2];
+ $this->fecha = $param[3];
+ }
+ }
+
+ function reload() {
+ if (is_file($this->comentarioCSVConst)) {
+ $record_info = fsearchcsv($this->comentarioCSVConst, $this->id);
+ if ($record_info) {
+ $this->id = $param[0];
+ $this->autor = $param[1];
+ $this->texto = $param[2];
+ $this->fecha = $param[3];
+ }
+ }
+ }
+
+ function saveNew() {
+ return fappendcsv($this->comentarioCSVConst, array( $this->id, $this->autor, $this->texto, $this->fecha ));
+ }
+
+ function saveExisting() {
+ if (($f = fopen($this->comentarioCSVConst, 'r')) == false) return false; // error
+ $index = 0;
+ $indexSave = 0;
+ while (!feof($f))
+ {
+ $d = fgetcsv($f, 4096);
+ $index++;
+ if ($d[0] == $this->id)
+ {
+ fclose($f);
+ if (($f = fopen($this->comentarioCSVConst, 'r+')) == false) return false; // error
+ while ($indexSave!=($index-1)) { fgetcsv($f, 4096); $indexSave++; }
+ fputcsv($f, array( $this->id, $this->autor, $this->texto, $this->fecha ));
+ fclose($f);
+ return true;
+ }
+ }
+ fclose($f);
+ return false;
+ }
+
+ function saveLoadThis( $pId, $pInfo_ID, $pComentario, $pAutor ) {
+ $this->id = $pId;
+ $this->autor = $pAutor;
+ $this->texto = preg_replace('[\n|\r\n]','
',$pComentario);
+ $this->fecha = time();
+ $this->comentarioCSVConst = $this->comentarioCSVBaseConst . "." . $pInfo_ID . ".csv";
+ }
+
+ function ingresar( $pId, $pInfo_ID, $pComentario, $pAutor ) {
+ $this->saveLoadThis( $pId, $pInfo_ID, $pComentario, $pAutor );
+ $resultado = "";
+ if (!$this->saveNew()) {
+ $resultado = "ERROR al agregar el comentario. Revise que los parametros sean los adecuados";
+ file_log_add($pAutor,$resultado);
+ } else {
+ file_log_add($pAutor,"Se agregó el comentario");
+ }
+ return $resultado;
+ }
+
+ function modificar( $pId, $pInfo_ID, $pComentario, $pAutor ) {
+ $this->saveLoadThis( $pId, $pInfo_ID, $pComentario, $pAutor );
+ $resultado = "";
+ if (!$this->saveExisting()) {
+ $resultado = "ERROR al modificar el comentario. Revise que los parametros sean los adecuados";
+ file_log_add($pAutor,$resultado);
+ } else {
+ file_log_add($pAutor,"Se modificó el comentario");
+ }
+ return $resultado;
+ }
+
+ function toHTML() {
+ ?>