]> git.llucax.com Git - z.facultad/75.43/tp1.git/blob - src/lib/Info.php
Cambio mi listador.
[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                 $indexSave = 0;\r
75         while (!feof($f))\r
76                 {\r
77                         $d = fgetcsv($f, 4096);\r
78                         $index++;\r
79                         if ($d[0] == $this->id)\r
80                         {\r
81                 fclose($f);\r
82                                 if (($f = fopen($this->infoCSVConst, 'r+')) == false) return false; // error\r
83                                 while ($indexSave!=($index-1)) { fgetcsv($f, 4096); $indexSave++; }\r
84                 fputcsv($f, array($this->id, $this->tema, $this->url, $this->autor, $this->comentario, $this->ranking, $this->fecha));\r
85                                 fclose($f);\r
86                                 return true;\r
87                         }\r
88                 }\r
89                 fclose($f);\r
90                 return false;\r
91         }\r
92 \r
93         function saveLoadThis( $pId, $pTema, $pURL, $pAutor, $pComentario ) {\r
94                 $this->id                       = $pId;\r
95                 $this->tema                     = $pTema;\r
96                 $this->url                      = $pURL;\r
97                 $this->autor            = $pAutor;\r
98                 $this->comentario       = preg_replace('[\n|\r\n]','<br/>',$pComentario);\r
99                 $this->ranking          = 0;\r
100                 $this->fecha            = time();\r
101                 $this->texto            = '';\r
102         }\r
103 \r
104     function ingresar( $pId, $pTema, $pURL, $pAutor, $pComentario ) {\r
105         $this->saveLoadThis( $pId, $pTema, $pURL, $pAutor, $pComentario );\r
106                 $resultado = "";\r
107         if (!$this->saveNew()) {\r
108                         $resultado = "<strong>ERROR</strong> al agregar la informacion. Revise que los parametros sean los adecuados";\r
109                         file_log_add($pAutor,$resultado);\r
110         } else {\r
111                         file_log_add($pAutor,"Se agregó la información");\r
112                 }\r
113                 return $resultado;\r
114         }\r
115 \r
116         function modificar( $pId, $pTema, $pURL, $pAutor, $pComentario ) {\r
117         $this->saveLoadThis( $pId, $pTema, $pURL, $pAutor, $pComentario );\r
118                 $resultado = "";\r
119         if (!$this->saveExisting()) {\r
120                         $resultado = "<strong>ERROR</strong> al modificar la informacion. Revise que los parametros sean los adecuados";\r
121                         file_log_add($pAutor,$resultado);\r
122         } else {\r
123                         file_log_add($pAutor,"Se modificó la información");\r
124                 }\r
125                 return $resultado;\r
126         }\r
127 \r
128         function toHTML() {\r
129         ?><tr>\r
130                         <td><img src="<?php echo $this->tema_icono;?>" border="0" alt="icono tema"/></td>\r
131                         <td><img src="<?php echo $this->autor_foto;?>" border="0" alt="icono usuario"/></td>\r
132             <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
133                         <td><?php echo $this->comentario;?></td>\r
134                         <td><?php echo $this->ranking;?></td>\r
135                         <td><a href="info.listarComentarios.php?id=<?php echo $this->id; ?>">Ver Comentarios</a></td>\r
136                   </tr>\r
137                 <?php\r
138         }\r
139 \r
140         function incrementarRanking() {\r
141                 //file_log_add($_SESSION['user']->getId(),"Se visitó una informacion (" . $this->url . ")");\r
142                 $this->ranking = $this->ranking + 1;\r
143         return $this->saveExisting();\r
144         }\r
145 }\r
146 ?>\r