PageRenderTime 32ms CodeModel.GetById 24ms RepoModel.GetById 0ms app.codeStats 0ms

/packages/PageInfo/PageInfo/Managers/PageInfo.class.php

https://bitbucket.org/alexamiryan/stingle
PHP | 99 lines | 88 code | 11 blank | 0 comment | 15 complexity | c54845007b1715d56d4ac461d5b1c8a1 MD5 | raw file
  1. <?php
  2. class PageInfo extends DbAccessor
  3. {
  4. private $host; //Host object
  5. private $language; //Language object
  6. const TBL_PAGE_INFO = "site_pages_info";
  7. public function __construct(Host $host, Language $language, $instanceName = null){
  8. parent::__construct($instanceName);
  9. $this->host = $host;
  10. $this->language = $language;
  11. }
  12. public function getInfo($module, $page){
  13. if(empty($module) or empty($page)){
  14. throw new InvalidArrayArgumentException("module or page can not be empty");
  15. }
  16. if(($info = $this->getExact($module, $page)) != false){
  17. return $info;
  18. }
  19. if(($info = $this->getModuleDefault($module)) != false){
  20. return $info;
  21. }
  22. if(($info = $this->getHostLangDefault()) != false){
  23. return $info;
  24. }
  25. if(($info = $this->getLangDefault()) != false){
  26. return $info;
  27. }
  28. if(($info = $this->getDefault()) != false){
  29. return $info;
  30. }
  31. return array("title"=>'',"meta_keywords"=>'',"meta_description"=>'');
  32. }
  33. private function getExact($module, $page, $cacheMinutes = null){
  34. $this->query->exec(static::queryString($this->language->id, $this->host->id, $module, $page), $cacheMinutes);
  35. $data = $this->query->fetchRecord();
  36. return $data;
  37. }
  38. private function getModuleDefault($module, $cacheMinutes = null){
  39. $this->query->exec(static::queryString($this->language->id, $this->host->id, $module), $cacheMinutes);
  40. $data = $this->query->fetchRecord();
  41. return $data;
  42. }
  43. private function getHostLangDefault($cacheMinutes = null){
  44. $this->query->exec(static::queryString($this->language->id, $this->host->id), $cacheMinutes);
  45. $data = $this->query->fetchRecord();
  46. return $data;
  47. }
  48. private function getLangDefault($cacheMinutes = null){
  49. $this->query->exec(static::queryString($this->language->id), $cacheMinutes);
  50. $data = $this->query->fetchRecord();
  51. return $data;
  52. }
  53. private function getDefault($cacheMinutes = null){
  54. $this->query->exec(static::queryString(), $cacheMinutes);
  55. $data = $this->query->fetchRecord();
  56. return $data;
  57. }
  58. protected static function queryString($lang_id=null, $host_id=null, $module=null, $page=null, $cacheMinutes = null){
  59. $qb = new QueryBuilder();
  60. $qb->select(new Field('title'), new Field('meta_keywords'), new Field('meta_description'))
  61. ->from(Tbl::get('TBL_PAGE_INFO'));
  62. if($lang_id === null){
  63. $qb->andWhere($qb->expr()->isNull(new Field('lang_id')));
  64. }
  65. else{
  66. $qb->andWhere($qb->expr()->equal(new Field('lang_id'), $lang_id));
  67. }
  68. if($host_id === null){
  69. $qb->andWhere($qb->expr()->isNull(new Field('host_id')));
  70. }
  71. else{
  72. $qb->andWhere($qb->expr()->equal(new Field('host_id'), $host_id));
  73. }
  74. if($module === null){
  75. $qb->andWhere($qb->expr()->isNull(new Field('module')));
  76. }
  77. else{
  78. $qb->andWhere($qb->expr()->equal(new Field('module'), $module));
  79. }
  80. if($page === null){
  81. $qb->andWhere($qb->expr()->isNull(new Field('page')));
  82. }
  83. else{
  84. $qb->andWhere($qb->expr()->equal(new Field('page'), $page));
  85. }
  86. return $qb->getSQL();
  87. }
  88. }