fix in caption_Field_Value hightlightThesaurus & PHPCS in caption_field

This commit is contained in:
Benoît Burnichon
2016-03-31 13:43:33 +02:00
parent 3f35efe30e
commit 15e4a5dd3a
2 changed files with 18 additions and 23 deletions

View File

@@ -390,7 +390,7 @@ class caption_Field_Value implements cache_cacheableInterface
$this->isThesaurusValue = false; $this->isThesaurusValue = false;
} }
return $this; return $this->value;
} }
/** /**

View File

@@ -40,8 +40,6 @@ class caption_field implements cache_cacheableInterface
* @param databox_field $databox_field * @param databox_field $databox_field
* @param record_adapter $record * @param record_adapter $record
* @param bool $retrieveValues * @param bool $retrieveValues
*
* @return caption_field
*/ */
public function __construct(Application $app, databox_field $databox_field, \record_adapter $record, $retrieveValues = self::RETRIEVE_VALUES) public function __construct(Application $app, databox_field $databox_field, \record_adapter $record, $retrieveValues = self::RETRIEVE_VALUES)
{ {
@@ -62,8 +60,6 @@ class caption_field implements cache_cacheableInterface
} }
} }
} }
return $this;
} }
/** /**
@@ -147,27 +143,27 @@ class caption_field implements cache_cacheableInterface
} }
/** /**
* @param array $values * @param caption_Field_Value[] $values
* @param string $separator * @param string $separator
* @param bool $highlight
* @return string * @return string
*/ */
protected static function serialize_value(Array $values, $separator, $highlight = false) protected function serialize_value(array $values, $separator, $highlight = false)
{ {
if (strlen($separator) > 1) if (strlen($separator) > 1) {
$separator = $separator[0]; $separator = $separator[0];
}
if (trim($separator) === '') if (trim($separator) === '') {
$separator = ' '; $separator = ' ';
else } else {
$separator = ' ' . $separator . ' '; $separator = ' ' . $separator . ' ';
}
$array_values = []; $array_values = [];
foreach ($values as $value) { foreach ($values as $value) {
if ($highlight) $array_values[] = $highlight ? $value->highlight_thesaurus() : $value->getValue();
$array_values[] = $value->highlight_thesaurus();
else
$array_values[] = $value->getValue();
} }
return implode($separator, $array_values); return implode($separator, $array_values);
@@ -191,10 +187,10 @@ class caption_field implements cache_cacheableInterface
} }
/** /**
* @param String $custom_separator * @param string|bool $custom_separator
* @param Boolean $highlightTheso * @param bool $highlight
* *
* @return mixed * @return string
*/ */
public function get_serialized_values($custom_separator = false, $highlight = false) public function get_serialized_values($custom_separator = false, $highlight = false)
{ {
@@ -205,12 +201,12 @@ class caption_field implements cache_cacheableInterface
if ($this->is_multi()) { if ($this->is_multi()) {
$separator = $custom_separator !== false ? $custom_separator : $this->databox_field->get_separator(); $separator = $custom_separator !== false ? $custom_separator : $this->databox_field->get_separator();
return self::serialize_value($this->values, $separator, $highlight); return $this->serialize_value($this->values, $separator, $highlight);
} }
/** @var caption_Field_Value $value */
$value = current($this->values); $value = current($this->values);
/* @var $value Caption_Field_Value */
if ($highlight) { if ($highlight) {
return $value->highlight_thesaurus(); return $value->highlight_thesaurus();
} }
@@ -258,7 +254,6 @@ class caption_field implements cache_cacheableInterface
*/ */
public static function get_multi_values($serialized_value, $separator) public static function get_multi_values($serialized_value, $separator)
{ {
$values = [];
if (strlen($separator) == 1) { if (strlen($separator) == 1) {
$values = explode($separator, $serialized_value); $values = explode($separator, $serialized_value);
} else { } else {
@@ -360,8 +355,7 @@ class caption_field implements cache_cacheableInterface
$caption_field->delete(); $caption_field->delete();
$record->set_metadatas([]); $record->set_metadatas([]);
unset($caption_field); unset($caption_field, $record);
unset($record);
} catch (\Exception $e) { } catch (\Exception $e) {
} }
@@ -389,6 +383,7 @@ class caption_field implements cache_cacheableInterface
* *
* @param string $option * @param string $option
* @return mixed * @return mixed
* @throws Exception
*/ */
public function get_data_from_cache($option = null) public function get_data_from_cache($option = null)
{ {