Index: voting_actions.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/voting_actions/voting_actions.module,v
retrieving revision 1.15.2.1
diff -u -r1.15.2.1 voting_actions.module
--- voting_actions.module 17 Apr 2007 21:59:36 -0000 1.15.2.1
+++ voting_actions.module 20 Nov 2007 15:59:54 -0000
@@ -1,10 +1,12 @@
";
$content = votingapi_load_content($content_id, $content_type);
- if ($content == NULL) {
+ if ($content_type != 'node' || $content == NULL) {
return;
}
$context = array(
@@ -101,7 +104,8 @@
// Other helper functions build the actions cache from the database.
function voting_actions_process_results($context) {
- if (($data = cache_get('voting_actions_cache')) == FALSE) {
+//print "inside votingAPIProcessResult
";
+if (($data = cache_get('voting_actions_cache')) == FALSE) {
$action_sets = voting_actions_get_sets();
}
elseif (($action_sets = unserialize($data->data)) == FALSE) {
@@ -109,10 +113,10 @@
}
if (is_array($action_sets)) {
foreach ($action_sets as $action_set) {
- if (!empty($action_set['status'])) {
+ if (!empty($action_set['status']) && $action_set['status'] == VOTING_ACTIONS_STATE_ENABLED) {
$actions = array();
- if (_voting_actions_process_set($context, $action_set, $actions) == TRUE) {
- actions_do($actions, $content);
+ if (_voting_actions_process_set($context, $action_set, $actions) === TRUE) {
+ actions_do($actions, $context['content']);
}
}
}
@@ -124,6 +128,7 @@
* Internal functions used to evaluate sets of actions, and individual conditions.
*/
function _voting_actions_process_set($context = array(), $action_set = array(), &$actions) {
+//print "inside votingAPIProcessSet
";
// a little safety code to catch malformed sets.
$action_set += _voting_actions_populate_set_defaults();
@@ -156,23 +161,23 @@
if ($set_result == TRUE) {
// Now check sub-actions.
- foreach ($action_set['subsets'] as $subset) {
+ foreach ($action_set['sets'] as $subset) {
// check the required flag of the subset. if it is, evaluate it.
if ($subset['required'] == TRUE) {
$set_result = $set_result && _voting_actions_process_set($context, $subset, $actions);
- if ($set_result == FALSE) {
+ if ($set_result === FALSE) {
return FALSE;
}
}
}
- if ($set_result == TRUE) {
+ if ($set_result === TRUE) {
// It's still true after executing required subsets. Add the actions, then process optional subsets.
foreach ($action_set['actions'] as $action) {
$actions[] = $action;
}
- foreach ($action_set['subsets'] as $subset) {
+ foreach ($action_set['sets'] as $subset) {
// now handle the non-required subsets
if ($subset['required'] == FALSE) {
_voting_actions_process_set($context, $subset, $actions);
@@ -185,12 +190,17 @@
}
function _voting_actions_process_condition($condition = array(), $context = array()) {
+//print "inside VotingActionProcessCondition
";
$condition_cache = voting_actions_get_conditions();
if ($condition_definition = $condition_cache[$condition['name']]) {
$function = $condition_definition['eval_handler'];
+//print $function;
if (function_exists($function)) {
return $function($context, $condition);
}
+ else{
+ print "Function Does not Exists?
";
+ }
}
return FALSE;
@@ -288,7 +298,7 @@
}
$set['status'] = voting_actions_get_status($set['name']);
- $set['subsets'] = _voting_actions_load_sets_from_db($vasid);
+ $set['sets'] = _voting_actions_load_sets_from_db($set['vasid']);
$sets[$set['name']] = $set;
}
@@ -305,9 +315,7 @@
db_query($sql, $vasid, $set['name'], $set['parent'],
$set['source'], $set['description'], $set['condition_mask'],
$set['required'], $set['weight']);
-
- voting_actions_set_status($set['name'], $set['status']);
-
+
if (is_array($set['conditions'])) {
foreach ($set['conditions'] as $condition) {
$condition['vasid'] = $vasid;
@@ -320,13 +328,6 @@
db_query("INSERT INTO {voting_actions_action} (vasid, aid) VALUES (%d, '%s')", $vasid, $action);
}
}
-
- if (is_array($set['sets'])) {
- foreach ($set['sets'] as $sname => $subset) {
- $subset['parent_name'] = $name;
- _voting_actions_insert_set($subset);
- }
- }
}
function _voting_actions_insert_condition($condition) {
@@ -350,17 +351,23 @@
$set['source'], $set['description'], $set['condition_mask'],
$set['required'], $set['weight'], $set['vasid']);
- voting_actions_set_status($set['name'], $set['status']);
-
if (is_array($set['conditions'])) {
+ // First we'll loop through and delete any that are
+ // in the db but not in the new version of the set.
+ $current_sets = array();
+ $current_sets['replacements'][] = $set['vasid'];
foreach ($set['conditions'] as $condition) {
if (isset($condition['vacid'])) {
- if (!empty($condition['deleted'])) {
- db_query("DELETE FROM {voting_actions_condition} WHERE vacid = %d", $set['vacid']);
- }
- else {
- _voting_actions_update_condition($condition);
- }
+ $current_sets['wildcards'][] = '%d';
+ $current_sets['replacements'][] = $condition['vacid'];
+ }
+ }
+ db_query("DELETE FROM {voting_actions_condition} WHERE vasid = %d AND vacid NOT IN (". implode(',', $current_sets['wildcards']) .")", $current_sets['replacements']);
+
+ foreach ($set['conditions'] as $condition) {
+ $condition['vasid'] = $set['vasid'];
+ if (isset($condition['vacid'])) {
+ _voting_actions_update_condition($condition);
}
else {
_voting_actions_insert_condition($condition);
@@ -374,24 +381,7 @@
db_query("DELETE FROM {voting_actions_action} WHERE vasid = %d", $set['vasid']);
if (is_array($set['actions'])) {
foreach ($set['actions'] as $action) {
- db_query("INSERT INTO {voting_actions_action} (parent_name, aid) VALUES ('%s', %d)", $name, $set['vasid']);
- }
- }
-
- if (is_array($set['sets'])) {
- foreach ($set['sets'] as $subset) {
- if (isset($subset['vasid'])) {
- _voting_actions_update_set($subset);
- }
- else {
- _voting_actions_insert_set($subset);
- }
- }
- }
-
- if (is_array($set['deleted_sets'])) {
- foreach ($set['deleted_sets'] as $subset) {
- _voting_actions_delete_set($subset);
+ db_query("INSERT INTO {voting_actions_action} (vasid, aid) VALUES (%d, '%s')", $set['vasid'], $action);
}
}
}
@@ -415,7 +405,6 @@
db_query("DELETE FROM {voting_actions_condition} WHERE vasid = %d", $set['vasid']);
db_query("DELETE FROM {voting_actions_action} WHERE vasid = %d", $set['vasid']);
db_query("DELETE FROM {voting_actions_set} WHERE vasid = %d", $set['vasid']);
- db_query("DELETE FROM {voting_actions_status} WHERE name = %d", $set['name']);
}
function _voting_actions_validate_set($set) {
@@ -454,17 +443,17 @@
function _voting_actions_validate_condition($condition) {
$errors = array();
if (!is_array($condition)) {
- $errors[] = "The condition is not an array!";
+ $errors[] = t("The condition is not an array!");
return $errors;
}
if (!isset($condition['eval_handler'])) {
- $errors[] = "The condition has no handler.";
+ $errors[] = t("The condition has no handler.");
}
if (!function_exists($condition['eval_handler'])) {
$handler = $condition['eval_handler'];
- $errors[] = "The condition has an invalid handler ($eval_handler).";
+ $errors[] = t("The condition has an invalid handler (@handler).", array('@handler' => $eval_handler));
}
return $errors;
@@ -478,6 +467,6 @@
'weight' => 0,
'conditions' => array(),
'actions' => array(),
- 'subsets' => array(),
+ 'sets' => array(),
);
}
\ No newline at end of file