Skip to content

Commit afc868e

Browse files
author
Ashwin Date
committed
Adding socialads & redshop plugins
0 parents  commit afc868e

File tree

13 files changed

+923
-0
lines changed

13 files changed

+923
-0
lines changed

redshop/index.html

Whitespace-only changes.

redshop/redshop.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php
2+
/**
3+
* @package API
4+
* @version 1.7
5+
* @author Brian Edgerton
6+
* @link http://www.edgewebworks.com
7+
* @copyright Copyright (C) 2011 Edge Web Works, LLC. All rights reserved.
8+
* @license http://www.gnu.org/copyleft/gpl.html GNU/GPL, see LICENSE.php
9+
*/
10+
11+
defined('_JEXEC') or die( 'Restricted access' );
12+
13+
jimport('joomla.plugin.plugin');
14+
15+
class plgApiRedshop extends ApiPlugin
16+
{
17+
public function __construct()
18+
{
19+
parent::__construct();
20+
21+
ApiResource::addIncludePath(dirname(__FILE__).'/redshop');
22+
}
23+
}

redshop/redshop.xml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<extension version="1.7" type="plugin" group="api" method="upgrade">
3+
<name>Api_Redshop</name>
4+
<version>1.0</version>
5+
<creationDate>November 2011</creationDate>
6+
<author>Reportoise</author>
7+
<authorEmail>[email protected]</authorEmail>
8+
<authorUrl>http://www.reportoise.com</authorUrl>
9+
<copyright>2011 Reportoise</copyright>
10+
<license>GNU General Public License v2</license>
11+
<description>This plugin exposes com_redshop to the Joomla! API</description>
12+
13+
<files>
14+
<filename plugin="redshop">redshop.php</filename>
15+
<folder>redshop</folder>
16+
</files>
17+
</extension>

redshop/redshop/details.php

Lines changed: 150 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,150 @@
1+
<?php
2+
/**
3+
* @package API
4+
* @version 1.5
5+
* @author Brian Edgerton
6+
* @link http://www.edgewebworks.com
7+
* @copyright Copyright (C) 2011 Edge Web Works, LLC. All rights reserved.
8+
* @license http://www.gnu.org/copyleft/gpl.html GNU/GPL, see LICENSE.php
9+
*/
10+
11+
defined('_JEXEC') or die( 'Restricted access' );
12+
13+
jimport('joomla.plugin.plugin');
14+
15+
class RedshopApiResourceDetails extends ApiResource
16+
{
17+
public function get()
18+
{
19+
$startdate = JRequest::getVar('startdate');
20+
$startdate .= '00:00:00';
21+
$enddate = JRequest::getVar('enddate');
22+
$enddate .= ' 23:59:59';
23+
$config =& JFactory::getConfig();
24+
$offset = $config->getValue('config.offset');
25+
$startdate= & JFactory::getDate($startdate,$offset);
26+
$enddate= & JFactory::getDate($enddate,$offset);
27+
$startdate = $startdate->toFormat('%F %T');
28+
$enddate = $enddate->toFormat('%F %T');
29+
30+
$db = JFactory::getDBO();
31+
$query = "SELECT a.order_item_sku AS product_sku,b.product_name,SUM(a.product_quantity)AS quantity,
32+
SUM(a.product_final_price) AS product_sales
33+
FROM #__redshop_order_item AS a,#__redshop_product AS b WHERE a.product_id=b.product_id
34+
AND a.order_id IN (SELECT order_id FROM #__redshop_orders
35+
WHERE order_status='S' AND order_payment_status='Paid')
36+
AND FROM_UNIXTIME(a.mdate)
37+
BETWEEN '$startdate' AND '$enddate'
38+
GROUP BY a.order_item_sku ORDER BY product_sales DESC";
39+
40+
$db->setQuery( $query );
41+
$details['data'] =array($db->loadObjectList());
42+
43+
$query ="SELECT SUM(order_total)
44+
FROM #__redshop_orders
45+
WHERE DATE(FROM_UNIXTIME(mdate))BETWEEN '".$startdate."'AND '".$enddate."'
46+
AND order_status='s' AND order_payment_status='Paid'";
47+
$db->setQuery( $query );
48+
$total =(int)$db->loadResult();
49+
50+
if($total>9999)
51+
{
52+
$total = $total/1000;
53+
$total .='K';
54+
}
55+
elseif(!$total)
56+
{ $total=0;}
57+
58+
$details['total'] =array("total"=>$total);
59+
60+
$this->plugin->setResponse($details);
61+
62+
//$this->plugin->setResponse( 'Guru Katre' );
63+
}
64+
65+
public function post()
66+
{
67+
$db = JFactory::getDBO();
68+
69+
require_once(dirname(__FILE__).DS.'helper.php');
70+
71+
//get date from app
72+
$startdate = JRequest::getVar('startdate');
73+
$enddate = JRequest::getVar('enddate');
74+
75+
$startdate .= ' 00:00:00';
76+
$enddate .= ' 23:59:59';
77+
78+
$sdate = $startdate;
79+
$edate = $enddate;
80+
81+
//get offset value
82+
$config =& JFactory::getConfig();
83+
$offset = $config->getValue('config.offset');
84+
85+
$startdate= & JFactory::getDate($startdate,$offset);
86+
$enddate= & JFactory::getDate($enddate,$offset);
87+
$startdate = $startdate->toFormat('%F %T');
88+
$enddate = $enddate->toFormat('%F %T');
89+
//query for product details
90+
$query = "SELECT a.order_item_sku AS product_sku,b.product_name,SUM(a.product_quantity)AS quantity,
91+
SUM(a.product_final_price) AS product_sales
92+
FROM #__redshop_order_item AS a,#__redshop_product AS b WHERE a.product_id=b.product_id
93+
AND a.order_id IN (SELECT order_id FROM #__redshop_orders
94+
WHERE order_status='S' AND order_payment_status='Paid')
95+
AND FROM_UNIXTIME(a.mdate)
96+
BETWEEN '$startdate' AND '$enddate'
97+
GROUP BY a.order_item_sku ORDER BY product_sales DESC";
98+
99+
$db->setQuery( $query );
100+
$details['data'] =array($db->loadObjectList());
101+
$i = 0;
102+
while(count($details['data'][0])>=$i)
103+
{
104+
if($details['data'][0][$i]->product_sales > 9999)
105+
{
106+
$value = $details['data'][0][$i]->product_sales/1000;
107+
$value = number_format($value, 2, '.', '');
108+
$value .='K';
109+
$details['data'][0][$i]->product_sales = $value;
110+
111+
}
112+
$i++;
113+
}
114+
$total = Sale_Data::total($startdate,$enddate);
115+
$projected_sale = Sale_Data::projected_sale($sdate,$edate,$total);
116+
$total = Sale_Data::compress($total);
117+
$projected_sale = Sale_Data::compress($projected_sale);
118+
119+
$details['total'] =array("total"=>$total);
120+
$details['projected_sale'] =array("projected_sale"=>$projected_sale);
121+
$this->plugin->setResponse($details);
122+
}
123+
124+
public function put()
125+
{
126+
$app = JFactory::getApplication();
127+
$data = JRequest::getVar('jform', array(), 'post', 'array');
128+
$context = 'com_content.edit.article';
129+
130+
// Fake parameters
131+
$values = (array) $app->getUserState($context.'.id');
132+
array_push($values, (int) $data['id']);
133+
$values = array_unique($values);
134+
$app->setUserState($context.'.id', $values);
135+
if ( !JRequest::getInt( 'id' ) ) {
136+
$_POST['id'] = $data['id'];
137+
$_REQUEST['id'] = $data['id'];
138+
}
139+
140+
// Simply call post as Joomla will just save an article with an id
141+
$this->post();
142+
143+
$response = $this->plugin->get( 'response' );
144+
if ( isset( $response->success ) && $response->success ) {
145+
JResponse::setHeader( 'status', 200, true );
146+
$response->code = 200;
147+
$this->plugin->setResponse( $response );
148+
}
149+
}
150+
}

redshop/redshop/helper.php

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
<?php
2+
class Sale_Data
3+
{
4+
function __construct()
5+
{
6+
7+
}
8+
public function total($startdate,$enddate)
9+
{
10+
$db = JFactory::getDBO();
11+
12+
$query = "SELECT SUM(order_total)
13+
FROM #__redshop_orders
14+
WHERE DATE(FROM_UNIXTIME(mdate)) BETWEEN '".$startdate."'AND '".$enddate."'
15+
AND order_status='s' AND order_payment_status='Paid'";
16+
17+
18+
$db->setQuery( $query );
19+
$total = $db->loadResult();
20+
if(!$total)
21+
{
22+
$total = 0;
23+
}
24+
//$total = number_format($total, 2, '.', '');
25+
26+
return $total;
27+
28+
29+
}
30+
public function projected_sale($startdate,$enddate,$total)
31+
{
32+
$db = JFactory::getDBO();
33+
$query = "SELECT DATEDIFF('".$enddate."', '".$startdate."')+1";
34+
$db->setQuery( $query );
35+
$tday = $db->loadResult();
36+
$tday = $tday;
37+
$query = "SELECT DATEDIFF(CURDATE(),'".$startdate."')+1";
38+
$db->setQuery( $query );
39+
$day = $db->loadResult();
40+
if($tday==0)
41+
{
42+
$tday=1;
43+
}
44+
if($day==0)
45+
{
46+
$day=1;
47+
}
48+
//calculation of projected_sale
49+
50+
$projected_sale = $total/$day*$tday;
51+
52+
return $projected_sale;
53+
54+
55+
}
56+
public function compress($value)
57+
{
58+
if($value>9999)
59+
{
60+
$value = $value/1000;
61+
$value = number_format($value, 2, '.', '');
62+
$value .='K';
63+
return $value;
64+
}
65+
else if($value>=99999)
66+
{
67+
$value = $value/100000;
68+
$value .='Lc';
69+
return $value;
70+
}
71+
$value = number_format($value, 2, '.', '');
72+
return $value;
73+
}
74+
75+
76+
}
77+
78+
79+
80+
?>

redshop/redshop/index.html

Whitespace-only changes.

0 commit comments

Comments
 (0)