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.108 seconds

Les générateurs de code je les connais presque tous pour les avoir essorés en long en large et en travers ... mais celui ci c'est vraiment un outil formidable de simplicité et d'efficacité !
Marc. (liubov - Forum)

Get Started