Jump to content

[deprecated] RockFinder2


bernhard

Recommended Posts

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 8
Link to comment
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
Link to comment
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', '=', ''],
  ]);
}

...

 

  • Like 1
Link to comment
Share on other sites

  • 2 weeks later...

Now you can join any finder to any column of another finder. That's quite powerful but might also get complicated or slow... It's especially handy when you want to use RockFinder2 as datasource of a RockGrid, because RockGrid does not support the new concept of relations that where introduced to RockTabulator

https://github.com/BernhardBaumrock/RockFinder2/commit/8c6b66ad3dda68de9c1008078420f13a034250bf

 

  • Like 3
Link to comment
Share on other sites

  • 4 months later...

Hi @bernhard,

I gave this module a try to see if it might be a good way to get data for a CSV download (on the front-end). But I'm having trouble getting off the ground.

I installed the module, put some demo code in my template file...

$rf = new RockFinder2();
$rf->find("id>2, limit=5");
$rf->addColumns([
	'title',
	'modified',
]);

...and I get this error:

Call to a member function __invoke() on null

The same code seems to execute in the Tracy Console in the back-end without an error. Is this module only for use in the PW admin?

I had trouble understanding the GitHub readme - are those just notes to yourself? It wasn't clear to me how the SQL examples at the top of the readme relate to the module, and several of the code examples use "new RockFinder()" when this module class is RockFinder2. 

Update: fixed as per post below

Edited by Robin S
Link to comment
Share on other sites

  • 2 months later...

This error is fixed in v0.0.3 ? 

The reason was simply that RockFinder2 is autoload=admin, so on the frontend you need to do $modules->get('RockFinder2') before any new RockFinder2() statements.

  • Like 1
Link to comment
Share on other sites

@David Karich asked me how one can get values of an options field instead of an ID. It's unfortunately not implemented yet, but it can be quite easily be done manually (and that has the benefit of being extremely flexible and not limiting). I added an example to the readme!

Example of how to get values of an options field instead of their IDs:

$f = new RockFinder2();
$f->find('template=basic-page, include=all');
$f->addColumns(['title', 'options']);
$f->query->select("opt.value AS `options.value`");
$f->query->leftjoin("fieldtype_options AS opt ON opt.option_id = _field_options.data");
db($f->getData()->data);

img

Dumping the query object will be really helpful on such tasks!

img

You can also replace the field's value instead of adding it to the result:

$f = new RockFinder2();
$f->find('template=basic-page, include=all');
$f->addColumns(['title', 'options']);

$select = $f->query->select;
unset($select[2]);
$f->query->set('select', $select);


$f->query->select("opt.value AS `options`");
$f->query->leftjoin("fieldtype_options AS opt ON opt.option_id = _field_options.data");
db($f->query);
db($f->getData()->data);

img

  • Like 2
Link to comment
Share on other sites

Sorry, forgot to mention that @David Karich added support for options fields and slide ranges, so there is no need for manually doing joins like shown before ? 

How to create custom column types

It is really easy to create custom column types that can retrieve any data from the PW database. See this commit for two simple examples: https://github.com/BernhardBaumrock/RockFinder2/commit/54476a24c78ae4d3b6d00f8adfb2c8cd9d764b9d

If the fieldtype is of broader interest please consider making a PR. If you are the only one needing it add the type via hook.

Adding a custom column type is as simple as this:

$f->addColumns(['FieldOptionsValue:your_options_fieldname']);
  • Like 3
Link to comment
Share on other sites

  • 2 weeks later...

I can only thank @bernhard again for this module and for the support he provided, for example in finding a solution for option fields. RockFinder2 can not only be used to load masses of pages faster, it can also be used at field level. For example, I used it to load about 40 to 60 fields per repeater matrix type, which are also further nested in FieldsetPages (for design settings) in one query. This amount of fields caused 700 or more single SQL queries to be executed and up to 140 PW-Page objects to be loaded into RAM. This caused a significant loading delay. By using RockFinder2 the SQL queries could be reduced to 200 on average. About 60 page objects less are loaded in RAM, the CPU is also happy and the loading time for pages without cache was also reduced on average to 700 ms to 1 second. Good job Bernhard! ?

  • Like 6
  • Thanks 1
Link to comment
Share on other sites

  • 4 weeks later...

v0.0.5 adds column alias support for @David Karich s options field shortcut and adds another one to get the title instead of the options value:

Showing the title/value of selected options instead of ID values

Options fields store 3 things in the database: The ID of the option, the value of the option and the title (for each language) of the option:

img

There are two custom column types to get the value or the title of a selected options field:

img

img

  • Like 2
Link to comment
Share on other sites

v0.0.6 is out and adds support for dumping RockFinder to the tracy console. Important: This dumping feature does only work when you are on the tracy process module of RockFinder:

JcEItWg.png

d9VRDnp.png

PS: RockFinder3 is in the works ?

Link to comment
Share on other sites

6 minutes ago, kongondo said:

?? Seems like a major release :-D. What's up? ?

Basically just refactoring and getting rid of all the bloat that is in RockFinder2 that is not needed (process module for defining finders, the sandbox, etc).

The API and usage will not change drastically though. I'm quite confident that RockFinder3 will be the final version that will be there to stay ? And it will also come with proper docs ?

  • Like 4
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...