Database query inside content plugin

88 views
Skip to first unread message

Elvis

unread,
Apr 1, 2013, 8:11:06 AM4/1/13
to joomla-de...@googlegroups.com
Hi!

I've found an old content plugin for Joomla 1.5 and older version of K2, which I upgraded to work with latest versions of Joomla 2.5 and K2: https://github.com/esedic/k2autoarchiver/
Plugin works like this:

If we set an items' "Created date" time, and it's reached, then it
  • Moves the item in a given category
  • Moves it into trash
  • Deletes it permanently
  • Unpublishes it
The categories to work from can be set up using the plugin parameters.

Now I wanted to change this behavior and use K2 extra field value as criteria for manipulating K2 item's state.
Extra field data is written inside k2_items table in extra_field column like this:

[{"id":"12","value":"18"},{"id":"16","value":"2013-01-28"},{"id":"13","value":""},{"id":"14","value":""}]

I want to perform action based on value of the id:16.

So I started buy putting this code in content plugin file:

$db = JFactory::getDBO();
$db = JFactory::getDbo();
$query = $db->getQuery(true);
$query = "SELECT extra_fields FROM #__k2_items WHERE catid IN ({$sourcecat}) AND published = 1 AND trash = 0";
$db->setQuery($query);
$dateExtraFields = $db->loadObjectList();
dump($dateExtraFields);

$sourcecat is list of category id's to work with and is found in plugin parameters, I access this data with this line:
$sourcecat = trim($pluginparams->def('sourcecat'));

I'm trying to dump $dateExtraFields variable with J!Dump component.

And as result I get array, but it's displayed 6 times as you can see in these screenshots:




I don't know why is that happening, any suggestions?

Mark Dexter

unread,
Apr 1, 2013, 1:04:13 PM4/1/13
to joomla-de...@googlegroups.com
Hi. Have you tried running the query outside Joomla (using phpMyAdmin
or equivalent), just to make sure it works as expected? It would
appear that you have 6 matching rows for that query, so maybe there is
some other criteria you need. Good luck. Mark
> --
> You received this message because you are subscribed to the Google Groups
> "Joomla! General Development" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to joomla-dev-gene...@googlegroups.com.
> To post to this group, send an email to joomla-de...@googlegroups.com.
> Visit this group at
> http://groups.google.com/group/joomla-dev-general?hl=en-GB.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>

Elvis

unread,
Apr 3, 2013, 8:08:55 AM4/3/13
to joomla-de...@googlegroups.com
Yes I have tried query in PHPMyAadmin and it returns expected result which is 164 rows.
As you can see in the linked images I get 6 arrays with 164 rows instead of 1 array with 164 rows .

Fedir

unread,
Apr 4, 2013, 10:33:40 AM4/4/13
to joomla-de...@googlegroups.com
what told var_dump($sourcecat); ?

Середа, 3 квітня 2013 р. 15:08:55 UTC+3 користувач Elvis написав:

Fedir

unread,
Apr 4, 2013, 10:38:51 AM4/4/13
to joomla-de...@googlegroups.com
you code for build query looks very bad ;)

sorry,previous post I sent to fast :)


Четвер, 4 квітня 2013 р. 17:33:40 UTC+3 користувач Fedir написав:
Reply all
Reply to author
Forward
0 new messages