how to check array in where condition in codeigniter? - sql

in code igniter a group of student details check in fore-each loop ,the student get by the bases of student admission number
my admission numbers are in $ad_no=$this->input->post('adn_no'); :-
array(5) { [0]=> string(5) "11784" [1]=> string(5) "11837" [2]=>
string(5) "11775" [3]=> string(5) "11937" [4]=> string(5) "12061" }
i try to select these admission numbers student, but the result show only first student result
.
my code:
foreach($ad_no as $key => $id) {
$this - > db - > where_in('ad_no', $id);
$query = $this - > db - > get('duration');
$r = $query - > result_array();
$dur = $r[0]['tot_hr'];
$start = explode(':', $dur);
$end = explode(':', $tm);
$total_hours = $start[0] - $end[0];
$total_hours1 = $start[1] - $end[1];
$mins = abs($total_hours1);
$dur = $total_hours.":".$mins;
$durs[$key] =
array(
'ad_no' => $ad_no[$key],
'tot_hr' => $dur
);
}
$reslt = $this - > Daily_temp_model - > duration($durs);

using array push in foreach loop
$result=[];
foreach($ad_no as $key => $id) {
$this->db->where_in('ad_no', $id);
$query = $this-> db-> get('duration');
$r = $query-> result_array();
array_push($result, $r);
$dur = $r[0]['tot_hr'];
$start = explode(':', $dur);
$end = explode(':', $tm);
$total_hours = $start[0] - $end[0];
$total_hours1 = $start[1] - $end[1];
$mins = abs($total_hours1);
$dur = $total_hours.":".$mins;
$durs[$key] =
array(
'ad_no' => $ad_no[$key],
'tot_hr' => $dur
);
}
$reslt = $this->Daily_temp_model->duration($durs);

using in_array
<?php
$a = array('1.10', 12.4, 1.13);
if (in_array('12.4', $a, true)) {
echo "'12.4' found with strict check\n";
}
if (in_array(1.13, $a, true)) {
echo "1.13 found with strict check\n";
}
?>

Related

Get database records in TYPO3 viewHelper

I want to create a database query in a view helper, this works with the following code:
$uid = 11;
$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('tx_test_domain_model_author');
$query = $queryBuilder
->select('*')
->addSelectLiteral(
$queryBuilder->expr()->count('tx_test_domain_model_author.author', 'counter')
)
->from('tx_test_domain_model_author')
->join(
'tx_test_domain_model_author',
'tx_test_publication_author_mm',
'tx_test_publication_author_mm',
$queryBuilder->expr()->eq(
'tx_test_domain_model_author.uid',
$queryBuilder->quoteIdentifier('tx_test_publication_author_mm.uid_foreign')
)
)
->where(
$queryBuilder->expr()->eq(
'tx_test_publication_author_mm.uid_local',
$queryBuilder->createNamedParameter($uid, \PDO::PARAM_INT)
)
)
->orderBy('tx_test_domain_model_author.uid', 'ASC');
$result = $query->execute();
$res = [];
while ($row = $result->fetch()) {
$res[] = $row;
}
print_r($res);
However, I only get one record, although the counter tells me it would be 3.
What am I doing wrong?
If the counter says its three items, then try change this:
$result = $query->execute();
$res = [];
while ($row = $result->fetch()) {
$res[] = $row;
}
into this:
$result = $query->execute()->fetchAll();
That fetches all rows into an array that you walk throug with:
foreach($result as $row){
...
}
It seems the QueryBuilder works differently, this gives me one result namely the first entry in the table:
$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('tx_test_publication_author_mm');
$query = $queryBuilder
->select('*')
->from('tx_test_publication_author_mm');
$result = $query->execute()->fetchAll();
foreach($result as $row){
echo $row['field'];;
}
This gives me all results:
$db = mysqli_connect($dbHost, $dbUser, $dbPassword, $dbName) or die (mysql_error ());
$sql = "SELECT * FROM tx_test_publication_author_mm";
foreach ($db->query($sql) as $row) {
echo $row['field'];
}

Creating a RSS feed for several selected categories

If I do this http://www.website.com/index.php?page=search&sCategory=123&sFeed=rss
I can create a RSS feed for a particular category. But what if I want to create a RSS feed for several selected categories? is it possible? OSClass version is 3.3.2
I didnt find a short or integrated way to do it, so I coded it.
<?php
define('ABS_PATH', str_replace('\\', '/', dirname($_SERVER['SCRIPT_FILENAME']) . '/'));
if(PHP_SAPI==='cli') {
define('CLI', true);
}
require_once ABS_PATH . 'oc-load.php';
$mSearch = Search::newInstance();
$array_categorias = array("16","22","23","24","31","33","43","102","119","121","122","123","124");
$aItems = $mSearch->doCustomSearch($array_categorias);
View::newInstance()->_exportVariableToView('items', $aItems);
// FEED REQUESTED!
header('Content-type: text/xml; charset=utf-8');
$feed = new RSSFeed;
$feed->setTitle(__('Latest listings added') . ' - ' . osc_page_title());
$feed->setLink(osc_base_url());
$feed->setDescription(__('Latest listings added in') . ' ' . osc_page_title());
$contador_items = osc_count_items();
if(osc_count_items()>0) {
while(osc_has_items()) {
if(osc_count_item_resources() > 0){
osc_has_item_resources();
$feed->addItem(array(
'title' => osc_item_title(),
'link' => htmlentities( osc_item_url(), ENT_COMPAT, "UTF-8" ),
'description' => osc_item_description(),
'dt_pub_date' => osc_item_pub_date(),
'image' => array( 'url' => htmlentities(osc_resource_thumbnail_url(), ENT_COMPAT, "UTF-8"),
'title' => osc_item_title(),
'link' => htmlentities( osc_item_url() , ENT_COMPAT, "UTF-8") )
));
} else {
$feed->addItem(array(
'title' => osc_item_title(),
'link' => htmlentities( osc_item_url() , ENT_COMPAT, "UTF-8"),
'description' => osc_item_description(),
'dt_pub_date' => osc_item_pub_date()
));
}
}
}
$feed->dumpXML();
?>
I also had to add a couple of custom methods to the search model
public function _makeSQLCustomCategories($categories)
{
$cadena_select = DB_TABLE_PREFIX."t_item.*, ".DB_TABLE_PREFIX."t_item.s_contact_name as s_user_name,";
$cadena_select = $cadena_select . DB_TABLE_PREFIX. "t_item_description.s_title, ";
$cadena_select = $cadena_select . DB_TABLE_PREFIX. "t_item_description.s_description";
$this->dao->select($cadena_select);
$this->dao->from( DB_TABLE_PREFIX.'t_item' );
$this->dao->from( DB_TABLE_PREFIX. 't_item_description');
$this->dao->where(DB_TABLE_PREFIX. 't_item_description.fk_i_item_id = '. DB_TABLE_PREFIX. 't_item.pk_i_id');
//$this->dao->where(DB_TABLE_PREFIX. 't_item.b_premium = 1');
$this->dao->where(DB_TABLE_PREFIX. 't_item.b_enabled = 1');
$this->dao->where(DB_TABLE_PREFIX. 't_item.b_active = 1');
$this->dao->where(DB_TABLE_PREFIX. 't_item.b_spam = 0');
$where_categorias = "(";
$contador_categorias = 0;
$tamano_categories = sizeof($categories);
foreach ($categories as $categoria)
{
$contador = $contador + 1;
$where_categorias = $where_categorias. DB_TABLE_PREFIX. 't_item.fk_i_category_id = ' . $categoria ;
if ($contador == $tamano_categories)
break;
$where_categorias = $where_categorias . " OR ";
}
$where_categorias = $where_categorias . ")";
$this->dao->where($where_categorias );
$this->dao->groupBy(DB_TABLE_PREFIX.'t_item.pk_i_id');
$this->dao->orderBy(DB_TABLE_PREFIX. 't_item.pk_i_id', 'DESC');
$sql = $this->dao->_getSelect();
// reset dao attributes
$this->dao->_resetSelect();
return $sql;
}
public function doCustomSearch($categories, $extended = true, $count = true)
{
$sql = $this->_makeSQLCustomCategories($categories);
$result = $this->dao->query($sql);
if($count) {
$sql = $this->_makeSQLCustomCategories($categories);
$datatmp = $this->dao->query( $sql );
if( $datatmp == false ) {
$this->total_results = 0;
} else {
$this->total_results = $datatmp->numRows();
}
} else {
$this->total_results = 0;
}
if( $result == false ) {
return array();
}
if($result) {
$items = $result->result();
} else {
$items = array();
}
if($extended) {
return Item::newInstance()->extendData($items);
} else {
return $items;
}
}

send payments to faucetbox

I have try to do my self this code to implement the automatic send bitcoin payments to faucet box but is some errors there I need help with.
and it give me this error
The bitcoinrotator.publiadds.org.pt page is not working bitcoinrotator.publiadds.org.pt can not process this request for time. 500
<?php
//custom parameters
$api_key = "my_api_key";
$userAddy = $_SESSION['user'];
require_once("faucetbox.php");
$currency = "BTC"; # or LTC or any other supported by FaucetBOX
$faucetbox = new FaucetBOX($api_key, $currency);
$users = array(
'user_id' => clean($user_id),
'user_name' => clean($user_name),
'user_email' => clean($user_email),
'user_pass' => clean($user_pass),
'user_points' => clean($user_points),
'user_wallet' => clean($user_wallet)
);
session_start();
include_once 'dbconnect.php';
if(!isset($_SESSION['user']))
{
header("Location: index.php");
}
$selfNav = mysqli_query($conn, "SELECT user_wallet, user_points FROM users WHERE user_id=".$_SESSION['user']);
$rowNav = mysqli_num_rows($selfNav);
$rowAssoc = mysqli_fetch_assoc($selfNav);
$balance = $rowAssoc['user_points'];
$wallet = $rowAssoc['user_wallet'];
//auto cashout if bal over 0.00010000
if($balance > 0.00010000){
$amount = $rowAssoc['user_points'];
$currency = "BTC";
$faucetbox = new Faucetbox($api_key, $currency);
$result = $faucetbox->send($wallet, $amount);
if($result["success"] === true){
$_SESSION['cashout'] = $result["html"];
//reset balance to zero
mysqli_query($conn, "UPDATE `users` SET user_points = 0 WHERE user_id = " . $_SESSION['user')];
header('Location: ../home.php');
?>
well there it is its work but it stay with some bug there but now its work
the error is
Array ( [user_wallet] => 111111111111111111111111111111111111 [user_points] => 0.00000010 ) Error en balance
<?php
session_start();//Session start is ALWAYS the first thing to do.
if(!isset($_SESSION['user']))
{
header("Location: index.php"); //Sending headers its the next thing to do. Always.
}
include_once 'dbconnect.php';
//custom parameters
$api_key = "my_api_key";
$userAddy = $_SESSION['user'];
require_once("faucetbox.php");
$currency = "BTC"; # or LTC or any other supported by FaucetBOX
$faucetbox = new FaucetBOX($api_key, $currency);
//$users = array(
// 'user_id' => clean($user_id),
// 'user_name' => clean($user_name),
// 'user_email' => clean($user_email),
// 'user_pass' => clean($user_pass),
// 'user_points' => clean($user_points),
// 'user_wallet' => clean($user_wallet)
//);
//You are mixing mysql and mysqli, you need to choose one. Since you are on a shared hosting, mysqli is probably
//not installed/available, so we will keep using mysql. mysqli is safer!
$selfNav = mysql_query("SELECT user_wallet, user_points FROM users WHERE user_id=".$_SESSION['user']);
$rowNav = mysql_num_rows($selfNav);
$rowAssoc = mysql_fetch_assoc($selfNav);
print_r($rowAssoc);
$balance = $rowAssoc['user_points'];
$wallet = $rowAssoc['user_wallet'];
//auto cashout if bal over 0.00010000
if($balance > 0.00010000){
$amount = $rowAssoc['user_points'];
$currency = "BTC";
$result = $faucetbox->send($wallet,$amount); //$amount);
if($result["success"] === true){
$_SESSION['cashout'] = $result["html"];
//reset balance to zero
mysql_query("UPDATE `users` SET user_points = 0 WHERE user_id = " . $_SESSION['user']);
echo "result sucess and location go";
//header('Location: ../home.php');
}else{
echo "Error on faucet";
var_dump($result);
//What happens if there is an error?
}
}else{
echo "do not have enough credit to cash out";
//what happens if they dont have enough balance?
}
?>

How to add a variable to the form so that it is then added to the database (paypal script)?

I would like to add a variable to paypal payment form. Then I would like it to be added to the database . The variable is called "membre_id" (user ID) and is found in the $_SESSION['membre_id'].
Here's the code of form processing :
<?php
require 'lib/init.php';
$action = isset($_POST['action']) ? $_POST['action'] : (isset($_GET['action']) ? $_GET['action'] : '');
if ( !empty($action) ) {
switch ( $action ) {
/***********************************************************************************************************************/
case 'paypal_ipn':
require ('lib/vendor/ipnlistener.php');
$listener = new IpnListener();
try {
$verified = $listener->processIpn();
if ( $verified ) {
// parse our custom field data
$custom = post('custom');
if ( $custom ) {
parse_str(post('custom'), $data);
} else {
$data = array();
}
// pull out some values
$payment_gross = post('payment_gross');
$item_name = post('item_name');
// build customer data
$name = isset($data['name']) && $data['name'] ? $data['name'] : null;
$name_arr = explode(' ', trim($name));
$first_name = $name_arr[0];
$last_name = trim(str_replace($first_name, '', $name));
$email = isset($data['email']) && $data['email'] ? $data['email'] : null;
$description = $item_name ? $item_name : 'no description entered';
$address = isset($data['address']) && $data['address'] ? $data['address'] : null;
$city = isset($data['city']) && $data['city'] ? $data['city'] : null;
$state = isset($data['state']) && $data['state'] ? $data['state'] : null;
$zip = isset($data['zip']) && $data['zip'] ? $data['zip'] : null;
$country = isset($data['country']) && $data['country'] ? $data['country'] : null;
// check for invoice first
if ( isset($data['invoice_id']) && $data['invoice_id'] ) {
$invoice = Model::factory('Invoice')->find_one($data['invoice_id']);
$amount = $invoice->amount;
$type = 'invoice';
$description = $invoice->description;
// now check for item
} elseif ( isset($data['item_id']) && $data['item_id'] ) {
$item = Model::factory('Item')->find_one($data['item_id']);
$amount = $item->price;
$type = 'item';
// check for input amount
} elseif ( $payment_gross ) {
$amount = $payment_gross;
$type = 'input';
// return error if none found
} else {
$amount = 0;
$type = '';
}
switch ( post('txn_type') ) {
case 'web_accept':
// save payment record
$payment = Model::factory('Payment')->create();
$payment->invoice_id = isset($invoice) ? $invoice->id : null;
$payment->name = $name;
$payment->email = $email;
$payment->amount = $amount;
$payment->description = isset($item) ? $item->name : $description;
$payment->address = $address;
$payment->city = $city;
$payment->state = $state;
$payment->zip = $zip;
$payment->country = $country;
$payment->type = $type;
$payment->paypal_transaction_id = post('txn_id');
$payment->save();
// update paid invoice
if ( isset($invoice) ) {
$invoice->status = 'Paid';
$invoice->date_paid = date('Y-m-d H:i:s');
$invoice->save();
}
// build email values first
$values = array(
'customer_name' => $payment->name,
'customer_email' => $payment->email,
'amount' => currency($payment->amount) . '<small>' . currencySuffix() . '</small>',
'description_title' => isset($item) ? 'Item' : 'Description',
'description' => $payment->description,
'payment_method' => 'PayPal',
'transaction_id' => $payment->paypal_transaction_id,
'url' => url(''),
);
email($config['email'], 'payment-confirmation-admin', $values, 'You\'ve received a new payment!');
email($payment->email, 'payment-confirmation-customer', $values, 'Thank you for your payment to ' . $config['name']);
break;
case 'subscr_signup':
try {
$unique_subscription_id = uniqid();
// save subscription record
$subscription = Model::factory('Subscription')->create();
$subscription->unique_id = $unique_subscription_id;
$subscription->paypal_subscription_id = post('subscr_id');
$subscription->name = $name;
$subscription->email = $email;
$subscription->address = $address;
$subscription->city = $city;
$subscription->state = $state;
$subscription->zip = $zip;
$subscription->country = $country;
$subscription->description = isset($item) ? $item->name : $description;
$subscription->price = post('amount3');
$subscription->billing_day = date('j', strtotime(post('subscr_date')));
$subscription->length = $config['subscription_length'];
$subscription->interval = $config['subscription_interval'];
$subscription->trial_days = $config['enable_trial'] ? $config['trial_days'] : null;
$subscription->status = 'Active';
$subscription->date_trial_ends = $config['enable_trial'] ? date('Y-m-d', strtotime('+' . $config['trial_days'] . ' days')) : null;
$subscription->save();
$trial = $subscription->date_trial_ends ? ' <span style="color:#999999;font-size:16px">(Billing starts after your ' . $config['trial_days'] . ' day free trial ends)</span>' : '';
$values = array(
'customer_name' => $name,
'customer_email' => $email,
'amount' => currency(post('amount3')) . '<small>' . currencySuffix() . '</small>' . $trial,
'description_title' => isset($item) ? 'Item' : 'Description',
'description' => isset($item) ? $item->name : $description,
'payment_method' => 'PayPal',
'subscription_id' => $subscription->paypal_subscription_id,
'manage_url' => url('manage.php?subscription_id=' . $unique_subscription_id)
);
email($config['email'], 'subscription-confirmation-admin', $values, 'You\'ve received a new recurring payment!');
email($email, 'subscription-confirmation-customer', $values, 'Thank you for your recurring payment to ' . $config['name']);
} catch (Exception $e) {
}
break;
case 'subscr_cancel':
$subscription = Model::factory('Subscription')->where('paypal_subscription_id', post('subscr_id'))->find_one();
if ( $subscription ) {
$subscription->status = 'Canceled';
$subscription->date_canceled = date('Y-m-d H:i:s');
$subscription->save();
// send subscription cancelation email now
$values = array(
'customer_name' => $subscription->name,
'customer_email' => $subscription->email,
'amount' => currency($subscription->price) . '<small>' . currencySuffix() . '</small>',
'description' => $subscription->description,
'payment_method' => 'PayPal',
'subscription_id' => $subscription->paypal_subscription_id
);
email($config['email'], 'subscription-canceled-admin', $values, 'A recurring payment has been canceled.');
email($subscription->email, 'subscription-canceled-customer', $values, 'Your recurring payment to ' . $config['name'] . ' has been canceled.');
}
break;
case 'subscr_eot':
$subscription = Model::factory('Subscription')->where('paypal_subscription_id', post('subscr_id'))->find_one();
if ( $subscription && $subscription->status == 'Active' ) {
$subscription->status = 'Expired';
$subscription->date_canceled = null;
$subscription->save();
}
break;
}
} else {
die();
}
} catch (Exception $e) {
die();
}
break;
/***********************************************************************************************************************/
case 'paypal_success':
go('index.php#status=paypal_success');
break;
/***********************************************************************************************************************/
case 'paypal_subscription_success':
go('index.php#status=paypal_subscription_success');
break;
/***********************************************************************************************************************/
case 'paypal_cancel':
msg('You canceled your PayPal payment, no payment has been made.', 'warning');
go('index.php');
break;
/***********************************************************************************************************************/
case 'delete_payment':
if ( isset($_GET['id']) ) {
$payment = Model::factory('Payment')->find_one($_GET['id']);
$payment->delete();
}
msg('Payment has been deleted successfully.', 'success');
go('admin.php#tab=payments');
break;
/***********************************************************************************************************************/
case 'delete_subscription':
if ( isset($_GET['id']) ) {
$subscription = Model::factory('Subscription')->find_one($_GET['id']);
$subscription->delete();
}
msg('Subscription has been deleted successfully.', 'success');
go('admin.php#tab=subscriptions');
break;
/***********************************************************************************************************************/
case 'create_invoice':
if ( post('email') && post('amount') && post('description') ) {
$unique_invoice_id = uniqid();
$invoice = Model::factory('Invoice')->create();
$invoice->unique_id = $unique_invoice_id;
$invoice->email = post('email');
$invoice->description = post('description');
$invoice->amount = post('amount');
$invoice->number = post('number');
$invoice->status = 'Unpaid';
$invoice->date_due = post('date_due') ? date('Y-m-d', strtotime(post('date_due'))) : null;
$invoice->save();
}
$number = $invoice->number ? $invoice->number : $invoice->id();
if ( post('send_email') && post('send_email') ) {
$values = array(
'number' => $number,
'amount' => currency($invoice->amount) . '<small>' . currencySuffix() . '</small>',
'description' => $invoice->description,
'date_due' => !is_null($invoice->date_due) ? date('F jS, Y', strtotime($invoice->date_due)) : '<em>no due date set</em>',
'url' => url('?invoice_id=' . $unique_invoice_id)
);
email($invoice->email, 'invoice', $values, 'Invoice from ' . $config['name']);
$msg = ' and sent';
}
msg('Invoice has been created' . (isset($msg) ? $msg : '') . ' successfully.', 'success');
go('admin.php#tab=invoices');
break;
/***********************************************************************************************************************/
case 'delete_invoice':
if ( isset($_GET['id']) ) {
$invoice = Model::factory('Invoice')->find_one($_GET['id']);
$invoice->delete();
}
msg('Invoice has been deleted successfully.', 'success');
go('admin.php#tab=invoices');
break;
/***********************************************************************************************************************/
case 'add_item':
if ( post('name') && post('price') ) {
$item = Model::factory('Item')->create();
$item->name = post('name');
$item->price = post('price');
$item->save();
}
msg('Item has been added successfully.', 'success');
go('admin.php#tab=items');
break;
/***********************************************************************************************************************/
case 'edit_item':
if ( post('id') && post('name') && post('price') ) {
$item = Model::factory('Item')->find_one(post('id'));
$item->name = post('name');
$item->price = post('price');
$item->save();
}
msg('Item has been edited successfully.', 'success');
go('admin.php#tab=items');
break;
/***********************************************************************************************************************/
case 'delete_item':
if ( isset($_GET['id']) ) {
$item = Model::factory('Item')->find_one($_GET['id']);
$item->delete();
}
msg('Item has been deleted successfully.', 'success');
go('admin.php#tab=items');
break;
/***********************************************************************************************************************/
case 'save_config':
if ( post('config') && is_array(post('config')) ) {
foreach ( post('config') as $key => $value ) {
$config = Model::factory('Config')->where('key', $key)->find_one();
if ( $config ) {
$config->value = $value;
$config->save();
}
}
}
msg('Your settings have been saved successfully.', 'success');
go('admin.php#tab=settings');
break;
/***********************************************************************************************************************/
case 'login':
if (
post('admin_username') && post('admin_username') == $config['admin_username'] &&
post('admin_password') && post('admin_password') == $config['admin_password']
) {
// login successful, set session
$_SESSION['admin_username'] = $config['admin_username'];
} else {
// login failed, set error message
msg('Login attempt failed, please try again.', 'danger');
}
go('admin.php');
break;
/***********************************************************************************************************************/
case 'logout':
unset($_SESSION['admin_username']);
session_destroy();
session_start();
msg('You have been logged out successfully.', 'success');
go('admin.php');
break;
/***********************************************************************************************************************/
case 'install':
$status = true;
$message = '';
try {
$db = new PDO('mysql:host=' . $config['db_host'] . ';dbname=' . $config['db_name'], $config['db_username'], $config['db_password']);
$sql = file_get_contents('lib/sql/install.sql');
$result = $db->exec($sql);
} catch (PDOException $e) {
$status = false;
$message = $e->getMessage();
}
$response = array(
'status' => $status,
'message' => $message
);
header('Content-Type: application/json');
die(json_encode($response));
break;
/***********************************************************************************************************************/
}
}
There is a parameter in the API request called "custom". That's what you need to pass your data in and then it will come back within IPN as $_POST['custom']

(Magento 1.7) How to modify the report module?

I followed a tutorial to create report module and the tutorial show me exactly what I wanted. Now, I would like to modify the database into my database. There are two tables that I want to join (member_download and sales_payment). What should I modify from this code to link it into my database?
Here is the code:
<?php
class Wcl_ReportNewOrders_Model_Reportneworders extends Mage_Reports_Model_Mysql4_Product_Ordered_Collection
{
function __construct() {
parent::__construct();
}
protected function _joinFields($from = '', $to = '')
{
$this->addAttributeToSelect('name')
->addAttributeToSelect('increment_id')
->addOrderedQty($from, $to)
->setOrder('sku', self::SORT_ORDER_ASC);
//Mage::log('SQL: '.$this->getSelect()->__toString());
return $this;
}
public function addOrderedQty($from = '', $to = '')
{
$adapter = $this->getConnection();
$compositeTypeIds = Mage::getSingleton('catalog/product_type')->getCompositeTypes();
$orderTableAliasName = $adapter->quoteIdentifier('order');
$addressTableAliasName = 'a';
$downloadTableAliasName = 'download';
$orderJoinCondition = array(
$orderTableAliasName . '.entity_id = order_items.order_id',
$adapter->quoteInto("{$orderTableAliasName}.state = ?", Mage_Sales_Model_Order::STATE_PROCESSING),
);
$addressJoinCondition = array(
$addressTableAliasName . '.entity_id = order.shipping_address_id'
);
$downloadJoinCondition = array(
$downloadTableAliasName . '.order_id = order_items.order_id'
);
$productJoinCondition = array(
//$adapter->quoteInto('(e.type_id NOT IN (?))', $compositeTypeIds),
'e.entity_id = order_items.product_id',
$adapter->quoteInto('e.entity_type_id = ?', $this->getProductEntityTypeId())
);
if ($from != '' && $to != '') {
$fieldName = $orderTableAliasName . '.created_at';
$orderJoinCondition[] = $this->_prepareBetweenSql($fieldName, $from, $to);
}
$this->getSelect()->reset()
->from(
array('order_items' => $this->getTable('sales/order_item')),
array(
'qty_ordered' => 'order_items.qty_ordered',
'order_items_name' => 'order_items.name',
'order_increment_id' => 'order.increment_id',
'sku' => 'order_items.sku',
'type_id' => 'order_items.product_type',
'shipping_address_id' => 'order.shipping_address_id'
))
->joinInner(
array('order' => $this->getTable('sales/order')),
implode(' AND ', $orderJoinCondition),
array())
->joinLeft(
array('a' => $this->getTable('sales/order_address')),
implode(' AND ', $addressJoinCondition),
array(
'shipto_name' => "CONCAT(COALESCE(a.firstname, ''), ' ', COALESCE(a.lastname, ''))"
),
array())
->joinLeft(
array('e' => $this->getProductEntityTableName()),
implode(' AND ', $productJoinCondition),
array(
'created_at' => 'e.created_at',
'updated_at' => 'e.updated_at'
))
->where('parent_item_id IS NULL')
//->group('order_items.product_id')
->having('order_items.qty_ordered > ?', 0);
return $this;
}
public function addItem(Varien_Object $item)
{
$itemId = $this->_getItemId($item);
if (!is_null($itemId)) {
if (isset($this->_items[$itemId])) {
// Unnecessary exception - http://www.magentocommerce.com/boards/viewthread/10634/P0/
//throw new Exception('Item ('.get_class($item).') with the same id "'.$item->getId().'" already exist');
}
$this->_items[$itemId] = $item;
} else {
$this->_items[] = $item;
}
return $this;
}
}
Please tell me how to modify the database. I am new with magento. Thanks!
i checked your link that you provided. open file at below location
Wcl_ReportNewOrders_Block_Adminhtml_ReportNewOrders_Grid
below is the function where you can modify the database
protected function _prepareCollection() {
parent::_prepareCollection();
// Get the data collection from the model
$this->getCollection()->initReport('reportneworders/reportneworders');
return $this;
}
Replace the above code with below code
protected function _prepareCollection() {
parent::_prepareCollection();
$collection = $this->getCollection()->initReport('reportneworders/reportneworders');
/*
perform your desired operation here
// print_r((string)$collection->getSelect();
*/
$this->setCollection($collection);
return $this;
}