"100"); // archive name private $name; // number of weeks (rows) we have for this IR private $num_of_weeks; // first, and most recent, weeks we have for this ir (date) private $firstCollectedDate; private $lastCollectDate; // highest and lowest counts private $highestNumRecords; private $lowestNumRecords; // current number of records in this repository private $current_records; // add this passed date and total records as key/value to // my recordslist public function addToRecordslist($date, $records) { $this->recordslist["$date"] = $records; //$this->recordslist["20060701"] = "200"; } // connect to db and populate this object with data public function getRepositoryData () { global $ircount_table; if ($this->identifier) { // need to check if identifier is mysql safe. $this->identifier = mysql_real_escape_string ($this->identifier); $query1 = " SELECT archivename, records, identifier, collected_date FROM $ircount_table WHERE identifier = \"$this->identifier\" AND records > 1 ORDER BY collected_date "; $result1 = mysql_query($query1) or die("Query failed : " . mysql_error()); $datelog = ""; $num = 0; // loop for each row, which will be one weeks collection. // add to has weekdate->number of records while ($line = mysql_fetch_array($result1, MYSQL_ASSOC)) { $archivename = $line["archivename"]; $records = $line["records"]; $date1 = $line["collected_date"]; // do a couple of things for the first loop iteration only if ($num == 0) { $currentarchivename = $archivename; $currentrecords = $records; // set lowestnumrecords to this, but check // all others incase they are lower $this->lowestNumRecords = $records; // presume this is the earliest date (which it should be because we have ordered the SQL $this->firstCollectedDate = $date1; } $num++; $this->recordslist["$date1"] = $records; //check to see if this is highest/lowest number of records for this ir // ...if it is set it as such if ($this->highestNumRecords < $records) { $this->highestNumRecords = $records; } elseif ($this->lowestNumRecords > $records) { $this->lowestNumRecords = $records; } } // end of db row loop // set name of archive and some other info $this->name = $currentarchivename; $this->num_of_weeks = $num; $this->current_records = $records; $this->lastCollectDate = $date1; return 1; } // end of: if we have identifier set else { // identifier not set return 0; } } // end of function //////////////////////////////////////////////////////////////// // return a string of data ready for google charts public function getGoogleChartData ($allDates, $doMonthly) { $monthDates = array(); // used to hold // loop for each date we have for the page we are building foreach ($allDates as $date => $timesSeen) { // if we have lots of data, we do it by month not week, otherwise // googlechart doesn't work cos url too long if ($doMonthly) { // remove the day of month from the date, so left with yy-mm $monthdate = substr($date, 0, 7); // do we already have a yy-mm like this in the hash, if so, skip this date // otherwise, add it to array and then carry on if (array_key_exists($monthdate, $monthDates)) { continue; } $monthDates["$monthdate"]++; // add this yyyy-mm to array so we skip any more dates for this month } // Now the main bit, for this date, get this IRs count, if we have one $currentCount = $this->recordslist[$date]; if ($currentCount == "") { $data .= "0,"; // if no data for this date, use zero } else { $data .= $currentCount . ","; } } // remove last comma... $data = rtrim($data, ","); return $data; } public function getMonthlyList() { // todo // plan, go through recodlist looking at YYYYMM, if not seen add to a // tmp array on the fly, if we have seen something, if the DD is lower than // the one we previously had then used this one instead (hmmm, can we return the array // in order instead?? much better!) } // return number of records in this IR public function returnNumberRecords() { // this needs to be re-written, we need to check if we have connected to the db // at all, and if not, do so. if ($current_records) { return $current_records; } else { return count($recordlist); } } public function printRecordList() { echo "

\n"; print_r ($this->recordslist); } public function setName($name) { $this->name = $name; } public function setIdentifier($identifier) { $this->identifier = $identifier; } public function getName() { return $this->name; } public function getIdentifier() { return $this->identifier; } public function printName() { echo "$this->name

\n"; } public function returnRecords() { return $this->recordslist; } // return some overview information about this ir public function returnIRFacts() { // note: this currently presumes all these vars are set, // which they may not be. need to add checks in future. $facts = array( firstCollectedDate => $this->firstCollectedDate, lastCollectedDate => $this->lastCollectDate, num_of_weeks => $this->num_of_weeks, highestNumRecords => $this->highestNumRecords, lowestNumRecords => $this->lowestNumRecords, current_records => $this->current_records ); return $facts; } }