LPH
Well-known member
I have a working PHP script that would be better if the query printed to a XenForo page instead of outside XenForo. My brain has been numb for several days and so I'm chasing my tail instead of running straight. I could use a little direction because none of my code over the past week has worked (numerous projects).
I'd love a little success tonight.
Option 1: Create an XF page, add the query into a class, call that class
Option 2: Sigh and Whine. Pause. Figure out how to build this as a report form in the admin area of XenForo.
Option 3: Just keep being miserable; It's an art form worthy of simple minded people like myself.
If you aren't sure how to kickstart me on this little project, maybe you can at least figure out why the array_sum is wrong Update ... changed to $sum .
Also -- I suspect there is a much simpler way to get this information rather than using direct queries. Alas, XenProduct_Model_ is something that I'm still trying to figure out but a direct queries works for now.
Maybe it's time to go for a walk.
I'd love a little success tonight.
Option 1: Create an XF page, add the query into a class, call that class
Option 2: Sigh and Whine. Pause. Figure out how to build this as a report form in the admin area of XenForo.
Option 3: Just keep being miserable; It's an art form worthy of simple minded people like myself.
PHP:
<?php
/**
* XenProduct Sales Report
*/
$startTime = microtime(true);
// Set to forum location - See XenForo index.php for information
$fileDir = '/path/to/community';
require($fileDir . '/library/XenForo/Autoloader.php');
XenForo_Autoloader::getInstance()->setupAutoloader($fileDir . '/library');
XenForo_Application::initialize($fileDir . '/library', $fileDir);
XenForo_Application::set('page_start_time', $startTime);
// Report Query
$report_qry = "
SELECT license_id, license_price, purchase_date FROM `xenproduct_license`
WHERE license_state = 'active' AND license_price != 0
ORDER BY `purchase_date` ASC
";
$licenses = XenForo_Application::get( 'db' )->fetchAll( $report_qry );
echo '<h2>Total Active Licenses: ' . count( $licenses ) . '</h2>';
// Change to desired year
$year = 15;
// Change to desired month
$month = 3;
$sum = 0;
foreach ( $licenses as $license ) {
if ( date("y", $license['purchase_date'] ) == $year && date("m", $license['purchase_date'] ) == $month ) {
$sum += $license['license_price'];
echo 'License ID: '
. $license['license_id']
. ' Purchase Date: '
. gmdate( "m-d-y", $license['purchase_date'] )
. ' Price: '
. $license['license_price']
. '<br />';
}
}
echo 'The total sales $' . number_format( $sum, 2 );
Also -- I suspect there is a much simpler way to get this information rather than using direct queries. Alas, XenProduct_Model_ is something that I'm still trying to figure out but a direct queries works for now.
Maybe it's time to go for a walk.
Last edited: