| 1 |
<?php |
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 |
|
|---|
| 6 |
|
|---|
| 7 |
|
|---|
| 8 |
|
|---|
| 9 |
|
|---|
| 10 |
|
|---|
| 11 |
|
|---|
| 12 |
|
|---|
| 13 |
|
|---|
| 14 |
|
|---|
| 15 |
|
|---|
| 16 |
|
|---|
| 17 |
|
|---|
| 18 |
|
|---|
| 19 |
class sfMessageSource_Aggregate extends sfMessageSource |
|---|
| 20 |
{ |
|---|
| 21 |
protected |
|---|
| 22 |
$messageSources = array(); |
|---|
| 23 |
|
|---|
| 24 |
|
|---|
| 25 |
* Constructor. |
|---|
| 26 |
* |
|---|
| 27 |
* The order of the messages sources in the array is important. |
|---|
| 28 |
* This class will take the first translation found in the message sources. |
|---|
| 29 |
* |
|---|
| 30 |
* @param array $messageSources An array of message sources. |
|---|
| 31 |
* |
|---|
| 32 |
* @see MessageSource::factory(); |
|---|
| 33 |
*/ |
|---|
| 34 |
function __construct($messageSources) |
|---|
| 35 |
{ |
|---|
| 36 |
$this->messageSources = $messageSources; |
|---|
| 37 |
} |
|---|
| 38 |
|
|---|
| 39 |
public function setCulture($culture) |
|---|
| 40 |
{ |
|---|
| 41 |
parent::setCulture($culture); |
|---|
| 42 |
|
|---|
| 43 |
foreach ($this->messageSources as $messageSource) |
|---|
| 44 |
{ |
|---|
| 45 |
$messageSource->setCulture($culture); |
|---|
| 46 |
} |
|---|
| 47 |
} |
|---|
| 48 |
|
|---|
| 49 |
protected function getLastModified($sources) |
|---|
| 50 |
{ |
|---|
| 51 |
$lastModified = time(); |
|---|
| 52 |
foreach ($sources as $source) |
|---|
| 53 |
{ |
|---|
| 54 |
if (0 !== $sourceLastModified = $source[0]->getLastModified($source[1])) |
|---|
| 55 |
{ |
|---|
| 56 |
$lastModified = min($lastModified, $sourceLastModified); |
|---|
| 57 |
} |
|---|
| 58 |
} |
|---|
| 59 |
|
|---|
| 60 |
return $lastModified; |
|---|
| 61 |
} |
|---|
| 62 |
|
|---|
| 63 |
public function isValidSource($sources) |
|---|
| 64 |
{ |
|---|
| 65 |
foreach ($sources as $source) |
|---|
| 66 |
{ |
|---|
| 67 |
if (false === $source[0]->isValidSource($source[1])) |
|---|
| 68 |
{ |
|---|
| 69 |
continue; |
|---|
| 70 |
} |
|---|
| 71 |
|
|---|
| 72 |
return true; |
|---|
| 73 |
} |
|---|
| 74 |
|
|---|
| 75 |
return false; |
|---|
| 76 |
} |
|---|
| 77 |
|
|---|
| 78 |
public function getSource($variant) |
|---|
| 79 |
{ |
|---|
| 80 |
$sources = array(); |
|---|
| 81 |
foreach ($this->messageSources as $messageSource) |
|---|
| 82 |
{ |
|---|
| 83 |
$sources[] = array($messageSource, $messageSource->getSource(str_replace($messageSource->getId(), '', $variant))); |
|---|
| 84 |
} |
|---|
| 85 |
|
|---|
| 86 |
return $sources; |
|---|
| 87 |
} |
|---|
| 88 |
|
|---|
| 89 |
public function &loadData($sources) |
|---|
| 90 |
{ |
|---|
| 91 |
$messages = array(); |
|---|
| 92 |
foreach ($sources as $source) |
|---|
| 93 |
{ |
|---|
| 94 |
if (false === $source[0]->isValidSource($source[1])) |
|---|
| 95 |
{ |
|---|
| 96 |
continue; |
|---|
| 97 |
} |
|---|
| 98 |
|
|---|
| 99 |
$data = $source[0]->loadData($source[1]); |
|---|
| 100 |
if (is_array($data)) |
|---|
| 101 |
{ |
|---|
| 102 |
$messages = array_merge($data, $messages); |
|---|
| 103 |
} |
|---|
| 104 |
} |
|---|
| 105 |
|
|---|
| 106 |
return $messages; |
|---|
| 107 |
} |
|---|
| 108 |
|
|---|
| 109 |
public function getCatalogueList($catalogue) |
|---|
| 110 |
{ |
|---|
| 111 |
$variants = array(); |
|---|
| 112 |
foreach ($this->messageSources as $messageSource) |
|---|
| 113 |
{ |
|---|
| 114 |
foreach ($messageSource->getCatalogueList($catalogue) as $variant) |
|---|
| 115 |
{ |
|---|
| 116 |
$variants[] = $messageSource->getId().$variant; |
|---|
| 117 |
} |
|---|
| 118 |
} |
|---|
| 119 |
|
|---|
| 120 |
return $variants; |
|---|
| 121 |
} |
|---|
| 122 |
|
|---|
| 123 |
public function append($message) |
|---|
| 124 |
{ |
|---|
| 125 |
|
|---|
| 126 |
if (count($this->messageSources)) |
|---|
| 127 |
{ |
|---|
| 128 |
$this->messageSources[0]->append($message); |
|---|
| 129 |
} |
|---|
| 130 |
} |
|---|
| 131 |
|
|---|
| 132 |
public function update($text, $target, $comments, $catalogue = 'messages') |
|---|
| 133 |
{ |
|---|
| 134 |
|
|---|
| 135 |
foreach ($this->messageSources as $messageSource) |
|---|
| 136 |
{ |
|---|
| 137 |
if ($messageSource->update($text, $target, $comments, $catalogue)) |
|---|
| 138 |
{ |
|---|
| 139 |
return true; |
|---|
| 140 |
} |
|---|
| 141 |
} |
|---|
| 142 |
|
|---|
| 143 |
return false; |
|---|
| 144 |
} |
|---|
| 145 |
|
|---|
| 146 |
public function delete($message, $catalogue = 'messages') |
|---|
| 147 |
{ |
|---|
| 148 |
$retval = false; |
|---|
| 149 |
foreach ($this->messageSources as $messageSource) |
|---|
| 150 |
{ |
|---|
| 151 |
if ($messageSource->delete($message, $catalogue)) |
|---|
| 152 |
{ |
|---|
| 153 |
$retval = true; |
|---|
| 154 |
} |
|---|
| 155 |
} |
|---|
| 156 |
|
|---|
| 157 |
return $retval; |
|---|
| 158 |
} |
|---|
| 159 |
|
|---|
| 160 |
public function save($catalogue = 'messages') |
|---|
| 161 |
{ |
|---|
| 162 |
$retval = false; |
|---|
| 163 |
foreach ($this->messageSources as $messageSource) |
|---|
| 164 |
{ |
|---|
| 165 |
if ($messageSource->save($catalogue)) |
|---|
| 166 |
{ |
|---|
| 167 |
$retval = true; |
|---|
| 168 |
} |
|---|
| 169 |
} |
|---|
| 170 |
|
|---|
| 171 |
return $retval; |
|---|
| 172 |
} |
|---|
| 173 |
|
|---|
| 174 |
public function getId() |
|---|
| 175 |
{ |
|---|
| 176 |
$id = ''; |
|---|
| 177 |
foreach ($this->messageSources as $messageSource) |
|---|
| 178 |
{ |
|---|
| 179 |
$id .= $messageSource->getId(); |
|---|
| 180 |
} |
|---|
| 181 |
|
|---|
| 182 |
return md5($id); |
|---|
| 183 |
} |
|---|
| 184 |
|
|---|
| 185 |
public function catalogues() |
|---|
| 186 |
{ |
|---|
| 187 |
throw new sfException('The "catalogues()" method is not implemented for this message source.'); |
|---|
| 188 |
} |
|---|
| 189 |
} |
|---|
| 190 |
|
|---|