Welcome, Guest
Username: Password: Remember me

TOPIC: Load data attached to user ID? URGENT

Load data attached to user ID? URGENT 12 Jul 2016 17:01 #14211

Is there any way I can load data attached to a users ID dynamically? Basically I have a user data page overview and want to load the data attached to the logged in user. I'm Guessing in the model somwhere? any guidance would be greatly appreciated.
Last Edit: 12 Jul 2016 17:59 by bennett.d.design. Reason: Need help quickly
The administrator has disabled public write access.

Load data attached to user ID? URGENT 12 Jul 2016 22:25 #14214

Any one got any ideas? Im currently looking into the com_users component but it seems it loads data diffrently... All I need to know is how to set the active CID from the model...
Last Edit: 12 Jul 2016 23:47 by bennett.d.design.
The administrator has disabled public write access.

Load data attached to user ID? URGENT 12 Jul 2016 23:47 #14216

  • vlemos
  • vlemos's Avatar
  • Online
  • Elite Member
  • Posts: 295
  • Thank you received: 41
  • Karma: 21
Not sure I am totally clear on what you want to achieve but:
$user_id	 = JFactory::getUser()->id;
If ($user_id. . . . .

Will get you the current user id and Ajax could be used to load the data you need.
Last Edit: 12 Jul 2016 23:48 by vlemos.
The administrator has disabled public write access.
The following user(s) said Thank You: admin

Load data attached to user ID? URGENT 12 Jul 2016 23:50 #14217

yea ive got that but i need to set the cid[] from the model. I have managed to populate the fields in a form using
protected function loadFormData() {
	$user = JFactory::getUser();
	if($user->id != 0) {
		$this->setState('userdetails.id', 3);
		$this->setState('userdetails.first_name','test');
		$data = $this->getItem(3);
	}
}
this is just using hardcoded variables I will do a SQL search to get the one I need
however this does not show any data in the fly views...

but if i can set the cid[] var thats passed in the url then this would be unneeded...

Thanks for the help anyway
Last Edit: 12 Jul 2016 23:58 by bennett.d.design.
The administrator has disabled public write access.

Load data attached to user ID? URGENT 13 Jul 2016 00:22 #14218

  • vlemos
  • vlemos's Avatar
  • Online
  • Elite Member
  • Posts: 295
  • Thank you received: 41
  • Karma: 21
Which file are you working in, . . . \views\useritem\ view.html.php?

Are you looking for something like:
if($user->id != 0) {
header( 'Location: ' . JURI::base() . 'index.php/. . . .cid[0]=' . $user->id
:(
Last Edit: 13 Jul 2016 00:37 by vlemos.
The administrator has disabled public write access.

Load data attached to user ID? URGENT 13 Jul 2016 01:44 #14220

Thanks but Id like to do it from the model to avoid having to reload the page... I'm using a jquery hack to add the cid to the url at the mo
The administrator has disabled public write access.

Load data attached to user ID? URGENT 13 Jul 2016 03:32 #14221

  • vlemos
  • vlemos's Avatar
  • Online
  • Elite Member
  • Posts: 295
  • Thank you received: 41
  • Karma: 21
Still not totally sure what you require but good luck.

if you need an Ajax solution then it can be done with a bit of JavaScript and a call to the "view.html.php" like this:
JS:
var url = "index.php?option=com_demo&view=users&layout=ajax&render=userinfo";

PHP:
protected function displayAjax($tpl = null)
	{
		$jinput = JFactory::getApplication()->input;
		$render = $jinput->get('render', null, 'CMD');
		$token = $jinput->get('token', null, 'BASE64');
		$values = $jinput->get('values', null, 'ARRAY');

		switch($render)
		{
			case 'userinfo':
	
				$user = JFactory::getUser();
				$model = $this->getModel();
				$model->setState('filter.user_id', $user->id);
				$item = $model->getItems()[0];

				echo json_encode($item);
				.
				.
				.



Or the loadFormData Method should allow you to pass the user id in a filter like "&filter_user_id=1" as part of the url
/**
* Method to get the data that should be injected in the form.
*
* @access	protected
*
* @return	mixed	The data for the form.
*/
protected function loadFormData()
{
	// Check the session for previously entered form data.
	$data = JFactory::getApplication()->getUserState('com_demo.edit.useritem.data', array());

	if (empty($data)) {
		//Default values shown in the form for new item creation
		$data = $this->getItem();

		// Prime some default values.
		if ($this->getState('useritem.id') == 0)
		{
			$jinput = JFactory::getApplication()->input;

			$data->id = 0;
			.
			.
			.
			$data->user_id = $jinput->get('filter_user_id', $this->getState('filter.user_id'), 'INT');
Last Edit: 13 Jul 2016 12:44 by vlemos.
The administrator has disabled public write access.
The following user(s) said Thank You: bennett.d.design

Load data attached to user ID? URGENT 13 Jul 2016 14:40 #14229

This is the hack I've ended up using...
<?php
	if($user->id) {
		$db = JFactory::getDbo();
		$query = $db->getQuery(true);

		$query->select($db->quoteName('id'));
		$query->from($db->quoteName('#__bartschoir_userinformation'));
		$query->where($db->quoteName('user_id') . ' LIKE '. $db->quote($user->id));
 
		$db->setQuery($query);
		$db->execute();

		$account_id = $db->loadResult();
?>
	jQuery(document).ready(function() {
		jQuery(".item-159").html( '<a href="index.php/members/my-account?cid='+<?php echo $account_id; ?>+'">My Account</a>' );
		jQuery(".item-161").html( '<a href="index.php/members/edit-account?cid='+<?php echo $account_id; ?>+'">Edit Account</a>' );
	});
<?php
	}
?>

Thanks though, I still would have prefered to do it through the model... but ah well ay.
The administrator has disabled public write access.

Load data attached to user ID? URGENT 13 Jul 2016 15:32 #14230

  • vlemos
  • vlemos's Avatar
  • Online
  • Elite Member
  • Posts: 295
  • Thank you received: 41
  • Karma: 21
This wouldn't really be my first approach but for the model add it like this; it needs a filter in the model though.

jQuery(".item-159").html( '<a href="index.php/members/my-account?cid='
	+ <?php if($user->id) {
			$model = CkJModel::getInstance('Userinformation', 'BartschoirModel');
			$model->setState('filter.user_id', $user->id);
			$account = $model->getItems()[0];

			echo $account->id; 
		?>
	+ '">My Account</a>
Last Edit: 13 Jul 2016 15:35 by vlemos.
The administrator has disabled public write access.
The following user(s) said Thank You: bennett.d.design
Time to create page: 0.074 seconds

Get Started