Overview
Comment: | Donner la possibilité à un plugin de bypasser la base de données et fournir son propre itérateur |
---|---|
Downloads: | Tarball | ZIP archive | SQL archive |
Timelines: | family | ancestors | descendants | both | dev |
Files: | files | file ages | folders |
SHA1: |
f6bdca768ea532745436803fb0937387 |
User & Date: | bohwaz on 2017-08-01 06:43:07 |
Other Links: | branch diff | manifest | tags |
Context
2017-08-02
| ||
04:07 | Squelettes: Ajout filtre "date" pour les dates en anglais check-in: 42f3dfa075 user: bohwaz tags: dev | |
2017-08-01
| ||
06:43 | Donner la possibilité à un plugin de bypasser la base de données et fournir son propre itérateur check-in: f6bdca768e user: bohwaz tags: dev | |
06:42 | Corrections sur les filtres de dates check-in: 9fe78ccab2 user: bohwaz tags: dev | |
Changes
Modified src/include/lib/Garradin/Squelette.php from [eb9881daec] to [05afb449ce].
︙ | ︙ | |||
346 347 348 349 350 351 352 353 354 355 356 357 358 359 | } protected function processLoop($loopName, $loopType, $loopCriterias, $loopContent, $preContent, $postContent, $altContent) { $query = $loop_start = ''; $query_args = []; $db = DB::getInstance(); // Types de boucles natifs if ($loopType == 'articles' || $loopType == 'rubriques' || $loopType == 'pages') { $where = $order = ''; $limit = $begin = 0; | > > | 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 | } protected function processLoop($loopName, $loopType, $loopCriterias, $loopContent, $preContent, $postContent, $altContent) { $query = $loop_start = ''; $query_args = []; $db = DB::getInstance(); $statement_code = ''; // Types de boucles natifs if ($loopType == 'articles' || $loopType == 'rubriques' || $loopType == 'pages') { $where = $order = ''; $limit = $begin = 0; |
︙ | ︙ | |||
624 625 626 627 628 629 630 631 632 633 634 635 636 637 | 'altContent' => $altContent, ]; $callback_return = [ 'query' => &$query, 'query_args' => &$query_args, 'loop_start' => &$loop_start, ]; // Appel du plugin lié à cette boucle, si ça existe $return = Plugin::fireSignal('boucle.' . $loopType, $params, $callback_return); // Si le retour est du texte on le traite comme tel if (is_string($return)) | > | 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 | 'altContent' => $altContent, ]; $callback_return = [ 'query' => &$query, 'query_args' => &$query_args, 'loop_start' => &$loop_start, 'code' => &$statement_code, ]; // Appel du plugin lié à cette boucle, si ça existe $return = Plugin::fireSignal('boucle.' . $loopType, $params, $callback_return); // Si le retour est du texte on le traite comme tel if (is_string($return)) |
︙ | ︙ | |||
681 682 683 684 685 686 687 | if (substr($k, 0, 4) == ':php') { $query = str_replace($k, $arg, $query); unset($query_args[$k]); } } | > > > > > > > > | | | | | | | | > > | 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 | if (substr($k, 0, 4) == ':php') { $query = str_replace($k, $arg, $query); unset($query_args[$k]); } } // Si le plugin a donné du code à exécuter à la place d'une requête SQL if ($statement_code) { $out->append(1, str_replace('$OBJ_VAR', '$result_' . $hash, $statement_code)); $out->append(1, '$nb_rows = $result_'.$hash.'->countRows();'); } else { $out->append(1, '$statement = $db->prepare('.$query.'); '); foreach ($query_args as $k=>$arg) { $out->append(1, '$value = ' . (is_array($arg) ? $arg[0] : var_export($arg, true)) . ';'); $out->append(1, '$statement->bindValue(' . ($k+1) . ', $value, $db->getArgType($value));'); } $out->append(1, '$result_'.$hash.' = $statement->execute(); '); $out->append(1, '$nb_rows = $db->countRows($result_'.$hash.'); '); } if (!empty($search)) { $out->append(1, '} else { $result_'.$hash.' = false; $nb_rows = 0; }'); } $out->append(1, '$this->_vars[\''.$hash.'\'] = [\'_self_hash\' => \''.$hash.'\', \'_parent_hash\' => $parent_hash, \'total_boucle\' => $nb_rows, \'compteur_boucle\' => 0];'); $out->append(1, '$this->current =& $this->_vars[\''.$hash.'\']; '); $out->append(1, 'if ($nb_rows > 0):'); // Ajout contenu avant tag if ($preContent) { $out->append(2, $this->parse($preContent, $loopName, self::PRE_CONTENT)); } $out->append(1, 'while ($row = $result_'.$hash.'->fetchArray(SQLITE3_ASSOC)): '); $out->append(1, '$this->_vars[\''.$hash.'\'][\'compteur_boucle\'] += 1; '); |
︙ | ︙ | |||
732 733 734 735 736 737 738 | } $out->append(1, 'endif; '); $out->append(1, '$parent_hash = $this->_vars[\''.$hash.'\'][\'_parent_hash\']; '); $out->append(1, 'unset($result_'.$hash.', $nb_rows, $this->_vars[\''.$hash.'\']); '); $out->append(1, 'if ($parent_hash) { $this->current =& $this->_vars[$parent_hash]; $parent_hash = $this->current[\'_parent_hash\']; } '); $out->append(1, 'else { $this->current = null; }'); | | | 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 | } $out->append(1, 'endif; '); $out->append(1, '$parent_hash = $this->_vars[\''.$hash.'\'][\'_parent_hash\']; '); $out->append(1, 'unset($result_'.$hash.', $nb_rows, $this->_vars[\''.$hash.'\']); '); $out->append(1, 'if ($parent_hash) { $this->current =& $this->_vars[$parent_hash]; $parent_hash = $this->current[\'_parent_hash\']; } '); $out->append(1, 'else { $this->current = null; }'); $out->append(1, '$this->parent =& $parent_hash ? $this->_vars[$parent_hash] : null;'); return $out; } public function fetch($template, $no_display = false) { $this->currentTemplate = $template; |
︙ | ︙ |