1. Osclass Forum
  2. Other
  3. My first try with DAO

My first try with DAO

Started by João Carrolo, September 26, 2019, 11:40 pm

  • 1

João Carrolo

My first try with DAO

on :September 26, 2019, 11:40 pm #29

Dear all.


Please see the attachment


The idea is get the all categories numbers from fk_i_category_id with s_plugin_name = skip_latest in table os_t_plugin_category.


so in model.php i create a function


Code: [Select]
​ public function take_category_name($catId){
$this->dao->select('s_plugin_name');
$this->dao->from(DB_TABLE_PREFIX.'t_plugin_category');
$this->dao->where('fk_i_category_id', $catId);
$result = $this->dao->get();
return $result->row();
}

 in index.php to call and get the data i use


Code: [Select]
$search_category_id = Model::newInstance()->take_category_name($search_category_name);

if ($result) {
$items = $result->result();
foreach ($items as $item) {
  var_dump($item);
 
}
}


What i need is for i can use is  $catId = 100, 101, 102, 103, 104, 105


this because i need to replace in theme functions.php


Code: [Select]
​$whe .= DB_TABLE_PREFIX.'t_item.fk_i_category_id NOT IN (140, 421, 611, 612, 613, 614, 422, 615, 618, 619, 620, 423, 621, 617, 616, 424, 622, 623, 624, 625, 425, 626, 627, 628, 608, 629, 630, 609, 631, 632, 633, 634, 610, 635, 637, 638, 636, 639, 640, 641, 642, 426) AND ';

by

Code: [Select]
​$whe .= DB_TABLE_PREFIX.'t_item.fk_i_category_id NOT IN (' . $catId . ' AND ';


This is a interesting excercise, i know i have allot of thinks wrong, please  try not yo laugh to much .




Thanks allot


Best Regards


calinbehtuk

Re: My first try with DAO

on :September 27, 2019, 8:26 am #30

I am confused a little!
What you try to achieve here? To display the items based on categories set in oc_t_plugin_category

João Carrolo

Re: My first try with DAO

on :September 27, 2019, 9:08 am #31

Avoid listings from selected categories be displayed in latest listings sections. And is working!!! 


If i add this line in theme function.php

Code: [Select]

$whe .= DB_TABLE_PREFIX.'t_item.fk_i_category_id NOT IN (140, 421, 611, 612, 613, 614, 422, 615, 618, 619, 620, 423, 621, 617, 616, 424, 622, 623, 624, 625, 425, 626, 627, 628, 608, 629, 630, 609, 631, 632, 633, 634, 610, 635, 637, 638, 636, 639, 640, 641, 642, 426) AND ';

With this line all listings from this categories numbers are not displayed in latest categoeies section...

What im trying to do now is make it as a pluging and im only missing this part where i need to read the categories ids.. when i archive that i only need to mark the categories and all listings that belong to that categories are not displayed in latest listings section...

Best regards

  • << Last edit: September 27, 2019, 9:10 am by calinbehtuk >>
  • Quote

calinbehtuk

Re: My first try with DAO

on :September 27, 2019, 10:49 am #32

They are many ways that you can do this.


Your code:

Code: [Select]
$categories = PluginCategory::newInstance()->listSelected('skip_latest');
$categ_list = implode(', ', $categories);
$whe .= DB_TABLE_PREFIX.'t_item.fk_i_category_id NOT IN (' . $categ_list . ') AND ';


My code:

Code: [Select]
​//MY CODE
$categories = PluginCategory::newInstance()->listSelected('skip_latest');
$categ_list = implode(', ', $categories);
$items = Item::newInstance()->listWhere("fk_i_category_id NOT IN($categ_list)", 30);
View::newInstance()->_exportVariableToView('latestItems', $items);


You can add this code before the code that display latest items.

João Carrolo

Re: My first try with DAO

on :September 29, 2019, 2:19 pm #47

Thanks allot for your tips, they are very usefull


I do it like this, i need to do it insite my random_items function inside functions.php


and now is working as expected

Code: [Select]
​  // START: Block to avoid listings from selected categories in plugin skip_latest be visualized in latest listings block
  $categories = PluginCategory::newInstance()->listSelected('skip_latest');
  $categ_list = implode(', ', $categories);

  if ($categ_list <> '' ) {
$whe .= DB_TABLE_PREFIX.'t_item.fk_i_category_id NOT IN ('. $categ_list . ') AND ';
  }
  // END: Block to avoid listings from selected categories in plugin skip_latest be visualized in latest listings block

One more time, tjhanks allot for your tips and help...



Best Regards

João Carrolo

Re: My first try with DAO

on :October 15, 2019, 12:58 pm #57

Hello...


This is the block suggested by you for latest listings 


//MY CODE
$categories = PluginCategory::newInstance()->listSelected('skip_latest');

$categ_list = implode(', ', $categories);
$items = Item::newInstance()->listWhere("fk_i_category_id NOT IN($categ_list)", 30);
View::newInstance()->_exportVariableToView('latestItems', $items); 


And for premium listings??? It's similar or different???


My problem is with this line because i cant use latestListings but something for premium listings

Code: [Select]
View::newInstance()->_exportVariableToView('latestItems', $items); 


Best Regards

  • << Last edit: October 15, 2019, 6:46 pm by calinbehtuk >>
  • Quote
  • 1
Subscribe
X

Subscribe!

Subscribe to get the latest listings, updates and special offers delivered directly in your inbox.