PageRenderTime 52ms CodeModel.GetById 24ms RepoModel.GetById 1ms app.codeStats 0ms

/modules/website/documents/WebsiteBase.class.php

http://pagizer-cms.googlecode.com/
PHP | 397 lines | 244 code | 43 blank | 110 comment | 18 complexity | dae70bc6c1f00a8ee3210286088cb247 MD5 | raw file
Possible License(s): LGPL-3.0, LGPL-2.1
  1. <?php
  2. class m_website_documents_WebsiteBase extends f_document_BaseDocument
  3. {
  4. private $url;
  5. private $page = array();
  6. private $menus = array();
  7. private $displayLang;
  8. private $theme;
  9. public function __construct($id = null, $lang = null)
  10. {
  11. parent::__construct($id, null, $lang);
  12. }
  13. public function getTableName()
  14. {
  15. return "m_website__website";
  16. }
  17. public function getDocumentModel()
  18. {
  19. return "modules_website/website";
  20. }
  21. protected function getFieldsBag()
  22. {
  23. return array('document_id', 'document_uid', 'document_model', 'document_author', 'document_creationdate', 'document_modificationdate', 'document_publicationstatus', 'document_lang', 'document_revision', 'document_startpublicationdate', 'document_endpublicationdate', 'document_label', 'url', 'page', 'menus', 'displayLang', 'theme');
  24. }
  25. public function getdefaultPublicationstatus()
  26. {
  27. return "PUBLISHED";
  28. }
  29. /**
  30. * @return boolean
  31. */
  32. public function isRevisable()
  33. {
  34. return false;
  35. }
  36. /**
  37. * @return boolean
  38. */
  39. public function isLocalized()
  40. {
  41. return true;
  42. }
  43. /**
  44. * @return boolean
  45. */
  46. public function isRecursive()
  47. {
  48. return $this->isRecursive;
  49. }
  50. /**
  51. * @param boolean $value
  52. * @return m_website_documents_WebsiteBase
  53. */
  54. public function setIsRecursive($value)
  55. {
  56. $this->isRecursive = $value;
  57. }
  58. /**
  59. * @return string
  60. */
  61. public function getUrl()
  62. {
  63. return $this->url;
  64. }
  65. /**
  66. * @param string $value
  67. * @return m_website_documents_Website
  68. */
  69. public function setUrl($value)
  70. {
  71. $this->url = $value;
  72. return $this;
  73. }
  74. /**
  75. * Add a new related document by document_uid
  76. *
  77. * @return m_website_documents_Website
  78. */
  79. public function addPageById($documentId, $orderNumber = null)
  80. {
  81. $document = f_document_Provider::getInstance()->getByUniqueId($documentId);
  82. return $this->addPage($document, $orderNumber);
  83. }
  84. /**
  85. * Add a new related document
  86. *
  87. * @return m_website_documents_Website
  88. */
  89. public function addPage($document, $orderNumber = null)
  90. {
  91. if(is_object($document) && $document instanceof m_website_documents_Page)
  92. {
  93. if(!is_array($this->page))
  94. {
  95. $this->page = array();
  96. }
  97. if(!in_array($document, $this->page))
  98. {
  99. if(is_null($orderNumber))
  100. {
  101. $this->page[] = $document;
  102. }
  103. else
  104. {
  105. $this->page[$orderNumber] = $document;
  106. }
  107. }
  108. }
  109. else
  110. {
  111. throw new Exception("Document is not a valid object or from valid model(m_website_documents_Page)");
  112. }
  113. return $this;
  114. }
  115. /**
  116. * Get the related documents in array
  117. *
  118. * @return array m_website_documents_Page
  119. */
  120. public function getPage()
  121. {
  122. $relationManager = f_relation_Manager::getInstance();
  123. return $relationManager->getChilds($this, "page", $this->getLang());
  124. }
  125. /**
  126. * Get related documents number
  127. *
  128. * @return integer
  129. */
  130. public function getPageNb()
  131. {
  132. return $this->page;
  133. }
  134. /**
  135. * Set the number of related documents
  136. * Only used when saving or initialize document
  137. */
  138. protected function setPage($value)
  139. {
  140. if(!is_null($value) && is_int($value))
  141. {
  142. $this->page = $value;
  143. }
  144. else
  145. {
  146. $dbProvider = f_database_Provider::getInstance();
  147. $sql = "SELECT COUNT(`child_id`) FROM `f_relation` WHERE `relation_type`=:relationType AND `lang`=:lang AND `parent_id`=:parentId";
  148. $nbRelations = $dbProvider->setQuery($sql)->execute(array("relationType" => 'page', "lang" => $this->getLang(), "parentId" => $this->getUniqueId()))->getQueryResult(PDO::FETCH_COLUMN);
  149. $this->page = intval($nbRelations);
  150. }
  151. }
  152. /**
  153. * Add a new related document by document_uid
  154. *
  155. * @return m_website_documents_Website
  156. */
  157. public function addMenusById($documentId, $orderNumber = null)
  158. {
  159. $document = f_document_Provider::getInstance()->getByUniqueId($documentId);
  160. return $this->addMenus($document, $orderNumber);
  161. }
  162. /**
  163. * Add a new related document
  164. *
  165. * @return m_website_documents_Website
  166. */
  167. public function addMenus($document, $orderNumber = null)
  168. {
  169. if(is_object($document) && $document instanceof m_website_documents_Menu)
  170. {
  171. if(!is_array($this->menus))
  172. {
  173. $this->menus = array();
  174. }
  175. if(!in_array($document, $this->menus))
  176. {
  177. if(is_null($orderNumber))
  178. {
  179. $this->menus[] = $document;
  180. }
  181. else
  182. {
  183. $this->menus[$orderNumber] = $document;
  184. }
  185. }
  186. }
  187. else
  188. {
  189. throw new Exception("Document is not a valid object or from valid model(m_website_documents_Menu)");
  190. }
  191. return $this;
  192. }
  193. /**
  194. * Get the related documents in array
  195. *
  196. * @return array m_website_documents_Menu
  197. */
  198. public function getMenus()
  199. {
  200. $relationManager = f_relation_Manager::getInstance();
  201. return $relationManager->getChilds($this, "menus", $this->getLang());
  202. }
  203. /**
  204. * Get related documents number
  205. *
  206. * @return integer
  207. */
  208. public function getMenusNb()
  209. {
  210. return $this->menus;
  211. }
  212. /**
  213. * Set the number of related documents
  214. * Only used when saving or initialize document
  215. */
  216. protected function setMenus($value)
  217. {
  218. if(!is_null($value) && is_int($value))
  219. {
  220. $this->menus = $value;
  221. }
  222. else
  223. {
  224. $dbProvider = f_database_Provider::getInstance();
  225. $sql = "SELECT COUNT(`child_id`) FROM `f_relation` WHERE `relation_type`=:relationType AND `lang`=:lang AND `parent_id`=:parentId";
  226. $nbRelations = $dbProvider->setQuery($sql)->execute(array("relationType" => 'menus', "lang" => $this->getLang(), "parentId" => $this->getUniqueId()))->getQueryResult(PDO::FETCH_COLUMN);
  227. $this->menus = intval($nbRelations);
  228. }
  229. }
  230. /**
  231. * @return string
  232. */
  233. public function getDisplayLang()
  234. {
  235. return $this->displayLang;
  236. }
  237. /**
  238. * @param string $value
  239. * @return m_website_documents_Website
  240. */
  241. public function setDisplayLang($value)
  242. {
  243. $this->displayLang = $value;
  244. return $this;
  245. }
  246. /**
  247. * @return string
  248. */
  249. public function getTheme()
  250. {
  251. return $this->theme;
  252. }
  253. /**
  254. * @param string $value
  255. * @return m_website_documents_Website
  256. */
  257. public function setTheme($value)
  258. {
  259. $this->theme = $value;
  260. return $this;
  261. }
  262. public function relationFields()
  263. {
  264. return array_merge(array('page', 'menus'),parent::relationFields());
  265. }
  266. public function localizedFields()
  267. {
  268. return array(
  269. 'document_id',
  270. 'document_uid',
  271. 'document_author',
  272. 'document_creationdate',
  273. 'document_modificationdate',
  274. 'document_lang',
  275. 'document_revision',
  276. 'document_label',
  277. 'document_publicationstatus', 'url', 'page', 'menus', 'displayLang', 'theme');
  278. }
  279. public function nonLocalizedFields()
  280. {
  281. return array( 'document_id', 'document_uid', 'document_model', 'document_author', 'document_creationdate', 'document_modificationdate', 'document_lang', 'document_revision', 'document_startpublicationdate', 'document_endpublicationdate', 'document_label');
  282. }
  283. /**
  284. * Returns VO lang and translations langs
  285. * @return array
  286. */
  287. public function getAllLangs()
  288. {
  289. $langs = $this->getTranslationLangs();
  290. array_unshift($langs, $this->getVO());
  291. return $langs;
  292. }
  293. /**
  294. * Returns all translations langs
  295. * @return array
  296. */
  297. public function getTranslationLangs()
  298. {
  299. $dbProvider = f_database_Provider::getInstance();
  300. $sql = "SELECT `document_lang` FROM ".$this->getTableName()."_i18n WHERE `document_uid`=:id";
  301. return $dbProvider->setQuery($sql)->execute(array("id" => $this->getUniqueId()))->getQueryResults(PDO::FETCH_COLUMN);
  302. }
  303. /**
  304. * Check if current document has at least one translation or a translation with the given lang
  305. * @return boolean
  306. */
  307. public function hasTranslation($lang = null)
  308. {
  309. if(is_null($lang))
  310. {
  311. return count($this->getTranslationLangs()) > 0;
  312. }
  313. else
  314. {
  315. return in_array(strtoupper($lang), $this->getTranslationLangs());
  316. }
  317. }
  318. /**
  319. * Check if current document is translated or not
  320. * @return boolean
  321. */
  322. public function isTranslated()
  323. {
  324. return $this->getPublicationstatus() != parent::NOTRANSLATION;
  325. }
  326. /**
  327. * Check if current document is a translation
  328. * @return boolean
  329. */
  330. public function isATranslation()
  331. {
  332. return $this->getLang() != $this->getVO();
  333. }
  334. /**
  335. * Return the original document
  336. * @return m_website_documents_Website
  337. */
  338. public function getVoDocument()
  339. {
  340. if($this->isATranslation())
  341. {
  342. return m_website_documents_Website::getInstanceByUniqueId($this->getUniqueId(), $this->getVO());
  343. }
  344. return $this;
  345. }
  346. /**
  347. * Return current document translation
  348. * @return m_website_documents_Website
  349. */
  350. public function getTranslation($lang)
  351. {
  352. return m_website_documents_Website::getInstanceByUniqueId($this->getUniqueId(), $lang);
  353. }
  354. }