Last active
February 21, 2018 11:13
-
-
Save goesbysteve/432de9ac77b617e5f8dd96fa68a00464 to your computer and use it in GitHub Desktop.
This file contains 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
namespace Permutive { | |
class dataCollection { | |
protected $collection = array(); | |
public function __construct() | |
{ | |
} | |
public function setData($data = null, $transformer = null) | |
{ | |
// save $data, $transformer | |
$collection[] = array( | |
"data" => $data, | |
"transformer" => $transformer | |
) | |
} | |
public function getData() | |
{ | |
for_each($collection as $item) { | |
// transform $data | |
$transformed = array_map($item["data"],$item["transformer"]); | |
// merge $data | |
$array = array_unique(array_merge($array,$transformed)) | |
} | |
// insert into template for data island javascript as Javascript object creation NOT JSON | |
// return templated data | |
} | |
} | |
} | |
// Example | |
$permutive_data = new Permutive/dataCollection(); | |
// site specific data already retreived | |
$some_data = { | |
"section" => "news", | |
"sub_section" => "policing", | |
"article_id" => "45", | |
"article_title" => "The name of the thing", | |
"internal_hash" => "g234343dsfsg4", | |
"recipe_keys" => "123|456|789" | |
}; | |
// send data and transformer in | |
$permutive_data->setData($some_data, function($data) { | |
return { | |
"channel" => $data->section, | |
"category" => $data->sub_section, | |
"subcategory" => "misc", | |
"title" => $data->article_title, | |
"article" => array( | |
"id" => $data->article_id | |
), | |
"recipe" => array( | |
"keywords" => explode('|',$data->recipe_keys | |
) | |
} | |
}); | |
// get text to render out | |
$out = $permutive_data->getData(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment