1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71: 72: 73: 74: 75: 76:
<?php
require_once __DIR__."/../utils/Singleton.php";
use swag\Singleton;
class SwagMapController extends Singleton {
public function init() {
}
public function swagMapData($mode) {
$nodes=array();
$links=array();
$swagpaths=Swagpath::findAll();
$nodeIndexByPostId=array();
foreach ($swagpaths as $swagpath) {
$nodeData=NULL;
if ($swagpath->isCurrentUserPrepared() || $mode=="full") {
$nodeData=array(
"name"=>$swagpath->getPost()->post_title,
"type"=>"swag",
"completed"=>$swagpath->isCompletedByCurrentUser(),
"color"=>$swagpath->getDisplayColor(),
"url"=>get_permalink($swagpath->getPost()->ID)
);
}
else if ($swagpath->isCurrentUserPreparedForPrerequisites()) {
$nodeData=array(
"name"=>"?",
"type"=>"swag",
"completed"=>FALSE,
"color"=>"#999999",
"url"=>NULL
);
}
if ($nodeData) {
$nodeIndexByPostId[$swagpath->getPost()->ID]=sizeof($nodes);
$nodes[]=$nodeData;
}
}
foreach ($swagpaths as $swagpath) {
$pres=$swagpath->getPrerequisites();
foreach ($pres as $pre) {
if (isset($nodeIndexByPostId[$pre->getPost()->ID]) &&
isset($nodeIndexByPostId[$swagpath->getPost()->ID])) {
$link=array(
"source"=>$nodeIndexByPostId[$pre->getPost()->ID],
"target"=>$nodeIndexByPostId[$swagpath->getPost()->ID]
);
$links[]=$link;
}
}
}
return array(
"nodes"=>$nodes,
"links"=>$links
);
}
}