Change value on database

  • jarana
  • Topic Author
  • Offline
  • Fresh Boarder
  • Fresh Boarder
  • Posts: 2
  • Thank you received: 0

jarana created the topic: Change value on database

Hello, I need to change a field value of my database when i change the status on contentbuilder
#233863
  • Posts: 2109
  • Karma: 72
  • Thank you received: 268

mihaela replied the topic: Change value on database

Hello,

To achieve what you want you would have to create a plugin that will change a field value in database and set the Action of the State to that plugin.

To sum up, in ContentBuilder, you can use the state feature, which let's you assign states to a record and connect an action on the state. These actions can be defined through ContentBuilder's plugin system.
There are 2 example action plugins (trash / untrash), that can be used to create custom actions for record states.

Regards,

Mihaela
#233870
  • jarana
  • Topic Author
  • Offline
  • Fresh Boarder
  • Fresh Boarder
  • Posts: 2
  • Thank you received: 0

jarana replied the topic: Change value on database

Hello,
Thanks for your answer, I take the example and create a plugin to change the field value in the table. I change the status and I recieved the succesfull mesage but the field value not change. Maybe the code or query is the problem:

<?php
/**
* @package ContentBuilder
* @author Markus Bopp
* @link www.crosstec.de
* @license GNU/GPL
*/

// no direct access
defined( '_JEXEC' ) or die( 'Restricted access' );

jimport( 'joomla.plugin.plugin' );

class plgContentbuilder_listactionCerradoxventas extends JPlugin
{
function __construct( &$subject, $params )
{
parent::__construct($subject, $params);
}

/**
* @param int $form_id use it to find the record for the appropriate view
* @param array $record_ids an array of record_id. Please note that the record_ids may be _non_numeric_
* @return string error
*/
function onBeforeAction($form_id, $record_ids){
$db = JFactory::getDBO();

$lang = JFactory::getLanguage();
$lang->load('plg_contentbuilder_listaction_cerradoxventas', JPATH_ADMINISTRATOR);

foreach($record_ids As $record_id){

$db->setQuery("Update #__content As content, #__contentbuilder_articles As article Set content.state = -2 Where article.form_id = ".intval($form_id)." And article.record_id = ".$db->Quote($record_id)." And content.id = article.article_id");
$db->query();
}

JFactory::getApplication()->enqueueMessage(JText::_('COM_CONTENTBUILDER_CERRADOXVENTAS_SUCCESSFULL'));

return ''; // no error
}

/**
*
* @param int $form_id use it to find the record for the appropriate view
* @param array $record_ids an array of record_id. Please note that the record_ids may be _non_numeric_
* @param type $previous_errors error messages thrown by onBeforeAction
* @return type
*/
function onAfterAction($form_id, $record_ids, $previous_errors){
return ''; // no error
}

/**
* This event will be triggered on article creation and update.
*
* It gives you the chance to force the article to stay into previously set states
*
* In this case we delete the newly created article if there is a trashed state assigned to this record.
*
* @param int $form_id
* @param mixed $record_id
* @param int $article_id
* @return string message
*/
function onAfterArticleCreation($form_id, $record_id, $article_id){

$db = JFactory::getDBO();
$db->setQuery("Select action From #__contentbuilder_list_records As lr, #__contentbuilder_list_states As ls Where lr.state_id = ls.id And lr.form_id = ls.form_id And lr.form_id = " . intval($form_id) . " And lr.record_id = " . $db->Quote($record_id));
$action = $db->loadResult();

if($action == 'cerradoxventas'){
$db->setQuery("Update #__joarana_pedidosespeciales As pedidos Set pedidos.cerradoxventas = 'Cerrado' Where id = " . intval($article_id));
$db->query();

}

return '';
}
}

Can you help me? please
Best Regards
#234516
Moderators: ForumSupporttomeperica
Time to create page: 0.069 seconds

Community Reward

Help us to create new extensions and plugins! With only $5 you help us a lot and get unlimited download access to all of our products, professional support and even more. Get your reward now!

Read More Here

News and Updates

Get informed about new downloads, updates and more in our News and Updates newsletter.

All Extensions Subscription

Get 1 year access to all of our current and future products and 1 year of professional support -- 99€

No support per domain or website installation limits! Includes all of our current and future Joomla!® extensions, Joomla!® templates for the duration of your membership. This means, by purchasing an All Extensions Subscription you'll have it all covered!

Get it from here

3rd Party Discount - 25% Off

We help you to keep your costs under control. If you are a new member and purchased a form building tool from a different form vendor, then you'll get a 25% discount on our subscription plans.

How to receive the discount:

Send us a quick email to sales@crosstec.org with a proof of purchase (for example a paypal receipt), await payment instructions and enjoy your membership!

Community Reward

Help us to create new extensions and plugins! With only $5 you help us a lot and get unlimited download access to all of our products, professional support and even more. Get your reward now!

Read More Here