admin wrote:
I do not understand your source.
Can you reexplain why are you using such helper ? What are you trying to do ?
Hi Admin,
I am not surprised your confused its complicated
i will try to make it a little clearer
For example a tax component that has a number of tables
[TAX EVENTS LIST] [USER TAX DETAILS] [EXTENDED USERS] [TASKS TODO] [TAX CORRESPONDENCE] [CORRESPONDENCE DEFAULTS]
The Helper sends a generic email using the values from the table [CORRESPONDENCE DEFAULTS]
- such as "Thank you your tax has been submitted"
- if an alternate email override is defined in the table [TAX EVENTS LIST] or [USER TAX DETAILS] or [TASKS TODO] some default values are overridden such as email_subject, cc_to, or the email_body
The helper updates some tables that "sometimes" have no physical relation to the current table
Tax Correspondence - is simply a backup if you like of the email content sent between staff and customers
Tasks Todo - is a list of tasks for staff / customers to complete and is only updated if a specific correspondence type is sent
User Tax Details - is updated if a specific TASKS TODO type is completed
Although the actual helper is much more complicated I will try to provide two simple examples (and keep them as short as possible)
User Tax Details - Submitted Layout
Users are presented with a fly layout "Submitted" displaying the some basic details from the [USER TAX DETAILS] table such as submitted_date, submitted_time, reference_number...
The current model "submitted" query does not contain enough data to perform several required tasks
- send an email to the accountant or the customer
- update the [TASKS TODO] table
- update the [TAX CORRESPONDENCE] table
TAX Tasks - Task Completed Layout
A task has been completed by an accountant but the "default" email body normally used for this task needs to be overridden by the accountant because we to remind them to provide additional information
- send email to customer with an update of tax progress (override the default email body)
- update the [TAX CORRESPONDENCE] table
- update the [USER TAX DETAILS] table
My need to get the current query and parse it to a helper i guess is related to the query being more precise in Cook V2.0 and does not include "SELECT a.*, .... FROM ....".
AND HERE IS WHERE IT GETS MESSY!
The original code
"SELECT a.field1, a.field2, some_table.field1, some_table.field2"
- We all say "a simple fix" replace the precision with "a.*" now you can access all values of the main table
"SELECT a.*, some_table.field, some_table.anotherfield"
- but it now creates additional problems i guess because a.field3 was not defined in the original build???
so if you use something like below to set values in the helper
$email_subject = $this->field1;
$email_to = $this->field2;
$email_ccto = $this->field3;
Notice: Undefined property: SomeModelCorrespondconfiguration::$field3 in...
(no errors for field1 or field2 because they we defined before we changed the query)
BUT in this case if you
- call the helper from switch statement in the model and pass the current $query to the helper
MyAdditionalHelper::getOverrides($query);
return $query;
- you can access all values of the modified query without error by loading the query result as an associative array and assigning the values as below
class MyAdditionalHelper
{
function getOverrides($query)
{
// use the query from the model to create an associative array
$db = JFactory::getDBO();
$db->setQuery($query);
$result=$db->loadAssoc();
// set some email overrides
$email_subject = $result['field1'];
$email_to = $result['field2']);
$email_ccto=$result['field3'];
Confusing Ha??
Anyhow thanks for your time again