You are here

function ca_save_predicate in Ubercart 6.2

Save a predicate array to the database.

Parameters

$predicate: A fully loaded predicate array.

11 calls to ca_save_predicate()
ca_actions_form_update_actions in ca/ca.admin.inc
Updates a predicate's actions based on the values from an actions form.
ca_add_action in ca/ca.module
Add a new action to a predicate.
ca_add_condition in ca/ca.module
Add a new condition to a predicate.
ca_add_condition_group in ca/ca.module
Add a new condition group to a predicate.
ca_conditions_form_update_conditions in ca/ca.admin.inc
Update a predicate's conditions based on the values from a conditions form.

... See full list

File

ca/ca.module, line 992
This is a demonstration module for the new conditional actions API.

Code

function ca_save_predicate($predicate) {

  // Check to see if the predicate has been previously saved to the database.
  $result = db_result(db_query("SELECT COUNT(*) FROM {ca_predicates} WHERE pid = '%s'", $predicate['#pid']));
  if (!$result) {

    // If not, then insert it.
    db_query("INSERT INTO {ca_predicates} (pid, title, description, class, status, weight, uid, ca_trigger, conditions, actions, created, modified) VALUES ('%s', '%s', '%s', '%s', %d, %d, %d, '%s', '%s', '%s', %d, %d)", $predicate['#pid'], $predicate['#title'], $predicate['#description'], $predicate['#class'], $predicate['#status'], $predicate['#weight'], $predicate['#uid'], $predicate['#trigger'], serialize($predicate['#conditions']), serialize($predicate['#actions']), time(), time());
  }
  else {

    // Otherwise, update it.
    db_query("UPDATE {ca_predicates} SET title = '%s', description = '%s', class = '%s', status = %d, weight = %d, uid = %d, ca_trigger = '%s', conditions = '%s', actions = '%s', modified = %d WHERE pid = '%s'", $predicate['#title'], $predicate['#description'], $predicate['#class'], $predicate['#status'], $predicate['#weight'], $predicate['#uid'], $predicate['#trigger'], serialize($predicate['#conditions']), serialize($predicate['#actions']), time(), $predicate['#pid']);
  }
}