]> git.llucax.com Git - z.facultad/75.43/tp1.git/blobdiff - src/lib/Info.php
Aca esta mi bugfixing, para que le llevemos algo que le guste mas.
[z.facultad/75.43/tp1.git] / src / lib / Info.php
index 4579ed52dcae1fa8b3da901310a97e59ec1ca95e..a6d2baa30fea78c1119495122c11dc750906fe84 100644 (file)
@@ -1,15 +1,14 @@
 <?php\r
-// vim: set binary noeol et sw=4 sts=4 :\r
 // Grupo 10\r
 //\r
 // Lucarella, Schein, Arena\r
 //\r
-// Creado: Leandro Lucarella (sáb abr 30 20:21:30 ART 2005)\r
+// Creado: Sebastian Arena\r
 //\r
-// $Id: Link.php 9 2005-04-30 23:51:21Z llucare $\r
 \r
 require_once 'Item.php';\r
 require_once 'file.php';\r
+require_once 'file.log.php';\r
 \r
 class Info extends Item\r
 {\r
@@ -65,20 +64,49 @@ class Info extends Item
                }\r
        }\r
 \r
-    function ingresar( $pId, $pTema, $pURL, $pAutor, $pComentario ) {\r
+       function saveNew() {\r
+               return fappendcsv($this->infoCSVConst, array($this->id, $this->tema, $this->url, $this->autor, $this->comentario, $this->ranking, $this->fecha));\r
+       }\r
+\r
+       function saveExisting() {\r
+               if (($f = fopen($this->infoCSVConst, 'r+')) == false) return false; // error\r
+               $index = 0;\r
+        while (!feof($f))\r
+               {\r
+                       $index = ftell($f);\r
+                       $d = fgetcsv($f, 4096);\r
+            if ($d[0] == $this->id)\r
+                       {\r
+                fseek($f,$index);\r
+                               fputcsv($f, array($this->id, $this->tema, $this->url, $this->autor, $this->comentario, $this->ranking, $this->fecha));\r
+                               fclose($f);\r
+                               return true;\r
+                       }\r
+               }\r
+               fclose($f);\r
+               return false;\r
+       }\r
+\r
+       function saveLoadThis( $pId, $pTema, $pURL, $pAutor, $pComentario ) {\r
                $this->id                       = $pId;\r
                $this->tema                     = $pTema;\r
                $this->url                      = $pURL;\r
                $this->autor            = $pAutor;\r
-               $this->comentario       = $pComentario;\r
+               $this->comentario       = preg_replace('[\n|\r\n]','<br/>',$pComentario);\r
                $this->ranking          = 0;\r
                $this->fecha            = time();\r
                $this->texto            = '';\r
+       }\r
 \r
+    function ingresar( $pId, $pTema, $pURL, $pAutor, $pComentario ) {\r
+        $this->saveLoadThis( $pId, $pTema, $pURL, $pAutor, $pComentario );\r
                $resultado = "";\r
-        if (!fappendcsv($this->infoCSVConst, array($this->id, $this->tema, $this->url, $this->autor, $this->comentario, $this->ranking, $this->fecha))) {\r
+        if (!$this->saveNew()) {\r
                        $resultado = "<strong>ERROR</strong> al agregar la informacion. Revise que los parametros sean los adecuados";\r
-        }\r
+                       file_log_add($pAutor,$resultado);\r
+        } else {\r
+                       file_log_add($pAutor,"Se agregó la información");\r
+               }\r
                return $resultado;\r
        }\r
 \r
@@ -89,32 +117,15 @@ class Info extends Item
             <td><a href="<?php echo $this->url;?>" onclick="location.href='<?php echo $_SERVER['PHP_SELF'] ?>/../info.agregarRanking.php?id=<?php echo $this->id;?>';return false;"><?php echo $this->url;?></a></td>\r
                        <td><?php echo $this->comentario;?></td>\r
                        <td><?php echo $this->ranking;?></td>\r
+                       <td><a href="info.listarComentarios.php?id=<?php echo $this->id; ?>">Ver Comentarios</a></td>\r
                  </tr>\r
                <?php\r
        }\r
 \r
        function incrementarRanking() {\r
+               //file_log_add($_SESSION['user']->getId(),"Se visitó una informacion (" . $this->url . ")");\r
                $this->ranking = $this->ranking + 1;\r
-               if (($f = fopen($this->infoCSVConst, 'r')) == false) return false; // error\r
-               $index = 0;\r
-               $indexSave = 0;\r
-        while (!feof($f))\r
-               {\r
-                       $d = fgetcsv($f, 4096);\r
-                       $index++;\r
-                       if ($d[0] == $this->id)\r
-                       {\r
-                               $d[5] = $this->ranking;\r
-                               fclose($f);\r
-                               if (($f = fopen($this->infoCSVConst, 'r+')) == false) return false; // error\r
-                               while ($indexSave!=($index-1)) { fgetcsv($f, 4096); $indexSave++; }\r
-                fputcsv($f, $d);\r
-                               fclose($f);\r
-                               return true;\r
-                       }\r
-               }\r
-               fclose($f);\r
-               return false;\r
+        return $this->saveExisting();\r
        }\r
 }\r
 ?>\r