/** * Enforces a one person, one vote policy based on a unique identifier */ function connect_action_voteonce(&$parent, &$child, $op = '', $target = 'child') { $message = connect_node_options($parent->nid, 'voteonce_message'); $message = $message ? $message : t('You have already participated.'); switch ($op) { case 'requires': $return = array(); $return['child'] = array('voteonce_identifier' => 'Unique identifier (i.e., full name, membership #, or email address)'); $return['variables'] = array('voteonce_message' => array('#type' => 'textfield', '#title' => 'Message to display when someone attempts to participate more than once', '#default_value' => $message, '#required' => TRUE)); return $return; break; case 'validate': // don't check for this when editing an existing child node if (isset($child->status) && $child->status == 0) { return; } $map = connect_get_map($parent->nid); $test_value = connect_value('voteonce_identifier', $parent, $child, 'child'); $fieldname = $map['voteonce_identifier']; $field_keys = connect_get_field_keys($fieldname); $test_db = _connect_get_cck_db_info($fieldname); $test_table = $test_db['table']; $test_column = $test_db['columns'][$field_keys[0]]['column']; $sql = "SELECT count(*) FROM {" . $test_table . "} t, {connect_data} p WHERE t.nid=p.nid AND t.{$test_column} = '%s' AND p.pid = %d"; $count = db_result(db_query($sql, array($test_value, $parent->nid))); $already_voted = $count != 0; if ($already_voted) { form_set_error('', t($message)); } break; case 'status': // if this user has already participated if (isset($_SESSION['connect_action_basic_' . $parent->nid])) { return array('status' => $message, 'show_form' => FALSE); } break; } }
/** * allows participant-generated content to replace the parent content */ function connect_action_content_replace(&$parent, &$child, $op = '', $target = 'child') { switch ($op) { case 'requires': $return = array(); $return['parent'] = array('data_replace_parent' => 'Content replace: the content that can be rewritten.'); $return['child'] = array('data_replace_child' => 'Content replace: the participant\'s version.'); return $return; case 'form_alter': $map = connect_get_map($parent->nid); $field = $map['data_replace_child']; $key = connect_get_field_keys($field); // filter text if required $cck_info = _content_type_info(); $cck_vars = $cck_info['content types'][connect_node_options($parent->nid, 'participant_type')]['fields']; $text = connect_value('data_replace_parent', $parent, $child, 'parent'); if ($cck_vars[$field]['text_processing'] == 0) { $text = strip_tags($text); } $child[$field][0]['#default_value']['value'] = $text; break; case 'insert': if ($target == 'child') { $addition = connect_value('data_replace_child', $parent, $child, 'child'); connect_value('data_replace_parent', $parent, $child, 'parent', $addition); } break; } }