See Announcements
use CBLib\Application\Application;
/** ensure this file is being included by a parent file */
if ( ! ( defined( '_VALID_CB' ) || defined( '_JEXEC' ) || defined( '_VALID_MOS' ) ) ) { die( 'Direct Access to this location is not allowed.' ); }
global $_PLUGINS;
$_PLUGINS->loadPluginGroup( 'user', array( (int) 1 ) );
$_PLUGINS->registerUserFieldTypes( array( 'fabrikitem' => 'CBfield_fabrikitem' ) );
$_PLUGINS->registerUserFieldParams();
class CBfield_fabrikitem extends CBfield_text {
/**
* Returns a field in specified format
*
* @param moscomprofilerFields $field
* @param moscomprofilerUser $user
* @param string $output 'html', 'xml', 'json', 'php', 'csvheader', 'csv', 'rss', 'fieldslist', 'htmledit'
* @param string $reason 'profile' for user profile view, 'edit' for profile edit, 'register' for registration, 'list' for user-Lists
* @param int $list_compare_types IF reason == 'search' : 0 : simple 'is' search, 1 : advanced search with modes, 2 : simple 'any' search
* @return mixed
*/
function getField( &$field, &$user, $output, $reason, $list_compare_types ) {
global $_CB_framework, $ueConfig, $_CB_database;
$value = $user->get( $field->name );
if ( strlen($value) > 0 ) {
/* Get the stored label/value pairs */
$db = JFactory::getDBO();
$query = $db->getQuery(true);
$query
->select("params")
->from("#__fabrik_elements")
->where("name='member_interests'");
$db->setQuery($query);
$Options = json_decode($db->loadResult())->sub_options;
/* transform the CB values to display values */
$interests = array_map('trim',explode(",",$value));
foreach ($interests as $key => $interest) {
$interests[$key] = $Options->sub_labels[array_search($interest, $Options->sub_values)];
}
$interests = implode(", ", $interests);
} else $interests = "";
switch ( $output ) {
case 'html':
case 'rss':
return $this->_formatFieldOutput( $field->name, $interests, $output, false );
case 'htmledit':
$modal = " {modal index.php?option=com_fabrik&task=form.view&formid="
. $field->params->get( 'formId', '' )
. "&rowid=-1&usekey=user_id|iframe=1}Click Here to Change{/modal}";
/* First render the field */
if ($reason == 'search' ) {
$type = 'text';
$search = '/>';
} else {
$type = 'textarea';
$search = '">';
}
$content = $this->_fieldEditToHtml($field, $user, $reason, 'input', $type, $value, '');
/* hide the CB textarea */
$pos = strpos($content, $search);
if ( $reason != 'search' ) {
$content = substr_replace($content, '" style="display:none;', $pos, 0 );
/* Get the users display interests */
$content = '<textarea name="cb_member_interests_disp" id="cb_member_interests_disp" class="form-control" disabled>' . $interests . '</textarea>' . $content;
if ( !JFactory::getApplication()->isAdmin() ) {
/* add the modal link and Javascript */
$content .= Application::Cms()->prepareHtmlContentPlugins($modal);
}
} else {
$content = substr_replace($content, ' style="display:none;"', $pos, 0 );
// Render the dropdown for interest selection
// Javascript to push the selection to CB's hidden search field
$content .= '<script type="text/Javascript">'
. 'function pushInterest(sel) {'
. ' el = document.getElementById("cb_member_interests");'
. ' if ( sel.value == "Please select" )'
. ' el.value = "";'
. ' else el.value = sel.value;'
. '};'
. '</script>';
// Render the dropdown control
$content .= '<div class="col-sm-3" style="padding-left: 0px; padding-right: 0px;"><select name="interestid" id="interestid" class="form-control input-block" onchange="pushInterest(this);">
<option value="" id="interestid__" selected="selected">Please select</option>';
// Now get the Options
$db = JFactory::getDBO();
$query = $db->getQuery(true);
$query
->select("params")
->from("#__fabrik_elements")
->where("name='member_interests'");
$db->setQuery($query);
$params = json_decode(htmlspecialchars_decode($db->loadResult()));
$values = $params->sub_options->sub_values;
asort($values);
// Add each interest to the dropdown
foreach ($values as $key => $value) {
$label = $params->sub_options->sub_labels[$key];
$content .= '<option value="' . $value . '" id="interestid__' . $value . '">' . $label . '</option>';
}
$content .= '</select></div>';
}
return $content;
break;
default:
return $this->_formatFieldOutput( $field->name, $value, $output, false );
break;
}
}
}
?>