Skip to content

Instantly share code, notes, and snippets.

@MaffooBristol
Last active August 29, 2015 13:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MaffooBristol/8707396 to your computer and use it in GitHub Desktop.
Save MaffooBristol/8707396 to your computer and use it in GitHub Desktop.
Pseudo-code for MVC linked people logic
<?php
function get_people() {
// Do something...
return $all_the_people;
}
function remove_array_values($arr1, $arr2) {
foreach ($arr1 as $key => $item) {
if (in_array($item, $arr2)) {
unset($arr1[$key]);
}
}
return $arr1;
}
function workgroup_links($name) {
$people = get_people();
$output = array(
'my_linked' => array(),
'something_else' => array(),
'others' => array(),
);
// Fill up the values, removing duplicates from previous iterations.
$output['my_linked'] = get_my_linked_people($people);
$output['something_else'] = remove_array_values(get_something_else($people), $output['my_linked']);
$output['others'] = remove_array_values(get_others($people), $output['something_else']);
if (!$name) {
return $output;
}
return $output[$name];
}
function get_my_linked_people($people) {
// Do some logic with $people...
return $new_people;
}
function get_something_else($people) {
// Do some logic with $people...
return $new_people;
}
function get_others($people) {
// Do some logic with $people...
return $new_people;
}
function my_linked_block() {
return theme(workgroup_links('my_linked'));
}
function something_else_block() {
return theme(workgroup_links('something_else'));
}
function others_block() {
return theme(workgroup_links('others'));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment