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

  I found "cook" two days ago. Played around with it for a day and then within a day got rid of two legacy applications in IBM Lotus Domino Notes and replaced them with "cook". It was really easy. A piece of cake. Actually it was even easier than cooking. Cooking involves more work than developing with "cook". What can I say about "cook"? Great application great price for what it delivers great forum with a lot of information and fast responses active and friendly community fast forward moving development cycle So what should I say "Monsieur Le Cook"? Keep the good work going it will lead to success. Having become a paying member in the words of Edith Piaf may I say ..... non rien de rien ... je ne regrette rien. Vive La France.
FK (JED)
         

Get Started