How do you add and remove tags from a user?

Discussion for TimeTrex open source community developers.
Post Reply
Yajasi
Posts: 108
Joined: Wed Oct 17, 2012 4:48 pm

How do you add and remove tags from a user?

Post by Yajasi » Thu May 07, 2015 11:54 pm

I've tried using the API class CompanyGenericTag function called deleteCompanyGenericTag(), but this only removes the tag from the database. Opening the employee in TimeTrex shows the tag is still there but orphaned.

Code: Select all

// this code leaves an orphaned tag still associated with the user record
$ttAPI = new TimeTrexClientAPI( 'CompanyGenericTag' );
$ttAPI->deleteCompanyGenericTag($tag['id'])
I've tried modifying the ['tag'] element of the array of data obtained from the getUserfunction in the API class User, but the tag still remains orphaned.

Code: Select all

// this code does not remove a tag on the user record
$ttAPI = new TimeTrexClientAPI( 'User' );
$ttData = $ttAPI->getUser(null, true)->getResult();
$tagged_entry = $ttData[0];
$tagged_entry['tag'] = str_replace($tag_string,'',$tagged_entry['tag']);
$ttAPI->setUser($tagged_entry);

shaunw
Posts: 7360
Joined: Tue Sep 19, 2006 2:22 pm

Re: How do you add and remove tags from a user?

Post by shaunw » Fri May 08, 2015 10:57 am

Send the 'tag' array element like this:

Code: Select all

'tag' => 'keepthistag, -removethistag'
So basically just add a "-" infront of the tag you want to remove, while keeping any other tags there.

Yajasi
Posts: 108
Joined: Wed Oct 17, 2012 4:48 pm

Re: How do you add and remove tags from a user?

Post by Yajasi » Fri May 15, 2015 12:39 am

Thanks! That worked.

Post Reply