| | | | |
| | |
| PHP Code Flüsterer Registriert seit: 21.08.2005 Beiträge: 4682 PHP-Kenntnisse: Fortgeschritten | |
| | |
| Neuer Benutzer Registriert seit: 21.10.2008
Beiträge: 22
![]() | Hi danke! Auch wenn Dein Skript nicht mehr so richtig verstehe und das Beispiel sehr gut funktioniert bleibt das Problem der keys immer noch. Code: $item = array_shift ($value);
__________________ Hier findet Ihr alles, was ich dank eurer Hilfe geschafft habe und noch mehr: http://viskoda.viktor-dite.de |
| |
| | |
| Neuer Benutzer Registriert seit: 21.10.2008
Beiträge: 22
![]() | das funktioniert jetzt soweit, allerdings bekomme ich mittels eines Kreuzprodukts weniger Elemente als mit dieser Variante?!?! argh....das ist schon echt zu hoch für mich Kreuzprodukt: Code: function makeXML($input){
global $wgOut;
$xmlrelation='';
foreach($input as $value){
if(count($value)>2){
$count=$value['count'];
unset($value['count']);
foreach ($value as $ikey=>$ivalue){
foreach ($value as $jkey=>$jvalue)
{
$xmlrelation.='<UndirectedRelation fromID="'.$ikey.'" toID="'.$jkey.'" lineSize="'.$count.'"/>';
}
}
}
}
$wgOut->AddWikiText('<pre>'.$xmlrelation.'</pre>');
}
Code: function makeXML($input){
global $wgOut;
$xmlnode='';
$xmlrelation='';
$items = array ();
foreach($input as $value){
if(count($value)>2){
$count=$value['count'];
unset($value['count']);
$value=array_keys($value);
while (true)
{
$item = array_shift($value);
if (empty ($value)) break;
$items = array_merge ($items , array_map (null , $value, array_fill (0 , count ($value) , $item)));
}
}
foreach($items as $ivalue){
$one=array_pop($ivalue);
$two=array_pop($ivalue);
$xmlrelation.='<UndirectedRelation fromID="'.$one.'" toID="'.$two.'" lineSize="'.$count.'"/>
';
}
}
$wgOut->AddWikiText('<pre>'.$xmlrelation.'</pre>');
}
__________________ Hier findet Ihr alles, was ich dank eurer Hilfe geschafft habe und noch mehr: http://viskoda.viktor-dite.de Geändert von vdite (24.10.2008 um 19:57 Uhr). |
| |
| | |
| Neuer Benutzer Registriert seit: 21.10.2008
Beiträge: 22
![]() | hatte ich auch schon gedacht, aber da kommt nur murks raus Code: <UndirectedRelation fromID="Array" toID="Array" lineSize="1"/>
<UndirectedRelation fromID="Array" toID="Array" lineSize="1"/>
<UndirectedRelation fromID="Array" toID="" lineSize="1"/>
<UndirectedRelation fromID="Array" toID="Array" lineSize="1"/>
<UndirectedRelation fromID="Array" toID="Array" lineSize="1"/>
<UndirectedRelation fromID="Array" toID="" lineSize="1"/>
<UndirectedRelation fromID="Array" toID="" lineSize="1"/>
<UndirectedRelation fromID="Array" toID="" lineSize="1"/>
<UndirectedRelation fromID="Array" toID="" lineSize="1"/>
<UndirectedRelation fromID="Array" toID="" lineSize="1"/>
<UndirectedRelation fromID="Array" toID="" lineSize="1"/>
<UndirectedRelation fromID="Array" toID="" lineSize="1"/>
<UndirectedRelation fromID="Array" toID="" lineSize="3"/>
<UndirectedRelation fromID="Array" toID="" lineSize="3"/>
<UndirectedRelation fromID="Array" toID="" lineSize="2"/>
Dankeschön!!!!!! echt, vielen vielen dank!!!!! Ich war schon am verzweifeln!
__________________ Hier findet Ihr alles, was ich dank eurer Hilfe geschafft habe und noch mehr: http://viskoda.viktor-dite.de |
| |
| | |
| Neuer Benutzer Registriert seit: 21.10.2008
Beiträge: 22
![]() | So, hab es jetzt soweit fertig, vielen vielen Dank nochmal!!!! hier ist der Quellcode, falls es jm. interessiert Code: <?php
$wgExtensionFunctions[] = 'showRel';
/**
* @make a new tag <relations/>
*/
function showRel() {
global $wgParser;
$wgParser->setHook( "relations", "mainRel" );
return true;
}
function mainRel($text, $params, &$parser) {
global $wgOut;
global $wgTitle;
$cap = new Relations();
$cap->doRelationsQuery();
$graph=$cap->makeGraph($cap->my_counter($cap->maketupel($cap->users)));
$output = $parser->recursiveTagParse('<graphviz renderer="neato">'.$graph.'</graphviz>');
return $output;
}
class Relations{
var $users = Array();
var $ucount = Array();
var $debug=false;
function debugOut($input){
echo '<pre>';
print_r( $input);
echo '</pre>';
}
//GraphViz Dataset
function makeGraph($input){
global $wgOut;
$graphnode='';
$graphrelation='';
$graph = 'graph g{ overlap=scale; splines=true; node [height=0 style="filled", shape="ellipse", color="lightblue"];
';
foreach($input as $value){
if(count($value)==3){ //Falls Tupel nicht eine einzelne Person ist
$count=$value['count'];
unset($value['count']);
$one=array_pop($value);
$two=array_pop($value);
$graphrelation.=$one.' -- '.$two.' [style="setlinewidth('.$count.')"];
';
}
}
$graph.=$graphnode.$graphrelation.'}';
if($this->debug) $this->debugOut($graph);
return $graph;
}
function doRelationsQuery() {
$dbr =& wfGetDB( DB_SLAVE );
$res = $dbr->query('SELECT distinct rev_user, rev_user_text, rev_page FROM revision WHERE rev_minor_edit=0 AND NOT rev_user=0 order by rev_page');
while($obj = $dbr->fetchObject($res)){
$this->users[$obj->rev_page][$obj->rev_user]=$obj->rev_user_text;
}
if ($cap->debug) $cap->debugOut($cap->users);
}
function maketupel($input)
{
$output = array();
foreach($input as $key => $value) //nur das value
{
/* Wenn das Array ein nTupel ist, muss es zu einem
* 2er Tupel aufgebrochen werden */
if(count($value)>2){
$items = array ();
/*
****************************************************************
* Jedes mit jedem als Tupel
* Dieses Codefragment ist mit Hilfe des php.de Forums entstanden
* Mein besonderer Dank an nikosch!
*/
while (true)
{
$item = array_shift($value);
if (empty ($value)) break;
$items = array_merge ($items , array_map (null , $value, array_fill (0 , count ($value) , $item)));
}
/*
*****************************************************************
*/
/*Die Tupelelemente einzeln zum neuen Array zusammenfügen*/
foreach($items as $ivalue){
array_push($output,$ivalue);
}
}
else array_push($output,$value);
}
if ($this->debug) $this->debugOut($output);
return $output;
}
/*
* **************************************************************
* Fuer die naechsten beiden Funktionen moechte ich
* dem http://www.php.de Forum sehr danken!
* Mein besonderer Dank an nikosch!
*/
function my_unique($input)
{
$output = array();
foreach($input as $key => $value)
{
if(!in_array($value,$output))
$output[$key] = $input[$key];
}
if ($this->debug) $this->debugOut($output);
return $output;
}
function my_counter($input)
{ // funktioniert nur mit mehrdimensionalen arrays
$elements = $this->my_unique($input);
foreach($elements as $key => $value)
{
$elements[$key]["count"] = count(array_keys($input,$value));
}
if ($this->debug)$this->debugOut($elements);
return $elements;
}
/*
* ***************************************************************
*/
}
?>
__________________ Hier findet Ihr alles, was ich dank eurer Hilfe geschafft habe und noch mehr: http://viskoda.viktor-dite.de |
| |
| Themen-Optionen | |
| Thema bewerten | |
|
|
Ähnliche Themen | ||||
| Thema | Autor | Forum | Antworten | Letzter Beitrag |
| Turnierbaum aus array erstellen | kingflo | PHP-Fortgeschrittene | 11 | 30.07.2008 11:32 |
| Soapfault: Undefined Property | Argi | PHP-Fortgeschrittene | 0 | 28.07.2008 11:17 |
| [Erledigt] Einträge mit einer Foreach Schleife rausholen | saitho | PHP Tipps 2008 | 17 | 18.07.2008 22:46 |
| Eindimensionales Array ohne index per foreach erstellen | phpbeginner | PHP Tipps 2008 | 4 | 10.03.2008 14:18 |
| Übersicht aus mehrdimensionalem Array erzeugen | Crypi | PHP-Fortgeschrittene | 0 | 30.01.2006 13:44 |
| Array auslesen | andrew22 | PHP Tipps 2006 | 3 | 21.01.2006 23:06 |
| Array Formatierung | PHP Tipps 2006 | 3 | 17.01.2006 19:12 | |
| Menü mit Unterpunkten | supertramp | Beitragsarchiv | 7 | 18.10.2005 22:40 |
| Problem beim vergleichen von 2 Arrays | PHP Tipps 2005-2 | 1 | 06.10.2005 14:25 | |
| (schnellere) Funktion zum Zusammenfassen von CSS | PHP-Fortgeschrittene | 21 | 08.08.2005 16:47 | |
| Sortieren von Arrays mit mehr als 2 Dimensionen (Teil 2) | Buhmann | PHP-Fortgeschrittene | 4 | 12.07.2005 14:03 |
| Array wie auslesen? | PHP Tipps 2005 | 7 | 07.03.2005 11:43 | |
| [Erledigt] Mehrdimensionales Array in eindimensionales Array umwandeln | PHP-Fortgeschrittene | 3 | 03.01.2005 22:31 | |
| Abfrage mit id aus anderer Tabelle | suter | PHP Tipps 2004-2 | 15 | 16.12.2004 14:25 |