]> git.llucax.com Git - z.facultad/75.43/tp1.git/blob - src/lib/Info.php
Se vuelve a poner la imágen como título.
[z.facultad/75.43/tp1.git] / src / lib / Info.php
1 <?php\r
2 // vim: set binary noeol et sw=4 sts=4 :\r
3 // Grupo 10\r
4 //\r
5 // Lucarella, Schein, Arena\r
6 //\r
7 // Creado: Leandro Lucarella (sáb abr 30 20:21:30 ART 2005)\r
8 //\r
9 // $Id: Link.php 9 2005-04-30 23:51:21Z llucare $\r
10 \r
11 require_once 'Item.php';\r
12 require_once 'file.php';\r
13 \r
14 class Info extends Item\r
15 {\r
16         var $id;\r
17     var $url;\r
18         var $tema;\r
19         var $comentario;\r
20     var $ranking;\r
21 \r
22         /*Extra Data*/\r
23         var $autor_foto;\r
24         var $autor_apellido;\r
25         var $tema_icono;\r
26 \r
27         var $infoCSVConst = 'data/infos.csv';\r
28     /* \r
29                 Formato en Disco:\r
30                         id | tema | url | autor | comentario | ranking | fecha\r
31         */\r
32 \r
33         function Info($param, $loadFromRecord) {\r
34                 if (!$loadFromRecord) {\r
35             if ($param) {\r
36                                 $this->id = $param;\r
37                                 $this->reload();\r
38                         }\r
39                 } else {\r
40                         $this->id                       = $param[0];\r
41                         $this->tema                     = $param[1];\r
42                         $this->url                      = $param[2];\r
43             $this->autor                = $param[3];\r
44                         $this->comentario       = $param[4];\r
45             $this->ranking      = $param[5];\r
46                         $this->fecha            = $param[6];\r
47                         $this->texto            = '';\r
48                         \r
49                 }\r
50     }\r
51 \r
52         function reload() {\r
53                 if (is_file($this->infoCSVConst)) {\r
54                         $record_info = fsearchcsv($this->infoCSVConst, $this->id);\r
55             if ($record_info) {\r
56                                 $this->id                       = $record_info[0];\r
57                                 $this->tema                     = $record_info[1];\r
58                                 $this->url                      = $record_info[2];\r
59                                 $this->autor            = $record_info[3];\r
60                                 $this->comentario       = $record_info[4];\r
61                                 $this->ranking          = $record_info[5];\r
62                                 $this->fecha            = $record_info[6];\r
63                                 $this->texto            = '';\r
64                         }\r
65                 }\r
66         }\r
67 \r
68     function ingresar( $pId, $pTema, $pURL, $pAutor, $pComentario ) {\r
69                 $this->id                       = $pId;\r
70                 $this->tema                     = $pTema;\r
71                 $this->url                      = $pURL;\r
72                 $this->autor            = $pAutor;\r
73                 $this->comentario       = $pComentario;\r
74                 $this->ranking          = 0;\r
75                 $this->fecha            = time();\r
76                 $this->texto            = '';\r
77 \r
78                 $resultado = "";\r
79         if (!fappendcsv($this->infoCSVConst, array($this->id, $this->tema, $this->url, $this->autor, $this->comentario, $this->ranking, $this->fecha))) {\r
80                         $resultado = "<strong>ERROR</strong> al agregar la informacion. Revise que los parametros sean los adecuados";\r
81         }\r
82                 return $resultado;\r
83         }\r
84 \r
85         function toHTML() {\r
86         ?><tr>\r
87                         <td><img src="<?php echo $this->tema_icono;?>" border="0" alt="icono tema"/></td>\r
88                         <td><img src="<?php echo $this->autor_foto;?>" border="0" alt="icono usuario"/></td>\r
89             <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
90                         <td><?php echo $this->comentario;?></td>\r
91                         <td><?php echo $this->ranking;?></td>\r
92                   </tr>\r
93                 <?php\r
94         }\r
95 \r
96         function incrementarRanking() {\r
97                 $this->ranking = $this->ranking + 1;\r
98                 if (($f = fopen($this->infoCSVConst, 'r')) == false) return false; // error\r
99                 $index = 0;\r
100                 $indexSave = 0;\r
101         while (!feof($f))\r
102                 {\r
103                         $d = fgetcsv($f, 4096);\r
104                         $index++;\r
105                         if ($d[0] == $this->id)\r
106                         {\r
107                                 $d[5] = $this->ranking;\r
108                                 fclose($f);\r
109                                 if (($f = fopen($this->infoCSVConst, 'r+')) == false) return false; // error\r
110                                 while ($indexSave!=($index-1)) { fgetcsv($f, 4096); $indexSave++; }\r
111                 fputcsv($f, $d);\r
112                                 fclose($f);\r
113                                 return true;\r
114                         }\r
115                 }\r
116                 fclose($f);\r
117                 return false;\r
118         }\r
119 }\r
120 ?>\r