[TASK] Replace deprecated API calls and label references
[TYPO3CMS/Extensions/languagevisibility.git] / class.tx_languagevisibility_feservices.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 2007 AOE media (dev@aoemedia.de)
6 * All rights reserved
7 *
8 * This script is part of the TYPO3 project. The TYPO3 project is
9 * free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * The GNU General Public License can be found at
15 * http://www.gnu.org/copyleft/gpl.html.
16 *
17 * This script is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
21 *
22 * This copyright notice MUST APPEAR in all copies of the script!
23 ***************************************************************/
24
25 /**
26 * exceptions are not handled here.
27 * This class just provides simple services and uses the domainmodel in classes directory!
28 *
29 * Methods can be used uninstanciated
30 */
31 class tx_languagevisibility_feservices extends tx_languagevisibility_abstractservices {
32
33 /**
34 * @param $uid
35 * @param $table
36 * @param $lUid
37 * @return mixed
38 */
39 public static function getFallbackOrderForElement($uid, $table, $lUid) {
40 $dao = t3lib_div::makeInstance('tx_languagevisibility_daocommon');
41 $elementfactory = t3lib_div::makeInstance('tx_languagevisibility_elementFactory', $dao);
42 $element = $elementfactory->getElementForTable($table, $uid);
43 $languageRep = t3lib_div::makeInstance('tx_languagevisibility_languagerepository');
44 $language = $languageRep->getLanguageById($lUid);
45
46 return $language->getFallbackOrderElement($element);
47 }
48
49 /**
50 * @param $uid
51 * @param $table
52 * @param $lUid
53 * @return mixed
54 */
55 public static function checkVisiblityForElement($uid, $table, $lUid) {
56 $dao = t3lib_div::makeInstance('tx_languagevisibility_daocommon');
57 $elementfactory = t3lib_div::makeInstance('tx_languagevisibility_elementFactory', $dao);
58 $element = $elementfactory->getElementForTable($table, $uid);
59 $languageRep = t3lib_div::makeInstance('tx_languagevisibility_languagerepository');
60 $language = $languageRep->getLanguageById($lUid);
61 $visibility = t3lib_div::makeInstance('tx_languagevisibility_visibilityService');
62
63 return $visibility->isVisible($language, $element);
64 }
65
66 /**
67 * @param $uid
68 * @param $table
69 * @return tx_languagevisibility_element
70 */
71 public static function getElement($uid, $table) {
72 $dao = t3lib_div::makeInstance('tx_languagevisibility_daocommon');
73 /** @var $elementfactory tx_languagevisibility_elementFactory */
74 $elementfactory = t3lib_div::makeInstance('tx_languagevisibility_elementFactory', $dao);
75 $element = $elementfactory->getElementForTable($table, $uid);
76
77 return $element;
78 }
79
80 /**
81 * @param $element
82 * @param $lUid
83 * @return mixed
84 */
85 public static function getOverlayLanguageIdForElement($element, $lUid) {
86 $languageRep = t3lib_div::makeInstance('tx_languagevisibility_languagerepository');
87 $language = $languageRep->getLanguageById($lUid);
88 $visibility = t3lib_div::makeInstance('tx_languagevisibility_visibilityService'); /** @var $visibility tx_languagevisibility_visibilityService */
89
90 return $visibility->getOverlayLanguageIdForLanguageAndElement($language, $element);
91 }
92
93 /**
94 * @param $uid
95 * @param $table
96 * @param $lUid
97 * @return mixed
98 */
99 public static function getOverlayLanguageIdForElementRecord($uid, $table, $lUid) {
100 $dao = t3lib_div::makeInstance('tx_languagevisibility_daocommon');
101 $elementfactory = t3lib_div::makeInstance('tx_languagevisibility_elementFactory', $dao);
102 $element = $elementfactory->getElementForTable($table, $uid);
103 $languageRep = t3lib_div::makeInstance('tx_languagevisibility_languagerepository');
104 $language = $languageRep->getLanguageById($lUid);
105
106 $visibility = t3lib_div::makeInstance('tx_languagevisibility_visibilityService');
107 return $visibility->getOverlayLanguageIdForLanguageAndElement($language, $element);
108 }
109
110 /**
111 * @param $uid
112 * @param $table
113 * @param $lUid
114 * @return mixed
115 */
116 public static function getOverlayLanguageIdForElementRecordForced($uid, $table, $lUid) {
117 $dao = t3lib_div::makeInstance('tx_languagevisibility_daocommon');
118 $elementfactory = t3lib_div::makeInstance('tx_languagevisibility_elementFactory', $dao);
119 $element = $elementfactory->getElementForTable($table, $uid);
120 $languageRep = t3lib_div::makeInstance('tx_languagevisibility_languagerepository');
121 $language = $languageRep->getLanguageById($lUid);
122
123 $visibility = t3lib_div::makeInstance('tx_languagevisibility_visibilityService');
124 $visibility->isVisible($language, $element);
125 return $visibility->getLastRelevantOverlayLanguageId();
126 }
127
128 /**
129 * Check if given element has traslation in given language
130 *
131 * @param int $elementUid
132 * @param string $table
133 * @param int $languageUid
134 * @return boolean
135 */
136 public static function hasTranslation($elementUid, $table, $languageUid) {
137 $dao = t3lib_div::makeInstance('tx_languagevisibility_daocommon');
138 $elementfactory = t3lib_div::makeInstance('tx_languagevisibility_elementFactory', $dao);
139
140 $result = FALSE;
141 try {
142 $element = $elementfactory->getElementForTable($table, $elementUid);
143 $result = $element->hasTranslation($languageUid);
144 } catch ( UnexpectedValueException $e ) {
145 //the element can not be handeld by language visibility
146 $result = FALSE;
147 }
148
149 return $result;
150 }
151 }