Example #1
0
/**
 * Compile un critère non déclaré explicitement, dont on reçoit une analyse
 *
 * Ajoute en fonction des arguments trouvés par calculer_critere_infixe()
 * les conditions WHERE à appliquer sur la boucle.
 *
 * @see calculer_critere_infixe()
 *
 * @param string $idb     Identifiant de la boucle
 * @param array $boucles  AST du squelette
 * @param Critere $crit   Paramètres du critère dans cette boucle
 * @param array $args     Description du critère
 *                        Cf. retour de calculer_critere_infixe()
 * @return void
**/
function calculer_critere_DEFAUT_args($idb, &$boucles, $crit, $args)
{
    list($arg, $op, $val, $col, $where_complement) = $args;
    $where = array("'{$op}'", "'{$arg}'", $val[0]);
    // inserer la negation (cf !...)
    if ($crit->not) {
        $where = array("'NOT'", $where);
    }
    if ($crit->exclus) {
        if (!preg_match(",^L[0-9]+[.],", $arg)) {
            $where = array("'NOT'", $where);
        } else {
            // un not sur un critere de jointure se traduit comme un NOT IN avec une sous requete
            // c'est une sous requete identique a la requete principale sous la forme (SELF,$select,$where) avec $select et $where qui surchargent
            $where = array("'NOT'", array("'IN'", "'" . $boucles[$idb]->id_table . "." . $boucles[$idb]->primary . "'", array("'SELF'", "'" . $boucles[$idb]->id_table . "." . $boucles[$idb]->primary . "'", $where)));
        }
    }
    // inserer la condition (cf {lang?})
    // traiter a part la date, elle est mise d'office par SPIP,
    if ($crit->cond) {
        $pred = calculer_argument_precedent($idb, $col, $boucles);
        if ($col == "date" or $col == "date_redac") {
            if ($pred == "\$Pile[0]['" . $col . "']") {
                $pred = "(\$Pile[0]['{$col}_default']?'':{$pred})";
            }
        }
        if ($op == '=' and !$crit->not) {
            $where = array("'?'", "(is_array({$pred}))", critere_IN_cas($idb, $boucles, 'COND', $arg, $op, array($pred), $col), $where);
        }
        $where = array("'?'", "!(is_array({$pred})?count({$pred}):strlen({$pred}))", "''", $where);
        if ($where_complement) {
            // condition annexe du type "AND (objet='article')"
            $where_complement = array("'?'", "!(is_array({$pred})?count({$pred}):strlen({$pred}))", "''", $where_complement);
        }
    }
    $boucles[$idb]->where[] = $where;
    if ($where_complement) {
        // condition annexe du type "AND (objet='article')"
        $boucles[$idb]->where[] = $where_complement;
    }
}
Example #2
0
/**
 * Compile un critère non déclaré explicitement, dont on reçoit une analyse
 *
 * Ajoute en fonction des arguments trouvés par calculer_critere_infixe()
 * les conditions WHERE à appliquer sur la boucle.
 *
 * @see calculer_critere_infixe()
 *
 * @param string $idb Identifiant de la boucle
 * @param array $boucles AST du squelette
 * @param Critere $crit Paramètres du critère dans cette boucle
 * @param array $args Description du critère
 *                        Cf. retour de calculer_critere_infixe()
 * @return void
 **/
function calculer_critere_DEFAUT_args($idb, &$boucles, $crit, $args)
{
    list($arg, $op, $val, $col, $where_complement) = $args;
    $where = array("'{$op}'", "'{$arg}'", $val[0]);
    // inserer la negation (cf !...)
    if ($crit->not) {
        $where = array("'NOT'", $where);
    }
    if ($crit->exclus) {
        if (!preg_match(",^L[0-9]+[.],", $arg)) {
            $where = array("'NOT'", $where);
        } else {
            $where = array("'NOT'", array("'IN'", "'" . $boucles[$idb]->id_table . "." . $boucles[$idb]->primary . "'", array("'SELF'", "'" . $boucles[$idb]->id_table . "." . $boucles[$idb]->primary . "'", $where)));
        }
    }
    // inserer la condition (cf {lang?})
    // traiter a part la date, elle est mise d'office par SPIP,
    if ($crit->cond) {
        $pred = calculer_argument_precedent($idb, $col, $boucles);
        if ($col == "date" or $col == "date_redac") {
            if ($pred == "\$Pile[0]['" . $col . "']") {
                $pred = "(\$Pile[0]['{$col}_default']?'':{$pred})";
            }
        }
        if ($op == '=' and !$crit->not) {
            $where = array("'?'", "(is_array({$pred}))", critere_IN_cas($idb, $boucles, 'COND', $arg, $op, array($pred), $col), $where);
        }
        $where = array("'?'", "!(is_array({$pred})?count({$pred}):strlen({$pred}))", "''", $where);
        if ($where_complement) {
            $where_complement = array("'?'", "!(is_array({$pred})?count({$pred}):strlen({$pred}))", "''", $where_complement);
        }
    }
    $boucles[$idb]->where[] = $where;
    if ($where_complement) {
        $boucles[$idb]->where[] = $where_complement;
    }
}