]> git.llucax.com Git - z.facultad/75.43/tp1.git/blob - 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
1 <?php\r
2 // Grupo 10\r
3 //\r
4 // Lucarella, Schein, Arena\r
5 //\r
6 // Creado: Sebastian Arena\r
7 //\r
8 \r
9 require_once 'Item.php';\r
10 require_once 'file.php';\r
11 require_once 'file.log.php';\r
12 \r
13 class Info extends Item\r
14 {\r
15         var $id;\r
16     var $url;\r
17         var $tema;\r
18         var $comentario;\r
19     var $ranking;\r
20 \r
21         /*Extra Data*/\r
22         var $autor_foto;\r
23         var $autor_apellido;\r
24         var $tema_icono;\r
25 \r
26         var $infoCSVConst = 'data/infos.csv';\r
27     /* \r
28                 Formato en Disco:\r
29                         id | tema | url | autor | comentario | ranking | fecha\r
30         */\r
31 \r
32         function Info($param, $loadFromRecord) {\r
33                 if (!$loadFromRecord) {\r
34             if ($param) {\r
35                                 $this->id = $param;\r
36                                 $this->reload();\r
37                         }\r
38                 } else {\r
39                         $this->id                       = $param[0];\r
40                         $this->tema                     = $param[1];\r
41                         $this->url                      = $param[2];\r
42             $this->autor                = $param[3];\r
43                         $this->comentario       = $param[4];\r
44             $this->ranking      = $param[5];\r
45                         $this->fecha            = $param[6];\r
46                         $this->texto            = '';\r
47                         \r
48                 }\r
49     }\r
50 \r
51         function reload() {\r
52                 if (is_file($this->infoCSVConst)) {\r
53                         $record_info = fsearchcsv($this->infoCSVConst, $this->id);\r
54             if ($record_info) {\r
55                                 $this->id                       = $record_info[0];\r
56                                 $this->tema                     = $record_info[1];\r
57                                 $this->url                      = $record_info[2];\r
58                                 $this->autor            = $record_info[3];\r
59                                 $this->comentario       = $record_info[4];\r
60                                 $this->ranking          = $record_info[5];\r
61                                 $this->fecha            = $record_info[6];\r
62                                 $this->texto            = '';\r
63                         }\r
64                 }\r
65         }\r
66 \r
67         function saveNew() {\r
68                 return fappendcsv($this->infoCSVConst, array($this->id, $this->tema, $this->url, $this->autor, $this->comentario, $this->ranking, $this->fecha));\r
69         }\r
70 \r
71         function saveExisting() {\r
72                 if (($f = fopen($this->infoCSVConst, 'r+')) == false) return false; // error\r
73                 $index = 0;\r
74         while (!feof($f))\r
75                 {\r
76                         $index = ftell($f);\r
77                         $d = fgetcsv($f, 4096);\r
78             if ($d[0] == $this->id)\r
79                         {\r
80                 fseek($f,$index);\r
81                                 fputcsv($f, array($this->id, $this->tema, $this->url, $this->autor, $this->comentario, $this->ranking, $this->fecha));\r
82                                 fclose($f);\r
83                                 return true;\r
84                         }\r
85                 }\r
86                 fclose($f);\r
87                 return false;\r
88         }\r
89 \r
90         function saveLoadThis( $pId, $pTema, $pURL, $pAutor, $pComentario ) {\r
91                 $this->id                       = $pId;\r
92                 $this->tema                     = $pTema;\r
93                 $this->url                      = $pURL;\r
94                 $this->autor            = $pAutor;\r
95                 $this->comentario       = preg_replace('[\n|\r\n]','<br/>',$pComentario);\r
96                 $this->ranking          = 0;\r
97                 $this->fecha            = time();\r
98                 $this->texto            = '';\r
99         }\r
100 \r
101     function ingresar( $pId, $pTema, $pURL, $pAutor, $pComentario ) {\r
102         $this->saveLoadThis( $pId, $pTema, $pURL, $pAutor, $pComentario );\r
103                 $resultado = "";\r
104         if (!$this->saveNew()) {\r
105                         $resultado = "<strong>ERROR</strong> al agregar la informacion. Revise que los parametros sean los adecuados";\r
106                         file_log_add($pAutor,$resultado);\r
107         } else {\r
108                         file_log_add($pAutor,"Se agregó la información");\r
109                 }\r
110                 return $resultado;\r
111         }\r
112 \r
113         function toHTML() {\r
114         ?><tr>\r
115                         <td><img src="<?php echo $this->tema_icono;?>" border="0" alt="icono tema"/></td>\r
116                         <td><img src="<?php echo $this->autor_foto;?>" border="0" alt="icono usuario"/></td>\r
117             <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
118                         <td><?php echo $this->comentario;?></td>\r
119                         <td><?php echo $this->ranking;?></td>\r
120                         <td><a href="info.listarComentarios.php?id=<?php echo $this->id; ?>">Ver Comentarios</a></td>\r
121                   </tr>\r
122                 <?php\r
123         }\r
124 \r
125         function incrementarRanking() {\r
126                 //file_log_add($_SESSION['user']->getId(),"Se visitó una informacion (" . $this->url . ")");\r
127                 $this->ranking = $this->ranking + 1;\r
128         return $this->saveExisting();\r
129         }\r
130 }\r
131 ?>\r