What is post type of Replies in Wordpress BBPress? - sql

I did count active in 7 days topics of my Wordpress page. But It counts only Active (replied) topics not actual replies- I need more dynamic number to lure people using forum.
function count_new_forum_posts() {
$today = date("Y-m-d");
$date2 = date("Y-m-d", strtotime($today . "-7 Day"));
$args = array(
'post_type' => 'topic',
'meta_query' => array(
array(
'key' => '_bbp_last_active_time',
'value' => $date2,
'type' => 'DATE',
'compare' => '>='
),
)
);
$posts_query = new WP_Query($args);
$the_count = $posts_query->post_count;
return $the_count;
}
add_filter('wp_nav_menu_items', 'new_forums_notice_to_menu', 10, 2);
function new_forums_notice_to_menu($items, $args) {
if(count_new_forum_posts() > 0){
if( $args->theme_location == 'primary' )
$items .= '<li><font color="red">Šios savaitės naujos žinutės forume: <span>'.count_new_forum_posts().'</span></font></li>';
return $items;
}else{
if( $args->theme_location == 'primary' )
$items .= '<li><font color="gray">Šią savaitę forume dar niekas nepasisakė</span></font></li>';
return $items;
}
}
When i try to change post_type to 'reply' or 'replies' It counts to 0.

Related

First page of product got retrieved with rest admin api in shopify

I have almost 300 products in my development store.
But when I use product.json to retrieve, only 250 products are retrieved.
Please help me in solving this.
I have followed this link
My code is
$nextPageToken = null;
do {
$response = $this->shopify->call1('GET', '/admin/api/2019-07/products.json?
limit=250&page_info='.$nextPageToken.'&rel=next' );
foreach($response['resource'] as $product):$images = array();
foreach ($product['images'] as $image):
$images[] = $image['src'];
endforeach;
$products[] = array(
'shop' => $this->session->userdata('id'),
'handle' => $product['handle'],
'title' => $product['title'],
'product' => $product['id'],
'vendor' => $product['vendor'],
'type' => $product['product_type'],
'images' => json_encode($images),
'published_at' => $product['published_at']
);
endforeach;
$this->load->model('shop_products_model');
if ($this->shop_products_model->update($products)) {
$this->load->model('customers/customers_model');
$updated = array(
'shop' => $this->session->userdata('shop'),
'products_updated' => date('Y-m-d H:i:s')
);
$this->customers_model->update($updated);
return true;
} else {
return false;
}
$nextPageToken= isset($response['next']['page_token']) ? $response['next']
['page_token'] : null;
} while($nextPageToken != null);

Codeigniter post data from declared variable

function index_post() {
$sql = "SELECT id_so FROM so_detail ORDER BY id_so DESC LIMIT 1";
$last_id2 = $this->db->query($sql)->result();
foreach ($last_id2 as $row) {
$last_id = $row->id_so;
}
//echo $last_id;
$data = array(
'id_so' => $this->post($last_id),
'id_product' => $this->post('id_product'),
'harga' => $this->post('harga'),
'harga_dasar'=> $this->post('harga'),
'modal' => $this->post('modal'),
'pajak' => $this->post('pajak'),
'qty' => $this->post('qty'),
'keterangan' => $this->post('keterangan'),
'create_user'=> $this->post('create_user'),
'create_time'=> $this->post('create_time'),
'update_user'=> $this->post('create_user'),
'update_time'=> $this->post('create_time'));
$insert = $this->db->insert('so_detail', $data);
if ($insert) {
$this->response($data, 200);
} else {
$this->response(array('status' => 'fail', 502));
}
}
i got a problem that the posted id_so is "null". when i echo $last_id it show correct id ex: 120. but when i call it to $this->post($last_id), it just be null..
How to post id_so with a string that already declared before ($last_id) ??
there are many array in $last_id2 variable.data will insert multiple time based on your last_id2.try this:
foreach ($last_id2 as $row) {
$data = array(
'id_so' =>$row->id_so,
'id_product' => $this->post('id_product'),
'harga' => $this->post('harga'),
'harga_dasar'=> $this->post('harga'),
'modal' => $this->post('modal'),
'pajak' => $this->post('pajak'),
'qty' => $this->post('qty'),
'keterangan' => $this->post('keterangan'),
'create_user'=> $this->post('create_user'),
'create_time'=> $this->post('create_time'),
'update_user'=> $this->post('create_user'),
'update_time'=> $this->post('create_time'));
}
$this->db->insert_batch('so_detail',$data);

Prestashop: How to filter in HelperList

Hello I try to filter a List in the Backoffice. It shows the filter, it also saves it after clicking on search, but nothing is happening. Same with pagination.
$schueler = $this->getAllSchuelerbyDiplom($id_diplom);
$diplom_name = $this->getDiplomNamebyID($id_diplom);
$fields_list = array(
'id_schueler' => array(
'title' => 'ID',
'align' => 'center',
'class' => 'fixed-width-xs',
'search' => true),
'customer_name' => array(
'title' => $this->l('ID Customer')),
'id_gruppe' => array(
'title' => $this->l('ID Gruppe')),
'name' => array(
'title' => $this->l('Name'),
'filter_key' => 'name'.$diplom_name),
'vorname' => array(
'title' => $this->l('Vorname')),
'punkte' => array(
'title' => $this->l('Punkte')),
'bestanden' => array(
'title' => $this->l('Bestanden'),
'active' => 'toggle',
'class' => 'fixed-width-xs',
'type' => 'bool'),
'date_added' => array(
'title' => $this->l('Datum'),
'class' => 'fixed-width-xs',
'type' => 'date'),
);
$helper = new HelperList();
$helper->table = 'no-idea-what-this-is-for';
$helper->title = $diplom_name;
$helper->shopLinkType = '';
$helper->actions = array('view', 'edit', 'delete');
$helper->listTotal = count($schueler);
$helper->identifier = 'id_schueler';
$helper->token = Tools::getAdminTokenLite('AdminModules');
$helper->currentIndex = $this->context->link->getAdminLink('AdminModules', false) . '&configure=' . $this->name .'&diplom_name=' . $diplom_name;
return $helper->generateList($schueler, $fields_list);
What is wrong with my code? What is $helper->table for? I tried different things there, but nothing helps...
EDIT
public function getAllSchuelerbyDiplom($id_diplom) {
$query = new DbQuery();
$query->select('s.*, CONCAT(c.firstname,\' \',c.lastname) AS customer_name');
$query->from($this->table_name.'_schueler', 's');
$query->leftJoin('customer', 'c', 's.id_customer = c.id_customer');
$query->where('s.id_diplom = ' . (int)$id_diplom);
return Db::getInstance()->ExecuteS($query);
}
The problem is that HelperList object itself will only display filters being used but won't filter the actual data list for you.
In your $this->getAllSchuelerbyDiplom($id_diplom); method I assume you execute SQL query to retrieve all rows, however you need modify it to account for any filters, paginations (page number and rows per page) or ordering. You have to check GET/POST values or values set in cookie to detect them.
$helper->table sets the table name and list actions are prepended with that name so they are distinct from any other lists you might have on the page.
Edit:
Example of setting pagination and page
public function getPage()
{
// $tableName must be equal to what you set in $helper->table
// Check if page number was selected and return it
if (Tools::getIsset('submitFilter'.$tableName)) {
return (int)Tools::getValue('submitFilter'.$tableName);
}
else {
// Check if last selected page is stored in cookie and return it
if (isset($this->context->cookie->{'submitFilter'.$tableName})) {
return (int)$this->context->cookie->{'submitFilter'.$tableName};
}
else {
// Page was not set so we return 1
return 1;
}
}
}
public function getRowsPerPage()
{
// $tableName must be equal to what you set in $helper->table
// Check if number of rows was selected and return it
if (Tools::getIsset($tableName. '_pagination')) {
return (int)Tools::getValue($tableName. '_pagination');
}
else {
// Check if number of rows is stored in cookie and return it
if (isset($this->context->cookie->{$tableName. '_pagination'})) {
return (int)$this->context->cookie->{$tableName. '_pagination'};
}
else {
// Return 20 rows per page as default
return 20;
}
}
}
public function getAllSchuelerbyDiplom($id_diplom) {
$query = new DbQuery();
$query->select('s.*, CONCAT(c.firstname,\' \',c.lastname) AS customer_name');
$query->from($this->table_name.'_schueler', 's');
$query->leftJoin('customer', 'c', 's.id_customer = c.id_customer');
$query->where('s.id_diplom = ' . (int)$id_diplom);
// Limit the result based on page number and rows per page
$query->limit($this->getRowsPerPage(), ($this->getPage() - 1) * $this->getRowsPerPage());
return Db::getInstance()->ExecuteS($query);
}
You can place a p(Tools::getAllValues()); d($this->context->cookie->getAll(); after you generate a list then set a filter in your list and it will show you all the variables you need to create filters and ordering.

How To Integrate Easypay.pt API With Opengateway

I need to integrate Easypay.pt with opengateway so if any one know somehting about this i would like to know if some one can help for this i will appreciate thanks
function Settings () {
$settings = array();
$settings['name'] = 'Easypay';
$settings['class_name'] = 'easypay';
$settings['external'] = FALSE;
$settings['no_credit_card'] = FALSE;
$settings['description'] =
'Easypay is a portuguese company that offers a universal payment
platform and is certified by SIBS, Unicre, Visa and MasterCard. Our
primary mission is helping the market to shorten the payment
processing time and offer greater flexibility and convenience in
payment.';
$settings['is_preferred'] = 1;
$settings['setup_fee'] = '$0.00';
$settings['monthly_fee'] = '$30.00';
$settings['transaction_fee'] = '2.5% + $0.30';
$settings['purchase_link'] = 'https://www.easypay.pt/_s/api_easypay_01BG.php';
$settings['allows_updates'] = 0;
$settings['url_live'] = 'https://www.easypay.pt/_s/api_easypay_01BG.php ';
$settings['url_test'] = 'http://test.easypay.pt/_s/api_easypay_01BG.php';
$settings['allows_refunds'] = 1;
$settings['requires_customer_information'] = 1;
$settings['requires_customer_ip'] = 1;
$settings['required_fields'] = array(
'enabled',
'mode',
'ep_cin',
'ep_user',
'ep_ref_type',
'ep_entity',
't_key',
'ep_language',
'ep_country'
);
$settings['field_details'] = array(
'enabled' => array(
'text' => 'Enable this gateway?',
'type' => 'radio',
'options' => array(
'1' => 'Enabled',
'0' => 'Disabled'
)
),
'mode' => array(
'text' => 'Mode',
'type' => 'select',
'options' => array(
'live' => 'Live Mode',
'test' => 'Test Mode'
)
),
'ep_cin' => array(
'text' => 'Client Identification Number',
'type' => 'text'
),
'ep_user' => array(
'text' => 'Username',
'type' => 'text'
),
'ep_ref_type' => array(
'text' => 'Type of Identifier',
'type' => 'select',
'options' => array(
'auto' => 'Auto',
)
),
'ep_type' => array(
'text' => 'Type',
'type' => 'select',
'options' => array(
'boleto' => 'Boleto',
)
),
'ep_entity' => array(
'text' => 'Entity in use by Your Account.',
'type' => 'text',
),
't_key' => array(
'text' => 'Transaction key',
'type' => 'text',
),
'ep_language' => array(
'text' => 'Language',
'type' => 'select',
'options' => array(
'PT' => 'PT',
)
),
'ep_country' => array(
'text' => 'Currency',
'type' => 'select',
'options' => array(
'PT' => 'PT',
)
)
);
return $settings;
}
function TestConnection($client_id, $gateway) {
// Get the proper URL
switch($gateway['mode']) {
case 'live':
$post_url = $gateway['url_live'];
break;
case 'test':
$post_url = $gateway['url_test'];
break;
}
$post = array();
$post['ep_cin'] = $gateway['ep_cin'];
$post['ep_user'] = $gateway['ep_user'];
$post['ep_entity'] = $gateway['ep_entity'];
$post['ep_ref_type'] = $gateway['ep_ref_type'];
$post['ep_type'] = 'boleto';
$post['t_value'] = '504.4';
$post['ep_country'] = $gateway['ep_country'];
$post['ep_language'] = $gateway['ep_language'];
$post['s_code'] = 'sssssssssssyour code ddddddd';
$post['t_key'] = $gateway['t_key'];;
$response = $this->Process($post_url, $post);
$status=$response->ep_status;
//$CI =& get_instance();
if($status != 'err1') {
return TRUE;
} else {
return FALSE;
}
}
//--------------------------------------------------------------------
function Process($url, $post, $order_id = FALSE) {
$response = simplexml_load_file(
$url . "ep_cin=" . $post['ep_cin'] . "&ep_user=" . $post['ep_user']
. "&ep_entity=" . $post['ep_entity'] . "&ep_ref_type=" . $post['ep_ref_type']
. "&ep_type=" . $post['ep_type'] . "&ep_country=" . $post['ep_country']
. "&ep_language='" . $post['ep_language'] . "'&s_code=" . $post['s_code']
. "&t_key=" . $post['t_key'] . "&t_value=" . $post['t_value']
);
return $response;
}
//--------------------------------------------------------------------
//--------------------------------------------------------------------
private function response_to_array($string) {
$string = urldecode($string);
$pairs = explode('&', $string);
$values = array();
foreach($pairs as $pair) {
list($key, $value) = explode('=', $pair);
$values[$key] = $value;
}
return $values;
}

Yii: searching for a date period

I've a table with 2 mysql DATE field 'validFrom' and 'validTo'.
I need to allow user to search for a period beetween validFrom and validTo (included)
search using
validFrom >= searched validFrom
and
validTo <= searched validTo
What must I change ? the search() ? .
The Gii created code tell me this (i think it's a 'LIKE %string%' search )
$criteria->compare('validFromDate',$this->validFromDate,true);
$criteria->compare('validToDate',$this->validToDate,true);
$criteria->addBetweenCondition('colName', $this->validFrom, $this->validTo);
public function search() {
// Warning: Please modify the following code to remove attributes that
// should not be searched.
$criteria = new CDbCriteria;
$criteria->with = array('user');
$criteria->compare('nota_id', $this->nota_id, true);
$criteria->compare('user.nume', $this->filter_nume, true);
$criteria->compare('persoana1', $this->persoana1, true);
$criteria->compare('persoana2', $this->persoana2, true);
$d = $this->getFilterDateRange($this->data_discutie);
if (!empty($d[0]) && !empty($d[1])) {
// between condition
$criteria->addBetweenCondition('data_discutie', $d[0], $d[1]);
} else if (!empty($d[0])) {
$criteria->compare('data_discutie', '>=' . $d[0]);
} else if (!empty($d[1])) {
$criteria->compare('data_discutie', '<=' . $d[1]);
}
$d = null;
//echo $this->urmatoarea_discutie;
$d = $this->getFilterDateRange($this->urmatoarea_discutie);
//print_R($d);
if (!empty($d[0]) && !empty($d[1])) {
// between condition
$criteria->addBetweenCondition('urmatoarea_discutie', $d[0], $d[1]);
} else if (!empty($d[0])) {
$criteria->compare('urmatoarea_discutie', '>=' . $d[0]);
} else if (!empty($d[1])) {
$criteria->compare('urmatoarea_discutie', '<=' . $d[1]);
}
return new CActiveDataProvider($this, array(
'criteria' => $criteria,
'pagination' => array(
'pageSize' => '15',
),
'sort' => array(
'defaultOrder' => 'coalesce(nullif(t.urmatoarea_discutie, ""), \'zzzzzz\') ASC, t.data_discutie ASC',
'attributes' => array(
'urmatoarea_discutie',
'data_discutie',
'persoana2',
'persoana1',
'filter_nume' => array(
'asc' => 'user.nume asc',
'desc' => 'user.nume desc'
),
),
),
));
}
protected function getFilterDateRange($key) {
$ret = array(&$from, &$to);
switch ($key) {
case '-1':
// past
$to = strtotime('next hour');
break;
case '1':
// future
$from = strtotime('last hour');
break;
case '-7':
$from = strtotime('-1 week last monday midnight');
$to = strtotime('last sunday midnight');
break;
case '7':
$from = strtotime('last monday');
$to = strtotime('next sunday midnight');
break;
}
return $ret;
}
Depending on what you want to do, the search() in the model is not necessarily be the place you want to be looking. Here is a standard Yii query:
$model = WhateverModel::model()->findAll(array(
"condition" => "'.date('Y-m-d H:i:s' BETWEEN validRrom AND validTo).'",
));
You will have to give a bit more detail if you more detailed help :)