@@ -132,6 +132,10 @@ discard block |
||
132 | 132 | } |
133 | 133 | |
134 | 134 | |
135 | + /** |
|
136 | + * @param integer $depth |
|
137 | + * @param string $parentKey |
|
138 | + */ |
|
135 | 139 | private function recurseArrayAssertion($toAssert, $depth, $parentKey) { |
136 | 140 | $prefix = str_repeat("\t",$depth); |
137 | 141 | echo "\t{$prefix}'$parentKey' => array(\n"; |
@@ -160,6 +164,10 @@ discard block |
||
160 | 164 | /* |
161 | 165 | Helper methods for testing CMS fields |
162 | 166 | */ |
167 | + |
|
168 | + /** |
|
169 | + * @param string $tabName |
|
170 | + */ |
|
163 | 171 | public function checkTabExists($fields, $tabName) { |
164 | 172 | echo "Searching for tab $tabName\n"; |
165 | 173 | $tab = $fields->findOrMakeTab("Root.{$tabName}"); |
@@ -184,6 +192,9 @@ discard block |
||
184 | 192 | } |
185 | 193 | |
186 | 194 | |
195 | + /** |
|
196 | + * @param string $fieldName |
|
197 | + */ |
|
187 | 198 | public function checkFieldExists($tab,$fieldName) { |
188 | 199 | $fields = $tab->Fields(); |
189 | 200 | echo "TAB:{$tab->Name}\n"; |
@@ -208,11 +208,11 @@ |
||
208 | 208 | */ |
209 | 209 | public function invokeMethod(&$object, $methodName, array $parameters = array()) |
210 | 210 | { |
211 | - $reflection = new \ReflectionClass(get_class($object)); |
|
212 | - $method = $reflection->getMethod($methodName); |
|
213 | - $method->setAccessible(true); |
|
211 | + $reflection = new \ReflectionClass(get_class($object)); |
|
212 | + $method = $reflection->getMethod($methodName); |
|
213 | + $method->setAccessible(true); |
|
214 | 214 | |
215 | - return $method->invokeArgs($object, $parameters); |
|
215 | + return $method->invokeArgs($object, $parameters); |
|
216 | 216 | } |
217 | 217 | |
218 | 218 |
@@ -9,8 +9,8 @@ discard block |
||
9 | 9 | public static $ignoreFixtureFileFor = array(); |
10 | 10 | |
11 | 11 | protected $extraDataObjects = array( |
12 | - 'SearchableTestPage','FlickrPhotoTO','FlickrAuthorTO','FlickrSetTO','FlickrTagTO', |
|
13 | - 'SearchableTestFatherPage','SearchableTestGrandFatherPage','AutoCompleteOption' |
|
12 | + 'SearchableTestPage', 'FlickrPhotoTO', 'FlickrAuthorTO', 'FlickrSetTO', 'FlickrTagTO', |
|
13 | + 'SearchableTestFatherPage', 'SearchableTestGrandFatherPage', 'AutoCompleteOption' |
|
14 | 14 | ); |
15 | 15 | |
16 | 16 | |
@@ -39,7 +39,7 @@ discard block |
||
39 | 39 | |
40 | 40 | // this needs to be called in order to create the list of searchable |
41 | 41 | // classes and fields that are available. Simulates part of a build |
42 | - $classes = array('SearchableTestPage','SiteTree','Page','FlickrPhotoTO','FlickrSetTO', |
|
42 | + $classes = array('SearchableTestPage', 'SiteTree', 'Page', 'FlickrPhotoTO', 'FlickrSetTO', |
|
43 | 43 | 'FlickrTagTO', 'FlickrAuthorTO'); |
44 | 44 | $this->requireDefaultRecordsFrom = $classes; |
45 | 45 | |
@@ -61,13 +61,13 @@ discard block |
||
61 | 61 | $orig_fixture_file = static::$fixture_file; |
62 | 62 | |
63 | 63 | foreach (static::$ignoreFixtureFileFor as $testPattern) { |
64 | - $pattern = '/'.$testPattern.'/'; |
|
64 | + $pattern = '/' . $testPattern . '/'; |
|
65 | 65 | if (preg_match($pattern, $this->getName())) { |
66 | 66 | static::$fixture_file = null; |
67 | 67 | } |
68 | 68 | } |
69 | 69 | |
70 | - echo "\n\n\n\nEXECUTING TEST {$this->getName()}, FIXTURES=".static::$fixture_file."\n"; |
|
70 | + echo "\n\n\n\nEXECUTING TEST {$this->getName()}, FIXTURES=" . static::$fixture_file . "\n"; |
|
71 | 71 | |
72 | 72 | parent::setUp(); |
73 | 73 | static::$fixture_file = $orig_fixture_file; |
@@ -97,53 +97,53 @@ discard block |
||
97 | 97 | // temporarily disable Elasticsearch indexing, it will be done in a batch |
98 | 98 | $page->IndexingOff = true; |
99 | 99 | |
100 | - echo "Publishing ".$page->Title."\n"; |
|
101 | - $page->publish('Stage','Live'); |
|
100 | + echo "Publishing " . $page->Title . "\n"; |
|
101 | + $page->publish('Stage', 'Live'); |
|
102 | 102 | } |
103 | 103 | } |
104 | 104 | |
105 | 105 | |
106 | 106 | public function generateAssertionsFromArray($toAssert) { |
107 | - echo '$expected = array('."\n"; |
|
107 | + echo '$expected = array(' . "\n"; |
|
108 | 108 | foreach ($toAssert as $key => $value) { |
109 | 109 | $escValue = str_replace("'", '\\\'', $value); |
110 | 110 | echo "'$key' => '$escValue',\n"; |
111 | 111 | } |
112 | 112 | echo ");\n"; |
113 | - echo '$this->assertEquals($expected, $somevar);'."\n"; |
|
113 | + echo '$this->assertEquals($expected, $somevar);' . "\n"; |
|
114 | 114 | } |
115 | 115 | |
116 | 116 | |
117 | 117 | public function generateAssertionsFromArray1D($toAssert) { |
118 | - echo '$expected = array('."\n"; |
|
118 | + echo '$expected = array(' . "\n"; |
|
119 | 119 | foreach ($toAssert as $key => $value) { |
120 | 120 | $escValue = str_replace("'", '\\\'', $value); |
121 | 121 | echo "'$escValue',"; |
122 | 122 | } |
123 | 123 | echo ");\n"; |
124 | - echo '$this->assertEquals($expected, $somevar);'."\n"; |
|
124 | + echo '$this->assertEquals($expected, $somevar);' . "\n"; |
|
125 | 125 | } |
126 | 126 | |
127 | 127 | |
128 | 128 | public function generateAssertionsFromArrayRecurse($toAssert) { |
129 | 129 | echo '$expected = '; |
130 | - $this->recurseArrayAssertion($toAssert,1, 'FIXME'); |
|
131 | - echo '$this->assertEquals($expected, $somevar);'."\n"; |
|
130 | + $this->recurseArrayAssertion($toAssert, 1, 'FIXME'); |
|
131 | + echo '$this->assertEquals($expected, $somevar);' . "\n"; |
|
132 | 132 | } |
133 | 133 | |
134 | 134 | |
135 | 135 | private function recurseArrayAssertion($toAssert, $depth, $parentKey) { |
136 | - $prefix = str_repeat("\t",$depth); |
|
136 | + $prefix = str_repeat("\t", $depth); |
|
137 | 137 | echo "\t{$prefix}'$parentKey' => array(\n"; |
138 | 138 | $ctr = 0; |
139 | 139 | $len = sizeof(array_keys($toAssert)); |
140 | 140 | foreach ($toAssert as $key => $value) { |
141 | 141 | if (is_array($value)) { |
142 | - $this->recurseArrayAssertion($value, $depth+1, $key); |
|
142 | + $this->recurseArrayAssertion($value, $depth + 1, $key); |
|
143 | 143 | } else { |
144 | 144 | $escValue = str_replace("'", '\\\'', $value); |
145 | 145 | $comma = ','; |
146 | - if ($ctr == $len-1) { |
|
146 | + if ($ctr == $len - 1) { |
|
147 | 147 | $comma = ''; |
148 | 148 | } |
149 | 149 | echo "\t\t$prefix'$key' => '$escValue'$comma\n"; |
@@ -184,11 +184,11 @@ discard block |
||
184 | 184 | } |
185 | 185 | |
186 | 186 | |
187 | - public function checkFieldExists($tab,$fieldName) { |
|
187 | + public function checkFieldExists($tab, $fieldName) { |
|
188 | 188 | $fields = $tab->Fields(); |
189 | 189 | echo "TAB:{$tab->Name}\n"; |
190 | 190 | foreach ($fields as $fi) { |
191 | - echo "NAME:".$fi->Name."\n"; |
|
191 | + echo "NAME:" . $fi->Name . "\n"; |
|
192 | 192 | } |
193 | 193 | $field = $tab->fieldByName($fieldName); |
194 | 194 | $this->assertTrue($field != null); |
@@ -225,7 +225,7 @@ discard block |
||
225 | 225 | $numberDocsInIndex = $status['indices']['elastica_ss_module_test_en_us']['docs']['num_docs']; |
226 | 226 | } |
227 | 227 | |
228 | - $this->assertEquals($expectedAmount,$numberDocsInIndex); |
|
228 | + $this->assertEquals($expectedAmount, $numberDocsInIndex); |
|
229 | 229 | } |
230 | 230 | |
231 | 231 | /* |
@@ -282,7 +282,6 @@ discard block |
||
282 | 282 | * to "auto-filter" all SELECT queries by this language. |
283 | 283 | * See {@link disable_locale_filter()} on how to override this behaviour temporarily. |
284 | 284 | * |
285 | - * @param string $lang New reading language. |
|
286 | 285 | */ |
287 | 286 | static function set_current_locale($locale) { |
288 | 287 | self::$current_locale = $locale; |
@@ -373,7 +372,7 @@ discard block |
||
373 | 372 | * Check if a given SQLQuery filters on the Locale field |
374 | 373 | * |
375 | 374 | * @param SQLQuery $query |
376 | - * @return boolean |
|
375 | + * @return boolean|null |
|
377 | 376 | */ |
378 | 377 | protected function filtersOnLocale($query) { |
379 | 378 | foreach($query->getWhere() as $condition) { |
@@ -536,7 +535,7 @@ discard block |
||
536 | 535 | * This ID might equal the record ID, but doesn't have to - |
537 | 536 | * it just points to one "original" record in the list. |
538 | 537 | * |
539 | - * @return int Numeric ID of the translationgroup in the <classname>_translationgroup table |
|
538 | + * @return false|string Numeric ID of the translationgroup in the <classname>_translationgroup table |
|
540 | 539 | */ |
541 | 540 | public function getTranslationGroup() { |
542 | 541 | if(!$this->owner->exists()) return false; |
@@ -344,14 +344,14 @@ discard block |
||
344 | 344 | parent::setOwner($owner, $ownerBaseClass); |
345 | 345 | |
346 | 346 | // setting translatable fields by inspecting owner - this should really be done in the constructor |
347 | - if($this->owner && $this->translatableFields === null) { |
|
347 | + if ($this->owner && $this->translatableFields === null) { |
|
348 | 348 | $this->translatableFields = array_merge( |
349 | 349 | array_keys($this->owner->db()), |
350 | 350 | array_keys($this->owner->has_many()), |
351 | 351 | array_keys($this->owner->many_many()) |
352 | 352 | ); |
353 | 353 | foreach (array_keys($this->owner->has_one()) as $fieldname) { |
354 | - $this->translatableFields[] = $fieldname.'ID'; |
|
354 | + $this->translatableFields[] = $fieldname . 'ID'; |
|
355 | 355 | } |
356 | 356 | } |
357 | 357 | } |
@@ -376,8 +376,8 @@ discard block |
||
376 | 376 | * @return boolean |
377 | 377 | */ |
378 | 378 | protected function filtersOnLocale($query) { |
379 | - foreach($query->getWhere() as $condition) { |
|
380 | - if(preg_match('/("|\'|`)Locale("|\'|`)/', $condition)) return true; |
|
379 | + foreach ($query->getWhere() as $condition) { |
|
380 | + if (preg_match('/("|\'|`)Locale("|\'|`)/', $condition)) return true; |
|
381 | 381 | } |
382 | 382 | } |
383 | 383 | |
@@ -389,18 +389,18 @@ discard block |
||
389 | 389 | * |
390 | 390 | * Use {@link disable_locale_filter()} to temporarily disable this "auto-filtering". |
391 | 391 | */ |
392 | - public function augmentSQL(SQLQuery &$query, DataQuery $dataQuery = null) { |
|
392 | + public function augmentSQL(SQLQuery & $query, DataQuery $dataQuery = null) { |
|
393 | 393 | // If the record is saved (and not a singleton), and has a locale, |
394 | 394 | // limit the current call to its locale. This fixes a lot of problems |
395 | 395 | // with other extensions like Versioned |
396 | - if($this->owner->ID && !empty($this->owner->Locale)) { |
|
396 | + if ($this->owner->ID && !empty($this->owner->Locale)) { |
|
397 | 397 | $locale = $this->owner->Locale; |
398 | 398 | } else { |
399 | 399 | $locale = Translatable::get_current_locale(); |
400 | 400 | } |
401 | 401 | |
402 | 402 | $baseTable = ClassInfo::baseDataClass($this->owner->class); |
403 | - if( |
|
403 | + if ( |
|
404 | 404 | $locale |
405 | 405 | // unless the filter has been temporarily disabled |
406 | 406 | && self::locale_filter_enabled() |
@@ -415,13 +415,13 @@ discard block |
||
415 | 415 | // call or through custom SQL filters) |
416 | 416 | && !$this->filtersOnLocale($query) |
417 | 417 | //&& !$query->filtersOnFK() |
418 | - ) { |
|
418 | + ) { |
|
419 | 419 | $qry = sprintf('"%s"."Locale" = \'%s\'', $baseTable, Convert::raw2sql($locale)); |
420 | 420 | $query->addWhere($qry); |
421 | 421 | } |
422 | 422 | } |
423 | 423 | |
424 | - function augmentDataQueryCreation(SQLQuery &$sqlQuery, DataQuery &$dataQuery) { |
|
424 | + function augmentDataQueryCreation(SQLQuery & $sqlQuery, DataQuery & $dataQuery) { |
|
425 | 425 | $enabled = self::locale_filter_enabled(); |
426 | 426 | $dataQuery->setQueryParam(self::QUERY_LOCALE_FILTER_ENABLED, $enabled); |
427 | 427 | } |
@@ -429,7 +429,7 @@ discard block |
||
429 | 429 | // FIXME - NO TEST COVERAGE BUT REQUIRED |
430 | 430 | function augmentDatabase() { |
431 | 431 | $baseDataClass = ClassInfo::baseDataClass($this->owner->class); |
432 | - if($this->owner->class != $baseDataClass) return; |
|
432 | + if ($this->owner->class != $baseDataClass) return; |
|
433 | 433 | |
434 | 434 | $fields = array( |
435 | 435 | 'OriginalID' => 'Int', |
@@ -445,7 +445,7 @@ discard block |
||
445 | 445 | |
446 | 446 | // Remove 2.2 style tables |
447 | 447 | DB::dontRequireTable("{$baseDataClass}_lang"); |
448 | - if($this->owner->hasExtension('Versioned')) { |
|
448 | + if ($this->owner->hasExtension('Versioned')) { |
|
449 | 449 | DB::dontRequireTable("{$baseDataClass}_lang_Live"); |
450 | 450 | DB::dontRequireTable("{$baseDataClass}_lang_versions"); |
451 | 451 | } |
@@ -456,7 +456,7 @@ discard block |
||
456 | 456 | */ |
457 | 457 | public function requireDefaultRecords() { |
458 | 458 | // @todo This relies on the Locale attribute being on the base data class, and not any subclasses |
459 | - if($this->owner->class != ClassInfo::baseDataClass($this->owner->class)) return false; |
|
459 | + if ($this->owner->class != ClassInfo::baseDataClass($this->owner->class)) return false; |
|
460 | 460 | |
461 | 461 | // Permissions: If a group doesn't have any specific TRANSLATE_<locale> edit rights, |
462 | 462 | // but has CMS_ACCESS_CMSMain (general CMS access), then assign TRANSLATE_ALL permissions as a default. |
@@ -468,14 +468,14 @@ discard block |
||
468 | 468 | 'CMS_ACCESS_LeftAndMain', |
469 | 469 | 'ADMIN' |
470 | 470 | )); |
471 | - if($groups) foreach($groups as $group) { |
|
471 | + if ($groups) foreach ($groups as $group) { |
|
472 | 472 | $codes = $group->Permissions()->column('Code'); |
473 | 473 | $hasTranslationCode = false; |
474 | - foreach($codes as $code) { |
|
475 | - if(preg_match('/^TRANSLATE_/', $code)) $hasTranslationCode = true; |
|
474 | + foreach ($codes as $code) { |
|
475 | + if (preg_match('/^TRANSLATE_/', $code)) $hasTranslationCode = true; |
|
476 | 476 | } |
477 | 477 | // Only add the code if no more restrictive code exists |
478 | - if(!$hasTranslationCode) Permission::grant($group->ID, 'TRANSLATE_ALL'); |
|
478 | + if (!$hasTranslationCode) Permission::grant($group->ID, 'TRANSLATE_ALL'); |
|
479 | 479 | } |
480 | 480 | |
481 | 481 | // If the Translatable extension was added after the first records were already |
@@ -485,7 +485,7 @@ discard block |
||
485 | 485 | 'SELECT "ID" FROM "%s" WHERE "Locale" IS NULL OR "Locale" = \'\'', |
486 | 486 | ClassInfo::baseDataClass($this->owner->class) |
487 | 487 | ))->column(); |
488 | - if(!$idsWithoutLocale) return; |
|
488 | + if (!$idsWithoutLocale) return; |
|
489 | 489 | |
490 | 490 | |
491 | 491 | |
@@ -502,13 +502,13 @@ discard block |
||
502 | 502 | * @param boolean $overwrite |
503 | 503 | */ |
504 | 504 | public function addTranslationGroup($originalID, $overwrite = false) { |
505 | - if(!$this->owner->exists()) return false; |
|
505 | + if (!$this->owner->exists()) return false; |
|
506 | 506 | |
507 | 507 | $baseDataClass = ClassInfo::baseDataClass($this->owner->class); |
508 | 508 | $existingGroupID = $this->getTranslationGroup($originalID); |
509 | 509 | |
510 | 510 | // Remove any existing groups if overwrite flag is set |
511 | - if($existingGroupID && $overwrite) { |
|
511 | + if ($existingGroupID && $overwrite) { |
|
512 | 512 | $sql = sprintf( |
513 | 513 | 'DELETE FROM "%s_translationgroups" WHERE "TranslationGroupID" = %d AND "OriginalID" = %d', |
514 | 514 | $baseDataClass, |
@@ -520,7 +520,7 @@ discard block |
||
520 | 520 | } |
521 | 521 | |
522 | 522 | // Add to group (only if not in existing group or $overwrite flag is set) |
523 | - if(!$existingGroupID) { |
|
523 | + if (!$existingGroupID) { |
|
524 | 524 | $sql = sprintf( |
525 | 525 | 'INSERT INTO "%s_translationgroups" ("TranslationGroupID","OriginalID") VALUES (%d,%d)', |
526 | 526 | $baseDataClass, |
@@ -539,7 +539,7 @@ discard block |
||
539 | 539 | * @return int Numeric ID of the translationgroup in the <classname>_translationgroup table |
540 | 540 | */ |
541 | 541 | public function getTranslationGroup() { |
542 | - if(!$this->owner->exists()) return false; |
|
542 | + if (!$this->owner->exists()) return false; |
|
543 | 543 | |
544 | 544 | $baseDataClass = ClassInfo::baseDataClass($this->owner->class); |
545 | 545 | return DB::query( |
@@ -587,7 +587,7 @@ discard block |
||
587 | 587 | // of the content, as a "single language" website might be expanded |
588 | 588 | // later on. See {@link requireDefaultRecords()} for batch setting |
589 | 589 | // of empty Locale columns on each dev/build call. |
590 | - if(!$this->owner->Locale) { |
|
590 | + if (!$this->owner->Locale) { |
|
591 | 591 | $this->owner->Locale = Translatable::get_current_locale(); |
592 | 592 | } |
593 | 593 | |
@@ -597,12 +597,12 @@ discard block |
||
597 | 597 | // Caution: This logic is very sensitve to infinite loops when translation status isn't determined properly |
598 | 598 | // If a parent for the newly written translation was existing before this |
599 | 599 | // onBeforeWrite() call, it will already have been linked correctly through createTranslation() |
600 | - if( |
|
600 | + if ( |
|
601 | 601 | class_exists('SiteTree') |
602 | 602 | && $this->owner->hasField('ParentID') |
603 | 603 | && $this->owner instanceof SiteTree |
604 | 604 | ) { |
605 | - if( |
|
605 | + if ( |
|
606 | 606 | !$this->owner->ID |
607 | 607 | && $this->owner->ParentID |
608 | 608 | && !$this->owner->Parent()->hasTranslation($this->owner->Locale) |
@@ -614,7 +614,7 @@ discard block |
||
614 | 614 | |
615 | 615 | // Has to be limited to the default locale, the assumption is that the "page type" |
616 | 616 | // dropdown is readonly on all translations. |
617 | - if($this->owner->ID && $this->owner->Locale == Translatable::default_locale()) { |
|
617 | + if ($this->owner->ID && $this->owner->Locale == Translatable::default_locale()) { |
|
618 | 618 | $changedFields = $this->owner->getChangedFields(); |
619 | 619 | $changed = isset($changedFields['ClassName']); |
620 | 620 | |
@@ -642,11 +642,11 @@ discard block |
||
642 | 642 | } |
643 | 643 | } |
644 | 644 | |
645 | - if($changed) { |
|
645 | + if ($changed) { |
|
646 | 646 | $this->owner->ClassName = $changedFields['ClassName']['before']; |
647 | 647 | $translations = $this->owner->getTranslations(); |
648 | 648 | $this->owner->ClassName = $changedFields['ClassName']['after']; |
649 | - if($translations) foreach($translations as $translation) { |
|
649 | + if ($translations) foreach ($translations as $translation) { |
|
650 | 650 | $translation->setClassName($this->owner->ClassName); |
651 | 651 | $translation = $translation->newClassInstance($translation->ClassName); |
652 | 652 | $translation->populateDefaults(); |
@@ -657,7 +657,7 @@ discard block |
||
657 | 657 | } |
658 | 658 | |
659 | 659 | // see onAfterWrite() |
660 | - if(!$this->owner->ID) { |
|
660 | + if (!$this->owner->ID) { |
|
661 | 661 | $this->owner->_TranslatableIsNewRecord = true; |
662 | 662 | } |
663 | 663 | } |
@@ -665,12 +665,12 @@ discard block |
||
665 | 665 | function onAfterWrite() { |
666 | 666 | // hacky way to determine if the record was created in the database, |
667 | 667 | // or just updated |
668 | - if($this->owner->_TranslatableIsNewRecord) { |
|
668 | + if ($this->owner->_TranslatableIsNewRecord) { |
|
669 | 669 | // this would kick in for all new records which are NOT |
670 | 670 | // created through createTranslation(), meaning they don't |
671 | 671 | // have the translation group automatically set. |
672 | 672 | $translationGroupID = $this->getTranslationGroup(); |
673 | - if(!$translationGroupID) { |
|
673 | + if (!$translationGroupID) { |
|
674 | 674 | $this->addTranslationGroup( |
675 | 675 | $this->owner->_TranslationGroupID ? $this->owner->_TranslationGroupID : $this->owner->ID |
676 | 676 | ); |
@@ -705,7 +705,7 @@ discard block |
||
705 | 705 | |
706 | 706 | // Find the locale language-independent of the page |
707 | 707 | self::disable_locale_filter(); |
708 | - $default = SiteTree::get()->where(sprintf ( |
|
708 | + $default = SiteTree::get()->where(sprintf( |
|
709 | 709 | '"URLSegment" = \'%s\'%s', |
710 | 710 | Convert::raw2sql($URLSegment), |
711 | 711 | (is_int($parentID) ? " AND \"ParentID\" = $parentID" : null) |
@@ -721,7 +721,7 @@ discard block |
||
721 | 721 | public function updateRelativeLink(&$base, &$action) { |
722 | 722 | // Prevent home pages for non-default locales having their urlsegments |
723 | 723 | // reduced to the site root. |
724 | - if($base === null && $this->owner->Locale != self::default_locale()){ |
|
724 | + if ($base === null && $this->owner->Locale != self::default_locale()) { |
|
725 | 725 | $base = $this->owner->URLSegment; |
726 | 726 | } |
727 | 727 | } |
@@ -745,14 +745,14 @@ discard block |
||
745 | 745 | * @return DataObjectSet |
746 | 746 | */ |
747 | 747 | function getTranslations($locale = null, $stage = null) { |
748 | - if(!$this->owner->exists()) return new ArrayList(); |
|
748 | + if (!$this->owner->exists()) return new ArrayList(); |
|
749 | 749 | |
750 | 750 | // HACK need to disable language filtering in augmentSQL(), |
751 | 751 | // as we purposely want to get different language |
752 | 752 | // also save state of locale-filter, revert to this state at the |
753 | 753 | // end of this method |
754 | 754 | $localeFilterEnabled = false; |
755 | - if(self::locale_filter_enabled()) { |
|
755 | + if (self::locale_filter_enabled()) { |
|
756 | 756 | self::disable_locale_filter(); |
757 | 757 | $localeFilterEnabled = true; |
758 | 758 | } |
@@ -761,7 +761,7 @@ discard block |
||
761 | 761 | |
762 | 762 | $baseDataClass = ClassInfo::baseDataClass($this->owner->class); |
763 | 763 | $filter = sprintf('"%s_translationgroups"."TranslationGroupID" = %d', $baseDataClass, $translationGroupID); |
764 | - if($locale) { |
|
764 | + if ($locale) { |
|
765 | 765 | $filter .= sprintf(' AND "%s"."Locale" = \'%s\'', $baseDataClass, Convert::raw2sql($locale)); |
766 | 766 | } else { |
767 | 767 | // exclude the language of the current owner |
@@ -769,15 +769,15 @@ discard block |
||
769 | 769 | } |
770 | 770 | $currentStage = Versioned::current_stage(); |
771 | 771 | $joinOnClause = sprintf('"%s_translationgroups"."OriginalID" = "%s"."ID"', $baseDataClass, $baseDataClass); |
772 | - if($this->owner->hasExtension("Versioned")) { |
|
773 | - if($stage) Versioned::reading_stage($stage); |
|
772 | + if ($this->owner->hasExtension("Versioned")) { |
|
773 | + if ($stage) Versioned::reading_stage($stage); |
|
774 | 774 | $translations = Versioned::get_by_stage( |
775 | 775 | $baseDataClass, |
776 | 776 | Versioned::current_stage(), |
777 | 777 | $filter, |
778 | 778 | null |
779 | 779 | )->leftJoin("{$baseDataClass}_translationgroups", $joinOnClause); |
780 | - if($stage) Versioned::reading_stage($currentStage); |
|
780 | + if ($stage) Versioned::reading_stage($currentStage); |
|
781 | 781 | } else { |
782 | 782 | $class = $this->owner->class; |
783 | 783 | $translations = $baseDataClass::get() |
@@ -786,7 +786,7 @@ discard block |
||
786 | 786 | } |
787 | 787 | |
788 | 788 | // only re-enable locale-filter if it was enabled at the beginning of this method |
789 | - if($localeFilterEnabled) { |
|
789 | + if ($localeFilterEnabled) { |
|
790 | 790 | self::enable_locale_filter(); |
791 | 791 | } |
792 | 792 | |
@@ -827,7 +827,7 @@ discard block |
||
827 | 827 | */ |
828 | 828 | static function get_existing_content_languages($className = 'SiteTree', $where = '') { |
829 | 829 | $baseTable = ClassInfo::baseDataClass($className); |
830 | - $query = new SQLQuery("Distinct \"Locale\"","\"$baseTable\"",$where, '', "\"Locale\""); |
|
830 | + $query = new SQLQuery("Distinct \"Locale\"", "\"$baseTable\"", $where, '', "\"Locale\""); |
|
831 | 831 | $dbLangs = $query->execute()->column(); |
832 | 832 | $langlist = array_merge((array)Translatable::default_locale(), (array)$dbLangs); |
833 | 833 | $returnMap = array(); |
@@ -836,8 +836,8 @@ discard block |
||
836 | 836 | Config::inst()->get('i18n', 'common_locales') |
837 | 837 | ); |
838 | 838 | foreach ($langlist as $langCode) { |
839 | - if($langCode && isset($allCodes[$langCode])) { |
|
840 | - if(is_array($allCodes[$langCode])) { |
|
839 | + if ($langCode && isset($allCodes[$langCode])) { |
|
840 | + if (is_array($allCodes[$langCode])) { |
|
841 | 841 | $returnMap[$langCode] = $allCodes[$langCode]['name']; |
842 | 842 | } else { |
843 | 843 | $returnMap[$langCode] = $allCodes[$langCode]; |
@@ -860,8 +860,8 @@ discard block |
||
860 | 860 | $original = SiteTree::get_by_link(RootURLController::config()->default_homepage_link); |
861 | 861 | self::set_current_locale($originalLocale); |
862 | 862 | |
863 | - if($original) { |
|
864 | - if($translation = $original->getTranslation($locale)) return trim($translation->RelativeLink(true), '/'); |
|
863 | + if ($original) { |
|
864 | + if ($translation = $original->getTranslation($locale)) return trim($translation->RelativeLink(true), '/'); |
|
865 | 865 | } |
866 | 866 | } |
867 | 867 | |
@@ -870,7 +870,7 @@ discard block |
||
870 | 870 | * @deprecated 2.4 Use {@link Translatable::get_homepage_link_by_locale()} |
871 | 871 | */ |
872 | 872 | static function get_homepage_urlsegment_by_locale($locale) { |
873 | - user_error ( |
|
873 | + user_error( |
|
874 | 874 | 'Translatable::get_homepage_urlsegment_by_locale() is deprecated, please use get_homepage_link_by_locale()', |
875 | 875 | E_USER_NOTICE |
876 | 876 | ); |
@@ -884,7 +884,7 @@ discard block |
||
884 | 884 | * Return a piece of text to keep DataObject cache keys appropriately specific |
885 | 885 | */ |
886 | 886 | function cacheKeyComponent() { |
887 | - return 'locale-'.self::get_current_locale(); |
|
887 | + return 'locale-' . self::get_current_locale(); |
|
888 | 888 | } |
889 | 889 | |
890 | 890 | /** |
@@ -895,18 +895,18 @@ discard block |
||
895 | 895 | */ |
896 | 896 | public function augmentValidURLSegment() { |
897 | 897 | $reEnableFilter = false; |
898 | - if(!Config::inst()->get('Translatable', 'enforce_global_unique_urls')) { |
|
898 | + if (!Config::inst()->get('Translatable', 'enforce_global_unique_urls')) { |
|
899 | 899 | self::enable_locale_filter(); |
900 | - } elseif(self::locale_filter_enabled()) { |
|
900 | + } elseif (self::locale_filter_enabled()) { |
|
901 | 901 | self::disable_locale_filter(); |
902 | 902 | $reEnableFilter = true; |
903 | 903 | } |
904 | 904 | |
905 | - $IDFilter = ($this->owner->ID) ? "AND \"SiteTree\".\"ID\" <> {$this->owner->ID}" : null; |
|
905 | + $IDFilter = ($this->owner->ID) ? "AND \"SiteTree\".\"ID\" <> {$this->owner->ID}" : null; |
|
906 | 906 | $parentFilter = null; |
907 | 907 | |
908 | 908 | if (Config::inst()->get('SiteTree', 'nested_urls')) { |
909 | - if($this->owner->ParentID) { |
|
909 | + if ($this->owner->ParentID) { |
|
910 | 910 | $parentFilter = " AND \"SiteTree\".\"ParentID\" = {$this->owner->ParentID}"; |
911 | 911 | } else { |
912 | 912 | $parentFilter = ' AND "SiteTree"."ParentID" = 0'; |
@@ -916,7 +916,7 @@ discard block |
||
916 | 916 | $existingPage = SiteTree::get() |
917 | 917 | // disable get_one cache, as this otherwise may pick up results from when locale_filter was on |
918 | 918 | ->where("\"URLSegment\" = '{$this->owner->URLSegment}' $IDFilter $parentFilter")->First(); |
919 | - if($reEnableFilter) self::enable_locale_filter(); |
|
919 | + if ($reEnableFilter) self::enable_locale_filter(); |
|
920 | 920 | |
921 | 921 | // By returning TRUE or FALSE, we overrule the base SiteTree->validateURLSegment() logic |
922 | 922 | return !$existingPage; |
@@ -377,7 +377,9 @@ discard block |
||
377 | 377 | */ |
378 | 378 | protected function filtersOnLocale($query) { |
379 | 379 | foreach($query->getWhere() as $condition) { |
380 | - if(preg_match('/("|\'|`)Locale("|\'|`)/', $condition)) return true; |
|
380 | + if(preg_match('/("|\'|`)Locale("|\'|`)/', $condition)) { |
|
381 | + return true; |
|
382 | + } |
|
381 | 383 | } |
382 | 384 | } |
383 | 385 | |
@@ -429,7 +431,9 @@ discard block |
||
429 | 431 | // FIXME - NO TEST COVERAGE BUT REQUIRED |
430 | 432 | function augmentDatabase() { |
431 | 433 | $baseDataClass = ClassInfo::baseDataClass($this->owner->class); |
432 | - if($this->owner->class != $baseDataClass) return; |
|
434 | + if($this->owner->class != $baseDataClass) { |
|
435 | + return; |
|
436 | + } |
|
433 | 437 | |
434 | 438 | $fields = array( |
435 | 439 | 'OriginalID' => 'Int', |
@@ -456,7 +460,9 @@ discard block |
||
456 | 460 | */ |
457 | 461 | public function requireDefaultRecords() { |
458 | 462 | // @todo This relies on the Locale attribute being on the base data class, and not any subclasses |
459 | - if($this->owner->class != ClassInfo::baseDataClass($this->owner->class)) return false; |
|
463 | + if($this->owner->class != ClassInfo::baseDataClass($this->owner->class)) { |
|
464 | + return false; |
|
465 | + } |
|
460 | 466 | |
461 | 467 | // Permissions: If a group doesn't have any specific TRANSLATE_<locale> edit rights, |
462 | 468 | // but has CMS_ACCESS_CMSMain (general CMS access), then assign TRANSLATE_ALL permissions as a default. |
@@ -468,14 +474,20 @@ discard block |
||
468 | 474 | 'CMS_ACCESS_LeftAndMain', |
469 | 475 | 'ADMIN' |
470 | 476 | )); |
471 | - if($groups) foreach($groups as $group) { |
|
477 | + if($groups) { |
|
478 | + foreach($groups as $group) { |
|
472 | 479 | $codes = $group->Permissions()->column('Code'); |
480 | + } |
|
473 | 481 | $hasTranslationCode = false; |
474 | 482 | foreach($codes as $code) { |
475 | - if(preg_match('/^TRANSLATE_/', $code)) $hasTranslationCode = true; |
|
483 | + if(preg_match('/^TRANSLATE_/', $code)) { |
|
484 | + $hasTranslationCode = true; |
|
485 | + } |
|
476 | 486 | } |
477 | 487 | // Only add the code if no more restrictive code exists |
478 | - if(!$hasTranslationCode) Permission::grant($group->ID, 'TRANSLATE_ALL'); |
|
488 | + if(!$hasTranslationCode) { |
|
489 | + Permission::grant($group->ID, 'TRANSLATE_ALL'); |
|
490 | + } |
|
479 | 491 | } |
480 | 492 | |
481 | 493 | // If the Translatable extension was added after the first records were already |
@@ -485,7 +497,9 @@ discard block |
||
485 | 497 | 'SELECT "ID" FROM "%s" WHERE "Locale" IS NULL OR "Locale" = \'\'', |
486 | 498 | ClassInfo::baseDataClass($this->owner->class) |
487 | 499 | ))->column(); |
488 | - if(!$idsWithoutLocale) return; |
|
500 | + if(!$idsWithoutLocale) { |
|
501 | + return; |
|
502 | + } |
|
489 | 503 | |
490 | 504 | |
491 | 505 | |
@@ -502,7 +516,9 @@ discard block |
||
502 | 516 | * @param boolean $overwrite |
503 | 517 | */ |
504 | 518 | public function addTranslationGroup($originalID, $overwrite = false) { |
505 | - if(!$this->owner->exists()) return false; |
|
519 | + if(!$this->owner->exists()) { |
|
520 | + return false; |
|
521 | + } |
|
506 | 522 | |
507 | 523 | $baseDataClass = ClassInfo::baseDataClass($this->owner->class); |
508 | 524 | $existingGroupID = $this->getTranslationGroup($originalID); |
@@ -539,7 +555,9 @@ discard block |
||
539 | 555 | * @return int Numeric ID of the translationgroup in the <classname>_translationgroup table |
540 | 556 | */ |
541 | 557 | public function getTranslationGroup() { |
542 | - if(!$this->owner->exists()) return false; |
|
558 | + if(!$this->owner->exists()) { |
|
559 | + return false; |
|
560 | + } |
|
543 | 561 | |
544 | 562 | $baseDataClass = ClassInfo::baseDataClass($this->owner->class); |
545 | 563 | return DB::query( |
@@ -646,8 +664,10 @@ discard block |
||
646 | 664 | $this->owner->ClassName = $changedFields['ClassName']['before']; |
647 | 665 | $translations = $this->owner->getTranslations(); |
648 | 666 | $this->owner->ClassName = $changedFields['ClassName']['after']; |
649 | - if($translations) foreach($translations as $translation) { |
|
667 | + if($translations) { |
|
668 | + foreach($translations as $translation) { |
|
650 | 669 | $translation->setClassName($this->owner->ClassName); |
670 | + } |
|
651 | 671 | $translation = $translation->newClassInstance($translation->ClassName); |
652 | 672 | $translation->populateDefaults(); |
653 | 673 | $translation->forceChange(); |
@@ -745,7 +765,9 @@ discard block |
||
745 | 765 | * @return DataObjectSet |
746 | 766 | */ |
747 | 767 | function getTranslations($locale = null, $stage = null) { |
748 | - if(!$this->owner->exists()) return new ArrayList(); |
|
768 | + if(!$this->owner->exists()) { |
|
769 | + return new ArrayList(); |
|
770 | + } |
|
749 | 771 | |
750 | 772 | // HACK need to disable language filtering in augmentSQL(), |
751 | 773 | // as we purposely want to get different language |
@@ -770,14 +792,18 @@ discard block |
||
770 | 792 | $currentStage = Versioned::current_stage(); |
771 | 793 | $joinOnClause = sprintf('"%s_translationgroups"."OriginalID" = "%s"."ID"', $baseDataClass, $baseDataClass); |
772 | 794 | if($this->owner->hasExtension("Versioned")) { |
773 | - if($stage) Versioned::reading_stage($stage); |
|
795 | + if($stage) { |
|
796 | + Versioned::reading_stage($stage); |
|
797 | + } |
|
774 | 798 | $translations = Versioned::get_by_stage( |
775 | 799 | $baseDataClass, |
776 | 800 | Versioned::current_stage(), |
777 | 801 | $filter, |
778 | 802 | null |
779 | 803 | )->leftJoin("{$baseDataClass}_translationgroups", $joinOnClause); |
780 | - if($stage) Versioned::reading_stage($currentStage); |
|
804 | + if($stage) { |
|
805 | + Versioned::reading_stage($currentStage); |
|
806 | + } |
|
781 | 807 | } else { |
782 | 808 | $class = $this->owner->class; |
783 | 809 | $translations = $baseDataClass::get() |
@@ -861,7 +887,9 @@ discard block |
||
861 | 887 | self::set_current_locale($originalLocale); |
862 | 888 | |
863 | 889 | if($original) { |
864 | - if($translation = $original->getTranslation($locale)) return trim($translation->RelativeLink(true), '/'); |
|
890 | + if($translation = $original->getTranslation($locale)) { |
|
891 | + return trim($translation->RelativeLink(true), '/'); |
|
892 | + } |
|
865 | 893 | } |
866 | 894 | } |
867 | 895 | |
@@ -916,7 +944,9 @@ discard block |
||
916 | 944 | $existingPage = SiteTree::get() |
917 | 945 | // disable get_one cache, as this otherwise may pick up results from when locale_filter was on |
918 | 946 | ->where("\"URLSegment\" = '{$this->owner->URLSegment}' $IDFilter $parentFilter")->First(); |
919 | - if($reEnableFilter) self::enable_locale_filter(); |
|
947 | + if($reEnableFilter) { |
|
948 | + self::enable_locale_filter(); |
|
949 | + } |
|
920 | 950 | |
921 | 951 | // By returning TRUE or FALSE, we overrule the base SiteTree->validateURLSegment() logic |
922 | 952 | return !$existingPage; |
@@ -1,156 +1,156 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | /** |
3 | - * The Translatable decorator allows your DataObjects to have versions in different languages, |
|
4 | - * defining which fields are can be translated. Translatable can be applied |
|
5 | - * to any {@link DataObject} subclass, but is mostly used with {@link SiteTree}. |
|
6 | - * Translatable is compatible with the {@link Versioned} extension. |
|
7 | - * To avoid cluttering up the database-schema of the 99% of sites without multiple languages, |
|
8 | - * the translation-feature is disabled by default. |
|
9 | - * |
|
10 | - * Locales (e.g. 'en_US') are used in Translatable for identifying a record by language, |
|
11 | - * see section "Locales and Language Tags". |
|
12 | - * |
|
13 | - * <h2>Configuration</h2> |
|
14 | - * |
|
15 | - * The extension is automatically enabled for SiteTree and SiteConfig records, |
|
16 | - * if they can be found. Add the following to your config.yml in order to |
|
17 | - * register a custom class: |
|
18 | - * |
|
19 | - * <code> |
|
20 | - * MyClass: |
|
21 | - * extensions: |
|
22 | - * Translatable |
|
23 | - * </code> |
|
24 | - * |
|
25 | - * Make sure to rebuild the database through /dev/build after enabling translatable. |
|
26 | - * Use the correct {@link set_default_locale()} before building the database |
|
27 | - * for the first time, as this locale will be written on all new records. |
|
28 | - * |
|
29 | - * <h3>"Default" locales</h3> |
|
30 | - * |
|
31 | - * Important: If the "default language" of your site is not US-English (en_US), |
|
32 | - * please ensure to set the appropriate default language for |
|
33 | - * your content before building the database with Translatable enabled: |
|
34 | - * <code> |
|
35 | - * Translatable::set_default_locale(<locale>); // e.g. 'de_DE' or 'fr_FR' |
|
36 | - * </code> |
|
37 | - * |
|
38 | - * For the Translatable class, a "locale" consists of a language code plus a region |
|
39 | - * code separated by an underscore, |
|
40 | - * for example "de_AT" for German language ("de") in the region Austria ("AT"). |
|
41 | - * See http://www.w3.org/International/articles/language-tags/ for a detailed description. |
|
42 | - * |
|
43 | - * <h2>Usage</h2> |
|
44 | - * |
|
45 | - * Getting a translation for an existing instance: |
|
46 | - * <code> |
|
47 | - * $translatedObj = Translatable::get_one_by_locale('MyObject', 'de_DE'); |
|
48 | - * </code> |
|
49 | - * |
|
50 | - * Getting a translation for an existing instance: |
|
51 | - * <code> |
|
52 | - * $obj = DataObject::get_by_id('MyObject', 99); // original language |
|
53 | - * $translatedObj = $obj->getTranslation('de_DE'); |
|
54 | - * </code> |
|
55 | - * |
|
56 | - * Getting translations through {@link Translatable::set_current_locale()}. |
|
57 | - * This is *not* a recommended approach, but sometimes inavoidable (e.g. for {@link Versioned} methods). |
|
58 | - * <code> |
|
59 | - * $origLocale = Translatable::get_current_locale(); |
|
60 | - * Translatable::set_current_locale('de_DE'); |
|
61 | - * $obj = Versioned::get_one_by_stage('MyObject', "ID = 99"); |
|
62 | - * Translatable::set_current_locale($origLocale); |
|
63 | - * </code> |
|
64 | - * |
|
65 | - * Creating a translation: |
|
66 | - * <code> |
|
67 | - * $obj = new MyObject(); |
|
68 | - * $translatedObj = $obj->createTranslation('de_DE'); |
|
69 | - * </code> |
|
70 | - * |
|
71 | - * <h2>Usage for SiteTree</h2> |
|
72 | - * |
|
73 | - * Translatable can be used for subclasses of {@link SiteTree}, |
|
74 | - * it is automatically configured if this class is foun. |
|
75 | - * |
|
76 | - * If a child page translation is requested without the parent |
|
77 | - * page already having a translation in this language, the extension |
|
78 | - * will recursively create translations up the tree. |
|
79 | - * Caution: The "URLSegment" property is enforced to be unique across |
|
80 | - * languages by auto-appending the language code at the end. |
|
81 | - * You'll need to ensure that the appropriate "reading language" is set |
|
82 | - * before showing links to other pages on a website through $_GET['locale']. |
|
83 | - * Pages in different languages can have different publication states |
|
84 | - * through the {@link Versioned} extension. |
|
85 | - * |
|
86 | - * Note: You can't get Children() for a parent page in a different language |
|
87 | - * through set_current_locale(). Get the translated parent first. |
|
88 | - * |
|
89 | - * <code> |
|
90 | - * // wrong |
|
91 | - * Translatable::set_current_locale('de_DE'); |
|
92 | - * $englishParent->Children(); |
|
93 | - * // right |
|
94 | - * $germanParent = $englishParent->getTranslation('de_DE'); |
|
95 | - * $germanParent->Children(); |
|
96 | - * </code> |
|
97 | - * |
|
98 | - * <h2>Translation groups</h2> |
|
99 | - * |
|
100 | - * Each translation can have one or more related pages in other languages. |
|
101 | - * This relation is optional, meaning you can |
|
102 | - * create translations which have no representation in the "default language". |
|
103 | - * This means you can have a french translation with a german original, |
|
104 | - * without either of them having a representation |
|
105 | - * in the default english language tree. |
|
106 | - * Caution: There is no versioning for translation groups, |
|
107 | - * meaning associating an object with a group will affect both stage and live records. |
|
108 | - * |
|
109 | - * SiteTree database table (abbreviated) |
|
110 | - * ^ ID ^ URLSegment ^ Title ^ Locale ^ |
|
111 | - * | 1 | about-us | About us | en_US | |
|
112 | - * | 2 | ueber-uns | Über uns | de_DE | |
|
113 | - * | 3 | contact | Contact | en_US | |
|
114 | - * |
|
115 | - * SiteTree_translationgroups database table |
|
116 | - * ^ TranslationGroupID ^ OriginalID ^ |
|
117 | - * | 99 | 1 | |
|
118 | - * | 99 | 2 | |
|
119 | - * | 199 | 3 | |
|
120 | - * |
|
121 | - * <h2>Character Sets</h2> |
|
122 | - * |
|
123 | - * Caution: Does not apply any character-set conversion, it is assumed that all content |
|
124 | - * is stored and represented in UTF-8 (Unicode). Please make sure your database and |
|
125 | - * HTML-templates adjust to this. |
|
126 | - * |
|
127 | - * <h2>Permissions</h2> |
|
128 | - * |
|
129 | - * Authors without administrative access need special permissions to edit locales other than |
|
130 | - * the default locale. |
|
131 | - * |
|
132 | - * - TRANSLATE_ALL: Translate into all locales |
|
133 | - * - Translate_<locale>: Translate a specific locale. Only available for all locales set in |
|
134 | - * `Translatable::set_allowed_locales()`. |
|
135 | - * |
|
136 | - * Note: If user-specific view permissions are required, please overload `SiteTree->canView()`. |
|
137 | - * |
|
138 | - * <h2>Uninstalling/Disabling</h2> |
|
139 | - * |
|
140 | - * Disabling Translatable after creating translations will lead to all |
|
141 | - * pages being shown in the default sitetree regardless of their language. |
|
142 | - * It is advised to start with a new database after uninstalling Translatable, |
|
143 | - * or manually filter out translated objects through their "Locale" property |
|
144 | - * in the database. |
|
145 | - * |
|
146 | - * @see http://doc.silverstripe.org/doku.php?id=multilingualcontent |
|
147 | - * |
|
148 | - * @author Ingo Schommer <ingo (at) silverstripe (dot) com> |
|
149 | - * @author Michael Gall <michael (at) wakeless (dot) net> |
|
150 | - * @author Bernat Foj Capell <[email protected]> |
|
151 | - * |
|
152 | - * @package translatable |
|
153 | - */ |
|
3 | + * The Translatable decorator allows your DataObjects to have versions in different languages, |
|
4 | + * defining which fields are can be translated. Translatable can be applied |
|
5 | + * to any {@link DataObject} subclass, but is mostly used with {@link SiteTree}. |
|
6 | + * Translatable is compatible with the {@link Versioned} extension. |
|
7 | + * To avoid cluttering up the database-schema of the 99% of sites without multiple languages, |
|
8 | + * the translation-feature is disabled by default. |
|
9 | + * |
|
10 | + * Locales (e.g. 'en_US') are used in Translatable for identifying a record by language, |
|
11 | + * see section "Locales and Language Tags". |
|
12 | + * |
|
13 | + * <h2>Configuration</h2> |
|
14 | + * |
|
15 | + * The extension is automatically enabled for SiteTree and SiteConfig records, |
|
16 | + * if they can be found. Add the following to your config.yml in order to |
|
17 | + * register a custom class: |
|
18 | + * |
|
19 | + * <code> |
|
20 | + * MyClass: |
|
21 | + * extensions: |
|
22 | + * Translatable |
|
23 | + * </code> |
|
24 | + * |
|
25 | + * Make sure to rebuild the database through /dev/build after enabling translatable. |
|
26 | + * Use the correct {@link set_default_locale()} before building the database |
|
27 | + * for the first time, as this locale will be written on all new records. |
|
28 | + * |
|
29 | + * <h3>"Default" locales</h3> |
|
30 | + * |
|
31 | + * Important: If the "default language" of your site is not US-English (en_US), |
|
32 | + * please ensure to set the appropriate default language for |
|
33 | + * your content before building the database with Translatable enabled: |
|
34 | + * <code> |
|
35 | + * Translatable::set_default_locale(<locale>); // e.g. 'de_DE' or 'fr_FR' |
|
36 | + * </code> |
|
37 | + * |
|
38 | + * For the Translatable class, a "locale" consists of a language code plus a region |
|
39 | + * code separated by an underscore, |
|
40 | + * for example "de_AT" for German language ("de") in the region Austria ("AT"). |
|
41 | + * See http://www.w3.org/International/articles/language-tags/ for a detailed description. |
|
42 | + * |
|
43 | + * <h2>Usage</h2> |
|
44 | + * |
|
45 | + * Getting a translation for an existing instance: |
|
46 | + * <code> |
|
47 | + * $translatedObj = Translatable::get_one_by_locale('MyObject', 'de_DE'); |
|
48 | + * </code> |
|
49 | + * |
|
50 | + * Getting a translation for an existing instance: |
|
51 | + * <code> |
|
52 | + * $obj = DataObject::get_by_id('MyObject', 99); // original language |
|
53 | + * $translatedObj = $obj->getTranslation('de_DE'); |
|
54 | + * </code> |
|
55 | + * |
|
56 | + * Getting translations through {@link Translatable::set_current_locale()}. |
|
57 | + * This is *not* a recommended approach, but sometimes inavoidable (e.g. for {@link Versioned} methods). |
|
58 | + * <code> |
|
59 | + * $origLocale = Translatable::get_current_locale(); |
|
60 | + * Translatable::set_current_locale('de_DE'); |
|
61 | + * $obj = Versioned::get_one_by_stage('MyObject', "ID = 99"); |
|
62 | + * Translatable::set_current_locale($origLocale); |
|
63 | + * </code> |
|
64 | + * |
|
65 | + * Creating a translation: |
|
66 | + * <code> |
|
67 | + * $obj = new MyObject(); |
|
68 | + * $translatedObj = $obj->createTranslation('de_DE'); |
|
69 | + * </code> |
|
70 | + * |
|
71 | + * <h2>Usage for SiteTree</h2> |
|
72 | + * |
|
73 | + * Translatable can be used for subclasses of {@link SiteTree}, |
|
74 | + * it is automatically configured if this class is foun. |
|
75 | + * |
|
76 | + * If a child page translation is requested without the parent |
|
77 | + * page already having a translation in this language, the extension |
|
78 | + * will recursively create translations up the tree. |
|
79 | + * Caution: The "URLSegment" property is enforced to be unique across |
|
80 | + * languages by auto-appending the language code at the end. |
|
81 | + * You'll need to ensure that the appropriate "reading language" is set |
|
82 | + * before showing links to other pages on a website through $_GET['locale']. |
|
83 | + * Pages in different languages can have different publication states |
|
84 | + * through the {@link Versioned} extension. |
|
85 | + * |
|
86 | + * Note: You can't get Children() for a parent page in a different language |
|
87 | + * through set_current_locale(). Get the translated parent first. |
|
88 | + * |
|
89 | + * <code> |
|
90 | + * // wrong |
|
91 | + * Translatable::set_current_locale('de_DE'); |
|
92 | + * $englishParent->Children(); |
|
93 | + * // right |
|
94 | + * $germanParent = $englishParent->getTranslation('de_DE'); |
|
95 | + * $germanParent->Children(); |
|
96 | + * </code> |
|
97 | + * |
|
98 | + * <h2>Translation groups</h2> |
|
99 | + * |
|
100 | + * Each translation can have one or more related pages in other languages. |
|
101 | + * This relation is optional, meaning you can |
|
102 | + * create translations which have no representation in the "default language". |
|
103 | + * This means you can have a french translation with a german original, |
|
104 | + * without either of them having a representation |
|
105 | + * in the default english language tree. |
|
106 | + * Caution: There is no versioning for translation groups, |
|
107 | + * meaning associating an object with a group will affect both stage and live records. |
|
108 | + * |
|
109 | + * SiteTree database table (abbreviated) |
|
110 | + * ^ ID ^ URLSegment ^ Title ^ Locale ^ |
|
111 | + * | 1 | about-us | About us | en_US | |
|
112 | + * | 2 | ueber-uns | Über uns | de_DE | |
|
113 | + * | 3 | contact | Contact | en_US | |
|
114 | + * |
|
115 | + * SiteTree_translationgroups database table |
|
116 | + * ^ TranslationGroupID ^ OriginalID ^ |
|
117 | + * | 99 | 1 | |
|
118 | + * | 99 | 2 | |
|
119 | + * | 199 | 3 | |
|
120 | + * |
|
121 | + * <h2>Character Sets</h2> |
|
122 | + * |
|
123 | + * Caution: Does not apply any character-set conversion, it is assumed that all content |
|
124 | + * is stored and represented in UTF-8 (Unicode). Please make sure your database and |
|
125 | + * HTML-templates adjust to this. |
|
126 | + * |
|
127 | + * <h2>Permissions</h2> |
|
128 | + * |
|
129 | + * Authors without administrative access need special permissions to edit locales other than |
|
130 | + * the default locale. |
|
131 | + * |
|
132 | + * - TRANSLATE_ALL: Translate into all locales |
|
133 | + * - Translate_<locale>: Translate a specific locale. Only available for all locales set in |
|
134 | + * `Translatable::set_allowed_locales()`. |
|
135 | + * |
|
136 | + * Note: If user-specific view permissions are required, please overload `SiteTree->canView()`. |
|
137 | + * |
|
138 | + * <h2>Uninstalling/Disabling</h2> |
|
139 | + * |
|
140 | + * Disabling Translatable after creating translations will lead to all |
|
141 | + * pages being shown in the default sitetree regardless of their language. |
|
142 | + * It is advised to start with a new database after uninstalling Translatable, |
|
143 | + * or manually filter out translated objects through their "Locale" property |
|
144 | + * in the database. |
|
145 | + * |
|
146 | + * @see http://doc.silverstripe.org/doku.php?id=multilingualcontent |
|
147 | + * |
|
148 | + * @author Ingo Schommer <ingo (at) silverstripe (dot) com> |
|
149 | + * @author Michael Gall <michael (at) wakeless (dot) net> |
|
150 | + * @author Bernat Foj Capell <[email protected]> |
|
151 | + * |
|
152 | + * @package translatable |
|
153 | + */ |
|
154 | 154 | class Translatable extends DataExtension implements TestOnly { |
155 | 155 | |
156 | 156 | const QUERY_LOCALE_FILTER_ENABLED = 'Translatable.LocaleFilterEnabled'; |
@@ -892,7 +892,7 @@ discard block |
||
892 | 892 | * to Translatable |
893 | 893 | * |
894 | 894 | * @return bool |
895 | - */ |
|
895 | + */ |
|
896 | 896 | public function augmentValidURLSegment() { |
897 | 897 | $reEnableFilter = false; |
898 | 898 | if(!Config::inst()->get('Translatable', 'enforce_global_unique_urls')) { |
@@ -38,6 +38,9 @@ |
||
38 | 38 | } |
39 | 39 | |
40 | 40 | |
41 | + /** |
|
42 | + * @param string $q |
|
43 | + */ |
|
41 | 44 | private function getDefaultSuggest($q) { |
42 | 45 | return array( |
43 | 46 | 'query-phrase-suggestions' => array( |
@@ -122,7 +122,7 @@ discard block |
||
122 | 122 | |
123 | 123 | $qg->setShowResultsForEmptyQuery(false); |
124 | 124 | $qs = array('multi_match' => array( |
125 | - 'fields' => array('Title','Title.*','Description','Description.*'), |
|
125 | + 'fields' => array('Title', 'Title.*', 'Description', 'Description.*'), |
|
126 | 126 | 'type' => 'most_fields', |
127 | 127 | 'query' => 'New Zealand', |
128 | 128 | 'lenient' => true |
@@ -158,7 +158,7 @@ discard block |
||
158 | 158 | $qg->setShowResultsForEmptyQuery(false); |
159 | 159 | $qs = array( |
160 | 160 | 'multi_match' => array( |
161 | - 'fields' => array('Title','Title.*','Description','Description.*'), |
|
161 | + 'fields' => array('Title', 'Title.*', 'Description', 'Description.*'), |
|
162 | 162 | 'type' => 'most_fields', |
163 | 163 | 'query' => '', |
164 | 164 | 'lenient' => true |
@@ -369,8 +369,8 @@ discard block |
||
369 | 369 | 'filtered' => array( |
370 | 370 | 'filter' => |
371 | 371 | array('and' => array( |
372 | - 0 => array( 'term' => array('ISO' => 400)), |
|
373 | - 1 => array( 'range' => array( |
|
372 | + 0 => array('term' => array('ISO' => 400)), |
|
373 | + 1 => array('range' => array( |
|
374 | 374 | 'AspectRatio' => array( |
375 | 375 | 'gte' => '0.9', |
376 | 376 | 'lt' => '1.2' |
@@ -413,14 +413,14 @@ discard block |
||
413 | 413 | 'query' => array( |
414 | 414 | 'filtered' => array('filter' => |
415 | 415 | array('and' => array( |
416 | - 0 => array( 'term' => array('ISO' => 400)), |
|
417 | - 1 => array( 'range' => array( |
|
416 | + 0 => array('term' => array('ISO' => 400)), |
|
417 | + 1 => array('range' => array( |
|
418 | 418 | 'AspectRatio' => array( |
419 | 419 | 'gte' => '0.9', |
420 | 420 | 'lt' => '1.2' |
421 | 421 | ) |
422 | 422 | )), |
423 | - 2 => array( 'term' => array('Aperture' => 5.6)), |
|
423 | + 2 => array('term' => array('Aperture' => 5.6)), |
|
424 | 424 | ) |
425 | 425 | )) |
426 | 426 | ), |
@@ -472,7 +472,7 @@ discard block |
||
472 | 472 | $expected['query']['filtered']['query']['multi_match'] = array( |
473 | 473 | 'query' => 'New Zealand', |
474 | 474 | 'lenient' => true, |
475 | - 'fields' => array('Title^2', 'Title.*^2','Content', 'Content.*'), |
|
475 | + 'fields' => array('Title^2', 'Title.*^2', 'Content', 'Content.*'), |
|
476 | 476 | 'type' => 'most_fields' |
477 | 477 | ); |
478 | 478 | |
@@ -503,8 +503,8 @@ discard block |
||
503 | 503 | 'filtered' => array( |
504 | 504 | 'filter' => |
505 | 505 | array('and' => array( |
506 | - 0 => array( 'term' => array('ISO' => 400)), |
|
507 | - 1 => array( 'range' => array( |
|
506 | + 0 => array('term' => array('ISO' => 400)), |
|
507 | + 1 => array('range' => array( |
|
508 | 508 | 'AspectRatio' => array( |
509 | 509 | 'gte' => '0.9', |
510 | 510 | 'lt' => '1.2' |
@@ -525,7 +525,7 @@ discard block |
||
525 | 525 | $expected['query']['filtered']['query']['multi_match'] = array( |
526 | 526 | 'query' => 'New Zealand', |
527 | 527 | 'lenient' => true, |
528 | - 'fields' => array('Title^2', 'Title.*^2','Content', 'Content.*'), |
|
528 | + 'fields' => array('Title^2', 'Title.*^2', 'Content', 'Content.*'), |
|
529 | 529 | 'type' => 'most_fields' |
530 | 530 | ); |
531 | 531 | $expected['suggest'] = $this->getDefaultSuggest('New Zealand'); |
@@ -553,14 +553,14 @@ discard block |
||
553 | 553 | 'query' => array( |
554 | 554 | 'filtered' => array('filter' => |
555 | 555 | array('and' => array( |
556 | - 0 => array( 'term' => array('ISO' => 400)), |
|
557 | - 1 => array( 'range' => array( |
|
556 | + 0 => array('term' => array('ISO' => 400)), |
|
557 | + 1 => array('range' => array( |
|
558 | 558 | 'AspectRatio' => array( |
559 | 559 | 'gte' => '0.9', |
560 | 560 | 'lt' => '1.2' |
561 | 561 | ) |
562 | 562 | )), |
563 | - 2 => array( 'term' => array('Aperture' => 5.6)), |
|
563 | + 2 => array('term' => array('Aperture' => 5.6)), |
|
564 | 564 | ) |
565 | 565 | )) |
566 | 566 | ), |
@@ -575,7 +575,7 @@ discard block |
||
575 | 575 | $expected['query']['filtered']['query']['multi_match'] = array( |
576 | 576 | 'query' => 'New Zealand', |
577 | 577 | 'lenient' => true, |
578 | - 'fields' => array('Title^2', 'Title.*^2','Content', 'Content.*'), |
|
578 | + 'fields' => array('Title^2', 'Title.*^2', 'Content', 'Content.*'), |
|
579 | 579 | 'type' => 'most_fields' |
580 | 580 | ); |
581 | 581 | $expected['suggest'] = $this->getDefaultSuggest('New Zealand'); |
@@ -590,7 +590,7 @@ discard block |
||
590 | 590 | $qg = new QueryGenerator(); |
591 | 591 | $qg->setClasses('FlickrPhotoTO'); |
592 | 592 | $fields = array('Title' => 1, 'Description' => 1); |
593 | - $expected = array('Title', 'Title.*','Description', 'Description.*'); |
|
593 | + $expected = array('Title', 'Title.*', 'Description', 'Description.*'); |
|
594 | 594 | $this->assertEquals($expected, $qg->convertWeightedFieldsForElastica($fields)); |
595 | 595 | } |
596 | 596 | |
@@ -599,7 +599,7 @@ discard block |
||
599 | 599 | $qg = new QueryGenerator(); |
600 | 600 | $qg->setClasses('FlickrPhotoTO'); |
601 | 601 | $fields = array('Title' => 2, 'Description' => 1); |
602 | - $expected = array('Title^2', 'Title.*^2','Description', 'Description.*'); |
|
602 | + $expected = array('Title^2', 'Title.*^2', 'Description', 'Description.*'); |
|
603 | 603 | $this->assertEquals($expected, $qg->convertWeightedFieldsForElastica($fields)); |
604 | 604 | } |
605 | 605 | |
@@ -631,10 +631,10 @@ discard block |
||
631 | 631 | $qg = new QueryGenerator(); |
632 | 632 | $qg->setClasses('FlickrPhotoTO,Page'); |
633 | 633 | $fields = array('Title' => 2, 'Description' => 1); |
634 | - $expected = array('Title^2', 'Title.*^2','Description', 'Description.*'); |
|
634 | + $expected = array('Title^2', 'Title.*^2', 'Description', 'Description.*'); |
|
635 | 635 | $this->assertEquals($expected, $qg->convertWeightedFieldsForElastica($fields)); |
636 | 636 | |
637 | - $qg->setClasses(array('FlickrPhotoTO','Page')); |
|
637 | + $qg->setClasses(array('FlickrPhotoTO', 'Page')); |
|
638 | 638 | $this->assertEquals($expected, $qg->convertWeightedFieldsForElastica($fields)); |
639 | 639 | |
640 | 640 | } |
@@ -648,7 +648,7 @@ discard block |
||
648 | 648 | $qg = new QueryGenerator(); |
649 | 649 | $qg->setClasses('FlickrPhotoTO,Page'); |
650 | 650 | $fields = array('Title' => 2, 'Description' => 1); |
651 | - $expected = array('Title^2', 'Title.*^2','Description', 'Description.*'); |
|
651 | + $expected = array('Title^2', 'Title.*^2', 'Description', 'Description.*'); |
|
652 | 652 | $this->assertEquals($expected, $qg->convertWeightedFieldsForElastica($fields)); |
653 | 653 | |
654 | 654 | //Execute a 2nd time |
@@ -667,11 +667,11 @@ discard block |
||
667 | 667 | $qg = new QueryGenerator(); |
668 | 668 | $qg->setClasses(null); // select all of site tree classes |
669 | 669 | $fields = array('Title' => 2, 'Content' => 1); |
670 | - $expected = array('Title^2', 'Title.*^2','Content', 'Content.*'); |
|
670 | + $expected = array('Title^2', 'Title.*^2', 'Content', 'Content.*'); |
|
671 | 671 | $this->assertEquals($expected, $qg->convertWeightedFieldsForElastica($fields)); |
672 | 672 | |
673 | 673 | echo "--------------------\n"; |
674 | - $qg->setClasses(array('FlickrPhotoTO','Page')); |
|
674 | + $qg->setClasses(array('FlickrPhotoTO', 'Page')); |
|
675 | 675 | $this->assertEquals($expected, $qg->convertWeightedFieldsForElastica($fields)); |
676 | 676 | |
677 | 677 | } |
@@ -720,21 +720,21 @@ discard block |
||
720 | 720 | 'order' => array('_term' => 'asc') |
721 | 721 | ) |
722 | 722 | ); |
723 | - $result['ShutterSpeed'] = array( |
|
723 | + $result['ShutterSpeed'] = array( |
|
724 | 724 | 'terms' => array( |
725 | 725 | 'field' => 'ShutterSpeed', |
726 | 726 | 'size' => 0, |
727 | 727 | 'order' => array('_term' => 'asc') |
728 | 728 | ) |
729 | 729 | ); |
730 | - $result['FocalLength35mm'] = array( |
|
730 | + $result['FocalLength35mm'] = array( |
|
731 | 731 | 'terms' => array( |
732 | 732 | 'field' => 'FocalLength35mm', |
733 | 733 | 'size' => 0, |
734 | 734 | 'order' => array('_term' => 'asc') |
735 | 735 | ) |
736 | 736 | ); |
737 | - $result['ISO'] = array( |
|
737 | + $result['ISO'] = array( |
|
738 | 738 | 'terms' => array( |
739 | 739 | 'field' => 'ISO', |
740 | 740 | 'size' => 0, |
@@ -749,7 +749,7 @@ discard block |
||
749 | 749 | $ranges[3] = array('from' => '1.2', 'to' => '1.79', 'key' => 'Vertical'); |
750 | 750 | $ranges[4] = array('from' => '1.79', 'to' => '10000000', 'key' => 'Tallest'); |
751 | 751 | |
752 | - $result['Aspect'] = array( |
|
752 | + $result['Aspect'] = array( |
|
753 | 753 | 'range' => array( |
754 | 754 | 'field' => 'AspectRatio', |
755 | 755 | 'ranges' => $ranges |
@@ -769,7 +769,7 @@ discard block |
||
769 | 769 | |
770 | 770 | public function testToQuotedCSVFromArray() { |
771 | 771 | $expected = "'Bangkok','Nonthaburi','Saraburi','Chiang Mai'"; |
772 | - $items = array('Bangkok','Nonthaburi','Saraburi','Chiang Mai'); |
|
772 | + $items = array('Bangkok', 'Nonthaburi', 'Saraburi', 'Chiang Mai'); |
|
773 | 773 | $quoted = QueryGenerator::convertToQuotedCSV($items); |
774 | 774 | $this->assertEquals($expected, $quoted); |
775 | 775 | } |
@@ -479,6 +479,9 @@ |
||
479 | 479 | } |
480 | 480 | |
481 | 481 | |
482 | + /** |
|
483 | + * @param string $query |
|
484 | + */ |
|
482 | 485 | private function getResultsFor($query, $pageLength = 10, $fields = array('Title' => 1, 'Description' => 1)) { |
483 | 486 | $es = new ElasticSearcher(); |
484 | 487 | $es->setStart(0); |
@@ -140,7 +140,7 @@ |
||
140 | 140 | |
141 | 141 | public function testEach() { |
142 | 142 | $callback = function($fp) { |
143 | - $this->assertTrue(true, 'Callback reached'); |
|
143 | + $this->assertTrue(true, 'Callback reached'); |
|
144 | 144 | }; |
145 | 145 | $resultList = $this->getResultsFor('New Zealand',10); |
146 | 146 | $resultList->each($callback); |
@@ -43,16 +43,16 @@ discard block |
||
43 | 43 | $stopwords = "a,the,then,this"; |
44 | 44 | $englishIndex = new EnglishIndexSettings(); |
45 | 45 | $englishIndex->setStopwords($stopwords); |
46 | - $expected = array('a','the','then','this'); |
|
46 | + $expected = array('a', 'the', 'then', 'this'); |
|
47 | 47 | $this->assertEquals($expected, $englishIndex->getStopwords()); |
48 | 48 | } |
49 | 49 | |
50 | 50 | |
51 | 51 | public function testSetStopwordsConfigurationArray() { |
52 | - $stopwords = array('a','the','then','this'); |
|
52 | + $stopwords = array('a', 'the', 'then', 'this'); |
|
53 | 53 | $englishIndex = new EnglishIndexSettings(); |
54 | 54 | $englishIndex->setStopwords($stopwords); |
55 | - $expected = array('a','the','then','this'); |
|
55 | + $expected = array('a', 'the', 'then', 'this'); |
|
56 | 56 | $this->assertEquals($expected, $englishIndex->getStopwords()); |
57 | 57 | } |
58 | 58 | |
@@ -92,9 +92,9 @@ discard block |
||
92 | 92 | 'ISO' => 1 |
93 | 93 | ); |
94 | 94 | |
95 | - $expected = array('that','into','a','an','and','are','as','at','be','but','by','for','if', |
|
96 | - 'in','into','is','it','of','on','or','such','that','the','their','then','there','these', |
|
97 | - 'they','this','to','was','will','with'); |
|
95 | + $expected = array('that', 'into', 'a', 'an', 'and', 'are', 'as', 'at', 'be', 'but', 'by', 'for', 'if', |
|
96 | + 'in', 'into', 'is', 'it', 'of', 'on', 'or', 'such', 'that', 'the', 'their', 'then', 'there', 'these', |
|
97 | + 'they', 'this', 'to', 'was', 'will', 'with'); |
|
98 | 98 | $this->assertEquals($expected, $stopwords); |
99 | 99 | } |
100 | 100 | |
@@ -106,7 +106,7 @@ discard block |
||
106 | 106 | |
107 | 107 | |
108 | 108 | public function testResultListGetMap() { |
109 | - $resultList = $this->getResultsFor('New Zealand',10); |
|
109 | + $resultList = $this->getResultsFor('New Zealand', 10); |
|
110 | 110 | //default is ID -> Title, useful for dropdowns |
111 | 111 | $mapping = $resultList->map(); |
112 | 112 | $ctr = 0; |
@@ -119,7 +119,7 @@ discard block |
||
119 | 119 | |
120 | 120 | |
121 | 121 | public function testResultListColumn() { |
122 | - $resultList = $this->getResultsFor('New Zealand',10); |
|
122 | + $resultList = $this->getResultsFor('New Zealand', 10); |
|
123 | 123 | $ids = $resultList->column(); |
124 | 124 | |
125 | 125 | $expected = array(); |
@@ -127,14 +127,14 @@ discard block |
||
127 | 127 | array_push($expected, $item->ID); |
128 | 128 | } |
129 | 129 | |
130 | - $this->assertEquals($expected,$ids); |
|
130 | + $this->assertEquals($expected, $ids); |
|
131 | 131 | |
132 | 132 | $expected = array(); |
133 | 133 | foreach ($resultList as $item) { |
134 | 134 | array_push($expected, $item->Title); |
135 | 135 | } |
136 | 136 | $titles = $resultList->column('Title'); |
137 | - $this->assertEquals($expected,$titles); |
|
137 | + $this->assertEquals($expected, $titles); |
|
138 | 138 | } |
139 | 139 | |
140 | 140 | |
@@ -142,7 +142,7 @@ discard block |
||
142 | 142 | $callback = function($fp) { |
143 | 143 | $this->assertTrue(true, 'Callback reached'); |
144 | 144 | }; |
145 | - $resultList = $this->getResultsFor('New Zealand',10); |
|
145 | + $resultList = $this->getResultsFor('New Zealand', 10); |
|
146 | 146 | $resultList->each($callback); |
147 | 147 | } |
148 | 148 | |
@@ -152,22 +152,22 @@ discard block |
||
152 | 152 | that all of the fixtures should have 'New Zealand' in them. Test page length from 1 to 100 |
153 | 153 | */ |
154 | 154 | public function testResultListPageLength() { |
155 | - for ($i=1; $i <= 100 ; $i++) { |
|
156 | - $resultList = $this->getResultsFor('New Zealand',$i); |
|
155 | + for ($i = 1; $i <= 100; $i++) { |
|
156 | + $resultList = $this->getResultsFor('New Zealand', $i); |
|
157 | 157 | $this->assertEquals($i, $resultList->count()); |
158 | 158 | } |
159 | 159 | } |
160 | 160 | |
161 | 161 | |
162 | 162 | public function testResultListIndex() { |
163 | - $resultList = $this->getResultsFor('New Zealand',10); |
|
163 | + $resultList = $this->getResultsFor('New Zealand', 10); |
|
164 | 164 | $index = $resultList->getService()->getIndex(); |
165 | 165 | $this->assertEquals('elastica_ss_module_test_en_us', $index->getName()); |
166 | 166 | } |
167 | 167 | |
168 | 168 | |
169 | 169 | public function testResultListGetQuery() { |
170 | - $resultList = $this->getResultsFor('New Zealand',10); |
|
170 | + $resultList = $this->getResultsFor('New Zealand', 10); |
|
171 | 171 | $query = $resultList->getQuery()->toArray(); |
172 | 172 | |
173 | 173 | $expected = array(); |
@@ -192,7 +192,7 @@ discard block |
||
192 | 192 | Check that the time for the search was more than zero |
193 | 193 | */ |
194 | 194 | public function testResultListGetTotalTime() { |
195 | - $resultList = $this->getResultsFor('New Zealand',10); |
|
195 | + $resultList = $this->getResultsFor('New Zealand', 10); |
|
196 | 196 | $time = $resultList->getTotalTime(); |
197 | 197 | $this->assertGreaterThan(0, $time); |
198 | 198 | } |
@@ -202,12 +202,12 @@ discard block |
||
202 | 202 | Test the result list iterator function |
203 | 203 | */ |
204 | 204 | public function testResultListGetIterator() { |
205 | - $resultList = $this->getResultsFor('New Zealand',100); |
|
205 | + $resultList = $this->getResultsFor('New Zealand', 100); |
|
206 | 206 | $ctr = 0; |
207 | 207 | foreach ($resultList->getIterator() as $result) { |
208 | 208 | $ctr++; |
209 | 209 | } |
210 | - $this->assertEquals(100,$ctr); |
|
210 | + $this->assertEquals(100, $ctr); |
|
211 | 211 | } |
212 | 212 | |
213 | 213 | |
@@ -215,15 +215,15 @@ discard block |
||
215 | 215 | Check some basic properties of the array returned for a result |
216 | 216 | */ |
217 | 217 | public function testToArrayFunction() { |
218 | - $resultList = $this->getResultsFor('New Zealand',1); |
|
218 | + $resultList = $this->getResultsFor('New Zealand', 1); |
|
219 | 219 | $expected = array(); |
220 | 220 | $result = $resultList->toArray(); |
221 | 221 | |
222 | - $this->assertEquals(1,sizeof($result)); |
|
222 | + $this->assertEquals(1, sizeof($result)); |
|
223 | 223 | $fp = $result[0]; |
224 | 224 | $this->assertEquals('FlickrPhotoTO', $fp->ClassName); |
225 | 225 | $this->assertEquals(2147483647, $fp->FlickrID); |
226 | - $this->assertTrue(preg_match('/New Zealand/',$fp->Title) == 1); |
|
226 | + $this->assertTrue(preg_match('/New Zealand/', $fp->Title) == 1); |
|
227 | 227 | } |
228 | 228 | |
229 | 229 | |
@@ -231,21 +231,21 @@ discard block |
||
231 | 231 | Check some basic properties of the array returned for a result |
232 | 232 | */ |
233 | 233 | public function testToNestedArrayFunction() { |
234 | - $resultList = $this->getResultsFor('New Zealand',4); |
|
234 | + $resultList = $this->getResultsFor('New Zealand', 4); |
|
235 | 235 | $expected = array(); |
236 | 236 | $result = $resultList->toNestedArray(); |
237 | 237 | |
238 | - $this->assertEquals(4,sizeof($result)); |
|
238 | + $this->assertEquals(4, sizeof($result)); |
|
239 | 239 | $fp = $result[0]; |
240 | 240 | $this->assertEquals('FlickrPhotoTO', $fp['ClassName']); |
241 | 241 | $this->assertEquals(2147483647, $fp['FlickrID']); |
242 | - $this->assertTrue(preg_match('/New Zealand/',$fp['Title']) == 1); |
|
242 | + $this->assertTrue(preg_match('/New Zealand/', $fp['Title']) == 1); |
|
243 | 243 | } |
244 | 244 | |
245 | 245 | |
246 | 246 | public function testResultListOffsetExistsNotImplemented() { |
247 | 247 | try { |
248 | - $resultList = $this->getResultsFor('New Zealand',10); |
|
248 | + $resultList = $this->getResultsFor('New Zealand', 10); |
|
249 | 249 | $resultList->offsetExists(10); |
250 | 250 | $this->assertFalse(true, "This line should not have been reached"); |
251 | 251 | } catch (Exception $e) { |
@@ -256,7 +256,7 @@ discard block |
||
256 | 256 | |
257 | 257 | public function testResultListOffsetGetNotImplemented() { |
258 | 258 | try { |
259 | - $resultList = $this->getResultsFor('New Zealand',10); |
|
259 | + $resultList = $this->getResultsFor('New Zealand', 10); |
|
260 | 260 | $resultList->offsetGet(10); |
261 | 261 | $this->assertFalse(true, "This line should not have been reached"); |
262 | 262 | } catch (Exception $e) { |
@@ -267,8 +267,8 @@ discard block |
||
267 | 267 | |
268 | 268 | public function testResultListOffsetSetNotImplemented() { |
269 | 269 | try { |
270 | - $resultList = $this->getResultsFor('New Zealand',10); |
|
271 | - $resultList->offsetSet(10,null); |
|
270 | + $resultList = $this->getResultsFor('New Zealand', 10); |
|
271 | + $resultList->offsetSet(10, null); |
|
272 | 272 | $this->assertFalse(true, "This line should not have been reached"); |
273 | 273 | } catch (Exception $e) { |
274 | 274 | $this->assertEquals('Not implemented', $e->getMessage()); |
@@ -278,7 +278,7 @@ discard block |
||
278 | 278 | |
279 | 279 | public function testResultListOffsetUnsetNotImplemented() { |
280 | 280 | try { |
281 | - $resultList = $this->getResultsFor('New Zealand',10); |
|
281 | + $resultList = $this->getResultsFor('New Zealand', 10); |
|
282 | 282 | $resultList->offsetUnset(10); |
283 | 283 | $this->assertFalse(true, "This line should not have been reached"); |
284 | 284 | } catch (Exception $e) { |
@@ -289,7 +289,7 @@ discard block |
||
289 | 289 | |
290 | 290 | public function testResultListAddNotImplemented() { |
291 | 291 | try { |
292 | - $resultList = $this->getResultsFor('New Zealand',10); |
|
292 | + $resultList = $this->getResultsFor('New Zealand', 10); |
|
293 | 293 | $fp = new FlickrPhotoTO(); |
294 | 294 | $resultList->add($fp); |
295 | 295 | $this->assertFalse(true, "This line should not have been reached"); |
@@ -301,7 +301,7 @@ discard block |
||
301 | 301 | |
302 | 302 | public function testResultListRemoveNotImplemented() { |
303 | 303 | try { |
304 | - $resultList = $this->getResultsFor('New Zealand',10); |
|
304 | + $resultList = $this->getResultsFor('New Zealand', 10); |
|
305 | 305 | $fp = new FlickrPhotoTO(); |
306 | 306 | $resultList->remove($fp); |
307 | 307 | $this->assertFalse(true, "This line should not have been reached"); |
@@ -313,9 +313,9 @@ discard block |
||
313 | 313 | |
314 | 314 | public function testResultListFindNotImplemented() { |
315 | 315 | try { |
316 | - $resultList = $this->getResultsFor('New Zealand',10); |
|
316 | + $resultList = $this->getResultsFor('New Zealand', 10); |
|
317 | 317 | $fp = new FlickrPhotoTO(); |
318 | - $resultList->find(4,$fp); |
|
318 | + $resultList->find(4, $fp); |
|
319 | 319 | $this->assertFalse(true, "This line should not have been reached"); |
320 | 320 | } catch (Exception $e) { |
321 | 321 | $this->assertEquals('Not implemented', $e->getMessage()); |
@@ -351,9 +351,9 @@ discard block |
||
351 | 351 | |
352 | 352 | public function testResultListFirstNotImplemented() { |
353 | 353 | try { |
354 | - $resultList = $this->getResultsFor('New Zealand',10); |
|
354 | + $resultList = $this->getResultsFor('New Zealand', 10); |
|
355 | 355 | $fp = new FlickrPhotoTO(); |
356 | - $resultList->first(4,$fp); |
|
356 | + $resultList->first(4, $fp); |
|
357 | 357 | $this->assertFalse(true, "This line should not have been reached"); |
358 | 358 | } catch (Exception $e) { |
359 | 359 | $this->assertEquals('Not implemented', $e->getMessage()); |
@@ -363,9 +363,9 @@ discard block |
||
363 | 363 | |
364 | 364 | public function testResultListLastNotImplemented() { |
365 | 365 | try { |
366 | - $resultList = $this->getResultsFor('New Zealand',10); |
|
366 | + $resultList = $this->getResultsFor('New Zealand', 10); |
|
367 | 367 | $fp = new FlickrPhotoTO(); |
368 | - $resultList->last(4,$fp); |
|
368 | + $resultList->last(4, $fp); |
|
369 | 369 | $this->assertFalse(true, "This line should not have been reached"); |
370 | 370 | } catch (Exception $e) { |
371 | 371 | $this->assertEquals('Not implemented', $e->getMessage()); |
@@ -233,6 +233,9 @@ |
||
233 | 233 | |
234 | 234 | |
235 | 235 | |
236 | + /** |
|
237 | + * @param PaginatedList $paginated |
|
238 | + */ |
|
236 | 239 | private function makeCode($paginated) { |
237 | 240 | $results = $paginated->getList()->toArray(); |
238 | 241 | $ctr = 0; |
@@ -20,7 +20,7 @@ discard block |
||
20 | 20 | $form = new \ElasticSearchForm(new \Controller(), 'TestForm'); |
21 | 21 | $fields = $form->Fields(); |
22 | 22 | $result = array(); |
23 | - foreach($fields as $field) { |
|
23 | + foreach ($fields as $field) { |
|
24 | 24 | echo $field->getName(); |
25 | 25 | $result[$field->getName()] = $field->Value(); |
26 | 26 | } |
@@ -51,12 +51,12 @@ discard block |
||
51 | 51 | $wordFound = false; |
52 | 52 | $lcquery = explode(' ', strtolower($query)); |
53 | 53 | foreach ($lcquery as $part) { |
54 | - $bracketed = '<strong class="hl">'.$part.'</strong>'; |
|
54 | + $bracketed = '<strong class="hl">' . $part . '</strong>'; |
|
55 | 55 | if (strpos($snippet, $bracketed) > 0) { |
56 | 56 | $wordFound = true; |
57 | 57 | } |
58 | 58 | } |
59 | - $this->assertTrue($wordFound,'Highlight should have been found'); |
|
59 | + $this->assertTrue($wordFound, 'Highlight should have been found'); |
|
60 | 60 | } |
61 | 61 | } |
62 | 62 | } |
@@ -89,7 +89,7 @@ discard block |
||
89 | 89 | $es->setLocale($locale); |
90 | 90 | $es->setClasses('FlickrPhotoTO'); |
91 | 91 | |
92 | - $fields = array('Description.standard' => 1,'Title.standard' => 1); |
|
92 | + $fields = array('Description.standard' => 1, 'Title.standard' => 1); |
|
93 | 93 | $results = $es->moreLikeThis($fp, $fields, true); |
94 | 94 | |
95 | 95 | echo "RESULTS:\n"; |
@@ -110,7 +110,7 @@ discard block |
||
110 | 110 | $expected = array('texas'); |
111 | 111 | $this->assertEquals($expected, $terms['Title.standard']); |
112 | 112 | |
113 | - $expected = array('new', 'see','photographs', 'information','resolution', 'company', 'view', |
|
113 | + $expected = array('new', 'see', 'photographs', 'information', 'resolution', 'company', 'view', |
|
114 | 114 | 'high', 'collection', 'pacific', 'orleans', 'degolyer', 'southern', 'everett', |
115 | 115 | 'railroad', 'texas'); |
116 | 116 | |
@@ -144,7 +144,7 @@ discard block |
||
144 | 144 | $fields = array('Title.standard' => 1, 'Description.standard' => 1); |
145 | 145 | $paginated = $es->moreLikeThis($fp, $fields, true); |
146 | 146 | foreach ($paginated->getList() as $result) { |
147 | - echo $result->ID. ' : '.$result->Title."\n"; |
|
147 | + echo $result->ID . ' : ' . $result->Title . "\n"; |
|
148 | 148 | } |
149 | 149 | $this->assertEquals(32, $paginated->getTotalItems()); |
150 | 150 | $results = $paginated->getList()->toArray(); |
@@ -179,7 +179,7 @@ discard block |
||
179 | 179 | //Check that the number of indexing requests has increased by 2 |
180 | 180 | $deltaReqs = $this->service->getIndexingRequestCtr() - $reqs; |
181 | 181 | //One call is made for each of Page and FlickrPhotoTO |
182 | - $this->assertEquals(2,$deltaReqs); |
|
182 | + $this->assertEquals(2, $deltaReqs); |
|
183 | 183 | |
184 | 184 | // default installed pages plus 100 FlickrPhotoTOs |
185 | 185 | $this->checkNumberOfIndexedDocuments(103); |
@@ -195,7 +195,7 @@ discard block |
||
195 | 195 | $fields = array('Title.standard' => 1, 'Description.standard' => 1); |
196 | 196 | $paginated = $es->moreLikeThis($fp, $fields, true); |
197 | 197 | foreach ($paginated->getList() as $result) { |
198 | - echo $result->ID. ' : '.$result->Title."\n"; |
|
198 | + echo $result->ID . ' : ' . $result->Title . "\n"; |
|
199 | 199 | } |
200 | 200 | $this->assertEquals(14, $paginated->getTotalItems()); |
201 | 201 | $results = $paginated->getList()->toArray(); |
@@ -236,9 +236,9 @@ discard block |
||
236 | 236 | private function makeCode($paginated) { |
237 | 237 | $results = $paginated->getList()->toArray(); |
238 | 238 | $ctr = 0; |
239 | - echo '$result = $paginated->getList()->toArray();'."\n"; |
|
239 | + echo '$result = $paginated->getList()->toArray();' . "\n"; |
|
240 | 240 | foreach ($results as $result) { |
241 | - echo '$this->assertEquals("'.$result->Title.'", $results['.$ctr.']->Title);'."\n"; |
|
241 | + echo '$this->assertEquals("' . $result->Title . '", $results[' . $ctr . ']->Title);' . "\n"; |
|
242 | 242 | $ctr++; |
243 | 243 | } |
244 | 244 | } |
@@ -29,20 +29,20 @@ discard block |
||
29 | 29 | $config->removeComponent($config->getComponentByType('GridFieldDeleteAction')); |
30 | 30 | |
31 | 31 | $config->getComponentByType('GridFieldDataColumns')->setDisplayFields(array( |
32 | - 'Name' => 'Name', |
|
33 | - 'Weight' => 'Weighting', |
|
34 | - 'Searchable' => 'Search this field?' |
|
35 | - )); |
|
32 | + 'Name' => 'Name', |
|
33 | + 'Weight' => 'Weighting', |
|
34 | + 'Searchable' => 'Search this field?' |
|
35 | + )); |
|
36 | 36 | |
37 | 37 | |
38 | - $gridField = new GridField( |
|
39 | - 'SearchableField', // Field name |
|
40 | - 'Field Name', // Field title |
|
41 | - SearchableField::get()->filter('SearchableClassID', $this->ID)->sort('Name'), |
|
42 | - $config |
|
43 | - ); |
|
38 | + $gridField = new GridField( |
|
39 | + 'SearchableField', // Field name |
|
40 | + 'Field Name', // Field title |
|
41 | + SearchableField::get()->filter('SearchableClassID', $this->ID)->sort('Name'), |
|
42 | + $config |
|
43 | + ); |
|
44 | 44 | |
45 | - $fields->addFieldToTab('Root.Main', $gridField); |
|
45 | + $fields->addFieldToTab('Root.Main', $gridField); |
|
46 | 46 | |
47 | 47 | /* |
48 | 48 | $fields = new FieldList(); |
@@ -50,7 +50,7 @@ discard block |
||
50 | 50 | |
51 | 51 | |
52 | 52 | */ |
53 | - return $fields; |
|
53 | + return $fields; |
|
54 | 54 | } |
55 | 55 | |
56 | 56 |
@@ -15,10 +15,10 @@ |
||
15 | 15 | |
16 | 16 | $fields = new FieldList(); |
17 | 17 | |
18 | - $fields->push( new TabSet( "Root", $mainTab = new Tab( "Main" ) ) ); |
|
19 | - $mainTab->setTitle( _t( 'SiteTree.TABMAIN', "Main" ) ); |
|
18 | + $fields->push(new TabSet("Root", $mainTab = new Tab("Main"))); |
|
19 | + $mainTab->setTitle(_t('SiteTree.TABMAIN', "Main")); |
|
20 | 20 | |
21 | - $fields->addFieldToTab( 'Root.Main', $nf = new TextField( 'Name', 'Name') ); |
|
21 | + $fields->addFieldToTab('Root.Main', $nf = new TextField('Name', 'Name')); |
|
22 | 22 | $nf->setReadOnly(true); |
23 | 23 | $nf->setDisabled(true); |
24 | 24 |
@@ -24,10 +24,10 @@ |
||
24 | 24 | |
25 | 25 | function getCMSFields() { |
26 | 26 | $fields = new FieldList(); |
27 | - $fields->push( new TabSet( "Root", $mainTab = new Tab( "Main" ) ) ); |
|
28 | - $mainTab->setTitle( _t( 'SiteTree.TABMAIN', "Main" ) ); |
|
29 | - $fields->addFieldToTab( 'Root.Main', $cf = new TextField( 'ClazzName', 'Class sourced from') ); |
|
30 | - $fields->addFieldToTab( 'Root.Main', $nf = new TextField( 'Name', 'Name') ); |
|
27 | + $fields->push(new TabSet("Root", $mainTab = new Tab("Main"))); |
|
28 | + $mainTab->setTitle(_t('SiteTree.TABMAIN', "Main")); |
|
29 | + $fields->addFieldToTab('Root.Main', $cf = new TextField('ClazzName', 'Class sourced from')); |
|
30 | + $fields->addFieldToTab('Root.Main', $nf = new TextField('Name', 'Name')); |
|
31 | 31 | $cf->setDisabled(true); |
32 | 32 | $nf->setDisabled(true); |
33 | 33 | $cf->setReadOnly(true); |
@@ -20,7 +20,7 @@ discard block |
||
20 | 20 | // Makes most sense to only provide one field here, e.g. Title, Name |
21 | 21 | $field = $this->request->getVar('field'); |
22 | 22 | |
23 | - error_log('QUERY:'.$query); |
|
23 | + error_log('QUERY:' . $query); |
|
24 | 24 | |
25 | 25 | // start, and page length, i.e. pagination |
26 | 26 | $es->setPageLength(10); |
@@ -32,7 +32,7 @@ discard block |
||
32 | 32 | $es->addFilter('InSiteTree', true); |
33 | 33 | } |
34 | 34 | |
35 | - $resultList = $es->autocomplete_search($query,$field); |
|
35 | + $resultList = $es->autocomplete_search($query, $field); |
|
36 | 36 | $result = array(); |
37 | 37 | $result['Query'] = $query; |
38 | 38 | $suggestions = array(); |
@@ -92,26 +92,26 @@ discard block |
||
92 | 92 | //Need to check capitalisation of terms suggested that are different |
93 | 93 | |
94 | 94 | $chr = mb_substr ($possiblyUppercase, 0, 1, "UTF-8"); |
95 | - if (mb_strtolower($chr, "UTF-8") != $chr) { |
|
96 | - $upperLowercaseWord = $lowercaseWord; |
|
97 | - $upperLowercaseWord[0] = $chr; |
|
95 | + if (mb_strtolower($chr, "UTF-8") != $chr) { |
|
96 | + $upperLowercaseWord = $lowercaseWord; |
|
97 | + $upperLowercaseWord[0] = $chr; |
|
98 | 98 | |
99 | - //$possiblyUppercaseHighlighted = str_replace($lowercaseWord, $possiblyUppercase, $possiblyUppercaseHighlighted); |
|
100 | - $withHighlights = str_replace($lowercaseWord, $upperLowercaseWord, $possiblyUppercaseHighlighted); |
|
99 | + //$possiblyUppercaseHighlighted = str_replace($lowercaseWord, $possiblyUppercase, $possiblyUppercaseHighlighted); |
|
100 | + $withHighlights = str_replace($lowercaseWord, $upperLowercaseWord, $possiblyUppercaseHighlighted); |
|
101 | 101 | |
102 | - $lowercaseWord[0] = $chr; |
|
102 | + $lowercaseWord[0] = $chr; |
|
103 | 103 | |
104 | - //str_replace(search, replace, subject) |
|
104 | + //str_replace(search, replace, subject) |
|
105 | 105 | |
106 | - array_push($plain, $lowercaseWord); |
|
107 | - array_push($highlighted, $withHighlights); |
|
108 | - } else { |
|
109 | - //No need to capitalise, so add suggested word |
|
110 | - array_push($plain, $lowercaseWord); |
|
106 | + array_push($plain, $lowercaseWord); |
|
107 | + array_push($highlighted, $withHighlights); |
|
108 | + } else { |
|
109 | + //No need to capitalise, so add suggested word |
|
110 | + array_push($plain, $lowercaseWord); |
|
111 | 111 | |
112 | - //No need to capitalise, so add suggested highlighted word |
|
113 | - array_push($highlighted, $possiblyUppercaseHighlighted); |
|
114 | - } |
|
112 | + //No need to capitalise, so add suggested highlighted word |
|
113 | + array_push($highlighted, $possiblyUppercaseHighlighted); |
|
114 | + } |
|
115 | 115 | } |
116 | 116 | } |
117 | 117 | |
@@ -144,37 +144,37 @@ discard block |
||
144 | 144 | |
145 | 145 | $explanation = explode('-ConstantScore', $explanation)[0]; |
146 | 146 | |
147 | - $bracketPos = strpos($explanation, ')~'); |
|
147 | + $bracketPos = strpos($explanation, ')~'); |
|
148 | 148 | |
149 | - if (substr($explanation, 0,2) == '((') { |
|
150 | - $explanation = substr($explanation, 2, $bracketPos-2); |
|
151 | - } elseif (substr($explanation, 0,1) == '(') { |
|
152 | - $explanation = substr($explanation, 1, $bracketPos-2); |
|
153 | - } |
|
149 | + if (substr($explanation, 0,2) == '((') { |
|
150 | + $explanation = substr($explanation, 2, $bracketPos-2); |
|
151 | + } elseif (substr($explanation, 0,1) == '(') { |
|
152 | + $explanation = substr($explanation, 1, $bracketPos-2); |
|
153 | + } |
|
154 | 154 | |
155 | - $terms = array(); |
|
155 | + $terms = array(); |
|
156 | 156 | |
157 | - //Field name(s) => terms |
|
158 | - $splits = explode(' ', $explanation); |
|
157 | + //Field name(s) => terms |
|
158 | + $splits = explode(' ', $explanation); |
|
159 | 159 | |
160 | - foreach ($splits as $fieldAndTerm) { |
|
161 | - $splits = explode(':', $fieldAndTerm); |
|
160 | + foreach ($splits as $fieldAndTerm) { |
|
161 | + $splits = explode(':', $fieldAndTerm); |
|
162 | 162 | |
163 | - // This is the no terms case |
|
164 | - if (sizeof($splits) < 2) { |
|
165 | - break; |
|
166 | - } |
|
163 | + // This is the no terms case |
|
164 | + if (sizeof($splits) < 2) { |
|
165 | + break; |
|
166 | + } |
|
167 | 167 | |
168 | - $fieldname = $splits[0]; |
|
169 | - $term = $splits[1]; |
|
168 | + $fieldname = $splits[0]; |
|
169 | + $term = $splits[1]; |
|
170 | 170 | |
171 | - if (!isset($terms[$fieldname])) { |
|
172 | - $terms[$fieldname] = array(); |
|
173 | - } |
|
171 | + if (!isset($terms[$fieldname])) { |
|
172 | + $terms[$fieldname] = array(); |
|
173 | + } |
|
174 | 174 | |
175 | - array_push($terms[$fieldname], $term); |
|
176 | - } |
|
175 | + array_push($terms[$fieldname], $term); |
|
176 | + } |
|
177 | 177 | |
178 | - return $terms; |
|
178 | + return $terms; |
|
179 | 179 | } |
180 | 180 | } |
@@ -58,10 +58,10 @@ discard block |
||
58 | 58 | $originalParts = explode(' ', $originalQuery); |
59 | 59 | $suggestedParts = explode(' ', $suggestedPhrase); |
60 | 60 | |
61 | - $markedHighlightedParts = ' '.$suggestedPhraseHighlighted.' '; |
|
62 | - $markedHighlightedParts = str_replace(' '.$preTags, ' '.self::$pre_marker, $markedHighlightedParts); |
|
61 | + $markedHighlightedParts = ' ' . $suggestedPhraseHighlighted . ' '; |
|
62 | + $markedHighlightedParts = str_replace(' ' . $preTags, ' ' . self::$pre_marker, $markedHighlightedParts); |
|
63 | 63 | |
64 | - $markedHighlightedParts = str_replace($postTags.' ', self::$post_marker, $markedHighlightedParts); |
|
64 | + $markedHighlightedParts = str_replace($postTags . ' ', self::$post_marker, $markedHighlightedParts); |
|
65 | 65 | |
66 | 66 | $markedHighlightedParts = trim($markedHighlightedParts); |
67 | 67 | $markedHighlightedParts = trim($markedHighlightedParts); |
@@ -91,7 +91,7 @@ discard block |
||
91 | 91 | } else { |
92 | 92 | //Need to check capitalisation of terms suggested that are different |
93 | 93 | |
94 | - $chr = mb_substr ($possiblyUppercase, 0, 1, "UTF-8"); |
|
94 | + $chr = mb_substr($possiblyUppercase, 0, 1, "UTF-8"); |
|
95 | 95 | if (mb_strtolower($chr, "UTF-8") != $chr) { |
96 | 96 | $upperLowercaseWord = $lowercaseWord; |
97 | 97 | $upperLowercaseWord[0] = $chr; |
@@ -115,9 +115,9 @@ discard block |
||
115 | 115 | } |
116 | 116 | } |
117 | 117 | |
118 | - $highlighted = ' '.implode(' ', $highlighted).' '; |
|
119 | - $highlighted = str_replace(self::$pre_marker, ' '.$preTags, $highlighted); |
|
120 | - $highlighted = str_replace(self::$post_marker, $postTags.' ', $highlighted); |
|
118 | + $highlighted = ' ' . implode(' ', $highlighted) . ' '; |
|
119 | + $highlighted = str_replace(self::$pre_marker, ' ' . $preTags, $highlighted); |
|
120 | + $highlighted = str_replace(self::$post_marker, $postTags . ' ', $highlighted); |
|
121 | 121 | |
122 | 122 | $resultArray['suggestedQuery'] = implode(' ', $plain); |
123 | 123 | $resultArray['suggestedQueryHighlighted'] = trim($highlighted); |
@@ -146,10 +146,10 @@ discard block |
||
146 | 146 | |
147 | 147 | $bracketPos = strpos($explanation, ')~'); |
148 | 148 | |
149 | - if (substr($explanation, 0,2) == '((') { |
|
150 | - $explanation = substr($explanation, 2, $bracketPos-2); |
|
151 | - } elseif (substr($explanation, 0,1) == '(') { |
|
152 | - $explanation = substr($explanation, 1, $bracketPos-2); |
|
149 | + if (substr($explanation, 0, 2) == '((') { |
|
150 | + $explanation = substr($explanation, 2, $bracketPos - 2); |
|
151 | + } elseif (substr($explanation, 0, 1) == '(') { |
|
152 | + $explanation = substr($explanation, 1, $bracketPos - 2); |
|
153 | 153 | } |
154 | 154 | |
155 | 155 | $terms = array(); |