here is my code and my problem in comment line.
public function sonuc()
{
$config['total_rows'] = 5 //i want to set here count of result instead of digit. count($data['sonuc']) does not work.. what will i do?
$config['per_page'] = 2;
$data['sonuc'] = $this->emlak_model->arama(
$config['per_page'],
$this->uri->segment(3,0),
$this->input->post('semt'),
);
}
if i do it manually with digit, pagination will work, but i want to get total_row of query automatically, what will i do? thanks.
If you want a fresh count of your field on each page load,you have to count all your fields with a query count:
$total_rows = $this->db->count_all_results('mytable');
check the Codeigniter Doc
so according to your code:
public function sonuc()
{
$config['total_rows'] = $this->db->count_all_results('mytable'); //put your table name here
$config['per_page'] = 2;
$data['sonuc'] = $this->emlak_model->arama(
$config['per_page'],
$this->uri->segment(3,0),
$this->input->post('semt'),
);
}
Related
Newbie at codeigniter here. how can I save my total amount in my table per user? The only thing I did is to sum it and show it on my view. My target is to save the total commission on my "agent_commission" table". I have provided a screenshot of my target for better visualization. Thank you in advance. Any help will be appreciated.
Views:
<?php $formattedNum = number_format($commCurrentBalance, 2);
echo $formattedNum;
?
Controller:
public function commi()
{
$data['activeNav'] = "";
$data['subnav'] = "commissions";
$this->header($data);
$this->nav();
$data['currentPoints']=$this->session->userdata('currentPoints');
$data['result'] = $this->commissions->get1();
$data['commCurrentBalance']=$this->load->commissions->gettotalcommi(); //getting sum of amount
$this->load->view('comm_view', $data);
$this->footer();
}
Model:
function gettotalcommi(){
$reqcommi= $this->session->userdata('uid');
$this->db->select_sum('amount');
$this->db->where('commTo',$reqcommi);
$result = $this->db->get('agent_commission_history')->row();
return $result->amount;
}
I'm not sure if it will work but please try
$db->select_sum('amount');
$db->where('commTo',$param);
$aq = $db->get_compiled_select('agent_commission_history');
$db->set('commCurrentBalance',"($aq)",false);
$db->where('commTo',$param2);
$db->update('agent_commission');
This is the Codeigniter equivalent of the query I posted earlier:
UPDATE agent_commission
SET commCurrentBalance = ( SELECT SUM(amount) FROM agent_commission_history WHERE commTo = ?)
WHERE commTo = ?
public function commi(){
$data['commCurrentBalance']=$this->load->commissions->gettotalcommi(); //getting sum of amount
$dataArray = array(
'commCurrentBalance'=>$data['commCurrentBalance']
);
$this->db->insert('agent_commission',$dataArray);
$this->load->view('comm_view', $data);
$this->footer();
}
I am using Laravel Eloquent method to insert data to table, I want to increment invoice_no when user is admin, how can i achieve this with laravel Eloquent
$user = $request->input('user');
$add_order = new AddOrder;
if($user=="admin")
{
$add_order->invoice_no = 0;
//$add_order->invoice_no = "latest invoice_no in database + 1"
}
$add_order->invoice_prefix = 'NGW';
$add_order->store_name = 'Test Store';
$save_order = $add_order->save();
You have to do something like this.
$user = $request->input('user');
$add_order = new AddOrder;
$latestAddOrder = $add_order->latest()->first();
if($user=="admin"){
$add_order->invoice_no = $latestAddOrder->invoice_no + 1;
}
$add_order->invoice_prefix = 'NGW';
$add_order->store_name = 'Test Store';
$save_order = $add_order->save();
Here, I retrieved last row from the database.
I am using query string pagination. I have integrated this successfully. There are some issue with this.
when i click on second page first time it reloads the page but doesn't append ?per_page to the URL, it does appends like this controller/method/?2
when i click on second page second time it does the correct behavior but URL becomes like this controller/method/parameter/?0=&per_page=2
but the URL should be if there are not other get parameter
controller/method/parameter/?per_page=2
how to get this issue fixed ? i have enabled query string like this
$config['page_query_string'] = true;
$config['reuse_query_string'] = true;
Can anyone suggest what is the wrong in this implementation ? My base url is
$config['base_url'] = base_url().'controller/method/parameter/';
Basically it is not adding per_page query string if there is no query string already there in URL. How can i fix that ?
$config["total_rows"] = 200;
$config["per_page"] = 10;
$config['num_links'] = 4;
$config['page_query_string']= TRUE;
$config['use_page_numbers'] = TRUE;
$config["base_url"] = base_url().'controller/method/';
//Change uri segment according your url
$config["uri_segment"] = 3;
$this->pagination->initialize($config);
$links = $this->pagination->create_links();
Based on other stackoverflow posts, I've been able to use the following code to programmatically generate individual shopping cart price rule coupons in Magento.
How can I programmatically call the "Auto Generate Coupon" feature to create 100 unique coupons for each price rule I make? Thanks!
$coupon = Mage::getModel('salesrule/rule');
$coupon->setName($_coupon['name'])
->setDescription('this is a description')
->setFromDate(date('Y-m-d'))
->setCouponType(2)
->setCouponCode($_coupon['code'])
->setUsesPerCoupon(1000)
->setUsesPerCustomer(100)
->setCustomerGroupIds(array(1)) //an array of customer groupids
->setIsActive(1)
//serialized conditions. the following examples are empty
->setConditionsSerialized('a:6:{s:4:"type";s:32:"salesrule/rule_condition_combine";s:9:"attribute";N;s:8:"operator";N;s:5:"value";s:1:"1";s:18:"is_value_processed";N;s:10:"aggregator";s:3:"all";}')
->setActionsSerialized('a:6:{s:4:"type";s:40:"salesrule/rule_condition_product_combine";s:9:"attribute";N;s:8:"operator";N;s:5:"value";s:1:"1";s:18:"is_value_processed";N;s:10:"aggregator";s:3:"all";}')
->setStopRulesProcessing(0)
->setIsAdvanced(1)
->setProductIds('')
->setSortOrder(0)
->setSimpleAction('by_percent')
->setDiscountAmount(100)
->setDiscountQty(null)
->setDiscountStep('0')
->setSimpleFreeShipping('0')
->setApplyToShipping('0')
->setIsRss(0)
->setWebsiteIds(array(1));
$coupon->save();
For instance, this one price rule might have a whole list of Auto-Generated Coupon Codes (htgf-7774, htgf-2345, etc) using the function that is available when manually creating price rules in the admin panel.
EDIT:
I've gotten closer, using the following code. Still don't know how to specifically assign the auto generation pattern
->setName('Name')
->setDescription('this is a description')
->setFromDate('2013-03-06')
->setToDate(NULL)
->setUsesPerCustomer('100')
->setIsActive('1')
->setConditionsSerialized('a:6:{s:4:"type";s:32:"salesrule/rule_condition_combine";s:9:"attribute";N;s:8:"operator";N;s:5:"value";s:1:"1";s:18:"is_value_processed";N;s:10:"aggregator";s:3:"all";}')
->setActionsSerialized('a:6:{s:4:"type";s:40:"salesrule/rule_condition_product_combine";s:9:"attribute";N;s:8:"operator";N;s:5:"value";s:1:"1";s:18:"is_value_processed";N;s:10:"aggregator";s:3:"all";}')
->setStopRulesProcessing('0')
->setIsAdvanced('1')
->setProductIds(NULL)
->setSortOrder('0')
->setSimpleAction('by_percent')
->setDiscountAmount('100.0000')
->setDiscountQty(NULL)
->setDiscountStep('0')
->setSimpleFreeShipping('0')
->setApplyToShipping('0')
->setTimesUsed('1')
->setIsRss('0')
->setCouponType('2')
->setUseAutoGeneration('1')
->setUsesPerCoupon('1000')
->setCustomerGroupIds(array('1',))
->setWebsiteIds(array('1',))
->setCouponCode(NULL)
Thanks to a nifty post I found while googling this (http://fragmentedthought.com/fragments/programatically-creating-sales-rule-coupon-code), I answered my own question:
// Get the rule in question
$rule = Mage::getModel('salesrule/rule')->load(21); //21 = ID of coupon in question
// Define a coupon code generator model instance
// Look at Mage_SalesRule_Model_Coupon_Massgenerator for options
$generator = Mage::getModel('salesrule/coupon_massgenerator');
$parameters = array(
'count'=>5,
'format'=>'alphanumeric',
'dash_every_x_characters'=>4,
'prefix'=>'ABCD-EFGH-',
'suffix'=>'-WXYZ',
'length'=>8
);
if( !empty($parameters['format']) ){
switch( strtolower($parameters['format']) ){
case 'alphanumeric':
case 'alphanum':
$generator->setFormat( Mage_SalesRule_Helper_Coupon::COUPON_FORMAT_ALPHANUMERIC );
break;
case 'alphabetical':
case 'alpha':
$generator->setFormat( Mage_SalesRule_Helper_Coupon::COUPON_FORMAT_ALPHABETICAL );
break;
case 'numeric':
case 'num':
$generator->setFormat( Mage_SalesRule_Helper_Coupon::COUPON_FORMAT_NUMERIC );
break;
}
}
$generator->setDash( !empty($parameters['dash_every_x_characters'])? (int) $parameters['dash_every_x_characters'] : 0);
$generator->setLength( !empty($parameters['length'])? (int) $parameters['length'] : 6);
$generator->setPrefix( !empty($parameters['prefix'])? $parameters['prefix'] : '');
$generator->setSuffix( !empty($parameters['suffix'])? $parameters['suffix'] : '');
// Set the generator, and coupon type so it's able to generate
$rule->setCouponCodeGenerator($generator);
$rule->setCouponType( Mage_SalesRule_Model_Rule::COUPON_TYPE_AUTO );
// Get as many coupons as you required
$count = !empty($parameters['count'])? (int) $parameters['count'] : 1;
$codes = array();
for( $i = 0; $i < $count; $i++ ){
$coupon = $rule->acquireCoupon();
$code = $coupon->getCode();
$codes[] = $code;
}
return $codes;
This successfully generated the following codes:
ABCD-EFGH-ZC6V-ZJWD-WXYZ
ABCD-EFGH-4XMX-353L-WXYZ
ABCD-EFGH-XCJB-5GQI-WXYZ
ABCD-EFGH-UEAO-L1NJ-WXYZ
ABCD-EFGH-59B3-50T2-WXYZ
I want to create some kind of sitemap in extbase/fluid (based on the pagetree). I have loaded the pages table into a model:
config.tx_extbase.persistence.classes.Tx_MyExt_Domain_Model_Page.mapping.tableName = pages
I have created a controller and repository, but get stuck on the part wich can load the subpages as relation into my model.
For example:
$page = $this->pageRepository->findByPid($rootPid);
Returns my rootpage. But how can I extend my model that I can use $page->getSubpages() or $page->getNestedPages()?
Do I have to create some kind of query inside my model? Or do I have to resolve this with existing functions (like the object storage) and how?
I tried a lot of things but can simply figure out how this should work.
you have to overwrite your findByPid repository-method and add
public function findByPid($pid) {
$querySettings = $this->objectManager->create('Tx_Extbase_Persistence_Typo3QuerySettings');
$querySettings->setRespectStoragePage(FALSE);
$this->setDefaultQuerySettings($querySettings);
$query = $this->createQuery();
$query->matching($query->equals('pid', $pid));
$pages = $query->execute();
return $pages;
}
to get all pages. Than you can write your own getSubpages-method like
function getSubpages($currentPid) {
$subpages = $this->pagesRepository->findByPid($currentPid);
if (count($subpages) > 0) {
$i = 0;
foreach($subpages as $subpage) {
$subpageUid = $subpage->getUid();
$subpageArray[$i]['page'] = $subpage;
$subpageArray[$i]['subpages'] = $this->getSubpages($subpageUid);
$i++;
}
} else {
$subpageArray = Array();
}
return $subpageArray;
}
i didn't test this method, but it looks like this to get alle subpages.
i wonder that i couldĀ“t find a typo3 method that return the complete Page-Tree :( So i write a little function (you can use in an extbase extension), for sure not the best or fastes way, but easy to extend or customize ;)
first you need an instance of the PageRepository
$this->t3pageRepository = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Frontend\\Page\\PageRepository');
this->t3pageRepository->init();
make the init, to set some basic confs, like "WHERE deletet = 0 AND hidden = 0..."
then with this function you get an array with the page data and subpages in. I implement yust up to three levels:
function getPageTree($pid,$deep=2){
$fields = '*';
$sortField = 'sorting';
$pages = $this->t3pageRepository->getMenu($pid,$fields,$sortField);
if($deep>=1){
foreach($pages as &$page) {
$subPages1 = $this->t3pageRepository->getMenu($page['uid'],$fields,$sortField);
if(count($subPages1)>0){
if($deep>=2){
foreach($subPages1 as &$subPage1){
$subPages2 = $this->t3pageRepository->getMenu($subPage1['uid'],$fields,$sortField);
if(count($subPages2>0)){
$subPage1['subpages'] = $subPages2;
}
}
}
$page['subpages'] = $subPages1;
}
}
}
return $pages;
}