• Hello Fabrik Community

    Fabrik is now in the hands of the development team that brought you Fabrik for Joomla 4. We have recently transitioned the Fabrik site over to a new server and are busy trying to clean it up. We have upgraded the site to Joomla 4 and are running the latest version of Fabrik 4. We have also upgraded the Xenforo forum software to the latest version. Many of the widgets you might have been used to on the forum are no longer operational, many abandoned by the developers. We hope to bring back some of the important ones as we have time.

    Exciting times to be sure.

    The Fabrik 4.0 Official release is now available. In addition, the Fabrik codebase is now available in a public repository. See the notices about these in the announcements section

    We wish to shout out a very big Thank You to all of you who have made donations. They have really helped. But we can always use more...wink..wink..

    Also a big Thank You to those of you who have been assisting others in the forum. This takes a very big burden off of us as we work on bugs, the website and the future of Fabrik.

Automatic conditional row numbering

dimoss

Well-Known Member
Hi,

I am using the Php Events List plugin using the following code inside onLoadDat to autonumber the records of a list:
PHP:
$rownum = $model->limitStart;
$data = $args[0]->data;
foreach ($data as $group) {
   foreach ($group as $row) {
      $rownum++;
      $row->fab_list_able_28_repeat___no = $rownum;
      $row->fab_list_able_28_repeat___no_raw = $rownum;
   }
}
The 'fab_list_able_28_repeat___no' is a single field hidden which is used only for diplaying the row number.
Everything is fine and works as expected.
However I cannot find a way do not numbering rows when the value in the field fab_list_able_28_repeat___wl_raw is 'NER' or 'WDL'
In other words I am trying to have a conditional numbering.

Any ideas are appreciated.

Thanks.
 
Hi Troester,
thanks for that. It worked!

For anyone who might need something similar here is the complete code:
PHP:
$rownum = $model->limitStart;
$data = $args[0]->data;
foreach ($data as $group) {
   foreach ($group as $row) {
   $condition = $row->fab_list_able_28_repeat___wl_raw;
      if ($condition == 'NER' || $condition == 'WDN') continue;
      $rownum++;
      $row->fab_list_able_28_repeat___no = $rownum;
      $row->fab_list_able_28_repeat___no_raw = $rownum;
   }
}
 
Hi,

i open this thread because i would like to find a way using the PHP list plugin to apply the same method updating another field.
Tried this but didnt work:
PHP:
$db = JFactory::getDBO();
$query = $db->getQuery(true);
$app = JFactory::getApplication();
$rownum = $model->limitStart;
$data = $args[0]->data;
foreach ($data as $group) {
   foreach ($group as $row) {
   $condition = $row->fab_list_able_28_repeat___wl_raw;
      if ($condition == 'NER' || $condition == 'WDN') continue;
      $rownum++;
      $row->fab_list_able_28_repeat___no = $rownum;
      $row->fab_list_able_28_repeat___no_raw = $rownum;
$query = "UPDATE fab_list_able_28_repeat SET position = $rownum";
$db->setQuery( $query );
$db->execute();
   }
}

Any idea?
Thanks.
 
A couple of ideas.

It's not "in the way", but what do you need $app for?
Which plugin are you using? You say "PHP List plugin", but it rather seems to be the "PHP Events list plugin"?If (if!) this would work, it would update all "position" cells in the repeat table to that same $rownum value, and each time the condition allows it. Is that what you really want?
Eventually move $query = $db->getQuery(true); into the loop.
Syntax error?
$query = "UPDATE fab_list_able_28_repeat SET position = $rownum";
should probably be
$query = "UPDATE fab_list_able_28_repeat SET position = '{$rownum}'";
or
$query = "UPDATE fab_list_able_28_repeat SET position = ".$rownum;
or
$query = "UPDATE fab_list_able_28_repeat SET position = '$rownum'";
or
$query = "UPDATE fab_list_able_28_repeat SET position = '".$rownum."'";

Sorry, I feel it must be said again: before posting basic "generic" PHP code which "doesn't work" here in the Fabrik forum, please first make sure that you've followed all coding rules, use correct syntax, and so on. Error reporting will help you, as well as var_dump($xyz);exit; and other debugging to avoid using fellow forum members as spellcheckers or free workers -- thank you. ;)
 
Hi @lousyfool

I use PHP list plugin and in every case returns 0 instead of the number.
If you read the previous messages it works fine in PHP Event on load but this for a different purposes as it is created on the fly.
What I want is to use the same loop and update each record.
And yes, there was typo (thanks for that) but unfortunately that was irrelevant.
 
As I said: I think there's no $args[0]->data in list php plugin.

Use var_dump to check and see WIKI for selected row ids and data.
 
Wiki helped :)

PHP:
$app = JFactory::getApplication();
$ids = $app->input->get('ids', array(), 'array');
$count = 0;
foreach($ids as $id)
{
  $count = $count + 1;
  $model->updateRow($id, "fab_doubles.position", $count);
}

In case someone is interested.
 
We are in need of some funding.
More details.

Thank you.

Members online

Back
Top