Jump to content
bernhard

RockFinder2 - combine the power of PW selectors and SQL

Recommended Posts

RockFinder2 is the successor to RockFinder v1 and while the changes might not look that big on first sight they are quite huge behind the scenes. In RockFinder1 I used some kind of custom query builder because I didn't know of PW's built in one (see later). RockFinder2 will exist besides RockFinder1 because I have several projects relying on RockFinder1, but for any future projects you should definitely use RockFinder2.

This is how RF2 builds the SQL query:

J1QrJBw.png

So this is really easy to grasp, easy to maintain and easy to extend (like aggregations, selecting distinct values etc).

RockFinder2 also comes with a custom UI where you can manage your Finders:

36WxYz9.png

You can then easily access those finders by name:

E4CSwbg.png

This is a soft alpha release. The module can be downloaded from https://github.com/BernhardBaumrock/RockFinder2 and the docs are at the moment a mess. I'll work on several useful examples in the next weeks that showcase all the features.

 

  • Like 25
  • Thanks 2

Share this post


Link to post
Share on other sites

Just added support to hide columns in the final output. Before I've always hidden those columns via JavaScript in the final table, but if you don't need them, why not removing them from the result before transmitting them to the client?

Now it is as simple as that - and the example also shows the new concept for single-page-reference joins which I really enjoy using as it is so much clearer than in RockFinder1:

$rf = new RockFinder2();
$rf->find('template=husband');
$rf->addColumns(['title', 'wife']); // wife is a single page reference

// find all wifes
$wives = new RockFinder2();
$wives->find("template=wife");
$wives->addColumns(['title']);
$rf->addJoin($wives, 'wife');

Result so far:

 id | title  | wife | wife:title
---------------------------------
 11 | John   | 22   | Sue

Hide the wife column (the page id of wife pagefield):

$rf->hideColumns(['wife']);
 id | title  | wife:title
--------------------------
 11 | John   | Sue

😎

  • Like 7

Share this post


Link to post
Share on other sites
14 hours ago, bernhard said:

Hide the wife

😎😎

Just kidding...I'm loving this module and the improvements! Great work :-).

  • Haha 3

Share this post


Link to post
Share on other sites

Thx @kongondo I'm also really loving it already. RockFinder1 felt complex in comparison and every added feature added more complexity to id. Now using the queryselector syntax things got a LOT easier and therefore a lot more solid, eg https://github.com/BernhardBaumrock/RockFinder2/commit/6ca0937a499259afe46745ef4cce4486fdc9443d

  • Like 3

Share this post


Link to post
Share on other sites

Pushed a fix for RockMarkup2 and related modules (RockTabulator) not working in subdir installations. RockFinder2 was also affected because of the wrong api endpoint url.

  • Like 2
  • Thanks 1

Share this post


Link to post
Share on other sites

Just added support for sending variables to getByName()

// RockTabulator grid setup, eg dogs.php
$dogs = new RockFinder2();
$dogs->getByName('animals', ['type' => 'dog']);
$grid->setData($dogs);

// finder setup, eg animals.php
if(!$type) $type = "cat|dog";
$rf = new RockFinder2();
$rf->find("template=$type");
return $rf;

Also added a simple orGroups() method (see https://github.com/processwire/processwire-requests/issues/331😞

$rf = new RockFinder2();

// setup selector
$selector = ['parent' => '/foo/bar'];

if($from AND $to) {
  // show items that are not in the future
  $selector[] = ['date_start', '<', $to];

  // show items that ended this year or not yet
  $rf->orGroup($selector, [
    ['date_end', '>=', $from],
    ['date_end', '=', ''],
  ]);
}

...

 

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...