Trying to use views_get_views on the organic groups view OG all user group content to programmatically access the view using php. I am unable to set the parameter properly. I would like to get an example of working call.
Thanks,
Olivier
Try This:
/* load view object */
$views = views_get_view('og_all_user_group_content');
/* set default display */
$views->set_display('default');
/* pass group id as argument value */
$group_id =''; //set your group id here
$views->set_arguments(array($group_id));
/* execute view */
$views->execute();
/* result object */
if (!empty($views->result)) {
if (count($views->result) > 0) {
foreach ($views->result as $result) {
//$result contain array of data.
}
}
}
Related
I'm pretty new to PrestaShop - so sry if i ask basic thing
I'm currently working on a module which should display products you chose in the backend as additional section in the default products template - like "highly recommended products"
I finish the whole Backend part, and get the ID's as an array of the chosen products.
As I mentioned I wanna use the default templates which are available after a fresh installation and what I found is placed here themes\classic\templates\catalog\_partials\products.tpl.
Now my big problem is: I'm not able to get the data like it should be ...
If I debug e.g. the products which are displayed in the default search behaviour (this uses this template too) I see something like
object(PrestaShop\PrestaShop\Adapter\Presenter\Product\ProductListingLazyArray)#323 (11) { ["imageRetriever":"Pr .....
but as I get my products with
new Product($productId, true);
it is no ProductListingLazyArray ... its just an array with products ... and i dont see anything in the frontend (of course I dont, cause e.g. {$product.id_product} doesnt look like this in my array ...
Have you any ideas what I can do to "transform" my array of products to an ProductListingLazyArray ??
Or is my thinking wrong ?
THANKS to you all!
Solution
I just "faked" a search and check if the data is in my array:
/**
* creates relevant product information for frontend output
*
* #param array $allSelectedProductIds array with all id's of the selected products
* #param int $languageId language id of the shop you are in
*
* #return array all product information we need for our frontend rendering
*/
public function getFrontendProductInformation($allSelectedProductIds, $languageId)
{
// set default category Home
$category = new Category((int)2);
// create new product search proider
$searchProvider = new CategoryProductSearchProvider(
$this->context->getTranslator(),
$category
);
// set actual context
$context = new ProductSearchContext($this->context);
// create new search query
$query = new ProductSearchQuery();
$query->setResultsPerPage(PHP_INT_MAX)->setPage(1);
$query->setSortOrder(new SortOrder('product', 'position', 'asc'));
$result = $searchProvider->runQuery(
$context,
$query
);
// Product handling - to get relevant data
$assembler = new ProductAssembler($this->context);
$presenterFactory = new ProductPresenterFactory($this->context);
$presentationSettings = $presenterFactory->getPresentationSettings();
$presenter = new ProductListingPresenter(
new ImageRetriever(
$this->context->link
),
$this->context->link,
new PriceFormatter(),
new ProductColorsRetriever(),
$this->context->getTranslator()
);
$products = array();
foreach ($result->getProducts() as $rawProduct) {
$productId = $rawProduct['id_product'];
if(in_array($productId, $allSelectedProductIds)) {
$product = $presenter->present(
$presentationSettings,
$assembler->assembleProduct($rawProduct),
$this->context->language
);
array_push($products, $product);
}
}
return $products;
}
using symfony 3.0 where I want to get the ID from the URL.
/**
* #Route("/pathtocontent/{id}-{name}", defaults={"id"=null,"name"=null},
requirements={"name"="[a-zA-Z0-9\-_\/]+", "id"="\d+"}, name="routingname")
* #Route("/pathtocontent/{name}-{id}", defaults={"id"=null,"name"=null},
requirements={"name"="[a-zA-Z0-9\-_\/]+", "id"="\d+"},
name="routingname_alias")
*/
public function pathAction(Request $request, $id = null) {
}
So I have 2 rules for the same action. The URL can be:
/pathtocontent/Name-part-comes-here-1234
and also could be like that:
/pathtocontent/1234-Name-part-comes-here
The problem is the first case, where the name get all the:
Name-part-comes-here-1234 value and the Id is null
How can I force the first case to parse the Id value out too, so I need to get the Id (1234) from the :
/pathtocontent/Name-part-comes-here-1234
Use just:
#Route("/pathtocontent/{name}/{id}", defaults={"id"=null,"name"=null},
Because use have many hyphens (-)
Finditemsadvanced call in Ebay webservices and in the SDK for PHP includes the possibility to getHistograms for categories.
FindingServices.php display the following code:
public function getHistograms(\DTS\eBaySDK\Finding\Types\GetHistogramsRequest $request)
{
return $this->callOperation(
'getHistograms',
$request,
'\DTS\eBaySDK\Finding\Types\GetHistogramsResponse'
);
}
public function findItemsAdvanced(\DTS\eBaySDK\Finding\Types\FindItemsAdvancedRequest $request)
{
return $this->callOperation(
'findItemsAdvanced',
$request,
'\DTS\eBaySDK\Finding\Types\FindItemsAdvancedResponse'
);
}
In my controller I try two version to call FindingItemsAdvanced including GetHistograms.
/** Create the service object.*/
$service = new DTS\eBaySDK\Finding\Services\FindingService(array(
'appId' => $config['production']['appId'],
'apiVersion' => $config['findingApiVersion'],
'globalId' => DTS\eBaySDK\Constants\GlobalIds::US
));
/** Create the request object.*/
$request = new DTS\eBaySDK\Finding\Types\FindItemsAdvancedRequest();
$request->keywords = 'ipod nano';
$request->categoryId = array('73839');/** Search across two categories. * DVDs & Movies > DVDs & Blue-ray (617) * Books > Fiction & Literature (171228)*/
$request->outputSelector = array('AspectHistogram','CategoryHistogram','SellerInfo');
$itemFilter = new DTS\eBaySDK\Finding\Types\ItemFilter();/** Filter results to only include auction items or auctions with buy it now. */
$itemFilter->name = 'ListingType';
$itemFilter->value[] = 'FixedPrice';
$itemFilter->value[] = 'AuctionWithBIN';
$request->itemFilter[] = $itemFilter;
/** Get Histograms */
check below option 1 and option 2 and its errors
/** response */
$response = $service->findItemsAdvanced($request);
using option 1:
$request->getHistograms = new DTS\eBaySDK\Finding\Types\GetHistogramsRequest();
$request->getHistograms = (array('73839'));
but its giving me the following error: Unknown property: DTS\eBaySDK\Finding\Types\FindItemsAdvancedRequest::getHistograms
using option 2:
$request1 = new DTS\eBaySDK\Finding\Types\GetHistogramsRequest();
$histograms = $service->getHistograms($request1);
$request->$histograms = (array('73839'));
but its giving me the following error: "Unknown property: DTS\eBaySDK\Finding\Types\FindItemsAdvancedRequest::Object"
I know that in the SDK getHistograms() is not part of FindItemsAdvanced() but its a part of FindingService.php consequently I assume it could be called in the same action. Any help or example code using finditems with histograms in same call appreciated.
The category that you are using is Consumer Electronics > Portable Audio & Headphones > iPods & MP3 Players (73839). While this is a valid category ID, both getHistograms and findItemsAdvanced will not return a categoryHistogram element. The reason for this is explained in the documentation for getHistograms
This container is returned only when the specified category has
children categories.
And also in the findItemsAdvanced documentation.
The category IDs returned for items in search results are for the leaf
categories in which the items are listed. If you use these category
IDs as input, the response will not return a category histogram.
In other words the categoryHistogram element will not be returned by either service if a leaf category is specified in the request. A leaf category is just a category that has no children. Since the category 73839 is a leaf category you will instead have to use its parent Consumer Electronics > Portable Audio & Headphones (15052).
The links below should return the categoryHistogram. You just need to replace <YOUR APP ID> in the URL.
http://svcs.ebay.com/services/search/FindingService/v1?SECURITY-APPNAME=<YOUR APP ID>&OPERATION-NAME=findItemsAdvanced&SERVICE-VERSION=1.13.0&GLOBAL-ID=EBAY-US&RESPONSE-DATA-FORMAT=XML&REST-PAYLOAD&categoryId(0)=15052&outputSelector(0)=AspectHistogram&outputSelector(1)=CategoryHistogram&outputSelector(2)=SellerInfo
http://svcs.ebay.com/services/search/FindingService/v1?SECURITY-APPNAME=<YOUR APP ID>&OPERATION-NAME=getHistograms&SERVICE-VERSION=1.13.0&GLOBAL-ID=EBAY-US&RESPONSE-DATA-FORMAT=XML&REST-PAYLOAD&categoryId(0)=15052
I'm using ExpressionEngine for a multi-language website with products. I used Transcribe for controlling the multi-language. Products have the same title in different languages, and this gives me some problems selecting the correct product in a relationship field.
The builder of this site did not use the title for a unique name in the back-end only, but also displayed it everywhere in the front-end.
Dropdown example:
Product A
Product A
Product A
Product B
Product B
Product B
Product c
Product c
Product c
I found that the dropdown information is filled in /system/expressionengine/fieldtypes/rel/ft.rel.php from line 59
/**
* Display Relationship Field
*
* #access public
* #param string
* #return string
*/
function display_field($data)
{
if ($this->settings['field_related_orderby'] == 'date')
{
$this->settings['field_related_orderby'] = 'entry_date';
}
$this->EE->db->select('entry_id, title');
$this->EE->db->where('channel_id', $this->settings['field_related_id']);
$this->EE->db->order_by($this->settings['field_related_orderby'], $this->settings['field_related_sort']);
if ($this->settings['field_related_max'] > 0)
{
$this->EE->db->limit($this->settings['field_related_max']);
}
$relquery = $this->EE->db->get('channel_titles');
if ($relquery->num_rows() == 0)
{
return $this->EE->lang->line('no_related_entries');
}
else
{
if ( ! isset($_POST[$this->field_name]))
{
$this->EE->db->select('rel_child_id');
$relentry = $this->EE->db->get_where('relationships', array('rel_id' => $data));
if ($relentry->num_rows() == 1)
{
$data = $relentry->row('rel_child_id') ;
}
}
$field_options[''] = '--';
foreach ($relquery->result_array() as $relrow)
{
$field_options[$relrow['entry_id']] = $relrow['title'];
}
return form_dropdown($this->field_name, $field_options, $data, 'id="field_id_'.$this->field_id.'"');
}
}
How can I add the language name to the dropdown at line 98 ($field_options[$relrow['entry_id']] = $relrow['title'];)?
Transcribe did not found any possibilities in Expression Engine 2.5.
I created a workaround and added the url_title in the dropdown menu. It is not the best solution, but in this case it is workable.
$this->EE->db->select('entry_id, title');
changed into
$this->EE->db->select('entry_id, title, url_title');
And changed
$field_options[$relrow['entry_id']] = $relrow['title'];
into
$field_options[$relrow['entry_id']] = $relrow['title'] . " - " . $relrow['url_title'];
I'm trying to create country based charts. i'm using pchart for this, because it will create charts as image by default.
I've created a function which creates barchart. I'm selecting countries and its stats and passing it to the barchart function which creates a chart as a flat file.
When i pass a single a country stats it is creating chart. the problem is when i try to post more than one country, it is creating only one country image not more than that. i don't know where the issue exists? Help appreciated.
sample code is here:
<?php
$con=mysql_connect("localhost","root","");
$ln=mysql_select_db("conif_new",$con);
$qry="select country from chart group by country limit 2";
$cnlist=mysql_query($qry);
while($row=mysql_fetch_row($cnlist)){
$cn=$row[0];
$nqry="select server,count(*) from chart where country='$cn' group by server";
$dset=mysql_query($nqry);
$x="";
$xt="";
while($crow=mysql_fetch_row($dset)){
$x.=$crow[1].",";
$xt.=$crow[0].",";
}
$x=substr($x,0,strlen($x)-1);
$xt=substr($xt,0,strlen($xt)-1);
//echo "$x**$xt<br>";
if(barChart($x,$xt,$cn)){}
}
function barChart($x,$xt,$name){
$x=explode(",",$x);
$xt=explode(",",$xt);
/* CAT:Bar Chart */
/* pChart library inclusions */
include("class/pData.class.php");
include("class/pDraw.class.php");
include("class/pImage.class.php");
/* Create and populate the pData object */
$MyData = new pData();
$MyData->addPoints($x,"Server A");
$MyData->setAxisName(0,"Hits");
$MyData->addPoints($xt,"Months");
$MyData->setSerieDescription("Months","Month");
$MyData->setAbscissa("Months");
/* Create the pChart object */
$myPicture = new pImage(700,230,$MyData);
$myPicture->drawGradientArea(0,0,700,230,DIRECTION_VERTICAL,array("StartR"=>240,"StartG"=>240,"StartB"=>240,
"EndR"=>180,"EndG"=>180,"EndB"=>180,"Alpha"=>100));
$myPicture->drawGradientArea(0,0,700,230,DIRECTION_HORIZONTAL,array("StartR"=>240,"StartG"=>240,"StartB"=>240,
"EndR"=>180,"EndG"=>180,"EndB"=>180,"Alpha"=>20));
$myPicture->setFontProperties(array("FontName"=>"fonts/verdana.ttf","FontSize"=>9));
/* Draw the scale */
$myPicture->setGraphArea(50,30,680,200);
$myPicture->drawScale(array("CycleBackground"=>TRUE,"DrawSubTicks"=>TRUE,"GridR"=>0,"GridG"=>0,"GridB"=>0,
"GridAlpha"=>10));
/* Turn on shadow computing */
$myPicture->setShadow(TRUE,array("X"=>1,"Y"=>1,"R"=>0,"G"=>0,"B"=>0,"Alpha"=>10));
/* Draw the chart */
$settings = array("Gradient"=>TRUE,"DisplayPos"=>LABEL_POS_INSIDE,"DisplayValues"=>TRUE,"DisplayR"=>255,
"DisplayG"=>255,"DisplayB"=>255,"DisplayShadow"=>TRUE,"Surrounding"=>10);
$myPicture->drawBarChart($settings);
/* Write the chart legend */
$myPicture->drawLegend(580,12,array("Style"=>LEGEND_NOBORDER,"Mode"=>LEGEND_HORIZONTAL));
/* Render the picture (choose the best way) */
//$myPicture->autoOutput("pictures/example.drawBarChart.shaded.png");
if($myPicture->render("C:/wamp/www/chart/".$name.".png"))
echo "true";
else
echo "false";
}
?>
I found an answer!!!, just noticed "include statements" inside barchart function. Removed it, Thats it!
I should've placed "include_once" instead of "include" or should've moved the "include" statements outside the function to make it work.