Created
April 4, 2018 20:21
-
-
Save antoinefortin/1363cf3d7aaf6ce182927fc03e35caff to your computer and use it in GitHub Desktop.
[DataToolSet Php]
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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]++; | |
} | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment