diff options
author | Frederic Guillot <fred@kanboard.net> | 2016-06-24 10:05:45 -0400 |
---|---|---|
committer | Frederic Guillot <fred@kanboard.net> | 2016-06-24 10:05:45 -0400 |
commit | 700b4e8f0265e4eabd7a7c0eb6a06088d50554fe (patch) | |
tree | e38c011894e6f53b59557ad9a86fed8ad6bf6049 /app/functions.php | |
parent | 9e278a9370e3b651a4a545c0c0c0c256088ed187 (diff) |
Associate tags to tasks in BoardFormatter
Diffstat (limited to 'app/functions.php')
-rw-r--r-- | app/functions.php | 52 |
1 files changed, 51 insertions, 1 deletions
diff --git a/app/functions.php b/app/functions.php index 99431d9e..eaf33a52 100644 --- a/app/functions.php +++ b/app/functions.php @@ -3,10 +3,60 @@ use Kanboard\Core\Translator; /** + * Associate another dict to a dict based on a common key + * + * @param array $input + * @param array $relations + * @param string $relation + * @param string $column + */ +function array_merge_relation(array &$input, array &$relations, $relation, $column) +{ + foreach ($input as &$row) { + if (isset($row[$column]) && isset($relations[$row[$column]])) { + $row[$relation] = $relations[$row[$column]]; + } else { + $row[$relation] = array(); + } + } +} + +/** + * Create indexed array from a list of dict + * + * $input = [ + * ['k1' => 1, 'k2' => 2], ['k1' => 3, 'k2' => 4], ['k1' => 2, 'k2' => 5] + * ] + * + * array_column_index($input, 'k1') will returns: + * + * [ + * 1 => [['k1' => 1, 'k2' => 2], ['k1' => 2, 'k2' => 5]], + * 3 => [['k1' => 3, 'k2' => 4]], + * ] + * + * @param array $input + * @param string $column + * @return array + */ +function array_column_index(array &$input, $column) +{ + $result = array(); + + foreach ($input as &$row) { + if (isset($row[$column])) { + $result[$row[$column]][] = $row; + } + } + + return $result; +} + +/** * Sum all values from a single column in the input array * * $input = [ - * ['column' => 2'], ['column' => 3'] + * ['column' => 2], ['column' => 3] * ] * * array_column_sum($input, 'column') returns 5 |