PageRenderTime 46ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/web/OrganicPM/lib/Report.class.php

http://praticarh.googlecode.com/
PHP | 371 lines | 208 code | 64 blank | 99 comment | 24 complexity | a3a0e8de7dd593c1184273d662903464 MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.1
  1. <?php
  2. include_once ROOT.'config/config.inc.php';
  3. include_once ROOT.'lib/LoginSystem/Visit.class.php';
  4. include_once ROOT.'lib/LoginSystem/User.class.php';
  5. include_once ROOT.'lib/CandidatoProcessoSeletivo.class.php';
  6. include_once ROOT.'plugins/getLastDayOfMonth.function.php';
  7. include_once ROOT.'plugins/getDateInterval.function.php';
  8. /**
  9. * Relat?rio de compara??o
  10. * Retorna as datas e frequ?ncias em determinado per?odo de tempo
  11. * Tamb?m retorna arrays com os intervalos de datas por anos, meses, e dias
  12. *
  13. * Cria o array de per?odo com a data completa no seguinte formato: YYYY-MM-DD
  14. * Depois cruza com os dados de visitas, cadastros, etc.
  15. *
  16. * @author _Opeth_
  17. *
  18. */
  19. class Report
  20. {
  21. private $startYear;
  22. private $startMonth;
  23. private $startDay;
  24. private $endYear;
  25. private $endMonth;
  26. private $endDay;
  27. private $visitas = array();
  28. private $cadastros = array();
  29. private $candProcSel = array();
  30. /**
  31. * Pode ser: days, months, years
  32. * @var string
  33. */
  34. private $format;
  35. private $period = array();
  36. private $days = array();
  37. private $months = array();
  38. private $years = array();
  39. /**
  40. * @return the $format
  41. */
  42. public function getFormat() {
  43. return $this->format;
  44. }
  45. /**
  46. * @param $format the $format to set
  47. */
  48. public function setFormat($format) {
  49. $this->format = $format;
  50. }
  51. /**
  52. * @return the $period
  53. */
  54. public function getPeriod() {
  55. return $this->period;
  56. }
  57. /**
  58. * @param $period the $period to set
  59. */
  60. public function setPeriod($period) {
  61. $this->period = $period;
  62. }
  63. /**
  64. * @return the $days
  65. */
  66. public function getDays() {
  67. return $this->days;
  68. }
  69. /**
  70. * @return the $months
  71. */
  72. public function getMonths($type = 'numeric') {
  73. if ($type == "numeric")
  74. return $this->months;
  75. elseif ($type == "string")
  76. return $this->numericMonthToString($this->months);
  77. }
  78. /**
  79. * @return the $years
  80. */
  81. public function getYears() {
  82. return $this->years;
  83. }
  84. /**
  85. * @param $days the $days to set
  86. */
  87. public function setDays($days) {
  88. $this->days = $days;
  89. }
  90. /**
  91. * @param $months the $months to set
  92. */
  93. public function setMonths($months) {
  94. $this->months = $months;
  95. }
  96. /**
  97. * @param $years the $years to set
  98. */
  99. public function setYears($years) {
  100. $this->years = $years;
  101. }
  102. /**
  103. * @return the $startYear
  104. */
  105. public function getStartYear() {
  106. return $this->startYear;
  107. }
  108. /**
  109. * @return the $startMonth
  110. */
  111. public function getStartMonth() {
  112. return $this->startMonth;
  113. }
  114. /**
  115. * @return the $startDay
  116. */
  117. public function getStartDay() {
  118. return $this->startDay;
  119. }
  120. /**
  121. * @return the $endYear
  122. */
  123. public function getEndYear() {
  124. return $this->endYear;
  125. }
  126. /**
  127. * @return the $endMonth
  128. */
  129. public function getEndMonth() {
  130. return $this->endMonth;
  131. }
  132. /**
  133. * @return the $endDay
  134. */
  135. public function getEndDay() {
  136. return $this->endDay;
  137. }
  138. /**
  139. * @param $startYear the $startYear to set
  140. */
  141. public function setStartYear($startYear) {
  142. $this->startYear = $startYear;
  143. }
  144. /**
  145. * @param $startMonth the $startMonth to set
  146. */
  147. public function setStartMonth($startMonth) {
  148. $this->startMonth = $startMonth;
  149. }
  150. /**
  151. * @param $startDay the $startDay to set
  152. */
  153. public function setStartDay($startDay) {
  154. $this->startDay = $startDay;
  155. }
  156. /**
  157. * @param $endYear the $endYear to set
  158. */
  159. public function setEndYear($endYear) {
  160. $this->endYear = $endYear;
  161. }
  162. /**
  163. * @param $endMonth the $endMonth to set
  164. */
  165. public function setEndMonth($endMonth) {
  166. $this->endMonth = $endMonth;
  167. }
  168. /**
  169. * @param $endDay the $endDay to set
  170. */
  171. public function setEndDay($endDay) {
  172. $this->endDay = $endDay;
  173. }
  174. /**
  175. * @return the $visitas
  176. */
  177. public function getVisitas() {
  178. return $this->visitas;
  179. }
  180. /**
  181. * @return the $cadastros
  182. */
  183. public function getCadastros() {
  184. return $this->cadastros;
  185. }
  186. /**
  187. * @return the $candProcSel
  188. */
  189. public function getCandProcSel() {
  190. return $this->candProcSel;
  191. }
  192. /**
  193. * @param $visitas the $visitas to set
  194. */
  195. public function setVisitas($visitas) {
  196. $this->visitas = $visitas;
  197. }
  198. /**
  199. * @param $cadastros the $cadastros to set
  200. */
  201. public function setCadastros($cadastros) {
  202. $this->cadastros = $cadastros;
  203. }
  204. /**
  205. * @param $candProcSel the $candProcSel to set
  206. */
  207. public function setCandProcSel($candProcSel) {
  208. $this->candProcSel = $candProcSel;
  209. }
  210. public function generateReport()
  211. {
  212. $this->getPeriodArray();
  213. $this->getVisitsPerPeriod();
  214. $this->getCadastrosPerPeriod();
  215. $this->getCandidatosProcSelPerPeriod();
  216. }
  217. public function getVisitsPerPeriod()
  218. {
  219. $visit = new Visit();
  220. if ($this->format == "days")
  221. $data = $visit->listVisitsPerDay();
  222. elseif ($this->format == "months")
  223. $data = $visit->listVisitsPerMonth();
  224. foreach ($this->visitas as $index => $date)
  225. {
  226. if (isset($data[$index]))
  227. $this->visitas[$index] = $data[$index];
  228. }
  229. }
  230. public function getCadastrosPerPeriod()
  231. {
  232. $user = new User();
  233. if ($this->format == "days")
  234. $data = $user->listCadastrosPerDay();
  235. elseif ($this->format == "months")
  236. $data = $user->listCadastrosPerMonth();
  237. foreach ($this->cadastros as $index => $date)
  238. {
  239. if (isset($data[$index]))
  240. $this->cadastros[$index] = $data[$index];
  241. }
  242. }
  243. public function getCandidatosProcSelPerPeriod()
  244. {
  245. $procSel = new CandidatoProcessoSeletivo();
  246. if ($this->format == "days")
  247. $data = $procSel->listCandidatosProcSelPerDay();
  248. elseif ($this->format == "months")
  249. $data = $procSel->listCandidatosProcSelPerMonth();
  250. foreach ($this->candProcSel as $index => $date)
  251. {
  252. if (isset($data[$index]))
  253. $this->candProcSel[$index] = $data[$index];
  254. }
  255. }
  256. public function getPeriodArray()
  257. {
  258. $array = getDateInterval($this->startYear, $this->startMonth, $this->startDay, $this->endYear, $this->endMonth, $this->endDay);
  259. foreach ($array as $date)
  260. {
  261. if ($this->format == "days")
  262. {
  263. if ($date['MONTH'] < 10)
  264. $month = "0".$date['MONTH'];
  265. else
  266. $month = $date['MONTH'];
  267. if ($date['DAY'] < 10)
  268. $day = "0".$date['DAY'];
  269. else
  270. $day = $date['DAY'];
  271. $this->visitas[$date['YEAR']."-".$month."-".$day] = 0;
  272. $this->candProcSel[$date['YEAR']."-".$month."-".$day] = 0;
  273. $this->cadastros[$date['YEAR']."-".$month."-".$day] = 0;
  274. $this->period[] = $date['YEAR']."-".$month."-".$day;
  275. $this->years[] = $date['YEAR'];
  276. $this->months[] = $date['MONTH'];
  277. $this->days[] = $date['DAY'];
  278. }
  279. elseif ($this->format == "months")
  280. {
  281. if ($date['MONTH'] < 10)
  282. $month = "0".$date['MONTH'];
  283. else
  284. $month = $date['MONTH'];
  285. $this->visitas[$date['YEAR']."-".$month] = 0;
  286. $this->candProcSel[$date['YEAR']."-".$month] = 0;
  287. $this->cadastros[$date['YEAR']."-".$month] = 0;
  288. $this->period[] = $date['YEAR']."-".$month;
  289. $this->years[] = $date['YEAR'];
  290. $this->months[] = $date['MONTH'];
  291. }
  292. }
  293. $this->months = array_unique($this->months);
  294. $this->years = array_unique($this->years);
  295. }
  296. public function numericMonthToString($numeric)
  297. {
  298. $string = array("'Jan'", "'Fev'", "'Mar'", "'Abr'", "'Mai'", "'Jun'", "'Jul'", "'Ago'", "'Set'", "'Out'", "'Nov'", "'Dez'");
  299. $newArray = array();
  300. foreach ($numeric as $month)
  301. {
  302. if (is_numeric($month) && $month > 0 && $month < 13)
  303. $newArray[] = $string[$month];
  304. }
  305. return $newArray;
  306. }
  307. }