/trunk/modules/0011-News/admin/include/Object/News.class.php

http://antilophpe.googlecode.com/ · PHP · 454 lines · 229 code · 17 blank · 208 comment · 0 complexity · 25e67f12f4a86e1cd2959500ddde6388 MD5 · raw file

  1. <?php
  2. /**
  3. * File News.class.php
  4. *
  5. * This file contains the definition of the class object
  6. * type News and at the end of the file,
  7. * a way to test the class (simply passing sending test = 1
  8. * via GET or POST ).
  9. * @author Marco Novo <mnovo@ncfsistemi.com>
  10. * @version 1.0
  11. */
  12. /**
  13. * This class defines fields and methods of News
  14. */
  15. class News {
  16. /**
  17. * $resourceLinkID
  18. * @access private
  19. * @var resource
  20. */
  21. private $resourceLinkID;
  22. /**
  23. * id
  24. * @access private
  25. * @var integer
  26. */
  27. private $id;
  28. /**
  29. * data
  30. * @access private
  31. * @var date
  32. */
  33. private $data;
  34. /**
  35. * primoPiano
  36. * @access private
  37. * @var integer
  38. */
  39. private $primoPiano;
  40. /**
  41. * titolo
  42. * @access private
  43. * @var string
  44. */
  45. private $titolo;
  46. /**
  47. * sottotitolo
  48. * @access private
  49. * @var string
  50. */
  51. private $sottotitolo;
  52. /**
  53. * testoBreve
  54. * @access private
  55. * @var string
  56. */
  57. private $testoBreve;
  58. /**
  59. * testo
  60. * @access private
  61. * @var string
  62. */
  63. private $testo;
  64. /**
  65. * autore
  66. * @access private
  67. * @var string
  68. */
  69. private $autore;
  70. /**
  71. * active
  72. * @access private
  73. * @var integer
  74. */
  75. private $active;
  76. /**
  77. * deleted
  78. * @access private
  79. * @var integer
  80. */
  81. private $deleted;
  82. /**
  83. * Set the value of resourceLinkID
  84. * @param resource $resourceLinkID
  85. */
  86. function setResourceLinkID($resourceLinkID){
  87. $this->resourceLinkID=$resourceLinkID;
  88. }
  89. /**
  90. * Get the value of resourceLinkID
  91. * @return resource
  92. */
  93. function getResourceLinkID(){
  94. return $this->resourceLinkID;
  95. }
  96. /**
  97. * Sets the value of field id
  98. * @param integer $id
  99. */
  100. function setId($id){
  101. $this->id=$id;
  102. }
  103. /**
  104. * Gets the value of field id
  105. * @return integer
  106. */
  107. function getId(){
  108. return $this->id;
  109. }
  110. /**
  111. * Sets the value of field data
  112. * @param date $data
  113. */
  114. function setData($data){
  115. $this->data=$data;
  116. }
  117. /**
  118. * Gets the value of field data
  119. * @return date
  120. */
  121. function getData(){
  122. return $this->data;
  123. }
  124. /**
  125. * Sets the value of field primoPiano
  126. * @param integer $primoPiano
  127. */
  128. function setPrimoPiano($primoPiano){
  129. $this->primoPiano=$primoPiano;
  130. }
  131. /**
  132. * Gets the value of field primoPiano
  133. * @return integer
  134. */
  135. function getPrimoPiano(){
  136. return $this->primoPiano;
  137. }
  138. /**
  139. * Sets the value of field titolo
  140. * @param string $titolo
  141. */
  142. function setTitolo($titolo){
  143. $this->titolo=$titolo;
  144. }
  145. /**
  146. * Gets the value of field titolo
  147. * @return string
  148. */
  149. function getTitolo(){
  150. return $this->titolo;
  151. }
  152. /**
  153. * Sets the value of field sottotitolo
  154. * @param string $sottotitolo
  155. */
  156. function setSottotitolo($sottotitolo){
  157. $this->sottotitolo=$sottotitolo;
  158. }
  159. /**
  160. * Gets the value of field sottotitolo
  161. * @return string
  162. */
  163. function getSottotitolo(){
  164. return $this->sottotitolo;
  165. }
  166. /**
  167. * Sets the value of field testoBreve
  168. * @param string $testoBreve
  169. */
  170. function setTestoBreve($testoBreve){
  171. $this->testoBreve=$testoBreve;
  172. }
  173. /**
  174. * Gets the value of field testoBreve
  175. * @return string
  176. */
  177. function getTestoBreve(){
  178. return $this->testoBreve;
  179. }
  180. /**
  181. * Sets the value of field testo
  182. * @param string $testo
  183. */
  184. function setTesto($testo){
  185. $this->testo=$testo;
  186. }
  187. /**
  188. * Gets the value of field testo
  189. * @return string
  190. */
  191. function getTesto(){
  192. return $this->testo;
  193. }
  194. /**
  195. * Sets the value of field autore
  196. * @param string $autore
  197. */
  198. function setAutore($autore){
  199. $this->autore=$autore;
  200. }
  201. /**
  202. * Gets the value of field autore
  203. * @return string
  204. */
  205. function getAutore(){
  206. return $this->autore;
  207. }
  208. /**
  209. * Sets the value of field active
  210. * @param integer $active
  211. */
  212. function setActive($active){
  213. $this->active=$active;
  214. }
  215. /**
  216. * Gets the value of field active
  217. * @return integer
  218. */
  219. function getActive(){
  220. return $this->active;
  221. }
  222. /**
  223. * Sets the value of field deleted
  224. * @param integer $deleted
  225. */
  226. function setDeleted($deleted){
  227. $this->deleted=$deleted;
  228. }
  229. /**
  230. * Gets the value of field deleted
  231. * @return integer
  232. */
  233. function getDeleted(){
  234. return $this->deleted;
  235. }
  236. /**
  237. * Constructor of the class
  238. */
  239. function __construct($resourceLinkID='',
  240. $id='',
  241. $data='',
  242. $primoPiano='',
  243. $titolo='',
  244. $sottotitolo='',
  245. $testoBreve='',
  246. $testo='',
  247. $autore='',
  248. $active='',
  249. $deleted='') {
  250. $this->resourceLinkID = $resourceLinkID;
  251. $this->id = $id;
  252. $this->data = $data;
  253. $this->primoPiano = $primoPiano;
  254. $this->titolo = $titolo;
  255. $this->sottotitolo = $sottotitolo;
  256. $this->testoBreve = $testoBreve;
  257. $this->testo = $testo;
  258. $this->autore = $autore;
  259. $this->active = $active;
  260. $this->deleted = $deleted;
  261. }
  262. /**
  263. * Destructor of the class
  264. */
  265. function __destruct() {
  266. }
  267. /**
  268. * Get the value of descriptive field
  269. * @return string
  270. */
  271. function getDescriptiveFields(){
  272. return trim($this->getData().' '.$this->getTitolo().' '.' (id: '.$this->getId().')');
  273. }
  274. /**
  275. * Get the name and the value of mail fields
  276. * @return string
  277. */
  278. function getMailFields(){
  279. return trim("Id: ".$this->getId()."\n"."Data: ".$this->getData()."\n"."Primo piano: ".$this->getPrimoPiano()."\n"."Titolo: ".$this->getTitolo()."\n"."Sottotitolo: ".$this->getSottotitolo()."\n"."Testo breve: ".$this->getTestoBreve()."\n"."Testo: ".$this->getTesto()."\n"."Autore: ".$this->getAutore()."\n"."Active: ".$this->getActive()."\n"."Deleted: ".$this->getDeleted()."\n"."");
  280. }
  281. /**
  282. * Persistence selectById method (try to select)
  283. * @return true|false
  284. */
  285. function selectById(){
  286. $query="SELECT ant_News.*
  287. FROM ant_News
  288. WHERE ant_News.id = '".$this->getId()."'";
  289. $result = mysql_query($query, $this->getResourceLinkId()) or die('Query:<hr/> '.$query.'<hr/>Error during selection in table `ant_News`: '.mysql_errno($this->getResourceLinkId()).' - '.mysql_error($this->getResourceLinkId()));
  290. while($news_array=mysql_fetch_assoc($result)){
  291. $this->id = $news_array['id'];
  292. $this->data = $news_array['data'];
  293. $this->primoPiano = $news_array['primoPiano'];
  294. $this->titolo = $news_array['titolo'];
  295. $this->sottotitolo = $news_array['sottotitolo'];
  296. $this->testoBreve = $news_array['testoBreve'];
  297. $this->testo = $news_array['testo'];
  298. $this->autore = $news_array['autore'];
  299. $this->active = $news_array['active'];
  300. $this->deleted = $news_array['deleted'];
  301. }
  302. }
  303. /**
  304. * Persistence listSelectablesByAndFields method (try to select)
  305. * @param array with filedName as key and fieldValue as value
  306. * @return list/array
  307. */
  308. function listSelectablesByAndFields($fieldsArray){
  309. foreach($fieldsArray as $key => $value)
  310. $whereString.=" AND $key = '".str_replace("'","''",$value)."'";
  311. $query="SELECT ant_News.*
  312. FROM ant_News
  313. WHERE ant_News.active=1
  314. AND ant_News.deleted=0
  315. ".$whereString."
  316. ORDER BY data DESC;";
  317. $result = mysql_query($query, $this->getResourceLinkId()) or die('Query:<hr/> '.$query.'<hr/>Error during selection in table `ant_News`: '.mysql_errno($this->getResourceLinkId()).' - '.mysql_error($this->getResourceLinkId()));
  318. $listRow=array();
  319. while($arrayRow=mysql_fetch_assoc($result)){
  320. array_push($listRow,$arrayRow);
  321. }
  322. return $listRow;
  323. }
  324. /**
  325. * Persistence listSelectablesByOrFields method (try to select)
  326. * @param array with filedName as key and fieldValue as value
  327. * @return list/array
  328. */
  329. function listSelectablesByOrFields($fieldsArray){
  330. foreach($fieldsArray as $key => $value)
  331. $whereString.=" OR $key = '".str_replace("'","''",$value)."'";
  332. $query="SELECT ant_News.*
  333. FROM ant_News
  334. WHERE ant_News.active=1
  335. AND ant_News.deleted=0
  336. AND (0 ".$whereString.")
  337. ORDER BY data DESC;";
  338. $result = mysql_query($query, $this->getResourceLinkId()) or die('Query:<hr/> '.$query.'<hr/>Error during selection in table `ant_News`: '.mysql_errno($this->getResourceLinkId()).' - '.mysql_error($this->getResourceLinkId()));
  339. $listRow=array();
  340. while($arrayRow=mysql_fetch_assoc($result)){
  341. array_push($listRow,$arrayRow);
  342. }
  343. return $listRow;
  344. }
  345. /**
  346. * Persistence selectFiles method (try to select)
  347. * @return array
  348. */
  349. function selectFiles(){
  350. $query="SELECT ant_News_File.*
  351. FROM ant_News_File
  352. WHERE ant_News_File.idTableObject= '".$this->getId()."'
  353. AND ant_News_File.tableObject='ant_News'";
  354. $result = mysql_query($query, $this->getResourceLinkId()) or die('Query:<hr/> '.$query.'<hr/>Error during selection in table `ant_News_File`: '.mysql_errno($this->getResourceLinkId()).' - '.mysql_error($this->getResourceLinkId()));
  355. $filesList=array();
  356. while($news_File_array=mysql_fetch_assoc($result)){
  357. array_push($filesList, $news_File_array);
  358. }
  359. return $filesList;
  360. }
  361. /**
  362. * Persistence selectCopertina method (try to select)
  363. * @return array
  364. * ADDED
  365. */
  366. function selectCopertina(){
  367. $query="SELECT ant_News_File.*
  368. FROM ant_News_File
  369. WHERE ant_News_File.idTableObject= '".$this->getId()."'
  370. AND ant_News_File.tableObject='ant_News'
  371. AND ant_News_File.type = 'copertina'";
  372. $result = mysql_query($query, $this->getResourceLinkId()) or die('Query:<hr/> '.$query.'<hr/>Error during selection in table `ant_News_File`: '.mysql_errno($this->getResourceLinkId()).' - '.mysql_error($this->getResourceLinkId()));
  373. return mysql_fetch_assoc($result);
  374. }
  375. /**
  376. * Persistence selectFileById method (try to select)
  377. * @return array
  378. */
  379. function selectFileById($fileId){
  380. $query="SELECT ant_News_File.*
  381. FROM ant_News_File
  382. WHERE ant_News_File.id='$fileId'";
  383. $result = mysql_query($query, $this->getResourceLinkId()) or die('Query:<hr/> '.$query.'<hr/>Error during selection file in table `ant_News_File`: '.mysql_errno($this->getResourceLinkId()).' - '.mysql_error($this->getResourceLinkId()));
  384. $news_File_array=mysql_fetch_assoc($result);
  385. return $news_File_array;
  386. }
  387. /**
  388. * Persistence selectCountFiles method (try to select)
  389. * @return array
  390. */
  391. function selectCountFiles(){
  392. $query="SELECT COUNT(*)
  393. FROM ant_News_File
  394. WHERE ant_News_File.idTableObject= '".$this->getId()."'
  395. AND ant_News_File.tableObject='ant_News'";
  396. $result = mysql_query($query, $this->getResourceLinkId()) or die('Query:<hr/> '.$query.'<hr/>Error during selection in table `ant_News_File`: '.mysql_errno($this->getResourceLinkId()).' - '.mysql_error($this->getResourceLinkId()));
  397. $news_File_array=mysql_fetch_array($result);
  398. return $news_File_array[0];
  399. }
  400. /**
  401. * Persistence selectCountLogs method (try to select count)
  402. * @return integer
  403. */
  404. function selectCountLogs(){
  405. $query="SELECT COUNT(*)
  406. FROM ant_News_Log";
  407. $result = mysql_query($query, $this->getResourceLinkId()) or die('Query:<hr/> '.$query.'<hr/>Error during select count from table `ant_News_Log`: '.mysql_errno($this->getResourceLinkId()).' - '.mysql_error($this->getResourceLinkId()));
  408. $news_Log_array=mysql_fetch_array($result);
  409. return $news_Log_array[0];
  410. }
  411. /**
  412. * Persistence selectCountTrashes method (try to select count)
  413. * @return integer
  414. */
  415. function selectCountTrashes(){
  416. $query="SELECT COUNT(*)
  417. FROM ant_News
  418. WHERE deleted = 1";
  419. $result = mysql_query($query, $this->getResourceLinkId()) or die('Query:<hr/> '.$query.'<hr/>Error during select count from table `ant_News`: '.mysql_errno($this->getResourceLinkId()).' - '.mysql_error($this->getResourceLinkId()));
  420. $news_array=mysql_fetch_array($result);
  421. return $news_array[0];
  422. }
  423. /**
  424. * Persistence selectByFileId method (try to select)
  425. * @return true|false
  426. */
  427. function selectByFileId($idFile){
  428. $query="SELECT ant_News_File.*
  429. FROM ant_News_File
  430. WHERE ant_News_File.id = '$idFile'";
  431. $result = mysql_query($query, $this->getResourceLinkId()) or die('Query:<hr/> '.$query.'<hr/>Error during selection in table `ant_News_File`: '.mysql_errno($this->getResourceLinkId()).' - '.mysql_error($this->getResourceLinkId()));
  432. return mysql_fetch_array($result);
  433. }
  434. }
  435. ?>