Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Converted to PSR-2 #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
181 changes: 89 additions & 92 deletions code/GoogleBase.php
@@ -1,101 +1,98 @@
<?php

class GoogleBase extends Controller {

static $allowed_actions = array(
'products',
'getinfo'
);
class GoogleBase extends Controller
{

public static $allowed_actions = array(
'products',
'getinfo'
);


/**
* Returns a list of Products.
* extend with alterProducts to use a different set other than Product::get()
* @return DataList or ArrayList of Products
*/
function ProductList(){
/**
* Returns a list of Products.
* extend with alterProducts to use a different set other than Product::get()
* @return DataList or ArrayList of Products
*/
public function ProductList()
{
$products = $this->extend('alterProducts');

$products = $this->extend('alterProducts');
if (count($products)) {
$products = array_pop($products);
}

if(count($products)) {
$products = array_pop($products);
}
return $products ? $products : Product::get();
}

return $products ? $products : Product::get();
}
/**
* Action: get list of products for base feed
* @param SS_HTTPRequest $request
* @return XML list of GoogleBase products
*/
public function products($request)
{
$limit = $request->getVar('limit') ? $request->getVar('limit') : false;

if (!$limit) {
$link = Director::absoluteURL(HTTP::setGetVar('limit', 1000));
die('A Limit is required, please try again using something like: <a href="'.$link.'">'.$link.'</a>');
}

$products = $this->ProductList();

if ($products && $products->Count() > 0) {
$productsItems = PaginatedList::create($products, $request)
->setPageLength($limit)
->setPaginationGetVar('start');

$data = array(
'FeedTitle' => SiteConfig::current_site_config()->Title,
'FeedLink' => Director::absoluteURL('/'),
'FeedDescription' => 'Google Base Feed',
'Products' => $productsItems
);

return $this->renderWith('GoogleBase', $data);
}
}

/**
* Action: get list of products for base feed
* @param SS_HTTPRequest $request
* @return XML list of GoogleBase products
*/
function products($request){

$limit = $request->getVar('limit') ? $request->getVar('limit') : false;

if(!$limit){
$link = Director::absoluteURL(HTTP::setGetVar('limit',1000));
die('A Limit is required, please try again using something like: <a href="'.$link.'">'.$link.'</a>');
}

$products = $this->ProductList();

if($products && $products->Count() > 0){

$productsItems = PaginatedList::create($products, $request)
->setPageLength($limit)
->setPaginationGetVar('start');

$data = array(
'FeedTitle' => SiteConfig::current_site_config()->Title,
'FeedLink' => Director::absoluteURL('/'),
'FeedDescription' => 'Google Base Feed',
'Products' => $productsItems
);

return $this->renderWith('GoogleBase', $data);

}
}
/**
* Action: get info about product set to help you determine how to appropriately use /products
* @param SS_HTTPRequest $request
*/

public function getinfo($request)
{
$limit = $request->getVar('limit') ? $request->getVar('limit') : 1000;

/**
* Action: get info about product set to help you determine how to appropriately use /products
* @param SS_HTTPRequest $request
*/

function getinfo($request){
$limit = $request->getVar('limit') ? $request->getVar('limit') : 1000;

$products = $this->ProductList();

$productsItems = PaginatedList::create($products, $request)
->setPageLength($limit)
->setPaginationGetVar('start');

$count = $products->Count();

$sets = floor($count / $limit);

$setcount = $sets;

echo '<p>There are a total of <strong>'.$count.'</strong> products.</p>';
echo '<p>Google should be provided with <strong>'.$setcount.'</strong> different feeds, showing '.$limit.' per page.</strong>';

for($i = 0; $i <= $sets; $i++){

$counter = $limit * $i;

$link = Director::absoluteURL('/googlebase/products/?limit='.$limit);

if($i > 0){
$link .= '&start='.$counter;
}

echo '<p><a href="'.$link.'" target="_blank">'.$link.'</a></p>';
}

die;

}

}
$products = $this->ProductList();

$productsItems = PaginatedList::create($products, $request)
->setPageLength($limit)
->setPaginationGetVar('start');

$count = $products->Count();

$sets = floor($count / $limit);

$setcount = $sets;

echo '<p>There are a total of <strong>'.$count.'</strong> products.</p>';
echo '<p>Google should be provided with <strong>'.$setcount.'</strong> different feeds, showing '.$limit.' per page.</strong>';

for ($i = 0; $i <= $sets; $i++) {
$counter = $limit * $i;

$link = Director::absoluteURL('/googlebase/products/?limit='.$limit);

if ($i > 0) {
$link .= '&start='.$counter;
}

echo '<p><a href="'.$link.'" target="_blank">'.$link.'</a></p>';
}

die;
}
}
73 changes: 37 additions & 36 deletions code/GoogleBaseCategory.php
Expand Up @@ -9,41 +9,42 @@
* @date 04.23.2014
*/

class GoogleBaseCategory extends SiteTreeExtension {

static $db = array(
'GoogleBaseCategory' => 'Varchar(255)'
);

public function updateCMSFields(FieldList $fields) {
$fields->addFieldtoTab('Root.GoogleBase', TextField::create('GoogleBaseCategory','Google Base Category'));
}
class GoogleBaseCategory extends SiteTreeExtension
{

public static $db = array(
'GoogleBaseCategory' => 'Varchar(255)'
);

public function updateCMSFields(FieldList $fields)
{
$fields->addFieldtoTab('Root.GoogleBase', TextField::create('GoogleBaseCategory', 'Google Base Category'));
}


/**
* Get a recursive list of Product Categories where parents are ProductCategories
* @return array of categories
*/
public function GoogleBaseCategoryList(){

$categoryList = array();

$parent = $this->owner->Parent();
if ($parent->ClassName == 'ProductCategory') {

$parentList = $parent->GoogleBaseCategoryList();

if (empty($parentList)) {
$categoryList[] = $parent->GoogleBaseCategory;
} else {
$categoryList = array_merge($categoryList, $parentList);
}
}

if($this->owner->GoogleBaseCategory){
$categoryList[] = $this->owner->GoogleBaseCategory;
}

return $categoryList;
}
}
/**
* Get a recursive list of Product Categories where parents are ProductCategories
* @return array of categories
*/
public function GoogleBaseCategoryList()
{
$categoryList = array();

$parent = $this->owner->Parent();
if ($parent->ClassName == 'ProductCategory') {
$parentList = $parent->GoogleBaseCategoryList();

if (empty($parentList)) {
$categoryList[] = $parent->GoogleBaseCategory;
} else {
$categoryList = array_merge($categoryList, $parentList);
}
}

if ($this->owner->GoogleBaseCategory) {
$categoryList[] = $this->owner->GoogleBaseCategory;
}

return $categoryList;
}
}