Welcome, Guest
Username: Password: Remember me
  • Page:
  • 1

TOPIC:

Extra process in a toggle function 16 Oct 2015 15:44 #13602

  • MorganL
  • MorganL's Avatar Topic Author
  • Offline
  • Platinum Member
  • Platinum Member
  • Posts: 438
  • Thank you received: 53
I have a boolean in my table which is basically approved, but default it is FALSE

Users can click on the item in a grid and it fires a standard toggle and changes to true.. out the box J-Cook functionality

However I want to add an extra step which basiclcally adds the user into a USER GROUP (number 14 for the sake of argument)

I have found the toggle code
public function toggle()
	{
		CkJSession::checkToken() or CkJSession::checkToken('get') or jexit(JText::_('JINVALID_TOKEN'));
		$this->_result = $result = $this->_toggle(array(
			'toggle_approved' => 'approved'
		));
		$model = $this->getModel();

Where can I add an extra step in this which is basically

If you are toggling value to TRUE

(make sure to use $user = JFactory::getUser(); first)

Toggle the value AND
INSERT INTO #__user_usergroup_map (user_id,group_id) 
VALUES ($user->id, 14)

or if toggling to FALSE
DELETE FROM #__user_usergroup_map WHERE user_id = $user->id AND group_id=14
Morgan Leecy MCSE

Novell / Linux
PHP. MYSQL, Apache, node.js
Coldfusion, JQuery, HTML5
Joomla

Please Log in or Create an account to join the conversation.

Extra process in a toggle function 26 Oct 2015 09:34 #13608

You can try to user the UserModel.

Open up: administrator\components\com_users\models\user.php
In there you see a function batchUser($group_id, $user_ids, $action)

In your toggle, add after $model = $this->getModel();
$groupmodel = CkJModel::getInstance('Users', 'UsersModel');
$groupmodel->batchUser(14, JFactory::getUser()->get('id') , 'add');

I did not try this, I is a suggested solution which might work.

Please Log in or Create an account to join the conversation.

  • Page:
  • 1
Time to create page: 0.189 seconds
  I still don't believe he can really be human to do all this ! From all of the forums that I've ever participated in this is certainly the one that most encapsulates the feeling of being truly open source where everyone's opinions and contributions can and will shape the development of the service! It's truly awesome! Hope you enjoy cooking and look forward to reading and contributing to any of the editorial work that you proposed too!! Thanks
Gez (audibleid - JED)

Get Started