The Code-Bin
Links
Home
Add your code!
All Listings
About
Latest Entry
Featured Scripts
Author's Website
Latest Entries
FFMPEG Thumbnail Scr...
PHP, 0.8KB
Jul. 29, 10:24pm
John
Z80 Assembler, 190 bytes
Feb. 17, 3:36am
John
Z80 Assembler, 176 bytes
Sep. 13, 2:19am
John
Z80 Assembler, 77 bytes
Sep. 13, 2:18am
John
Z80 Assembler, 209 bytes
Sep. 13, 2:17am
untitled PHP Code
Posted by: Ben | July 10, 2009 @ 12:13pm
PHP Code
[
Download
]
<?php Class RelationshipHandler { public $xml_data; //this is an array thats passed and exists as the <relationship> field public $page_from_data; //this is the data that the page has come from, im not sure why this is neccesary but it might be public $feeder; //feeder is the name of the object that's page called the relationship handler, e.g. client or lead public function __construct($feeder, $xml_data, $page_from_data, $view, $chartType) { $this->feeder = $feeder; $this->xml_data = $xml_data; $this->page_from_data = $page_from_data; if ($xml_data['type']=="recip") { $this->handleRecip($view, $chartType); } } public function handleRecip($view, $chartType) { $feeder = $this->feeder; $xml = $this->xml_data; $data = $this->page_from_data; if ($view == "receivedComparisonGraph") { //We are going to create a graph (or until that point at least a little chart) that compares the amount of received OBJECTS from the recip object instance to the other top X (where X is your desired number) givers of the same recip object type $typeReceived = (string)$xml['receive']; $typeGiven = (string)$xml['give']; $givingObject = (string)$xml['with']; //Lets start by seeing the total number of objects received $query = mysql_query("SELECT * FROM `".$typeReceived."`"); $totalNumberReceived = mysql_affected_rows(); //Now we get the number received by the instance that gave the feeder_instance $query = mysql_query("SELECT * FROM `".$typeReceived."` WHERE `".$givingObject."_id`='".$data[$givingObject."_id"]."'"); $instanceNumberReceived = mysql_affected_rows(); //Now what we have to do is get the top X of the givingObjects type for giving this kind of object $query = mysql_query("SELECT * FROM `".$givingObject."`"); $otherGivingObjects = array(); $otherGivingObjectsGiven = array(); while ($d = mysql_fetch_assoc($query)) { $otherGivingObjects[$d['id']] = $d; $query2 = mysql_query("SELECT * FROM `".$typeReceived."` WHERE `".$givingObject."_id`='".$d['id']."'"); $otherGivingObjectsGiven[$d['id']] = mysql_affected_rows(); } //So now we have 2 arrays, each with corresponding IDs that we have to sort so that they ascend by the value of Objects Given array_multisort($otherGivingObjectsGiven, SORT_DESC, $otherGivingObjects); //now we shall slice it by amount desired $amount_desired_to_show = 5; $otherGivingObjects = array_slice($otherGivingObjects, 0, $amount_desired_to_show); $otherGivingObjectsGiven = array_slice($otherGivingObjectsGiven, 0, $amount_desired_to_show); //we also need to include the object that gave the feeder object $query = mysql_query("SELECT * FROM `".$givingObject."` WHERE `id`='".$data[$givingObject."_id"]."'"); $otherGivingObjects[] = mysql_fetch_assoc($query); $query = mysql_query("SELECT * FROM `".$typeReceived."` WHERE `".$givingObject."_id`='".$data[$givingObject."_id"]."'"); $otherGivingObjectsGiven[] = mysql_affected_rows(); //now we need to find out the secondary display type so that can work out how to view that type $givingObjectXML = simplexml_load_file($_SERVER['DOCUMENT_ROOT']."/EMS/data/lead.xml"); $toShow = (string)$givingObjectXML->basic[0]->secondary[0]['name']; //we also need to include a none object $otherGivingObjects[] = array ($toShow => "None"); $query = mysql_query("SELECT * FROM `".$typeReceived."` WHERE `".$givingObject."_id`=0"); $otherGivingObjectsGiven[] = mysql_affected_rows(); $dataLine = ""; //we need to work out the scale since GoogleGraph works on the basis of 0-100 if we change the scale to higher than 100 it scales everything as if it were that. //$delim = $totalNumberReceived/100; foreach ($otherGivingObjects as $id => $givingObject) { $dataLine .= $otherGivingObjectsGiven[$id].","; $labelLine .= $givingObject[$toShow]."|"; } $dataLine = substr($dataLine, 0, strlen($dataLine)-1); $labelLine = substr($labelLine, 0, strlen($labelLine)-1); //lets show the graph if ($chartType=="vbar") { $DataSet = new pData; foreach ($otherGivingObjectsGiven as $id => $ogog) { $DataSet->AddPoint(array($ogog), "Serie".$id); } $DataSet->AddAllSeries(); $DataSet->SetAbsciseLabelSerie(); foreach ($otherGivingObjectsGiven as $id => $ogog) { $DataSet->SetSerieName($otherGivingObjects[$id][$toShow], "Serie".$id); } // Initialise the graph $Test = new pChart(700,230); $Test->setFontProperties($_SERVER['DOCUMENT_ROOT']."/EMS/lib/pChart/Fonts/tahoma.ttf",8); $Test->setGraphArea(50,30,680,200); $Test->drawFilledRoundedRectangle(7,7,693,223,5,240,240,240); $Test->drawRoundedRectangle(5,5,695,225,5,230,230,230); $Test->drawGraphArea(255,255,255,TRUE); $Test->drawScale($DataSet->GetData(),$DataSet->GetDataDescription(),SCALE_NORMAL,150,150,150,TRUE,0,2,TRUE); $Test->drawGrid(4,TRUE,230,230,230,50); // Draw the 0 line $Test->setFontProperties($_SERVER['DOCUMENT_ROOT']."/EMS/lib/pChart/Fonts/tahoma.ttf",6); $Test->drawTreshold(0,143,55,72,TRUE,TRUE); // Draw the bar graph $Test->drawBarGraph($DataSet->GetData(),$DataSet->GetDataDescription(),TRUE); // Finish the graph $Test->setFontProperties($_SERVER['DOCUMENT_ROOT']."/EMS/lib/pChart/Fonts/tahoma.ttf",8); $Test->drawLegend(596,150,$DataSet->GetDataDescription(),255,255,255); $Test->setFontProperties($_SERVER['DOCUMENT_ROOT']."/EMS/lib/pChart/Fonts/tahoma.ttf",10); $Test->drawTitle(50,22,"Example 12",50,50,50,585); $key = md5(rand(1, 1000)).md5(rand(1, 1000)); $Test->Render("img/graph_".$key.".png"); ?> <img src="/EMS/img/graph_<?=$key?>.png" alt="Graph" /> ` <? //unlink("img/graph_".$key.".png"); } } } }
Syntax Highlighting
[
Open in new window
]
Author Comments
none
Rating
4.61 / 8
101 Votes
http://codebin.yi.org/326
page generated in 0.01 seconds