1 personman Dec 08, 2006 19:39
3 personman Dec 16, 2006 14:53
I should clarify. It's not the overriding that is really giving me the problem. It's no problem to create my own ItemList object using the standard method and call it $MainList. The problem is that I want to create th ItemList object using a completely custom method, viz. I'm using a separate sql table to decide which items make it into the list.
I'll add another option to my list above. YaBBa thought it already worked like this, but neither of us can find it.
c) Create an empty ItemList object, then add items to it one at a time like this: $MainList->add($item); where $item is either an Item object or an item id number.
4 balupton Dec 16, 2006 15:14
This should do it
global $MainList;
// Make a list of Item Rows
$rows = array();
// Get the Item
$Item_row = /* code goes here to get the database row of the item */;
$rows[] = $Item_row;
// Merge the rows
$MainList->rows = $rows;
$MainList->result_num_rows += sizeof($rows);
// Create the Objs
$i = 0;
foreach( $rows as $row )
{
// Prebuild object:
$MainList->Obj[$i] = new $MainList->objType( $row, $MainList->dbtablename, $MainList->dbprefix, $MainList->dbIDname ); // COPY!!
// To avoid potential future waste, cache this object:
$MainList->DataObjectCache->add( $MainList->Obj[$i] );
// Make a list of posts for future queries!
array_unshift( $MainList->postIDarray, $row->{$MainList->dbIDname} ); // new row at beginning (fplanque>>why?)
$i++;
}
// Update the categories to suit the new posts
cat_load_postcats_cache();
Edit: made a few updates.
Edit: another fix
5 personman Dec 16, 2006 15:40
I tried out your code:
6 balupton Dec 16, 2006 16:07
Yeh that code was a quick put together.
Here's the latest code i've used (it's working fine right now for me in my own plugin), you will need to adapt it appropriatly, and probably just use [] = , instead of array_unshift.
// Get the sticky post status id and restrict
$mysql_query =
'SELECT * '.
'FROM evo_posts '.
'WHERE `'.$MainList->dbprefix.'ptyp_ID` = '.$DB->quote($this->Sticky->ID).' '.
'ORDER BY post_datestart DESC';
$rows = $DB->get_results( $mysql_query, OBJECT, 'Get Sticky Posts' );
$rows_size = sizeof($rows);
// Create the Objs
for (
$i = 0, $n = $rows_size;
$i < $n;
$i++
)
{
# Get the row
$row = $rows[$i];
$row_exists = array_search($row, $MainList->rows);
# Prepend the item
// Prepend the row
array_unshift( $MainList->rows, $row );
// Create the Obj
$Obj = new $MainList->objType($row, $MainList->dbtablename, $MainList->dbprefix, $MainList->dbIDname);
// Append the object
array_unshift( $MainList->Obj, $Obj );
// Make a list of posts for future queries!
array_unshift( $MainList->postIDarray, $Obj->ID );
# If the row existed already then lets remove it
if ( $row_exists )
{
$row_exists++; // To accomadate for the newly added row
unset($MainList->rows[$row_exists]);
unset($MainList->Obj[$row_exists]);
unset($MainList->postIDarray[array_search($Obj->ID, $MainList->postIDarray)]);
}
}
$MainList->result_num_rows = sizeof($MainList->rows);
if( !empty($MainList->postIDarray) )
{
$MainList->postIDlist = implode( ',', $MainList->postIDarray );
}
7 personman Dec 16, 2006 16:18
It works. Well done and thank you.
8 balupton Dec 16, 2006 16:24
It works. Well done and thank you.
Thanks. :)
And you may want to update the select (if you are using my select) to something like this;
// Get the sticky post status id and restrict
$mysql_query =
'SELECT * '.
'FROM '.$MainList->ItemQuery->dbtablename.' '.
'INNER JOIN T_postcats ON '.$MainList->ItemQuery->dbIDname.' = postcat_post_ID '.
'INNER JOIN T_categories ON postcat_cat_ID = cat_ID '.
'WHERE `'.$MainList->dbprefix.'ptyp_ID` = '.$DB->quote($this->Sticky->ID).' '.
'AND '.statuses_where_clause('', $MainList->ItemQuery->dbprefix, $MainList->ItemQuery->blog).' '.
'AND cat_blog_ID = '.$MainList->ItemQuery->blog.' '.
'ORDER BY post_datestart ASC';
9 personman Dec 16, 2006 16:25
Nah, I've already replaced your query with mine.
Not sure if this has anything to do with what you want, but what i'm doing with a plugin right now, is create a $MainList / ItemList and then merge it's $Blah->rows with $MainList->rows, then kill my one. My one will be local.