Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Usage / rebuild getResources #1

Closed
exside opened this issue May 3, 2013 · 6 comments
Closed

Usage / rebuild getResources #1

exside opened this issue May 3, 2013 · 6 comments
Labels

Comments

@exside
Copy link

exside commented May 3, 2013

Hi,

I really want to try if I can somehow rebuild getResources (at least in part) with pdoTools and make it much faster in the process...but I couldn't get it right yet because I'm not getting enough out of the examples/documentation/code from tickets etc., so I wanted to ask if you maybe could give some additional hints of how to do it...what I tried for now was just fetching some simple resources fields of standard modResource objects like this

<?php
$pdoFetch = $modx->getService('pdofetch','pdoFetch', MODX_CORE_PATH.'components/pdotools/model/pdotools/');

if ( $pdoFetch instanceof pdoFetch ) {

    //echo '<pre>' . print_r($pdoFetch->config,1) . '</pre>';
    $rows = $pdoFetch->run();

    if (!empty($rows) && is_array($rows)) {
        echo 'rows is array'; // I never get this...var dump gives a biiiig string
        foreach ($rows as $row) {
            //echo $row['pagetitle'];
            //var_dump($row);
        }
    }
//var_dump($rows);
}
//var_dump($rows);
}

but I cannot even get the pagetitle out of this, already stuck after running pdoFetch, seems to just give me back one big string (with the right information inside, by the way) that I cannot process further. So I guess I'm missing something, probably some config stuff, but I don't get yet how to set it...would be very nice of you if you can give some hints to get me started =)

@bezumkin
Copy link
Collaborator

bezumkin commented May 4, 2013

You can try to use msProducts as replacement for getResources.

Later i want to include this functionality in pdoTools.

@bezumkin
Copy link
Collaborator

bezumkin commented May 4, 2013

By the way, here is possible config options.
You can look in methods, how they used in class.

I have documentation for pdoTools, but it on russian and availible only for my paid subscribers.

@exside
Copy link
Author

exside commented May 6, 2013

Hi,

thanks for the reply, tried a bit around with some additional config options and was a bit more successful (at least getting the resources in an array and can do something with them, not much yet, but better than nothing=D)

Would love to pay that 300 rubels to get more info about pdoTools, I have signed in, but cannot make that payment because google has troubles translating the pages when I'm logged + z-payment/qiwi dont let me do anything (z-payment bc russian only and qiwi because switzerland ist not on the supported country list). Any possibility that I pay the 300 rubles per paypal and can somehow access that pdoTools documentation / that article here Самые быстрые сниппеты с pdoTools http://bezumkin.ru/sections/php/556/

I have the following now:

<?php
$pdoFetch = $modx->getService('pdofetch','pdoFetch', MODX_CORE_PATH.'components/pdotools/model/pdotools/');

if ( $pdoFetch instanceof pdoFetch ) {
    $pdoFetch->config['tpl'] = 'article.teaser';
    $pdoFetch->config['return'] = 'data'; // this was necessary to get back an array
    $pdoFetch->config['fastMode'] = 1; // doesn't matter if I put 0 or 1 there, the placeholders with output filters don't get processed
    $pdoFetch->config['includeTVs'] = 1; // maybe related, but I don't see any tv data if I print_r the single resources
    //$pdoFetch->config['includeTVList'] = 'article.teaser.title,article.teaser.img,article.img.full,team-img,team-job'; // this gives me some sql syntax error
    //$pdoFetch->config['tvsSelect'] = array('article.teaser.title'); // same here
    echo '<pre>' . print_r($pdoFetch->config,1) . '</pre>';

    $rows = $pdoFetch->run();

    if (!empty($rows) && is_array($rows)) {
        //echo 'rows is array';
        foreach ($rows as $row) {
            //echo '<pre>' . print_r($row,1) . '</pre>';
            echo $pdoFetch->getChunk($pdoFetch->config['tpl']);
            //echo $row['pagetitle'];
            //var_dump($row);
        }
    }
//var_dump($rows);
}

and the tpl chunk is:

<article class="col teaser">
    <section class="teaserwrap">
        <figure>
            [[+article.teaser.img:isnot=``:then=`<img src="[[+article.teaser.img]]" alt="" />`:else=`[[+article.img.full:isnotempty=`<img src="[[+article.img.full]]" alt="" />`]][[+team-img:isnotempty=`<img src="[[+team-img]]" alt="" />`]]`]]
            <figcaption class="hoverlay border-box">

            </figcaption>
        </figure>
        <hgroup>
            <h3><a href="[[~[[+id]]]]" class="biggie">[[+article.teaser.title:default=`[[+pagetitle:limit=`44`]]`]]</a></h3>
            <h6 class="claim">[[+article.teaser.claim:default=`[[+longtitle:isnotempty=`[[+longtitle:limit=`26`]]`]][[+team-job:isnotempty=`[[+team-job:limit=`26`]]`]]`]]</h6>
        </hgroup>
    </section>
</article>

this gives me just output like this:

[[+article.teaser.img:isnot=``:then=``:else=`[[+article.img.full:isnotempty=``]][[+team-img:isnotempty=``]]`]]
[[+article.teaser.title:default=`[[+pagetitle:limit=`44`]]`]]
[[+article.teaser.claim:default=`[[+longtitle:isnotempty=`[[+longtitle:limit=`26`]]`]][[+team-job:isnotempty=`[[+team-job:limit=`26`]]`]]`]]

so the 2 main question are:

  1. how do I include TV's correctly so they can be parsed by getChunk()

and

  1. if not with fastMode=1or 0, how to get pdoFetch to parse placeholders with output filters?

@bezumkin
Copy link
Collaborator

bezumkin commented May 6, 2013

You do not send data to getChunk!

    if (!empty($rows) && is_array($rows)) {
        foreach ($rows as $row) {
            //echo '<pre>'; print_r($row); die; // this will print the whole fields of row and exit
            echo $pdoFetch->getChunk($pdoFetch->config['tpl'], $row); // You forgot to send $row into the method
        }
    }

If you want, you can manually send me $10 to PayPal (bezumkin@yandex.ru), then send a letter (with your credentials on my site) and i will open access to your account for a month.

  1. TVs including by
&includeTVs=`tvname,othertvname,etc`.

Also you can use &tvPrefix=, it is blank by default.

  1. Fast mode will cut all unprocessed placeholders with filters. It is need only if you receive all needed data from tables and prepare it manually. And it works very fast, becouse do not use tags processing.

@exside
Copy link
Author

exside commented May 6, 2013

Hi,

thanks again for the response! Just sent you the 10$ via paypal!

tried your suggestion with includeTVs but wasn't successful, could i t be a problem to have dots (.) in tv names somehow? Because I get

[pdoTools] Error 42000: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '.contentid=modResource.id AND TVarticle.img.full.tmplvarid=17 LEFT JOIN `modx_si' at line 1

when I run this in Console

<?php
$pdoFetch = $modx->getService('pdofetch','pdoFetch', MODX_CORE_PATH.'components/pdotools/model/pdotools/');

if ( $pdoFetch instanceof pdoFetch ) {
    $pdoFetch->config['tpl'] = 'article.teaser';
    $pdoFetch->config['return'] = 'data'; // this was necessary to get back an array
    $pdoFetch->config['fastMode'] = 0; // doesn't matter if I put 0 or 1 there, the placeholders with output filters don't get processed
    $pdoFetch->config['includeTVs'] = 'article.teaser.title,article.teaser.img,article.img.full,team-img,team-job'; // maybe related, but I don't see any tv data if I print_r the single resources
    //$pdoFetch->config['includeTVList'] = 'team-img,team-job'; // this gives me some sql syntax error
    //$pdoFetch->config['tvsSelect'] = array('article.teaser.title'); // same here
    echo '<pre>' . print_r($pdoFetch->config,1) . '</pre>';

    $rows = $pdoFetch->run();

    if (!empty($rows) && is_array($rows)) {
        //echo 'rows is array';
        foreach ($rows as $row) {
            //echo '<pre>' . print_r($row,1) . '</pre>';
            echo $pdoFetch->getChunk($pdoFetch->config['tpl'], $row);
            //echo $row['pagetitle'];
            //var_dump($row);
        }
    }
//var_dump($rows);
}

and if I remove the TVs with dots in their names (leaving just team-img and team-job) I get this error

[pdoTools] Error 42S22: Unknown column 'TVteam' in 'on clause'

@bezumkin
Copy link
Collaborator

bezumkin commented May 6, 2013

Of course, remove the point, they break SQL query.

Access granted. Please, write me futher comments on my site.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants