Page Menu
Home
In-Portal Phabricator
Search
Configure Global Search
Log In
Files
F1170238
D132.id382.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Sat, Sep 27, 12:33 AM
Size
4 KB
Mime Type
text/x-diff
Expires
Sun, Sep 28, 12:33 AM (15 h, 11 m)
Engine
blob
Format
Raw Data
Handle
758164
Attached To
D132: INP-1479 - Define "pp_*" virtual fields in "user-profile" unit config
D132.id382.diff
View Options
Index: branches/5.2.x/core/kernel/db/db_tag_processor.php
===================================================================
--- branches/5.2.x/core/kernel/db/db_tag_processor.php
+++ branches/5.2.x/core/kernel/db/db_tag_processor.php
@@ -3061,25 +3061,28 @@
}
/**
- * Checks, that requested option is checked inside field value
+ * Checks, that requested option is checked inside field value.
*
- * @param Array $params
- * @return bool
+ * @param array $params Tag params.
+ *
+ * @return boolean
*/
- function Selected($params)
+ protected function Selected(array $params)
{
+ /** @var kDBItem $object */
$object = $this->getObject($params);
- /* @var $object kDBItem */
$field = $this->SelectParam($params, 'name,field');
$value = $object->GetDBField($field);
- if (strpos($value, '|') !== false) {
- $value = explode('|', substr($value, 1, -1));
- return in_array($params['value'], $value);
+ if ( strpos($value, '|') !== false ) {
+ $selected_values = explode('|', substr($value, 1, -1));
+ }
+ else {
+ $selected_values = array((string)$value);
}
- return $value;
+ return in_array((string)$params['value'], $selected_values, true);
}
/**
Index: branches/5.2.x/core/units/user_profile/user_profile_eh.php
===================================================================
--- branches/5.2.x/core/units/user_profile/user_profile_eh.php
+++ branches/5.2.x/core/units/user_profile/user_profile_eh.php
@@ -90,4 +90,31 @@
}
}
}
+
+ /**
+ * Adds virtual fields for "Display To Public" fields.
+ *
+ * @param kEvent $event Event.
+ *
+ * @return void
+ */
+ protected function OnAfterConfigRead(kEvent $event)
+ {
+ parent::OnAfterConfigRead($event);
+
+ $profile_mapping = $this->Application->getUnitOption('u', 'UserProfileMapping');
+ $virtual_fields = $this->Application->getUnitOption($event->Prefix, 'VirtualFields');
+
+ foreach ( array_keys($profile_mapping) as $field_name ) {
+ $virtual_fields[$field_name] = array(
+ 'type' => 'int',
+ 'formatter' => 'kOptionsFormatter', 'options' => array(1 => 'la_Yes', 2 => 'la_No'),
+ 'use_phrases' => 1,
+ 'default' => 0,
+ );
+ }
+
+ $this->Application->setUnitOption($event->Prefix, 'VirtualFields', $virtual_fields);
+ }
+
}
Index: branches/5.2.x/core/units/user_profile/user_profile_tp.php
===================================================================
--- branches/5.2.x/core/units/user_profile/user_profile_tp.php
+++ branches/5.2.x/core/units/user_profile/user_profile_tp.php
@@ -16,33 +16,47 @@
class UserProfileTagProcessor extends kDBTagProcessor {
- function Field($params)
+ /**
+ * Get's requested field value.
+ *
+ * @param array $params Tag params.
+ *
+ * @return string
+ */
+ public function Field($params)
{
$field = $this->SelectParam($params, 'name,field');
$profile_mapping = $this->Application->getUnitOption('u', 'UserProfileMapping');
$user_field = array_key_exists($field, $profile_mapping) ? $profile_mapping[$field] : false;
- if (array_key_exists('profile_field', $params) && $params['profile_field']) {
- // get variable from mapping
- $params['name'] = $user_field;
- $value = $this->Application->ProcessParsedTag('u.profile', 'Field', $params);
- }
- elseif ($user_field) {
- // old style variable for displaying fields in public profile (named "pp_*")
- $block_params = Array ('name' => 'DisplayToPublic', 'value' => $user_field);
- $value = $this->Application->ProcessParsedTag($this->getUserPrefixSpecial(), 'Selected', $block_params);
+ // Get field value to show on "Public Profile" page.
+ if ( array_key_exists('profile_field', $params) && $params['profile_field'] ) {
+ if ( $user_field ) {
+ $params['name'] = $user_field;
+ }
+
+ return $this->Application->ProcessParsedTag('u.profile', 'Field', $params);
+ }
+
+ if ( $user_field ) {
+ // Determine if field should be shown on "Public Profile" page.
+ $block_params = array('name' => 'DisplayToPublic', 'value' => $user_field);
+ $selected = $this->Application->ProcessParsedTag(
+ $this->getUserPrefixSpecial(),
+ 'Selected',
+ $block_params
+ );
}
else {
- // get variable by name
- $value = $this->recallUserProfileVar($field);
+ // New user-defined public profile field - fallback to persistent session storage.
+ $selected = $this->recallUserProfileVar($field) == 1;
}
- if (isset($params['checked']) && $params['checked']) {
- $checked_value = isset($params['value']) ? $params['value'] : 1;
- $value = ($value == $checked_value) ? 'checked' : '';
+ if ( isset($params['checked']) && $params['checked'] ) {
+ return $selected ? 'checked' : '';
}
- return $value;
+ return $selected ? 1 : 0;
}
/**
@@ -142,4 +156,4 @@
return parent::prepareInputName($params);
}
- }
\ No newline at end of file
+ }
Event Timeline
Log In to Comment