Forums

CC V5 - Multiple "sql updates" with one 'Action' ?

paulzero 03 May, 2016
Hi ChronoEngine,

I'm new to CC V5 & have a (slightly) unique requirement.

I use a J2.5 app called 'Form2content' (F2C) in the Frontend to allow Users to create & submit formatted articles.

F2C creates its own 'Articles' in db table '#__fc2_form' with a published 'state' column (Default is '0' = Unpublished) & in sync creates an actual Joomla Article in '#__content' with its published 'state' also set to '0' = Unpublished' then dumps 'Smarty Templated' content into the actual Joomla article.

The x-ref between the two is 'reference_id' in '#__f2c_form' & 'id' in '#__content'.

To retain formatting, article editing has to be done in via F2C. On 'Save' after editing F2C overwrites the Joomla article with new formatted content.

On my site i'm using CC V5 to list Unpublished F2C articles (#__f2c_form' 'state = 0'). 'Editors' review each article using CC V5 'Button' to call 'F2C Smarty Template & contents', he/she reviews Article & saves - works fine. Next step for 'Editors' is to 'Publish' that Article.

I have used 'Toogle' on '#__f2c_form.state' to switch F2C article 'state' to 'Publised' ('1') - that also works fine BUT of course Joomla article '#__content.state' is not changed - no auto sync between the two! I need to update the 'state' of both the F2C & Joomla Articles simultaneously.

As 'Toogle' can only perform one action, my thinking was to replace 'Toogle' with a 'Button' that calls a MySQL Update query (in fact 2 querys, one to update '#__f2c_form.state' & one to update '#__content.state'. Not sure how to write the query/s or where to put them or how to add a 'Button-OnClick' event ! I thought the query/s might be as follows :

In my case CC V5 'Connection name' = 'unpubf2c' & 'Model title' = 'f2carticles' :


// Update joomla article query


$db = JFactory::getDbo();

$query = $db->getQuery(true);

// Fields to update in joomla #__content table.
$fields = array(
$db->quoteName('state') . ' = 1'
);

// Conditions for which records should be updated : 'id' = 'id' col in #__content
$conditions = array(
$db->quoteName('id') . ' = {f2carticles.reference_id}',
);

$query->update($db->quoteName('#__content'))->set($fields)->where($conditions);

$db->setQuery($query);

$result = $db->execute();



// Update f2c article query


$db = JFactory::getDbo();

$query = $db->getQuery(true);

// Fields to update in #__f2c_form table.
$fields = array(
$db->quoteName('state') . ' = 1'
);

// Conditions for which records should be updated : 'reference_id' = 'reference_id' col in #__f2c_form
$conditions = array(
$db->quoteName('reference_id') . ' = {f2carticles.reference_id}',
);

$query->update($db->quoteName('#__f2c_form'))->set($fields)->where($conditions);

$db->setQuery($query);

$result = $db->execute();



All advice most welcome ! Cheers - Paul Zero.
GreyHead 03 May, 2016
Hi Paul,

Too complex for me to take all of this in from a quick read but I can see two possibilities. One, perhaps the simplest would be to have your Publish button make an Ajax call back to a ChronoForm event where you run the query to do the update. You'd need to pass the ID but the rest should be straightforward.

If you don't want to use Ajax then you could also do it with a new CC event also calling a form event with the same (or very similar) code in it that then returns to the listing.

Bob
This topic is locked and no more replies can be posted.