Hello there, I recently started using Silverstripe as a part of my new job. It's going pretty good so far, seems like a really powerful tool and I like it alot.
Anyhow, I bumped into a problem which I can not solve (the Silverstripe way, I dont wanna do too much custom coding).
class ProductOutclickReport extends SS_Report {
...
static function CalculateTime($limit) {
$period = 0;
$temp = explode(" ",trim($limit));
foreach($temp as $time) {
if(strstr($time,"m")) {
$timeMultiplier = 60; // 1 minute
}
else if(strstr($time,"h")) {
$timeMultiplier = 60*60; // 1 hour
}
else if(strstr($time,"d")) {
$timeMultiplier = 60*60*24; // 1 day
}
$period = $period + (intval($time)*$timeMultiplier);
}
return $period;
}
function sourceRecords($params, $sort, $limit) {
$calculatedLimit = $this->CalculateTime($params['TimeRange']);
$time = time();
$timeFrom = $time - $calculatedLimit;
$timeTo = $time; // Support for date ranges in later updates
// $Products = DataObject::get("ProductOutclicks", "UNIX_TIMESTAMP(Created) >= {$timeFrom} AND UNIX_TIMESTAMP(Created) < {$timeTo}");
$allProducts = DataObject::get("ProductOutclicks", "UNIX_TIMESTAMP(Created) >= {$timeFrom} AND UNIX_TIMESTAMP(Created) < {$timeTo}");
foreach($allProducts as $Product) {
$Product['Name'] = DataObject::get_one("Product","ID = '{$Product->ProductID}'");
$Products = $Product;
}
return $Products;
}
...
This is a custom report. It records outclicks on products, to be presented in the Site Report section of the admin.
My question is:
How do I get a single row/field using SS functionality, and pushing it to the Product array?
At the moment, when print_r'ing the $Product variable, I get so much information I've never seen before, I dont know how it all works. I guess it's an image if some kind of array-object? Containing [protected]/[private] and alot of stuff... simply not a "normal" array.
Btw, using the commented line, "// $Products = DataObject ..." it works, returning all the affected rows, but the Name is in the Product object, not ProductOutclicks (which has a ProductID).
Thanks in advance,
Andreas Saarva.