public function filter($index, $value) {
if($this->tasks) {
foreach ($this->tasks as $id => $t) {
if($t->$index != $value) {
unset($this->tasks[$id]);
}
}
} else {
echo "Tasks are empty";
}
}
So I am having a problem with the function above searching multidimensional objects. What I mean by that is like these:
$task->form->id
$task->form->type
$task->author->id
$task->fields->[FIELDNAME]->value
$task->form->template->id
$task->id
etc. These are the kinds of fields that need to be accessed. I thought that I could just, in $index, put “form->id” but that didn’t work. For my application, I literally can spell it out. I just don’t want to have to write a function for each to the last, because some of them (as you can see) only need to be on the first level and some need to be all the way down four objects.
Just tell me what more data you need and I will give it. I know every keystroke intimately so it sometimes means I forget to share something.
If you help, thank you so much.
WHAT I DID
Okay so I got it to work but I did something different.
Within the Form class
public function search($value, $type = NULL) {
if(is_object($this->fields)) {
foreach($this->fields as $page) {
foreach($page as $name=>$field) {
if($name != "pdata") {
if ($type != NULL && $field->type == $type && $field->value == $value || $type == NULL && isset($field->value) && $field->value == $value) {
return true;
}
}
}
return false;
}
} else {
//Probably corrupted
return false;
}
return false;
}
Outside of it I can just call this function and delete or add based on whether it returns true or false.
OR
I know you don’t want to write it all out, but I have to say I love the way this is done in the Symfony framework. In symfony you have an Entity class that defines functions to retrieve each piece of information (variable) from a given object.
One way you could mimic this is to create a base class for tasks that has functions to retrieve each variable you need…such as getTaskId.
Then you could extend this base class with the one you are working with now. This would give you access to the functions you created to parse your object. Retrieving $task->form->template->id could be as simple as calling the getTemplateId function.
I know this would probably take longer than what you were looking for, but I hope it helps.