phpbb - Get value of custom profile field - php

I want to check a purchase code, entered by a user.
So on registration page, there is a custom profile field "purchase_code", which value I want to use, to check the code.
So my question:
With which function I can get value of the custom profile field "purchase_code"?
Something like "get_value_of_purchase_code"....

include_once($phpbb_root_path . 'includes/functions_profile_fields.' . $phpEx);
$user_id = 2; //The id of the user that you want to get the custom profiles fields
$cp = new custom_profile();
$user_fields = $cp->generate_profile_fields_template('grab', $user_id);
This creates a multidimensional array in $user_fields containing all the selected users custom fields, including the value and all the field data.

Related

Unable to write multiple values back to ACF user field (PHP. Wordpress)

My project is to make an initial match of mentors & mentees users. And then add multiple mentees to a mentor.
My mentor has an ACF current_mentees (list of users) field. I am able to add one user to that.
But when I try to push/add another one, it doesn't add the 2nd one.
// get mentor & new mentee user arrays from the Match Metadata fields
$mentor = get_field('match_mentor', $post_id);
$mentee = get_field('match_mentee', $post_id);
//get ID from mentor array
$match_mentor_id = $mentor['ID'];
//get ID from mentee array
$match_mentee_id = $mentee['ID'];
//set up the mentor user_post_id
$mentor_post_id = "user_".$match_mentor_id;
//get mentor curent_users contents
$current_mentees = get_field('current_mentees', $mentor_post_id, false);
// see if the current mentees is null or has a mentee already
if ($current_mentees == ''){
//write new current mentees back to the Mentor User Meta fields
update_field('current_mentees' , $match_mentee_id , $mentor_post_id);
} else {
//combine old mentee(s) with new mentee
array_push( $current_mentees , $match_mentee_id);
//write new current mentees back to the Mentor User Meta fields
update_field('current_mentees' , $current_mentees , $mentor_post_id);
The match_mentor & match_mentee and current_mentees are all ACF fields.
I am able to manually add (mentee) users (single & multiple) to the current_mentees through the dropdown in the user account. It appears as an array of arrays.
The first one looks like: a:1:{i:0;s:2:”60″;} //user 60
Adding the second one gives me: a:2:{i:0;s:2:”60″;i:1;s:2:”57″;} //users 60 & 57
This is functional for my purpose. I’d like the code to do the same.
But... using the above code to add one user, in the current_mentees field/DB I see 60.
And then adding the 2nd one, I get a:1:{i:0;i:57;}. (It replaces the first one instead of adding a 2nd user).
I'm not sure if this is starting off wrong (with the first user), or if I need to change my variables at some point before adding the 2nd (which I've tried). Thanks!
OK, I had thought of a couple ideas to try this morning, and things came together. Let me post my revised code. Essentially, I tried to follow the natural formatting to see if I could get everything to fall in line further along. I decided to convert the initial variable to an array, and that is what made everything else fall in line.
// get mentor & new mentee user arrays from the Match Metadata fields
$mentor = get_field(‘match_mentor’, $post_id);
$mentee = get_field(‘match_mentee’, $post_id);
//get ID from mentor array
$match_mentor_id = $mentor[‘ID’];
//get ID from mentee array
$match_mentee_id = $mentee[‘ID’];
//set up the mentor user_post_id
$mentor_post_id = “user_”.$match_mentor_id;
//get user array from mentor curent_users
$current_mentees = get_field(‘current_mentees’, $mentor_post_id, false);
// see if the current mentees is null or has a mentee already
if ($current_mentees == ”) {
//put data in proper format
$current_mentees = array();
}
//combine old mentee(s) with new mentee
array_push( $current_mentees , $match_mentee_id);
//write new current mentees back to the Mentor User Meta fields
update_field(‘current_mentees’ , $current_mentees , $mentor_post_id);

How to update custom user fields on Drupal 8

I try to update/save a custom Field of User Profile on Drupal 8.
I am lucky to get Values but not to save them back.
Here is my Code, any1 knows why this won’t work?
I've tried different variations of these already.
$user = \Drupal\user\Entity\User::load(1); // Load USER of ID=1
$user->set(‚field_user_curpage‘,38); //set my custom field = 38 !!!
$user->save(); // save …
This is how I Load these fields:
$user = \Drupal\user\Entity\User::load(1); // Load user with id = 1
$curpage_load = $user->get(‚field_user_curpage‘); // Load custom field from User Profile
$curpage = preg_replace(‚/[^0-9]/‚, ‚‘, $curpage_load->value); // filter for No. only
return $curpage; // return output this
The Entity Load function returns a static object.
Try loading the user with this instead.
\Drupal::entityTypeManager()->getStorage('user')->load($id);

Copy the text value of a referenced categoryfield into another textfield

I have made a webform using the sourcecode from Advanced Webform for Podio . I have a list made from a referenced categoryfield. When an item from the list is selected and the form is submitted, I want the text value from the referenced category field to be copied into the an other textfield.
After submit and before saving the data into Podio I can fetch the data from the
post array.
if ($_POST){
// all the values are stored in $_POST array
Then I get the value from the category field like this:
$value_from_selected_list = $_POST['uu center'];
After this I copy the value to the new text field
$_POST['organisation'] = $value_from_selected_list;
// set all the values in the Podio app
$podioform->set_values($_POST,$_FILES);
$podioform->save();
$podioform = 'Kære '.$_POST['navn'].' Tak for din tilmelding';
}
My problem is that $_POST['organisation'] only returns an id and not the text value.
I found the solution myself. $_POST['uu-center']
holds the item_id of the referenced app. So I found the field_id of the the referenced field and used the get_field_value method that takes the item_id and field_id as arguments
$item_id = $_POST['uu-center'];
$field_id = 154492804;
$uucenter = PodioItem::get_field_value($item_id,$field_id);
The method returns an array with the selected value of the field. Then I got the text string.
$value_to_be_copy = $uucenter[0][value];

How to display value option from dropdown list in Elgg

Elgg is build on the MVC framework. My main agenda is to be able to save the value selected from the dropdown list, after which is to then display the chosen value the item listing. The following code is actually constructed in PHP that is following the Elgg framework closely.
What I have managed to do is to make use of the existing Elgg framework to display the dropdown list. In which, the dropdown list is created by the creation of a form in the following directory: mod/plugin/views/default/forms/plugin/form.php. I have hence made use of the existing Elgg framework (input/dropdown)to create my dropdown list as a form.
Secondly, I have managed to save the values chosen in the dropdown list and display the value in a success message. This is done in the action directory which will allow the values to be saved into the database when user clicks on 'save' button.
Code for saving and displaying value:
<?php
/**
* Elgg options uploader/submit action
*
* #package ElggFile
*/
// get the input variables
$list = get_input('OptionItems');
$container_guid = (int) get_input('container_guid', 0);
if ($container_guid == 0)
{
$container_guid = elgg_get_logged_in_user_guid();
}
$my_select_guid = (int) get_input (file_guid);
//create a new my_select object
$my_select = new ElggObject();
$my_select -> dropdown = $list;
$my_select ->container_guid = $container_guid;
//save to database and get id of the new my_blog
$my_select_guid = $my_select->save();
if($my_select_guid){
system_message("Your action post = " . $list);
//to add new muy_select object to river
add_to_river('river/object/file/create', 'create', elgg_get_logged_in_user_guid(), $list->guid);
}
else{
register_error("Your action post is not saved");
}
However, at this point, I am stuck in displaying the chosen value of the dropdown list as an extended view, within the view/default/object/file/
How am I able to do this?
It's all in Elgg documentation about the views that I linked for you before: http://learn.elgg.org/en/1.12/guides/views.html#extending-views

Drupal: How to display part of an author's profile in a node

I have been trying to do display a custom field I created in the manage fields section of user accounts for nodes in addition to the profile page. The problem I am having with this code is that it will display the first field it finds and display that for every user, not the field for that particular user.
And ideas? I believe it's finding the first value in the array and not the value for the particular user in the array.
Here is m setup so far:
Added this to my template.php of my theme:
function mythemename_preprocess_node(&$vars) {
global $user;
$user = user_load($user->uid); // Make sure the user object is fully loaded
$team = field_get_items('user', $user, 'field_team');
if ($team) {
$vars['field_team'] = $team[0]['value'];
}
}
Then, added this to my node.tpl.php in order to display it on nodes.
if (isset($field_team) && !empty($field_team)) :
echo '$field_team.'</div>';
endif;
UPDATE:
Found my own aswer here:
http://drupal.org/node/1194506
Code used:
<?php
$node_author = user_load($node->uid);
print ($node_author->roles[3]);
print ($node_author->field_biography['und'][0]['value']);
?>
You can use drupal's 'Author Pane' module for that. Try this:
http://drupal.org/project/author_pane

Categories