In SPARQL it is possibile to obtain something like this?
SELECT ?Name ?Input
WHERE { ?s :Something ?Name .
?s :Something ?Ui .
{ SELECT ?Ui ?Pn ?t
WHERE {
?Ui :Something ?Pn .
?Ui :Something ?t } } }
where ?Input is an object that contains ?Ui ?Pn and ?t
Thanks
`
Related
Here's my modelSearch :
public function search($params)
{
$query = "select distinct number,
id,
write_date::date,
customer_id,
customer_name,
sales.name,
sales.id as sales_id
from item
inner join sales on sales.id = pa.sales_id
where status = 'oke'
order by write_date::date
";
// add conditions that should always apply here
$dataProvider = new SqlDataProvider([
'sql' => $query,
]);
$this->load($params);
if (!$this->validate()) {
// uncomment the following line if you do not want to return any records when validation fails
// $query->where('0=1');
return $dataProvider;
}
return $dataProvider;
}
this modelSearch work fine to load the data on the gridview, but fo the filtering it doesn't work. Can anyone help me? thanks.
Inherited old Joomla site I've upgraded since 2.5 circa 2012, now 3.6.4 with Virtuemart 3.0.16 (using PHP7.0).
Default Joomla search module results appear as:
[Lorem Ipsum product link]
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aenean accumsan est mi, et volutpat quam blandit a. Etiam blandit, massa ac consequat dapibus product description.
Except the hyperlink of the product title erroneously points to the product category instead of the product detail page.
I believe I have located the issue in this location: /plugins/search/virtuemart/virtuemart.php. Approx. line 223:
$row->virtuemart_product_id . '&virtuemart_category_id=' . $row->cat_id;
I do not know how to change the php into the correct format to point to the product itself. I have tried to change the language from category to product id declaration but this results in mix-matched product links.
How can edit this file to make the product title link point to actual product details page and not the category?
<?php
/**
*
* A search plugin for com_search
*
* #author Valérie Isaksen
* #author Samuel Mehrbrodt
* #version $Id: authorize.php 5122 2011-12-18 22:24:49Z alatak $
* #package VirtueMart
* #subpackage search
* #copyright Copyright (C) 2004-2008 soeren - All rights reserved.
* #license http://www.gnu.org/copyleft/gpl.html GNU/GPL, see LICENSE.php
* VirtueMart is free software. This version may have been modified pursuant
* to the GNU General Public License, and as distributed it includes or
* is derivative of works licensed under the GNU General Public License or
* other free or open source software licenses.
* See /administrator/components/com_virtuemart/COPYRIGHT.php for copyright notices and details.
*
* http://virtuemart.net
* #modified by Jeno Kovacs --- Offlajn.com 2014
* #description image & price support for Universal AJAX Live Search
*/
// no direct access
defined ('_JEXEC') or die('Restricted access');
class PlgSearchVirtuemart extends JPlugin {
/**
* #return array An array of search areas
*/
function onContentSearchAreas () {
$this->loadLanguage();
static $areas = array(
'virtuemart' => 'PLG_SEARCH_VIRTUEMART_PRODUCTS'
);
return $areas;
}
/**
* Content Search method
* The sql must return the following fields that are used in a common display
* routine: href, title, section, created, text, browsernav
*
* #param string $text Target search string
* #param string $phrase matching option, exact|any|all
* #param string $ordering ordering option, newest|oldest|popular|alpha|category
* #param mixed $areas An array if the search it to be restricted to areas, null if search all
*
* #return array An array of database result objects
*/
function onContentSearch ($text, $phrase = '', $ordering = '', $areas = NULL) {
$db = JFactory::getDbo();
if (is_array($areas)) {
if (!array_intersect ($areas, array_keys ($this->onContentSearchAreas()))) {
return array();
}
}
$limit = $this->params->get('search_limit', 50);
switch($this->params->get('subtitledisplay', '1')) {
case '1':
$category_field = 'category_name';
break;
case '2':
$category_field = 'customtitle';
break;
}
$search_product_description = (bool) $this->params->get('enable_product_description_search', TRUE);
$search_product_s_description = (bool) $this->params->get('enable_product_short_description_search', TRUE);
$search_customfields = (bool) $this->params->get('enable_customfields', TRUE);
$customfield_ids_condition = "";
if ($search_customfields) {
$value = trim($this->params->get('customfields', ""));
// Remove all spaces
$value = str_replace(' ', '', $value);
if (!empty($value)){
$customfield_ids = explode(",", $value);
// Make sure we have only integers
foreach($customfield_ids as &$id) {
$id = intval($id);
}
// The custom field ID must be either in the list specified or NULL.
$customfield_ids_condition = "AND cf.virtuemart_custom_id IN (" .
implode(',', $customfield_ids) . ")";
}
}
if (!class_exists('VmConfig')) {
// FIX THE MISSING DS ERROR ON JOOMLA 3 VM BETTER SEARCH PLUGIN : https://forum.virtuemart.net/index.php?topic=125681.0
defined('DS') or define('DS', DIRECTORY_SEPARATOR);
require(JPATH_ADMINISTRATOR . DS . 'components' . DS . 'com_virtuemart' . DS . 'helpers' . DS . 'config.php');
}
VmConfig::loadConfig();
$text = trim($text);
if (empty($text))
return array();
switch ($phrase) {
case 'exact':
$wheres2 = array();
// product_sku should be exact match
$text = $db->quote("%$text%", TRUE);
$wheres2[] = "p.product_sku LIKE $text";
$wheres2[] = "a.product_name LIKE $text";
$wheres2[] = "b.$category_field LIKE $text";
if ($search_product_s_description)
$wheres2[] = "a.product_s_desc LIKE $text";
if ($search_product_description)
$wheres2[] = "a.product_desc LIKE $text";
if ($search_customfields)
$wheres2[] = "(cf.customfield_value LIKE $text $customfield_ids_condition)";
$where = '(' . implode (') OR (', $wheres2) . ')';
break;
case 'all':
case 'any':
default:
$words = explode (' ', $text);
$wheres = array();
foreach ($words as $word) {
$wheres2 = array();
// product_sku should be exact match
$word = $db->quote("%$word%", TRUE);
$wheres2[] = "p.product_sku LIKE $word";
$wheres2[] = "a.product_name LIKE $word";
$wheres2[] = "b.$category_field LIKE $word";
if ($search_product_s_description)
$wheres2[] = "a.product_s_desc LIKE $word";
if ($search_product_description)
$wheres2[] = "a.product_desc LIKE $word";
if ($search_customfields)
$wheres2[] = "(cf.customfield_value LIKE $word $customfield_ids_condition)";
$wheres[] = implode (' OR ', $wheres2);
}
$where = '(' . implode (($phrase == 'all' ? ') AND (' : ') OR ('), $wheres) . ')';
break;
}
switch($ordering) {
case 'alpha':
$order = 'a.product_name ASC';
break;
case 'category':
$order = 'b.category_name ASC, a.product_name ASC';
break;
case 'popular':
$order = 'a.product_name ASC';
break;
case 'newest':
$order = 'p.created_on DESC';
break;
case 'oldest':
$order = 'p.created_on ASC';
break;
default:
$order = 'a.product_name ASC';
}
$shopper_group_condition="";
$currentVMuser = VmModel::getModel('user')->getUser();
$virtuemart_shoppergroup_ids = (array)$currentVMuser->shopper_groups;
if (is_array($virtuemart_shoppergroup_ids)) {
$sgrgroups = array();
foreach($virtuemart_shoppergroup_ids as $virtuemart_shoppergroup_id) {
$sgrgroups[] = 'psgr.`virtuemart_shoppergroup_id`= "' . (int)$virtuemart_shoppergroup_id . '" ';
}
$sgrgroups[] = 'psgr.`virtuemart_shoppergroup_id` IS NULL ';
$shopper_group_condition = " AND ( " . implode (' OR ', $sgrgroups) . " ) ";
}
$uncategorized_products_condition = VmConfig::get('show_uncat_child_products') ?
'' : ' AND b.virtuemart_category_id > 0 ';
$query = "
SELECT DISTINCT
a.product_name AS title,
a.product_s_desc AS text,
p.created_on as created,
p.published,
'2' AS browsernav,
(SELECT m.file_url AS path
FROM #__virtuemart_medias AS m
LEFT JOIN #__virtuemart_product_medias AS me ON m.virtuemart_media_id = me.virtuemart_media_id
WHERE me.virtuemart_product_id = a.virtuemart_product_id ORDER BY me.ordering ASC LIMIT 1 ) AS image,
GROUP_CONCAT(DISTINCT b.$category_field
ORDER BY b.$category_field SEPARATOR ', ') as section,
(SELECT pc2.virtuemart_category_id
FROM #__virtuemart_product_categories as pc2
WHERE pc2.virtuemart_product_id = a.virtuemart_product_id LIMIT 1) AS cat_id
FROM `#__virtuemart_products_" . VmConfig::$vmlang . "` AS a
JOIN #__virtuemart_products AS p USING (`virtuemart_product_id`)
LEFT JOIN `#__virtuemart_product_categories` AS xref
ON xref.`virtuemart_product_id` = a.`virtuemart_product_id`
LEFT JOIN `#__virtuemart_categories_" . VmConfig::$vmlang . "` AS b
ON b.`virtuemart_category_id` = xref.`virtuemart_category_id`
LEFT JOIN `#__virtuemart_product_shoppergroups` as `psgr`
ON (`psgr`.`virtuemart_product_id`=`a`.`virtuemart_product_id`)
LEFT JOIN `#__virtuemart_product_customfields` AS cf
ON cf.virtuemart_product_id = a.virtuemart_product_id
LEFT JOIN `#__virtuemart_customs` AS customs
ON customs.virtuemart_custom_id = cf.virtuemart_customfield_id
WHERE
($where)
AND p.published='1'
$shopper_group_condition
$uncategorized_products_condition
GROUP BY xref.virtuemart_product_id
ORDER BY $order";
$db->setQuery($query, 0, $limit);
//echo $query; exit;
$rows = $db->loadObjectList();
if ($rows) {
foreach ($rows as $key => $row) {
$rows[$key]->href = 'index.php?option=com_virtuemart&view=productdetails' .
// line below somehow changes search result links without changing title
$row->virtuemart_product_id . '&virtuemart_category_id=' . $row->cat_id;
$rows[$key]->price = $this->getPrice($row->virtuemart_product_id);
if($row->image != "" && (false === strpos($row->image, "stories"))) {
$rows[$key]->image = "images/stories/virtuemart/product/".$row->image;
}
}
}
return $rows;
}
function getPrice($pid) {
if (!class_exists('CurrencyDisplay')) {
require_once(JPATH_VM_ADMINISTRATOR . DS . 'helpers' . DS . 'currencydisplay.php');
}
$product_model = VmModel::getModel('product');
$currency = CurrencyDisplay::getInstance();
$product = $product_model->getProduct($pid,TRUE,TRUE,TRUE,1);
$p = str_replace("PricesalesPrice", "", $currency->createPriceDiv ('salesPrice', '', $product->prices));
return $p;
}
}
My psuedo-solution was to import the aforementioned virtuemart.php file from a vanilla Virtuemart download that matched the version I am using.
The file extracted was found in com_virtuemart.3.0.14_ext_aio.zip: /admin/plugins/search/virtuemart/virtuemart.php.
Renamed original post php file to .bak and dropped this one in the same location. Results are now behaving like stock Joomla search (sans all custom styling).
Hi i have this controler in Yii2 which render me view. Then i can write in console yii generator/generate example example and then This action generate me skeleton od model and controller which i have in my views. This is code
<?php
namespace console\controllers;
use yii\console\Controller;
class GeneratorController extends Controller {
private $viewControllerPath = "rest/modules/crm/v1/controllers/";
private $viewModelPath = 'rest/modules/crm/v1/models/';
public function actionGenerate($className, $modelClass) {
$controller = $this->renderFile('#app/views/generator/restController.php', ['className' => $className, 'modelClass' =>
$modelClass]);
file_put_contents(\Yii::getAlias($this->viewControllerPath . $className . 'Controller' . '.php'), $controller);
$model = $this->renderFile('#app/views/generator/restModel.php', ['className' => $className, 'modelClass' => $modelClass]);
file_put_contents(\Yii::getAlias($this->viewModelPath . $className . 'Model' . '.php'), $model);
}
}`
And this is this view:
`
<?php
echo "<?php\n";
?>
namespace rest\modules\<?= $modelClass ?>\v1\models;
use common\models\<?= $modelClass ?>\<?= $className ?> as CommonModel;
class <?= $className ?> extends CommonModel {
}`
The last think what i should to do is put mz variable $modelClass in this path
private $viewControllerPath = "rest/modules/crm/v1/controllers/";
instead of crm. Then my model and controler will be appear in in appropriate folders.
I try to do this but it isnt work:
private $viewControllerPath = "rest/modules/'.$modelClass.'/v1/controllers/";
Anyone can help me? Maybe i can use __constructor there but i dont know how to do it
Just replace crm word of your variables with $modelClass inside your actionGenerate function like this:
public function actionGenerate($className, $modelClass) {
// replacing 'crm' with $modelClass
if( ! empty($modelClass) ) {
$this->viewControllerPath = str_replace ( 'crm' , $modelClass , $this->viewControllerPath );
$this->viewModelPath = str_replace ( 'crm' , $modelClass , $this->viewModelPath );
}
$controller = $this->renderFile('#app/views/generator/restController.php', ['className' => $className, 'modelClass' =>
$modelClass]);
file_put_contents(\Yii::getAlias($this->viewControllerPath . $className . 'Controller' . '.php'), $controller);
$model = $this->renderFile('#app/views/generator/restModel.php', ['className' => $className, 'modelClass' => $modelClass]);
file_put_contents(\Yii::getAlias($this->viewModelPath . $className . 'Model' . '.php'), $model);
}
I have a simple and I think often occuring situation, but I was not able to find any solution throughout the Internet.
There are four related models: Place, Location, Province and Country. Each of these have several properties (like a name).
Country:
In the Country model I want to find all countries which names matches the given search string, which is very easy:
class Country extends \Eloquent
{
public function provinces()
{
return $this->hasMany('Province');
}
[...]
public function scopeSearch($query, $string)
{
if (isset($string) and !is_null($string)) {
$terms = explode(' ', $string); // Array of searchstrings
foreach ($terms as $term) {
$query = $query->orWhere('name', 'like', '%' . $term . '%');
}
}
return $query;
}
}
Province:
In the Province model I want to find all provinces which names matches the given search string (like in the country model) but also provinces, where the country name matches this search string. This is also not very difficult:
class Province extends \Eloquent
{
public function country()
{
return $this->belongsTo('Country');
}
public function locations()
{
return $this->hasMany('Location');
}
[...]
public function scopeSearch($query, $string)
{
if (isset($string) and !is_null($string)) {
$terms = explode(' ', $string); // Array of searchstrings
foreach ($terms as $term) {
$query = $query->orWhereHas('country', function ($query) use ($term) {
$query->where('name', 'like', '%' . $term . '%');
});
$query = $query->orWhere('name', 'like', '%' . $term . '%');
}
}
return $query;
}
}
Location:
Now it gets tricky: In the Location model I want to find all locations which names matches the given search string, but also provinces, where the province name matches this search string and - and this is the tricky part - where the country name matches the given search string. At the moment I have no idea how I can achieve this.
class Location extends \Eloquent
{
public function province()
{
return $this->belongsTo('Province');
}
public function places()
{
return $this->hasMany('Place');
}
[...]
public function scopeSearch($query, $string)
{
if (isset($string) and !is_null($string)) {
$terms = explode(' ', $string); // Array of searchstrings
foreach ($terms as $term) {
$query = $query->orWhereHas('province', function ($query) use ($term) {
$query->where('name', 'like', '%' . $term . '%');
});
$query = $query->orWhere('name', 'like', '%' . $term . '%');
}
}
return $query;
}
}
Place:
The same here: In the Place model I want to find all places which names matches the given search string, but also locations, where the location name matches this search string and where the province name matches the given search string and of course the country name matches the search string. Also here: At the moment I have no idea how I can achieve this.
class Place extends \Eloquent
{
public function location()
{
return $this->belongsTo('Location');
}
[...]
public function scopeSearch($query, $string)
{
if (isset($string) and !is_null($string)) {
$terms = explode(' ', $string); // Array of searchstrings
foreach ($terms as $term) {
$query = $query->orWhereHas('location', function ($query) use ($term) {
$query->where('name', 'like', '%' . $term . '%');
});
$query = $query->orWhere('name', 'like', '%' . $term . '%');
}
}
return $query;
}
}
So, does anybody know how I can resolve this? Is there a (simple) way to do it? Does anybody know a Laravel 4 plugin which might help me with this? Or am I completely on the wrong way and have to do all this stuff for example in a controller?
Thanks!
I have 10 subscriber tables from subscriber_0 to subscriber_9, I get all the data from them through union by custom query in subscriber model, in the function getAllSubscribers, this table executes the query and returns the result to the subscriber controller, I have set $useTable = false because there is no subscriber table, my question is how do I paginate this data in the controller?
For reference I am writing my query here and the result returned
Query:
$query = 'SELECT * FROM (
SELECT * FROM subscriber_1
UNION
SELECT * FROM subscriber_2
UNION
SELECT * FROM subscriber_3
UNION
SELECT * FROM subscriber_4
UNION
SELECT * FROM subscriber_5
UNION
SELECT * FROM subscriber_6
UNION
SELECT * FROM subscriber_7
UNION
SELECT * FROM subscriber_8
UNION
SELECT * FROM subscriber_9
UNION
SELECT * FROM subscriber_0
) AS subscriber WHERE created > \'' . $startDate . '\' AND created < \'' . $endDate . '\'';
Result:
array(
(int) 0 => array(
'subscriber' => array(
'a_party' => '923003210861',
'subtype' => '0',
'stat' => '0',
'created' => '2012-11-26 06:53:31',
'updated' => null
)
),
(int) 1 => array(
'subscriber' => array(
'a_party' => '923005264511',
'subtype' => '0',
'stat' => '0',
'created' => '2012-11-26 06:53:31',
'updated' => null
)
)
,
.
.
.
.(int) 50 => ...
I have added this in the subscribers controller
public $paginate = array(
'limit' => 10
);
What else do I need to add?
I have seen this but of no help
CakePHP pass custom query from controller into model paginate()
EDIT: Adding controller code below
$data = $this->Subscriber->getAllSubscribers();//This model method returns custom data from query
$this->paginate = array('fields' => $selectedField);
$paginatedData = $this->paginate($data);
//debug($paginatedData);
$this->set('subslist', $paginatedData);
The above code is not working, what am i doing wrong, thanks
Here is how I achieved it:
Model code
/**
* Overridden paginate method - group by week, away_team_id and home_team_id
*/
public function paginate($conditions,
$fields,
$order,
$limit,
$page = 1,
$recursive = null,
$extra = array()) {
$recursive = -1;
$sql = "SELECT * FROM (
SELECT * FROM blacklist_0
UNION
SELECT * FROM blacklist_1
UNION
SELECT * FROM blacklist_2
UNION
SELECT * FROM blacklist_3
UNION
SELECT * FROM blacklist_4
UNION
SELECT * FROM blacklist_5
UNION
SELECT * FROM blacklist_6
UNION
SELECT * FROM blacklist_7
UNION
SELECT * FROM blacklist_8
UNION
SELECT * FROM blacklist_9
UNION
SELECT * FROM blacklist_0
) AS Blacklist LIMIT " . (($page - 1) * $limit) . ', ' . $limit;
$results = $this->query($sql);
return $results;
}
/**
* Overridden paginateCount method
*/
public function paginateCount($conditions = null,
$recursive = 0,
$extra = array()) {
$sql = "SELECT * FROM (
SELECT * FROM blacklist_1
UNION
SELECT * FROM blacklist_2
UNION
SELECT * FROM blacklist_3
UNION
SELECT * FROM blacklist_4
UNION
SELECT * FROM blacklist_5
UNION
SELECT * FROM blacklist_6
UNION
SELECT * FROM blacklist_7
UNION
SELECT * FROM blacklist_8
UNION
SELECT * FROM blacklist_9
UNION
SELECT * FROM blacklist_0
) AS Blacklist";
if ($conditions['Blacklist.b_party'] <> null) {
$sql = $sql . ' WHERE Blacklist.b_party = \'' . $conditions['Blacklist.b_party'] . '\'';
} else if ($conditions['Blacklist.a_party'] <> null) {
$sql = $sql . ' WHERE Blacklist.a_party = \'' . $conditions['Blacklist.a_party'] . '\'';
}
$this->recursive = $recursive;
$results = $this->query($sql);
return count($results);
}
Not to forget i used
public $useTable = false;
in the model, but the key thing was how to override the methods, which i finally figured out with the help of my collegue, the controller code is simple. Here it is:
Controller code:
public function index() {
$this->set('msisdn', "");
$this->Blacklist->recursive = 0;
$this->set('blacklists', $this->paginate());
}
You can't use standard pagination on custom queries, you'll have to create those yourself.
Custom Query Pagination