datagrid adding sorting function to a non data column - qcubed

I have 4 columns in a datagrid. The manuals give examples on how to sort on a column derived from the database using the array('OrderByClause' => QQ::OrderBy(QQN::Pubs()->Name)
however, I want to sort on a calculated results $_FORM->getDistance($_ITEM)
What I have so far is this:
$this->dtgPersons->AddColumn(new QDataGridColumn('Row Number', 'CurrentRowIndex + 1) ?>'));
$this->dtgPersons->AddColumn(new QDataGridColumn('Pub Name', 'Name ?>', 'Width=200', //));
array('OrderByClause' => QQ::OrderBy(QQN::Pubs()->Name), 'ReverseOrderByClause' => QQ::OrderBy(QQN::Pubs()->Name, false))));
$this->dtgPersons->AddColumn(new QDataGridColumn('Street', 'Address1 ?>', 'Width=200',
array('OrderByClause' => QQ::OrderBy(QQN::Pubs()->Address1), 'ReverseOrderByClause' => QQ::OrderBy(QQN::Pubs()->Address1,
false))));
$this->dtgPersons->AddColumn(new QDataGridColumn('Distance from
Location', 'getDistance($_ITEM) ?>', 'Width=300'));
This following line works on columns that have a sort on them
$this->dtgPersons->SortColumnIndex = 2;

I am unsure about this. Try asking at the github page - http://github.com/qcubed/framework.

Related

WP_Query meta_query REGEXP

I am pretty much below beginner level for REGEX/REGEXP and have hit a blocking point in a project I am working in, where I am trying to get the ids for posts that match the search criteria , but I want to restrict the search between 2 sub-strings. I am trying to figure out is how to write the REGEXP in the meta_query:
$args = array(
'post_type'=> 'custom',
'order' => 'DESC',
'posts_per_page' => 10,
'paged' => $page,
'meta_query' => array(
array(
'key' => 'key',
'value' => "title*".$search."*_title",
'compare' => 'REGEXP',
)
),
);
And an example of the field in the DB :
a:302:{s:5:"title";s:10:"Test title";s:6:"_title";s:19:"
Unfortunately none of the combinations I tried based on documentation of SQL REGEXP won't return any values and I am trying to understand how I can pull this off and would appreciate any input.
Also would rather stick to WP_Query for now even though an SQL LIKE "%title%{$search}%_title%" works perfectly , so an alternative solution would be how to set the compare to 'LIKE' and parse it '%' since that is not possible out of the box as the % get escaped I believe.

Opencart full category ul li tree

Right now in opencart the system is limited to only showing 2 levels of categories. Does anyone know of a class to get all sub-categories and a full ul li tree?
For example: If you have ever used oscommerce it will show the full tree of sub-cats in the side category menu where as opencart is limited to only two levels.
The default code is like
$categories = $this->model_catalog_category->getCategories(0);
foreach ($categories as $category) {
$children_data = array();
if ($category['category_id'] == $data['category_id']) {
$children = $this->model_catalog_category->getCategories($category['category_id']);
foreach($children as $child) {
$filter_data = array('filter_category_id' => $child['category_id'], 'filter_sub_category' => true);
$children_data[] = array(
'category_id' => $child['category_id'],
'name' => $child['name'] . ($this->config->get('config_product_count') ? ' (' . $this->model_catalog_product->getTotalProducts($filter_data) . ')' : ''),
'href' => $this->url->link('product/category', 'path=' . $category['category_id'] . '_' . $child['category_id'])
);
}
}
However it only goes two levels, I am looking for all levels to build out an accordion menu.
Further I am not looking for someone to do this, (unless you want), but maybe you can point me in the right direction or to an existing class that will achieve this.
You'll need to add each sub-level manually for a 3rd, for a 4th etc. There is no way to just get all of them in one shot.
There was an older stackoverflow thread with a solution on how to add a 3rd level. Perhaps it will work with your version of OC:
get third level category in opencart 2
You basically will need to edit the controller and tpl files for category. If that's too much for you, they sell an extension on their marketplace for it, too.

Auto apply coupon in Opencart 2.3.0.2

Trying to auto apply a coupon code (2 of them actually) when a customer checks out so that I can offer discounts when 4 and 10 items in a specif category or bought, WITHOUT the need for the customer to enter a code. I have tried adding manually the name of my coupon into the "amount" voucher of the /catalog/controller/checkout/cart.php file without success. Is there an easy fix for this?
// Gift Voucher
$data['vouchers'] = array();
if (!empty($this->session->data['vouchers'])) {
foreach ($this->session->data['vouchers'] as $key => $voucher) {
$data['vouchers'][] = array(
'key' => $key,
'description' => $voucher['description'],
'amount' => $this->currency->format($voucher['FOUR'], $this->session->data['currency']),

Yii2 MaskedInput / MaskedMoney for Integer Only money storage

In my database I store money as an integer, similar to Stripe. For instance 12.99 is stored as 1299. Basically taking the number and dividing by 100.
I'm trying to incorporate this with Yii2 activeForm, specifically using either the MaskInput or MaskMoney widgets. However, I cannot figure out how to configure either widget so that when the value is "1299" it displays as "12.99". So if a person types in "1200" it displays as "12.00".
This is for a simple frontend solution and not backend so I'm not looking for Yii scenarios or behaviors in this question.
I'm not sure if I understood correctly, but this is the closest I've ever got to what you want.
<?php echo \yii\widgets\MaskedInput::widget([
'name' => 'masked-input',
'clientOptions' => [
'alias' => 'decimal',
'digits' => 2,
'digitsOptional' => false,
'radixPoint' => '.',
'groupSeparator' => ',',
'autoGroup' => true,
'removeMaskOnSubmit' => true,
],
]); ?>
The behaviour of the decimal part is what bothers me, but it works as intended.

wpdb Update function getting "Undefined Index" error for each table column

I'm developing a plugin that lets me add and delete custom table records. Adding and deleting records works fine.
I also want to be able to update the records. This is where I cannot figure out what I'm doing wrong.
Here is my update code if anyone can point me in the right direction (I'm currently focused on the "update selected record" script:
function url_update() {
global $wpdb;
$id = $_GET["id"];
$launchname=$_POST["launchname"];
$url1 = $_POST["url1"];
$url2 = $_POST["url2"];
$urluser = $_POST["urluser"];
$urlpwd = $_POST["urlpwd"];
$wpfirstname = $_POST["wpfirstname"];
$wplastname = $_POST["wplastname"];
$wpemail = $_POST["wpemail"];
$activated = $_POST["activated"];
//update selected record
if(isset($_POST['update'])){
$wpdb->update('launcher',
array(
'id' => $id,
'launchname' => $launchname,
'url1' => $url1,
'url2' => $url2,
'urluser' => $urluser,
'urlpwd' => $urlpwd,
'wpfirstname' => $wpfirstname,
'wplastname' => $wplastname,
'wpemail' => $wpemail,
'activated' => $activated
),
array( 'ID' => $id ), //this line fixed the issue
array('%d','%s','%s','%s','%s','%s','%s','%s','%s','%s'));
}
//delete
else if(isset($_POST['delete'])){
$wpdb->query($wpdb->prepare(
"DELETE FROM wp_tincan_launcher WHERE id = %d",$id
));
}
else{
//selecting row to update
$selected_record = $wpdb->get_results($wpdb->prepare(
"SELECT id,launchname,url1,url2,urluser,urlpwd,wpfirstname,
wplastname,wpemail,activated from launcher where id=%d",$id
));
foreach ( $selected_record as $s ){
$launchname=$s->launchname;
$url1=$s->url1;
$url2=$s->url2;
$urluser=$s->urluser;
$urlpwd=$s->urlpwd;
$wpfirstname=$s->wpfirstname;
$wplastname=$s->wplastname;
$wpemail=$s->wpemail;
$activated=$s->activated;
}
}
I think my code is correct, however, I would really appreciate some feedback that directly addresses my code.
EDIT: Thanks to Pekka for pointing out that I did not identify the error results.
The Error I'm getting from WP is "Notice: Undefined index: each column in the DB."
Best Regards
I resolved it myself by changing my update query to include a new line as follows: array( 'ID' => $id ), before the types line.
None of the links I was led to, not any of the generic advice I was provided was of any help what-so-ever.
I've edited the original code to reflect the complete working code.