Skip to content

Commit

Permalink
0.4.1
Browse files Browse the repository at this point in the history
* [+] Arr::groupDatasetByColumn()
* [+] FS::checkPath()
  • Loading branch information
KarelWintersky committed Jun 21, 2021
1 parent 45d72e6 commit 324ea2e
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
21 changes: 21 additions & 0 deletions sources/Helpers/Arr.php
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,27 @@ public static function searchCallback(array $input, callable $callback)

}

/**
* Возвращает новый датасет, индекс для строк которого равен значению колонки строки
* Предназначен для переформатирования PDO-ответов, полученных в режиме FETCH_ASSOC
*
* [ 0 => [ 'id' => 5, 'data' => 10], 1 => [ 'id' => 6, 'data' => 12] .. ]
* При вызове с аргументами ($dataset, 'id') возвращает
* [ 5 => [ 'id' => 5, 'data' => 10], 6 => [ 'id' => 6, 'data' => 12] .. ]
*
* @param $dataset
* @param $column_id
* @return array
*/
public static function groupDatasetByColumn($dataset, $column_id)
{
$result = [];
array_map(function ($row) use (&$result, $column_id){
$result[ $row[ $column_id ] ] = $row;
}, $dataset);
return $result;
}



}
Expand Down
15 changes: 15 additions & 0 deletions sources/Helpers/FS.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,4 +88,19 @@ public static function read_all_files($root = '.')
return $directory_content;
}

/**
*
* @param $path
* @return bool
*/
public static function checkPath($path)
{
if (!is_dir( $path ) && !mkdir( $path, 0777, true ) && !is_dir( $path )) {
return false;
//throw new \RuntimeException( sprintf( 'Directory "%s" was not created', $path ) );
}

return true;
}

}

0 comments on commit 324ea2e

Please sign in to comment.