aboutsummaryrefslogtreecommitdiffstats
path: root/phpBB/phpbb/profilefields
diff options
context:
space:
mode:
authorJoas Schilling <nickvergessen@gmx.de>2014-01-14 10:36:44 +0100
committerJoas Schilling <nickvergessen@gmx.de>2014-01-14 10:36:44 +0100
commit0d79ccaaddb8c34bdf34780de104beeaf559308f (patch)
tree1111e05d017158d3b0c1d55f9946d15ff9fa9fc0 /phpBB/phpbb/profilefields
parentdda5992a7931b4620d742e7ce489a006f1a7b05a (diff)
downloadforums-0d79ccaaddb8c34bdf34780de104beeaf559308f.tar
forums-0d79ccaaddb8c34bdf34780de104beeaf559308f.tar.gz
forums-0d79ccaaddb8c34bdf34780de104beeaf559308f.tar.bz2
forums-0d79ccaaddb8c34bdf34780de104beeaf559308f.tar.xz
forums-0d79ccaaddb8c34bdf34780de104beeaf559308f.zip
[ticket/11201] Move get_profile_value() to type class
PHPBB3-11201
Diffstat (limited to 'phpBB/phpbb/profilefields')
-rw-r--r--phpBB/phpbb/profilefields/profilefields.php121
-rw-r--r--phpBB/phpbb/profilefields/type/type_bool.php32
-rw-r--r--phpBB/phpbb/profilefields/type/type_date.php26
-rw-r--r--phpBB/phpbb/profilefields/type/type_dropdown.php35
-rw-r--r--phpBB/phpbb/profilefields/type/type_int.php12
-rw-r--r--phpBB/phpbb/profilefields/type/type_interface.php9
-rw-r--r--phpBB/phpbb/profilefields/type/type_string_common.php16
7 files changed, 132 insertions, 119 deletions
diff --git a/phpBB/phpbb/profilefields/profilefields.php b/phpBB/phpbb/profilefields/profilefields.php
index d8ba04a862..362859d57a 100644
--- a/phpBB/phpbb/profilefields/profilefields.php
+++ b/phpBB/phpbb/profilefields/profilefields.php
@@ -365,7 +365,8 @@ class profilefields
foreach ($profile_row as $ident => $ident_ary)
{
- $value = $this->get_profile_value($ident_ary);
+ $profile_field = $this->container->get('profilefields.type.' . $this->profile_types[$row['field_type']]);
+ $value = $profile_field->get_profile_value($ident_ary['value'], $ident_ary['data']);
if ($value === NULL)
{
@@ -400,124 +401,6 @@ class profilefields
}
/**
- * Get Profile Value for display
- */
- function get_profile_value($ident_ary)
- {
- $value = $ident_ary['value'];
- $field_type = $ident_ary['data']['field_type'];
-
- switch ($this->profile_types[$field_type])
- {
- case 'int':
- if ($value === '' && !$ident_ary['data']['field_show_novalue'])
- {
- return NULL;
- }
- return (int) $value;
- break;
-
- case 'string':
- case 'text':
- if (!$value && !$ident_ary['data']['field_show_novalue'])
- {
- return NULL;
- }
-
- $value = make_clickable($value);
- $value = censor_text($value);
- $value = bbcode_nl2br($value);
- return $value;
- break;
-
- // case 'datetime':
- case 'date':
- $date = explode('-', $value);
- $day = (isset($date[0])) ? (int) $date[0] : 0;
- $month = (isset($date[1])) ? (int) $date[1] : 0;
- $year = (isset($date[2])) ? (int) $date[2] : 0;
-
- if (!$day && !$month && !$year && !$ident_ary['data']['field_show_novalue'])
- {
- return NULL;
- }
- else if ($day && $month && $year)
- {
- // Date should display as the same date for every user regardless of timezone
- return $this->user->create_datetime()
- ->setDate($year, $month, $day)
- ->setTime(0, 0, 0)
- ->format($user->lang['DATE_FORMAT'], true);
- }
-
- return $value;
- break;
-
- case 'dropdown':
- $field_id = $ident_ary['data']['field_id'];
- $lang_id = $ident_ary['data']['lang_id'];
- if (!isset($this->options_lang[$field_id][$lang_id]))
- {
- $this->get_option_lang($field_id, $lang_id, FIELD_DROPDOWN, false);
- }
-
- if ($value == $ident_ary['data']['field_novalue'] && !$ident_ary['data']['field_show_novalue'])
- {
- return NULL;
- }
-
- $value = (int) $value;
-
- // User not having a value assigned
- if (!isset($this->options_lang[$field_id][$lang_id][$value]))
- {
- if ($ident_ary['data']['field_show_novalue'])
- {
- $value = $ident_ary['data']['field_novalue'];
- }
- else
- {
- return NULL;
- }
- }
-
- return $this->options_lang[$field_id][$lang_id][$value];
- break;
-
- case 'bool':
- $field_id = $ident_ary['data']['field_id'];
- $lang_id = $ident_ary['data']['lang_id'];
- if (!isset($this->options_lang[$field_id][$lang_id]))
- {
- $this->get_option_lang($field_id, $lang_id, FIELD_BOOL, false);
- }
-
- if (!$value && $ident_ary['data']['field_show_novalue'])
- {
- $value = $ident_ary['data']['field_default_value'];
- }
-
- if ($ident_ary['data']['field_length'] == 1)
- {
- return (isset($this->options_lang[$field_id][$lang_id][(int) $value])) ? $this->options_lang[$field_id][$lang_id][(int) $value] : NULL;
- }
- else if (!$value)
- {
- return NULL;
- }
- else
- {
- return $this->options_lang[$field_id][$lang_id][(int) ($value) + 1];
- }
- break;
-
- default:
- trigger_error('Unknown profile type', E_USER_ERROR);
- break;
- }
- }
-
- /**
* Get field value for registration/profile
* @access private
*/
diff --git a/phpBB/phpbb/profilefields/type/type_bool.php b/phpBB/phpbb/profilefields/type/type_bool.php
index c26e9aa160..7edb2ff2c6 100644
--- a/phpBB/phpbb/profilefields/type/type_bool.php
+++ b/phpBB/phpbb/profilefields/type/type_bool.php
@@ -94,4 +94,36 @@ class type_bool implements type_interface
return false;
}
+
+ /**
+ * {@inheritDoc}
+ */
+ public function get_profile_value($field_value, $field_data)
+ {
+ $field_id = $field_data['field_id'];
+ $lang_id = $field_data['lang_id'];
+
+ if (!isset($this->profilefields->options_lang[$field_id][$lang_id]))
+ {
+ $this->profilefields->get_option_lang($field_id, $lang_id, FIELD_BOOL, false);
+ }
+
+ if (!$field_value && $field_data['field_show_novalue'])
+ {
+ $field_value = $field_data['field_default_value'];
+ }
+
+ if ($field_data['field_length'] == 1)
+ {
+ return (isset($this->profilefields->options_lang[$field_id][$lang_id][(int) $field_value])) ? $this->options_lang[$field_id][$lang_id][(int) $field_value] : null;
+ }
+ else if (!$field_value)
+ {
+ return null;
+ }
+ else
+ {
+ return $this->profilefields->options_lang[$field_id][$lang_id][(int) ($field_value) + 1];
+ }
+ }
}
diff --git a/phpBB/phpbb/profilefields/type/type_date.php b/phpBB/phpbb/profilefields/type/type_date.php
index a9b4bc731b..e7f1e9543e 100644
--- a/phpBB/phpbb/profilefields/type/type_date.php
+++ b/phpBB/phpbb/profilefields/type/type_date.php
@@ -129,4 +129,30 @@ class type_date implements type_interface
return false;
}
+
+ /**
+ * {@inheritDoc}
+ */
+ public function get_profile_value($field_value, $field_data)
+ {
+ $date = explode('-', $field_value);
+ $day = (isset($date[0])) ? (int) $date[0] : 0;
+ $month = (isset($date[1])) ? (int) $date[1] : 0;
+ $year = (isset($date[2])) ? (int) $date[2] : 0;
+
+ if (!$day && !$month && !$year && !$field_data['field_show_novalue'])
+ {
+ return null;
+ }
+ else if ($day && $month && $year)
+ {
+ // Date should display as the same date for every user regardless of timezone
+ return $this->user->create_datetime()
+ ->setDate($year, $month, $day)
+ ->setTime(0, 0, 0)
+ ->format($user->lang['DATE_FORMAT'], true);
+ }
+
+ return $field_value;
+ }
}
diff --git a/phpBB/phpbb/profilefields/type/type_dropdown.php b/phpBB/phpbb/profilefields/type/type_dropdown.php
index 8f2fe01d75..cfc8b289da 100644
--- a/phpBB/phpbb/profilefields/type/type_dropdown.php
+++ b/phpBB/phpbb/profilefields/type/type_dropdown.php
@@ -100,4 +100,39 @@ class type_dropdown implements type_interface
return false;
}
+
+ /**
+ * {@inheritDoc}
+ */
+ public function get_profile_value($field_value, $field_data)
+ {
+ $field_id = $field_data['field_id'];
+ $lang_id = $field_data['lang_id'];
+ if (!isset($this->profilefields->options_lang[$field_id][$lang_id]))
+ {
+ $this->profilefields->get_option_lang($field_id, $lang_id, FIELD_DROPDOWN, false);
+ }
+
+ if ($field_value == $field_data['field_novalue'] && !$field_data['field_show_novalue'])
+ {
+ return null;
+ }
+
+ $field_value = (int) $field_value;
+
+ // User not having a value assigned
+ if (!isset($this->profilefields->options_lang[$field_id][$lang_id][$field_value]))
+ {
+ if ($field_data['field_show_novalue'])
+ {
+ $field_value = $field_data['field_novalue'];
+ }
+ else
+ {
+ return null;
+ }
+ }
+
+ return $this->profilefields->options_lang[$field_id][$lang_id][$field_value];
+ }
}
diff --git a/phpBB/phpbb/profilefields/type/type_int.php b/phpBB/phpbb/profilefields/type/type_int.php
index d27adf5696..5aaa0036f7 100644
--- a/phpBB/phpbb/profilefields/type/type_int.php
+++ b/phpBB/phpbb/profilefields/type/type_int.php
@@ -89,4 +89,16 @@ class type_int implements type_interface
return false;
}
+
+ /**
+ * {@inheritDoc}
+ */
+ public function get_profile_value($field_value, $field_data)
+ {
+ if ($field_value === '' && !$field_data['field_show_novalue'])
+ {
+ return null;
+ }
+ return (int) $field_value;
+ }
}
diff --git a/phpBB/phpbb/profilefields/type/type_interface.php b/phpBB/phpbb/profilefields/type/type_interface.php
index 3c0c479a09..57f495ec9a 100644
--- a/phpBB/phpbb/profilefields/type/type_interface.php
+++ b/phpBB/phpbb/profilefields/type/type_interface.php
@@ -53,4 +53,13 @@ interface type_interface
* @return mixed String with key of the error language string, false otherwise
*/
public function validate_profile_field(&$field_value, $field_data);
+
+ /**
+ * Get Profile Value for display
+ *
+ * @param mixed $field_value Field value as stored in the database
+ * @param array $field_data Array with requirements of the field
+ * @return mixed Field value to display
+ */
+ public function get_profile_value($field_value, $field_data);
}
diff --git a/phpBB/phpbb/profilefields/type/type_string_common.php b/phpBB/phpbb/profilefields/type/type_string_common.php
index afb75f3026..c026d93948 100644
--- a/phpBB/phpbb/profilefields/type/type_string_common.php
+++ b/phpBB/phpbb/profilefields/type/type_string_common.php
@@ -67,4 +67,20 @@ abstract class type_string_common
return false;
}
+
+ /**
+ * {@inheritDoc}
+ */
+ public function get_profile_value($field_value, $field_data)
+ {
+ if (!$field_value && !$field_data['field_show_novalue'])
+ {
+ return null;
+ }
+
+ $field_value = make_clickable($field_value);
+ $field_value = censor_text($field_value);
+ $field_value = bbcode_nl2br($field_value);
+ return $field_value;
+ }
}