Hierarchie uživatelů v modulu FrontEndUsers

Česká/Slovenská podpora pro CMS Made Simple
Post Reply
User avatar
osxfil
Forum Members
Forum Members
Posts: 186
Joined: Wed Apr 01, 2009 6:03 pm
Location: Plzen, CZ

Hierarchie uživatelů v modulu FrontEndUsers

Post by osxfil »

Zdravím,
potřeboval bych vytvořit UDT pro hierarchický výpis uživatelů FEU. Ve vlastnostech uživatelů mám (kromě jiných vlastností) toto:
- jmeno
- prijmeni
- parent_id
Vlastnost "parent_id" obsahuje ID nadřízeného uživatele pod kterého uživatel patří.
Potřeboval bych udělat UDT, který by vypisoval uživatele tak, jak jsou si navzájem podřízení/nadřízení (a seřadit výpis abecedně podle příjmení). Výsledek by měl vypadat asi takhle:

Ředitel
- Manažer 1
- - Pracovník 1
- - Pracovník 2
- - Pracovník 3
- Manažer 2
- - Pracovník 4
- - Pracovník 5

Nějaký nápad jak takový UDT napsat?

Předem díky
JohnnyB
Dev Team Member
Dev Team Member
Posts: 729
Joined: Tue Nov 21, 2006 5:05 pm
Location: OH, USA

Re: Hierarchie uživatelů v modulu FrontEndUsers

Post by JohnnyB »

Can you assign the users to FEU groups?

For example, - Worker 1, - Worker 2, and - Worker 3 belong with Manager 1 and create a group called "manager1" for them.

Then you can use Calguy's User Directory module to create a list from each of the manager groups.
"The art of life lies in a constant readjustment to our surroundings." -Okakura Kakuzo

--
LinkedIn profile
--
I only speak/write in English so I may not translate well on International posts.
--
User avatar
osxfil
Forum Members
Forum Members
Posts: 186
Joined: Wed Apr 01, 2009 6:03 pm
Location: Plzen, CZ

Re: Hierarchie uživatelů v modulu FrontEndUsers

Post by osxfil »

It was my first idea but the hierarchy depth can be more deeper finaly than i use in example. I need something as hierachy tree for CMS pages or products hierarchy. There is used parent_id paramater too.
Additionaly, subject to some conditions can workers to be managers too and then they will have they own tree of workers or managers can advance even furters in hierarchy. On each of this changeswill only changed parent_id value in DB and tree will automatically updated based on this.
JohnnyB
Dev Team Member
Dev Team Member
Posts: 729
Joined: Tue Nov 21, 2006 5:05 pm
Location: OH, USA

Re: Hierarchie uživatelů v modulu FrontEndUsers

Post by JohnnyB »

Here is a very basic idea to get you started. Not tested.
Does not contain any HTML markup, just a comma separated list. You will need to work out the layout and markup...

First, it looks up a FEU group by the group ID to loop through all of the users (ID) belonging to that group. This is needed to get all FEuser IDs.
Then, it loops through all of the User Properties and sets an array for them.
Finally, you can list the users that all have the same parent_id.

The $results will list every user's parent_id, name, surname.
The $list will list parent_id, name, surname for all users belonging to the parent_id set in the tag.

For example, if you have 10 different parent_id values, then you will need to use the UDT 10 times on the page:

Code: Select all

//assuming you have a feu group with ID of 1
{feu_hierarchy feu_group='1' parent_id='1'}
{feu_hierarchy feu_group='1' parent_id='2'}
...
{feu_hierarchy feu_group='1' parent_id='10'}
Create a user defined tag called "feu_hierarchy"

Code: Select all

// usage: {feu_hierarchy feu_group='1' parent_id=''} 

// set params
$gid = $params['feu_group']; // required use Group ID number
$pid = $params['parent_id'];  // optional

if (!isset($gid)) exit; // no group to look up so exit

// get CMSMMS and FEU stuff
$gCms = cmsms();
$feusers = cms_utils::get_module('FrontEndUsers');
$feugroup = $feusers->GetUsersInGroup($gid); // gets all FEUsers in Group

// get all user properties into array
foreach ($feugroup as $feuids) {
	$feuprops = $feusers->GetUserProperties($feuids['id']);

	$feu_props=array(); // make an array
	foreach ($feuprops as $key=>$value) {
		$feu_props[$value['title']]=$value['data'];
	}

	// get parent_id, jmeno, & prijmeni -- add other user properties here to look up
	if( isset($feu_props['parent_id']) && isset($feu_props['jmeno']) && isset($feu_props['prijmeni'])) {
	
		// set $results
		$results = $feu_props['parent_id'] . "," . $feu_props['jmeno'] . "," . $feu_props['prijmeni'] . "\n";
		
		// test for wanted parent_id
		if ( isset($pid) && $feu_props['parent_id'] == $pid ) {
		$list = $feu_props['parent_id'] . "," . $feu_props['jmeno'] . "," . $feu_props['prijmeni'] . "\n";
		}

	}
	
// test results
print_r($results);

// test list using specified parent_id
print_r($list);

}
I did something very similar to get a list of users having a specified user property. So, it should work but it may need some help.
"The art of life lies in a constant readjustment to our surroundings." -Okakura Kakuzo

--
LinkedIn profile
--
I only speak/write in English so I may not translate well on International posts.
--
User avatar
osxfil
Forum Members
Forum Members
Posts: 186
Joined: Wed Apr 01, 2009 6:03 pm
Location: Plzen, CZ

Re: Hierarchie uživatelů v modulu FrontEndUsers

Post by osxfil »

Look like this can working :) Will try your code over weekend and i hope it will works.

Thanks
Post Reply

Return to “Czech/Slovak - Česky/Slovensky”