Search

Hey guys! I am right now developing my own custom datasource (or at least this is what I want). But found my self in the middle of nowhere and with really few documentation about.

Right now I'm facing a problem, and it's all about filtering a second non-custom datasource based on the results returned by the custom datasource, I know a lot happens behind the stage (in the server) before all the results are spitted out as XML, but then how can I filter a second datasource? Can anybody provide me with some lights to enlighten my road?

I'm working everything on a system-generated datasource -just to begin with-.

data source chaining is used for this in most cases.

maybe an concrete example will help us to find your problems in detail.

Here's the scenario:

  • I fetched the data I needed via a SQL query to the Symphony DB
  • I recreated the datasource structure (entry with id)
  • I then needed another datasource to return entries based on the entries id already available in the custom datasource
  • But it doesn't work. The filtering is not working.

For example, if I have

 `<entry id="392"/>
 <entry id="393"/>
 <entry id="394"/>
 <entry id="395"/>`

I then need another datasource to return the same entries but including all the fields. I think this may have to do with the parameters pool, but how do I pass arguments to the parameter pool if I'm modifying the common execute() function?

There is another issue (I need to solve the first before). It's about joining in the SQL the select box link in each of the items with its respective link. Any ideas on how to do this?

you don't use the admin webinterface for these tasks ? you are writing fetch/execute and all these thing by hand?

or am I complete wrong?

No, I'm not using the backend interface for this, since I need to do certain evaluations to each of the entries returned before returning a clean array with the final results. This is imposible to do it in the backend interface. All of this is by hand, that's why I need some help here to understand how the execute() function works.

I guess I have to pass some parameter to it in order to filter the second datasource... I'm not sure.

You should mainly just need two things: a dependency, and filters. You can set a dependency in the constructor method of the second datasource. Something like:

public function __construct(&$parent, $env=NULL, $process_params=true){
    parent::__construct($parent, $env, $process_params);
    $this->_dependencies = array('$ds-handle1', '$ds-handle2');
}

Before that you can set your filters:

public $dsParamFILTERS = array(
    '15' => '{key:value}',
    ...
);

In the public execute() method you can then run your custom logic to do whatever you need it to do and return the result. Keep the try/catch block in place and insert your logic into the try statement to be executed. It will failover to the catch block if no results were found or there was a problem.

The basic structure should be provided in the system generated datasource so you just need to flesh it out from there.

So, basically emulating the bascid structure is enough for the custom datasource to be seen as a "real" datasource? I'm right now just appending the nodes that match my criteria with $result->appendChild($tag_node);.

And what about the bunch of other public vars, like for example $dsParamSORT, should I reuse them or just ignore them?

I just discovered that the $param_pool can be changed, and that this is an associative array. How can I pass that IDs of my results for the system to take them in count? I tried $param_pool = array('72' => 'yes', 'system:id' => '298'); just to do a test but it didn't work.

Okay, I just solved this! I replaced the system:id in the $dsParamFILTERS array with a test ID $this->dsParamFILTERS['system:id'] = '298'; and it worked like a charm!

Damn, is hard to learn how to code for symphony without a clear documentation for dummies like me.

Thank you, guys!

However I still have an issue to solve here. In my custom datasource, if there are no results I think it should display then the no results XML structure, but instead it is displaying all the entries no matter what.

This is the code I'm using at the end of the try in the execute() function of my custom datasource:

$this->dsParamFILTERS['system:id'] = implode(',',$clean_results);
$result = parent::execute($param_pool);

Where the part implode(',',$clean_results); becomes a string with all the IDs of the resulted entries, for example: '235, 383, 421'. Of course that when the array doesn't contain any entry, it just becomes an empty string ' ';

When there are results it works great, but when there aren't any this just keeps throwing all the entries. I'm pretty sure it has to do with a datasource configuration matter but as far as for today I haven't had good luck finding it out. Any ideas?

Got to answer this myself. $this->_force_empty_result = true; forces the empty result.

You're better off using an if condition there like this:

if($this->_force_empty_result) $result = $this->emptyXMLSet();

Create an account or sign in to comment.

Symphony • Open Source XSLT CMS

Server Requirements

  • PHP 5.3-5.6 or 7.0-7.3
  • PHP's LibXML module, with the XSLT extension enabled (--with-xsl)
  • MySQL 5.5 or above
  • An Apache or Litespeed webserver
  • Apache's mod_rewrite module or equivalent

Compatible Hosts

Sign in

Login details