I want to convert below array.
Criteria is,
If projectId same then store same project id data under array of project which contains projectId as key.
Array
(
[0] => Array
(
[PMST] => Array
(
[id] => 4
[project_id] => 25
[task_name] => Final task 3
[start_date] => 2016-06-21 00:00:00
[end_date] => 2016-06-29 00:00:00
)
[PMSP] => Array
(
[id] => 25
[project_name] => Project 3
[start_date] => 2016-06-01 00:00:00
[end_date] => 2016-06-04 00:00:00
)
)
[1] => Array
(
[PMST] => Array
(
[id] => 9
[project_id] => 28
[task_name] => Task Test 333 edit
[start_date] => 2016-06-19 00:00:00
[end_date] => 2016-06-29 00:00:00
)
[PMSP] => Array
(
[id] => 28
[project_name] => Project Employee Test
[start_date] => 2016-06-10 00:00:00
[end_date] => 2016-06-30 00:00:00
)
)
[2] => Array
(
[PMST] => Array
(
[id] => 1
[project_id] => 28
[task_name] => Task 1
[start_date] => 2016-06-01 00:00:00
[end_date] => 2016-06-04 00:00:00
)
[PMSP] => Array
(
[id] => 28
[project_name] => Project Employee Test
[start_date] => 2016-06-10 00:00:00
[end_date] => 2016-06-30 00:00:00
)
)
)
Desire Output
Array
(
[25] => Array
(
[PMSP] => Array
(
[id] => 25
[company_id] => 1114701
[project_name] => Project 3
[start_date] => 2016-06-01 00:00:00
[end_date] => 2016-06-04 00:00:00
)
[taskdetails] => Array
(
[0] => Array(
[PMST] => Array
(
[id] => 4
[project_id] => 25
[company_id] => 1114701
[task_name] => Final task 3
[start_date] => 2016-06-21 00:00:00
[end_date] => 2016-06-29 00:00:00
)
)
)
)
[28] => Array
(
[PMSP] => Array
(
[id] => 28
[company_id] => 1114701
[project_name] => Project Employee Test
[start_date] => 2016-06-10 00:00:00
[end_date] => 2016-06-30 00:00:00
)
[taskdetails] => Array
(
[0] => Array
(
[PMST] => Array
(
[id] => 9
[project_id] => 28
[company_id] => 1114701
[task_name] => Task Test 333 edit
[start_date] => 2016-06-19 00:00:00
[end_date] => 2016-06-29 00:00:00
)
)
[1] => Array(
[PMST] => Array
(
[id] => 1
[project_id] => 28
[company_id] => 1114701
[task_name] => Task 1
[start_date] => 2016-06-01 00:00:00
[end_date] => 2016-06-04 00:00:00
)
)
)
)
)
Loop over your input array using foreach, adding the PMST data to an output array as you go. It looks like it's safe to assume the PMSP data for two tasks on the same project will be the same.
$output = [];
foreach ($input as $task) {
if (!isset($output[$task["PMSP"]["id"]])) {
$output[$task["PMSP"]["id"]] = ["PMSP" => $task["PMSP"], "taskdetails" => []];
}
$output[$task["PMSP"]["id"]]["taskdetails"][] = $task["PMST"];
}
See the below example
Example
$data = [];
foreach ($a as $b) {
$key = $b["PMSP"]["id"];
if (!isset($data[$key])) {
$data[$key] = ["PMSP" => $b["PMSP"], "taskdetails" => []];
}
$data[$key]["taskdetails"][] = $b["PMST"];
}
echo "<pre>";
print_r($data);exit();
Your latest data
Example 2
Related
I have this array of professionals, locations, dates and times. How can I list these dates and times within it. And at the same time, if a certain time was chosen, I need to know the date, local_id, and the professional_id it belongs to.
I tried foreach nested and saving each information for each iteration, but in the end it didn't work because I need to display the dates in chronological order.
I've never worked with an array like this, I'm pretty lost.
Array
(
[profissional_id] => Array
(
[74] => Array
(
[local_id] => Array
(
[0] => Array
(
[2021-11-09] => Array
(
)
[2021-11-16] => Array
(
[0] => 08:00:00
[1] => 08:40:00
[2] => 09:20:00
[3] => 10:40:00
[4] => 12:00:00
)
[2021-11-23] => Array
(
[0] => 08:00:00
[1] => 08:40:00
[2] => 09:20:00
[3] => 10:00:00
[4] => 10:40:00
[5] => 11:20:00
[6] => 12:00:00
)
[2021-11-30] => Array
(
[0] => 08:00:00
[1] => 08:40:00
[2] => 09:20:00
[3] => 10:00:00
[4] => 10:40:00
[5] => 11:20:00
[6] => 12:00:00
)
[2021-12-07] => Array
(
[0] => 08:00:00
[1] => 08:40:00
[2] => 09:20:00
[3] => 10:00:00
[4] => 10:40:00
[5] => 11:20:00
[6] => 12:00:00
)
)
[5] => Array
(
[2021-11-09] => Array
(
[0] =>
)
[2021-11-16] => Array
(
[0] =>
)
[2021-11-23] => Array
(
[0] =>
)
[2021-11-30] => Array
(
[0] =>
)
[2021-12-07] => Array
(
[0] =>
)
)
)
)
[33] => Array
(
[local_id] => Array
(
[3] => Array
(
[2021-11-13] => Array
(
[0] => 08:00:00
[1] => 08:30:00
[2] => 09:00:00
[3] => 09:30:00
[4] => 10:00:00
[5] => 10:30:00
[6] => 11:00:00
[7] => 11:30:00
[8] => 12:00:00
)
[2021-11-20] => Array
(
)
[2021-11-27] => Array
(
[0] => 08:30:00
[1] => 09:00:00
[2] => 09:30:00
[3] => 10:00:00
[4] => 10:30:00
[5] => 11:00:00
[6] => 11:30:00
[7] => 12:00:00
)
[2021-12-04] => Array
(
[0] => 08:00:00
[1] => 08:30:00
[2] => 09:30:00
[3] => 10:00:00
[4] => 10:30:00
[5] => 11:00:00
[6] => 11:30:00
[7] => 12:00:00
)
)
)
)
)
)
This is an example of an array type return I get
I have to filter this array to see only future items.
How do I unset items from which the timeEnd has expired?
i.e when I call this array at 17:00 there's only array[2] left.
Array
(
[0] => Array
(
[id] => 3034
[date] => 28-09-2016
[timeStart] => 08:30
[timeEnd] => 09:30
[description] => User_A
[locationId] => 1
[roomId] => 8
[relationId] => 104
)
[1] => Array
(
[id] => 2524
[date] => 28-09-2016
[timeStart] => 08:30
[timeEnd] => 12:00
[description] => User_B
[locationId] => 1
[roomId] => 5
[relationId] => 86
)
[2] => Array
(
[id] => 2533
[date] => 28-09-2016
[timeStart] => 09:00
[timeEnd] => 18:00
[description] => User_C
[locationId] => 1
[roomId] => 4
[relationId] => 31
)
)
foreach ($reservations as $key=>$reservation) {
$expireDate = $reservation['date'].' '.$reservation['timeEnd'];
if (strtotime($expireDate) <= strtotime('now')){
unset($reservations[$key]);
}
}
I have the next issue, I have this multidimensional array:
Array
(
[0] => Array
(
[0] => Array
(
[start_date] => 2016-07-14 07:00
[end_date] => 2016-07-14 07:20
[type] => 2
)
[1] => Array
(
[start_date] => 2016-07-14 07:20
[end_date] => 2016-07-14 07:40
[type] => 2
)
[2] => Array
(
[start_date] => 2016-07-14 07:40
[end_date] => 2016-07-14 08:00
[type] => 2
)
[3] => Array
(
[start_date] => 2016-07-14 08:00
[end_date] => 2016-07-14 08:15
[type] => 3
)
[4] => Array
(
[start_date] => 2016-07-14 08:15
[end_date] => 2016-07-14 08:30
[type] => 3
)
)
[1] => Array
(
[0] => Array
(
[start_date] => 2016-07-15 07:00
[end_date] => 2016-07-15 07:20
[type] => 2
)
[1] => Array
(
[start_date] => 2016-07-15 07:20
[end_date] => 2016-07-15 07:40
[type] => 2
)
[2] => Array
(
[start_date] => 2016-07-15 07:40
[end_date] => 2016-07-15 08:00
[type] => 2
)
[3] => Array
(
[start_date] => 2016-07-15 08:00
[end_date] => 2016-07-15 08:15
[type] => 3
)
[4] => Array
(
[start_date] => 2016-07-15 08:15
[end_date] => 2016-07-15 08:30
[type] => 3
)
)
[2] => Array
(
[0] => Array
(
[start_date] => 2016-07-18 07:00
[end_date] => 2016-07-18 07:20
[type] => 2
)
[1] => Array
(
[start_date] => 2016-07-18 07:20
[end_date] => 2016-07-18 07:40
[type] => 2
)
[2] => Array
(
[start_date] => 2016-07-18 07:40
[end_date] => 2016-07-18 08:00
[type] => 2
)
[3] => Array
(
[start_date] => 2016-07-18 08:00
[end_date] => 2016-07-18 08:15
[type] => 3
)
[4] => Array
(
[start_date] => 2016-07-18 08:15
[end_date] => 2016-07-18 08:30
[type] => 3
)
)
[3] => Array
(
[0] => Array
(
[start_date] => 2016-07-19 07:00
[end_date] => 2016-07-19 07:20
[type] => 2
)
[1] => Array
(
[start_date] => 2016-07-19 07:20
[end_date] => 2016-07-19 07:40
[type] => 2
)
[2] => Array
(
[start_date] => 2016-07-19 07:40
[end_date] => 2016-07-19 08:00
[type] => 2
)
[3] => Array
(
[start_date] => 2016-07-19 08:00
[end_date] => 2016-07-19 08:15
[type] => 3
)
[4] => Array
(
[start_date] => 2016-07-19 08:15
[end_date] => 2016-07-19 08:30
[type] => 3
)
)
[4] => Array
(
[0] => Array
(
[start_date] => 2016-07-20 07:00
[end_date] => 2016-07-20 07:20
[type] => 2
)
[1] => Array
(
[start_date] => 2016-07-20 07:20
[end_date] => 2016-07-20 07:40
[type] => 2
)
[2] => Array
(
[start_date] => 2016-07-20 07:40
[end_date] => 2016-07-20 08:00
[type] => 2
)
[3] => Array
(
[start_date] => 2016-07-20 08:00
[end_date] => 2016-07-20 08:15
[type] => 3
)
[4] => Array
(
[start_date] => 2016-07-20 08:15
[end_date] => 2016-07-20 08:30
[type] => 3
)
)
[5] => Array
(
[0] => Array
(
[start_date] => 2016-07-21 07:00
[end_date] => 2016-07-21 07:20
[type] => 2
)
[1] => Array
(
[start_date] => 2016-07-21 07:20
[end_date] => 2016-07-21 07:40
[type] => 2
)
[2] => Array
(
[start_date] => 2016-07-21 07:40
[end_date] => 2016-07-21 08:00
[type] => 2
)
[3] => Array
(
[start_date] => 2016-07-21 08:00
[end_date] => 2016-07-21 08:15
[type] => 3
)
[4] => Array
(
[start_date] => 2016-07-21 08:15
[end_date] => 2016-07-21 08:30
[type] => 3
)
)
[6] => Array
(
[0] => Array
(
[start_date] => 2016-07-22 07:00
[end_date] => 2016-07-22 07:20
[type] => 2
)
[1] => Array
(
[start_date] => 2016-07-22 07:20
[end_date] => 2016-07-22 07:40
[type] => 2
)
[2] => Array
(
[start_date] => 2016-07-22 07:40
[end_date] => 2016-07-22 08:00
[type] => 2
)
[3] => Array
(
[start_date] => 2016-07-22 08:00
[end_date] => 2016-07-22 08:15
[type] => 3
)
[4] => Array
(
[start_date] => 2016-07-22 08:15
[end_date] => 2016-07-22 08:30
[type] => 3
)
)
)
In addition, I have the following function:
public function transformValue($array = [], $level = 1) {
$return = [];
foreach($array as $key => $value){
if(is_array($value)){
$this->transformValue($value, $level + 1);
} else{
$return[$key] = $value;
}
}
return $return;
}
This function receives this multi-array as a parameter, as I need to normalize it as follows:
Array
(
[start_date] => 2016-07-14 07:00
[end_date] => 2016-07-14 07:20
[type] => 2
)
Array
(
[start_date] => 2016-07-14 07:20
[end_date] => 2016-07-14 07:40
[type] => 2
)
Array
(
[start_date] => 2016-07-14 07:40
[end_date] => 2016-07-14 08:00
[type] => 2
)
Array
(
[start_date] => 2016-07-14 08:00
[end_date] => 2016-07-14 08:15
[type] => 3
)
Array
(
[start_date] => 2016-07-14 08:15
[end_date] => 2016-07-14 08:30
[type] => 3
)
Array
(
[start_date] => 2016-07-15 07:00
[end_date] => 2016-07-15 07:20
[type] => 2
)
Array
(
[start_date] => 2016-07-15 07:20
[end_date] => 2016-07-15 07:40
[type] => 2
)
Array
(
[start_date] => 2016-07-15 07:40
[end_date] => 2016-07-15 08:00
[type] => 2
)
Array
(
[start_date] => 2016-07-15 08:00
[end_date] => 2016-07-15 08:15
[type] => 3
)
Array
(
[start_date] => 2016-07-15 08:15
[end_date] => 2016-07-15 08:30
[type] => 3
)
Array
(
[start_date] => 2016-07-18 07:00
[end_date] => 2016-07-18 07:20
[type] => 2
)
Array
(
[start_date] => 2016-07-18 07:20
[end_date] => 2016-07-18 07:40
[type] => 2
)
Array
(
[start_date] => 2016-07-18 07:40
[end_date] => 2016-07-18 08:00
[type] => 2
)
Array
(
[start_date] => 2016-07-18 08:00
[end_date] => 2016-07-18 08:15
[type] => 3
)
Array
(
[start_date] => 2016-07-18 08:15
[end_date] => 2016-07-18 08:30
[type] => 3
)
Array
(
[start_date] => 2016-07-19 07:00
[end_date] => 2016-07-19 07:20
[type] => 2
)
Array
(
[start_date] => 2016-07-19 07:20
[end_date] => 2016-07-19 07:40
[type] => 2
)
Array
(
[start_date] => 2016-07-19 07:40
[end_date] => 2016-07-19 08:00
[type] => 2
)
Array
(
[start_date] => 2016-07-19 08:00
[end_date] => 2016-07-19 08:15
[type] => 3
)
Array
(
[start_date] => 2016-07-19 08:15
[end_date] => 2016-07-19 08:30
[type] => 3
)
Array
(
[start_date] => 2016-07-20 07:00
[end_date] => 2016-07-20 07:20
[type] => 2
)
Array
(
[start_date] => 2016-07-20 07:20
[end_date] => 2016-07-20 07:40
[type] => 2
)
Array
(
[start_date] => 2016-07-20 07:40
[end_date] => 2016-07-20 08:00
[type] => 2
)
Array
(
[start_date] => 2016-07-20 08:00
[end_date] => 2016-07-20 08:15
[type] => 3
)
Array
(
[start_date] => 2016-07-20 08:15
[end_date] => 2016-07-20 08:30
[type] => 3
)
Array
(
[start_date] => 2016-07-21 07:00
[end_date] => 2016-07-21 07:20
[type] => 2
)
Array
(
[start_date] => 2016-07-21 07:20
[end_date] => 2016-07-21 07:40
[type] => 2
)
Array
(
[start_date] => 2016-07-21 07:40
[end_date] => 2016-07-21 08:00
[type] => 2
)
Array
(
[start_date] => 2016-07-21 08:00
[end_date] => 2016-07-21 08:15
[type] => 3
)
Array
(
[start_date] => 2016-07-21 08:15
[end_date] => 2016-07-21 08:30
[type] => 3
)
Array
(
[start_date] => 2016-07-22 07:00
[end_date] => 2016-07-22 07:20
[type] => 2
)
Array
(
[start_date] => 2016-07-22 07:20
[end_date] => 2016-07-22 07:40
[type] => 2
)
Array
(
[start_date] => 2016-07-22 07:40
[end_date] => 2016-07-22 08:00
[type] => 2
)
Array
(
[start_date] => 2016-07-22 08:00
[end_date] => 2016-07-22 08:15
[type] => 3
)
Array
(
[start_date] => 2016-07-22 08:15
[end_date] => 2016-07-22 08:30
[type] => 3
)
MY PROBLEM: When I call my function and assigned to a variable, it appears that the function does not assign any value to the variable, but if I check the return of the function with a print_r() shows the values as we need. I should be skipping is things and I need a "push" to continue. It is in this way that declare the variable with the return of function:
$return_value_function = [];
$return_value_function = $this->transformValue($array_values);
The variable $return_value_function does not save the function return. Where is my mistake?
You should assign the value from this call:
$this->transformValue($value, $level + 1);
to a variable. Like:
$return[$key] = $this->transformValue($value, $level + 1);
Everytime this function is called recursively, the return statement sends the data back & there is nothing to hold that returned data.
SOLUTION
You can change your function as below & achieve the same output without recursion:
function transformValue($array = []) {
$return = [];
foreach($array as $key => $value) {
if(is_array($value)) {
$return = array_merge( $return, $value );
}
}
return $return;
}
The output is:
Array
(
[0] => Array
(
[start_date] => 01 Jul, 2016
[type] => 1
)
[1] => Array
(
[start_date] => 02 Jul, 2016
[type] => 1
)
[2] => Array
(
[start_date] => 03 Jul, 2016
[type] => 1
)
[3] => Array
(
[start_date] => 04 Jul, 2016
[type] => 1
)
[4] => Array
(
[start_date] => 05 Jul, 2016
[type] => 1
)
[5] => Array
(
[start_date] => 06 Jul, 2016
[type] => 2
)
[6] => Array
(
[start_date] => 07 Jul, 2016
[type] => 2
)
[7] => Array
(
[start_date] => 08 Jul, 2016
[type] => 2
)
[8] => Array
(
[start_date] => 09 Jul, 2016
[type] => 2
)
[9] => Array
(
[start_date] => 10 Jul, 2016
[type] => 2
)
[10] => Array
(
[start_date] => 11 Jul, 2016
[type] => 3
)
[11] => Array
(
[start_date] => 12 Jul, 2016
[type] => 3
)
[12] => Array
(
[start_date] => 13 Jul, 2016
[type] => 3
)
[13] => Array
(
[start_date] => 14 Jul, 2016
[type] => 3
)
[14] => Array
(
[start_date] => 15 Jul, 2016
[type] => 3
)
[15] => Array
(
[start_date] => 16 Jul, 2016
[type] => 4
)
[16] => Array
(
[start_date] => 17 Jul, 2016
[type] => 4
)
[17] => Array
(
[start_date] => 18 Jul, 2016
[type] => 4
)
[18] => Array
(
[start_date] => 19 Jul, 2016
[type] => 4
)
[19] => Array
(
[start_date] => 20 Jul, 2016
[type] => 4
)
[20] => Array
(
[start_date] => 21 Jul, 2016
[type] => 5
)
[21] => Array
(
[start_date] => 22 Jul, 2016
[type] => 5
)
[22] => Array
(
[start_date] => 23 Jul, 2016
[type] => 5
)
[23] => Array
(
[start_date] => 24 Jul, 2016
[type] => 5
)
[24] => Array
(
[start_date] => 25 Jul, 2016
[type] => 5
)
)
Please note my sample array only contains those 2 keys.
And this output is returned through the following code:
$return_value_function = [];
$return_value_function = transformValue($arr);
echo '<pre>';print_r($return_value_function);echo '</pre>';
Please refer below code. It will return array as you wish.
public function transformValue($array) {
foreach($array as $subarray){
foreach($subarray as $value){
$finalArray[] = $value;
}
}
return $finalArray;
}
$finalArray= $this->transformValue($array_values);
echo "<pre>";
print_r($finalArray);
I have tried many different variation, but cannot get the right structure. Maybe, you expert might what to give it a try.
What I need to do is return the therapist who may have multiple children assigned to him. It will return the children's schedules that are assigned to him.
I have tried the following Code. This is the closest I can get to the format I need.
// Grab the therapist
$therapist = $this->Therapist->find('first', array('conditions' => array('Therapist.' . $this->Therapist->primaryKey => $id)));
// Grab the child(ren) assigned to the therapist
// Returns id as key and name as value.
$children = $this->Child->get_children($id);
$schedule = array();
// Loop through the assigned children and get the id (key).
foreach($children as $key => $value):
// Loop through and grab all the scheduled days and times for child(ren).
foreach($this->Schedule->get_full_schedule($key) as $child):
// Have the child name at the top of the array.
if($name != $child['Child']['child_name']):
$schedule[] = array_push($schedule, array('child_name' => $child['Child']['child_name']));
$name = $child['Child']['child_name'];
endif;
// Get all the scheduled days for the child and add to array.
if($child['Schedule']['child_id'] == $child['Child']['id']):
$schedule[]['Schedule'] = $child['Schedule'];
endif;
endforeach;
endforeach;
Which outputs the following Array:
Array
(
[0] => Array
(
[child_name] => John Smith
)
[1] => 1
[2] => Array
(
[Schedule] => Array
(
[id] => 19
[child_id] => 197
[days] => Monday
[start_time] => 17:00:00
[end_time] => 22:00:00
)
)
[3] => Array
(
[child_name] => Jane Smith
)
[4] => 4
[5] => Array
(
[Schedule] => Array
(
[id] => 16
[child_id] => 138
[days] => Monday
[start_time] => 09:00:00
[end_time] => 17:00:00
)
)
[6] => Array
(
[Schedule] => Array
(
[id] => 17
[child_id] => 138
[days] => Sunday
[start_time] => 09:00:00
[end_time] => 12:00:00
)
)
[7] => Array
(
[Schedule] => Array
(
[id] => 18
[child_id] => 138
[days] => Tuesday
[start_time] => 09:00:00
[end_time] => 17:00:00
)
)
)
What I would like is:
Array
(
[0] => Array
(
[child_name] => John Smith
[0] => Array
(
[Schedule] => Array
(
[id] => 19
[child_id] => 197
[days] => Monday
[start_time] => 17:00:00
[end_time] => 22:00:00
)
)
)
[1] => Array
(
[child_name] => Jane Smith
[0] => Array
(
[Schedule] => Array
(
[id] => 16
[child_id] => 138
[days] => Monday
[start_time] => 09:00:00
[end_time] => 17:00:00
)
)
[1] => Array
(
[Schedule] => Array
(
[id] => 17
[child_id] => 138
[days] => Sunday
[start_time] => 09:00:00
[end_time] => 12:00:00
)
)
[2] => Array
(
[Schedule] => Array
(
[id] => 18
[child_id] => 138
[days] => Tuesday
[start_time] => 09:00:00
[end_time] => 17:00:00
)
)
)
Any help is appreciated.
Thank,
Greg
Have you thought about just using Containable Behavior? Seems MUCH easier than the way you're trying to do it:
$this->Therapist->find('first', array(
'conditions' => array(
'Therapist.' . $this->Therapist->primaryKey => $id
),
'contain' => array(
'Child' => array(
'Schedule'
)
)
));
Not only is it a lot easier, but your data should come back in an acceptable and nested format.
I am using a $this->find('threaded') in my CakePHP application and am trying to pull in an associated model within the find (HABTM). I have tried several methods, such as 'joins', 'recursive' and 'contains' all with no luck. I am using CakePHP 2.3.6
Here is my (working) code.
class EventsController extends AppController {
public function promoters($id = null) {
$options = array('conditions' => array('Event.id' => $id));
$event = $this->Event->find('first', $options);
$this->set('event', $event);
$this->loadModel('EventsPromoter');
$treelistConditions = array(
'conditions' => array(
'event_id' => $id
),
);
$promoterTree = $this->EventsPromoter->find('threaded', $treelistConditions);
$this->set('promoters', $promoterTree);
}
}
This results in the following array output
Array
(
[0] => Array
(
[EventsPromoter] => Array
(
[id] => 1
[promoter_id] => 1
[event_id] => 1
[parent_id] =>
[created] => 2013-07-26 00:30:09
[modified] => 2013-07-26 00:30:09
)
[children] => Array
(
[0] => Array
(
[EventsPromoter] => Array
(
[id] => 10
[promoter_id] => 4
[event_id] => 1
[parent_id] => 1
[created] => 0000-00-00 00:00:00
[modified] => 0000-00-00 00:00:00
)
[children] => Array
(
)
)
[1] => Array
(
[EventsPromoter] => Array
(
[id] => 13
[promoter_id] => 6
[event_id] => 1
[parent_id] => 1
[created] => 0000-00-00 00:00:00
[modified] => 0000-00-00 00:00:00
)
[children] => Array
(
)
)
)
)
[1] => Array
(
[EventsPromoter] => Array
(
[id] => 2
[promoter_id] => 2
[event_id] => 1
[parent_id] =>
[created] => 2013-07-26 00:30:09
[modified] => 2013-07-26 00:30:09
)
[children] => Array
(
[0] => Array
(
[EventsPromoter] => Array
(
[id] => 11
[promoter_id] => 5
[event_id] => 1
[parent_id] => 2
[created] => 0000-00-00 00:00:00
[modified] => 0000-00-00 00:00:00
)
[children] => Array
(
[0] => Array
(
[EventsPromoter] => Array
(
[id] => 6
[promoter_id] => 3
[event_id] => 1
[parent_id] => 11
[created] => 0000-00-00 00:00:00
[modified] => 0000-00-00 00:00:00
)
[children] => Array
(
)
)
)
)
[1] => Array
(
[EventsPromoter] => Array
(
[id] => 14
[promoter_id] => 7
[event_id] => 1
[parent_id] => 2
[created] => 2013-07-26 00:30:09
[modified] => 2013-07-26 00:30:09
)
[children] => Array
(
)
)
)
)
)
What I would like my code to output is the following
Array
(
[0] => Array
(
[EventsPromoter] => Array
(
[id] => 1
[promoter_id] => 1
[event_id] => 1
[parent_id] =>
[created] => 2013-07-26 00:30:09
[modified] => 2013-07-26 00:30:09
)
[Promoter] => Array
(
[promoter_id] => 1
[first_name] => 'Bob'
[last_name] => 'Smith'
)
[children] => Array
(
[0] => Array
(
[EventsPromoter] => Array
(
[id] => 10
[promoter_id] => 4
[event_id] => 1
[parent_id] => 1
[created] => 0000-00-00 00:00:00
[modified] => 0000-00-00 00:00:00
)
[Promoter] => Array
(
[promoter_id] => 4
[first_name] => 'Sally'
[last_name] => 'Sue'
)
[children] => Array
(
)
)
[1] => Array
(
[EventsPromoter] => Array
(
[id] => 13
[promoter_id] => 6
[event_id] => 1
[parent_id] => 1
[created] => 0000-00-00 00:00:00
[modified] => 0000-00-00 00:00:00
)
[Promoter] => Array
(
[promoter_id] => 6
[first_name] => 'Ben'
[last_name] => 'King'
)
[children] => Array
(
)
)
)
)
[1] => Array
(
[EventsPromoter] => Array
(
[id] => 2
[promoter_id] => 2
[event_id] => 1
[parent_id] =>
[created] => 2013-07-26 00:30:09
[modified] => 2013-07-26 00:30:09
)
[Promoter] => Array
(
[promoter_id] => 2
[first_name] => 'Jack'
[last_name] => 'Sparrow'
)
[children] => Array
(
[0] => Array
(
[EventsPromoter] => Array
(
[id] => 11
[promoter_id] => 5
[event_id] => 1
[parent_id] => 2
[created] => 0000-00-00 00:00:00
[modified] => 0000-00-00 00:00:00
)
[Promoter] => Array
(
[promoter_id] => 5
[first_name] => 'Jane'
[last_name] => 'Doe'
)
[children] => Array
(
[0] => Array
(
[EventsPromoter] => Array
(
[id] => 6
[promoter_id] => 3
[event_id] => 1
[parent_id] => 11
[created] => 0000-00-00 00:00:00
[modified] => 0000-00-00 00:00:00
)
[Promoter] => Array
(
[promoter_id] => 3
[first_name] => 'Mike'
[last_name] => 'Jones'
)
[children] => Array
(
)
)
)
)
[1] => Array
(
[EventsPromoter] => Array
(
[id] => 14
[promoter_id] => 7
[event_id] => 1
[parent_id] => 2
[created] => 2013-07-26 00:30:09
[modified] => 2013-07-26 00:30:09
)
[Promoter] => Array
(
[promoter_id] => 7
[first_name] => 'Spider'
[last_name] => 'Man'
)
[children] => Array
(
)
)
)
)
)
Nothing I have been trying is working, and this seems like something Cake should be able to handle fairly easily. Thanks in advance for any help!
I was taking a slightly wrong approach for what I was trying to accomplish. While I still think this should be possible from my EventsController class, I elected to make it in the EventsPromotersController HABTM class. The code is much simpler using this method
class EventsPromotersController extends AppController {
public function event($event_id = null) {
$options = array('conditions' => array('event_id' => $event_id));
$promoters = $this->EventsPromoter->find('threaded', $options);
$this->set('promoters', $promoters);
}
}