本文整理汇总了PHP中Datamodel::s_graph方法的典型用法代码示例。如果您正苦于以下问题:PHP Datamodel::s_graph方法的具体用法?PHP Datamodel::s_graph怎么用?PHP Datamodel::s_graph使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Datamodel
的用法示例。
在下文中一共展示了Datamodel::s_graph方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: __construct
/**
*
*/
public function __construct($pb_dont_cache = false)
{
global $_DATAMODEL_CACHE;
// is the graph already in memory?
if (!$pb_dont_cache && Datamodel::$s_graph) {
return;
}
// is there an on-disk cache of the internal graph?
if (is_object($vo_cache = $this->_getCacheObject())) {
if ($va_graph = $vo_cache->load('ca_datamodel_graph')) {
$this->opo_graph = new Graph($va_graph);
return;
}
}
$o_config = Configuration::load();
if ($vs_data_model_path = $o_config->get("data_model")) {
// is it cached in memory?
if ($_DATAMODEL_CACHE[$vs_data_model_path]) {
$this->opo_graph = $_DATAMODEL_CACHE[$vs_data_model_path];
return true;
}
$o_datamodel = Configuration::load($vs_data_model_path);
$this->opo_graph = new Graph();
# add tables
if (!($va_tables = $o_datamodel->getAssoc("tables"))) {
$va_tables = array();
}
foreach ($va_tables as $vs_table => $vn_num) {
$this->opo_graph->addNode($vs_table);
$this->opo_graph->addAttribute("num", $vn_num, $vs_table);
$this->opo_graph->addNode("t#" . $vn_num);
$this->opo_graph->addAttribute("name", $vs_table, "t#" . $vn_num);
}
# add relationships
if (!($va_relationships = $o_datamodel->getList("relationships"))) {
$va_relationships = array();
}
foreach ($va_relationships as $vs_relationship) {
$va_keys = preg_split("/[\t ]*=[\t ]*/", $vs_relationship);
$vn_num_keys = sizeof($va_keys);
switch ($vn_num_keys) {
case 2:
$vs_key1 = $va_keys[0];
$va_tmp = preg_split('/[ ]+/', $va_keys[1]);
$vs_key2 = $va_tmp[0];
list($vs_table1, $vs_field1) = explode(".", $vs_key1);
list($vs_table2, $vs_field2) = explode(".", $vs_key2);
$vn_weight = isset($va_tmp[1]) && intval($va_tmp[1]) > 0 ? intval($va_tmp[1]) : 10;
break;
default:
die("Fatal error: syntax error in datamodel relationship specification: '{$vs_relationship}'\n");
break;
}
if (!$this->opo_graph->hasNode($vs_table1)) {
die("Fatal error: invalid table '{$vs_table1}' in relationship in datamodel definition\n");
}
if (!$this->opo_graph->hasNode($vs_table2)) {
die("Fatal error: invalid table '{$vs_table2}' in relationship in datamodel definition\n");
}
if (!($va_attr = $this->opo_graph->getAttributes($vs_table1, $vs_table2))) {
$va_attr = array();
$this->opo_graph->addRelationship($vs_table1, $vs_table2);
}
$va_attr["relationships"][$vs_table1][$vs_table2][] = array($vs_field1, $vs_field2);
$va_attr["relationships"][$vs_table2][$vs_table1][] = array($vs_field2, $vs_field1);
$va_attr['WEIGHT'] = $vn_weight;
$this->opo_graph->setAttributes($va_attr, $vs_table1, $vs_table2);
}
if (is_object($vo_cache)) {
$vo_cache->save(Datamodel::$s_graph = $this->opo_graph->getInternalData(), 'ca_datamodel_graph', array('ca_datamodel_cache'));
}
}
}