Welcome, Guest
Username: Password: Remember me

TOPIC: n:n saving function

n:n saving function 12 Sep 2016 14:23 #14523

  • MorganL
  • MorganL's Avatar
  • Offline
  • Platinum Member
  • Posts: 438
  • Thank you received: 53
  • Karma: 16
Hi all

So I have a table JOB which has a 1:n relationship

jobs
|
jobsexperts
|
experts

so when you are in a job, you have the usual multi select of all the experts which I can select from

Here is my issue

when an expert(s) is added to this job and the job is saved, i want to fire an email to those users.. now.. the email bit is EASY, getting their ID and email is, but where is the save function that controls that multiselect so I can add the mailer code to the process?

I have looked in the jobsexpert model but there is no save function, and now sure how the job save function even reference that multselect
Morgan Leecy MCSE

Novell / Linux
PHP. MYSQL, Apache, node.js
Coldfusion, JQuery, HTML5
Joomla
The administrator has disabled public write access.

n:n saving function 12 Sep 2016 19:45 #14525

  • Romkabouter
  • Romkabouter's Avatar
  • Offline
  • Elite Member
  • Posts: 310
  • Thank you received: 131
  • Karma: 48
If I have reverse enginered it correctly:
- save is a controller function, it is in you job controller file.
- that is a decendant from the item.php in the classes/controller folder in the admin part of your component.
- in there, somewhere is: if (!$model->save($validData))
- the model, in this case, you can find in classes/model/item.php, look for the save function.
- In there is: $this->syncRelation($name, $data[$name]);
- the syncRelation function does the saving, it is also in the item.php

What you can do to get the experts:
Check the controller for job and look for the save function.
In there, there is a bit:
			//Get the model through postSaveHook()
			if ($this->model)
			{
				$model = $this->model;
				$item = $model->getItem();	
				$model->loadRelations('classes');
				$model->loadRelations('options');
			}

You can fork the controller and function and change above to
			//Get the model through postSaveHook()
			if ($this->model)
			{
				$model = $this->model;
				$item = $model->getItem();	
				$model->loadRelations('experts');
			}
Then you will have the experts and you can create a loop or so to add them to the recipients. ($item->experts is probably a array of objects)
The administrator has disabled public write access.
Time to create page: 0.105 seconds

Get Started