[DataToolSet Php]
<?php
class DatasTool {
public $sources;
public $processed = array();
// Give me a SQL ressource and bind it with the "label" to the DatasTool
public function parseSql($ressource, $label) {
$this->processed[$label]= array();
foreach ($ressource as $key => $value) {
$this->processed[$label][] = $value;
}
}
// Give me a sets of datas and an item to check
// I will return the number of occurance of this item
public function itemDetection($sets,$items, $precisedIndex = false) {
$occurences = array();
$multipleitems = false;
// Check if the items to count is array, so multiple
if (is_array($items)) {
$multipleitems = true;
// Then init entry in the occurences counter
foreach ($items as $key => $unique) {
$multipleitems[$unique] = 0;
}
}
/* Check if the items checker needs to only be apply
to a certains items in the sets
IE->
SQL result where -> Lined ["columnsXORY"];
*/
if ($precisedIndex) {
// Start to loop through each entry of the sets
foreach ($sets as $key => $entry) {
// If multiple items needs to be count
if ($multipleitems == true) {
// check each items as single
foreach ($items as $key => $itemToCheck) {
// If the entry[columns] is the same as the items["current_items"]
if ($entry[$precisedIndex] == $itemToCheck) {
// Then take occurences["currentItemToCheck"]++
$occurences[$itemToCheck]++;
}
}
} else {
$occurences[$items] = 0;
if ($entry[$precisedIndex] == $items) {
$occurences[$items]++;
}
}
}
}
}
}