Welcome, Guest
Username: Password: Remember me

TOPIC: Extra process in a toggle function

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

  • MorganL
  • MorganL's Avatar
  • Offline
  • Platinum Member
  • Posts: 438
  • Thank you received: 53
  • Karma: 16
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
The administrator has disabled public write access.

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

  • Romkabouter
  • Romkabouter's Avatar
  • Offline
  • Elite Member
  • Posts: 310
  • Thank you received: 131
  • Karma: 48
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.
The administrator has disabled public write access.
Time to create page: 0.086 seconds

Get Started