Hi,

Is possible to have a custom field that removes the row from a table if some conditions are met?

Thanks,
introfini

Comments

casey’s picture

Status: Active » Postponed

Nope, but I'll think about it.

introfini’s picture

Thanks!

That way we can for example make group by queries...

introfini

sidharth_k’s picture

subscribing. Need this feature too.

bfr’s picture

Here is my "delete" button i just got working(adds button to each row to delete node. You can change the button condition to anything else you want:

print "<form method='post'>";
print "<input name='".$data->nid."' type='submit' value='delete' />";
print "</form>";
$a=$_POST[$data->nid];
if (!empty($a))
	{
	node_delete($data->nid); //delete node
	node_load($data->nid, NULL, TRUE); //clear node from cache
	print "removed";
	}
if(isset($_POST['submit']))
	{
	unset($_POST['submit']);
	}

Any ideas how i could refresh the view after this(as you can see, now i have to use the "removed" text to inform that the row will be gone after next refresh)?

Also, can the "node blahblah has been deleted" text be disabled somehow?

hatsch’s picture

i need the same feature on a site. what i do for now is setting all the $data->field variables to 0 so they don't show up at least...
deleting the row from the view would be much nicer.

btw: i don't think #4 has a solution to the problem. it's not about deleting the node, but deleting the row of the view.

bfr’s picture

Well, if you just want to remove one row from showing, why dont you just use normal views filters?
For example, make "remove" check box cck field to node and add that to filters.
Or check if content of some field is empty, then filter out the entry.

hatsch’s picture

because views filter do not offer what i need in this situation.
i have a field called length which holds the length of an uploaded video. the view should only show so many videos that a given total length is not exceeded.

in my Views Custom Field i calculate the sum of these lengths. thanks to the $static variable i can easily pass the value from one row to another.

when $static is bigger than i want, the row should be "destroyed" so they are not included in the final view.
what i do now is setting all the values to 0 (which is not a beautiful solution).

now i've tried your suggestion:
i added a field (with default value = 1) and set it to 0 when $static is too big. the thing is that it is now shown in my preview with the value 0, but i can't filter it for some reason.

maybe i have to take a deeper look into the views api and put it in a custom module. but views is very complex, so i was seeking a simpler solution, where Views Custom Field seemed to be perfect...

sgerbino’s picture

This is my views solution, using Customfield PHP based on bfr's response.
It includes a javascript Are you sure message and automatically refreshes the page if the queries are executed

print "<form method='post'>";
print "<input name='".$data->time_track_ttid."' class='form-submit' type='submit' value='Remove entry' onclick=\"return confirm('Are you sure you want to remove this entry?');\" />";
print "</form>";
$a=$_POST[$data->time_track_ttid];
if (!empty($a)) {
  db_query("DELETE FROM {time_track} WHERE ttid = %d", $data->time_track_ttid);
  header("Location: #");
}
if(isset($_POST['submit'])) {
  unset($_POST['submit']);
}