Verzeichnisstruktur phpBB-3.2.0


Veröffentlicht
06.01.2017

So funktioniert es


Auf das letzte Element klicken. Dies geht jeweils ein Schritt zurück

Auf das Icon klicken, dies öffnet das Verzeichnis. Nochmal klicken schließt das Verzeichnis.
Auf den Verzeichnisnamen klicken, dies zeigt nur das Verzeichnis mit Inhalt an

      (Beispiel Datei-Icons)

Auf das Icon klicken um den Quellcode anzuzeigen

row_based_plugin.php

Zuletzt modifiziert: 09.10.2024, 12:52 - Dateigröße: 2.44 KiB


 001  <?php
 002  /**
 003  *
 004  * This file is part of the phpBB Forum Software package.
 005  *
 006  * @copyright (c) phpBB Limited <https://www.phpbb.com>
 007  * @license GNU General Public License, version 2 (GPL-2.0)
 008  *
 009  * For full copyright and license information, please see
 010  * the docs/CREDITS.txt file.
 011  *
 012  */
 013   
 014  namespace phpbb\textreparser;
 015   
 016  abstract class row_based_plugin extends base
 017  {
 018      /**
 019      * @var \phpbb\db\driver\driver_interface
 020      */
 021      protected $db;
 022   
 023      /**
 024       * @var string
 025       */
 026      protected $table;
 027   
 028      /**
 029      * Constructor
 030      *
 031      * @param \phpbb\db\driver\driver_interface $db Database connection
 032      * @param string $table
 033      */
 034      public function __construct(\phpbb\db\driver\driver_interface $db, $table)
 035      {
 036          $this->db = $db;
 037          $this->table = $table;
 038      }
 039   
 040      /**
 041      * Return the name of the column that correspond to each field
 042      *
 043      * @return array
 044      */
 045      abstract public function get_columns();
 046   
 047      /**
 048      * {@inheritdoc}
 049      */
 050      public function get_max_id()
 051      {
 052          $columns = $this->get_columns();
 053   
 054          $sql = 'SELECT MAX(' . $columns['id'] . ') AS max_id FROM ' . $this->table;
 055          $result = $this->db->sql_query($sql);
 056          $max_id = (int) $this->db->sql_fetchfield('max_id');
 057          $this->db->sql_freeresult($result);
 058   
 059          return $max_id;
 060      }
 061   
 062      /**
 063      * {@inheritdoc}
 064      */
 065      protected function get_records_by_range($min_id, $max_id)
 066      {
 067          $sql = $this->get_records_by_range_query($min_id, $max_id);
 068          $result = $this->db->sql_query($sql);
 069          $records = $this->db->sql_fetchrowset($result);
 070          $this->db->sql_freeresult($result);
 071   
 072          return $records;
 073      }
 074   
 075      /**
 076      * Generate the query that retrieves all records for given range
 077      *
 078      * @param  integer $min_id Lower bound
 079      * @param  integer $max_id Upper bound
 080      * @return string          SQL query
 081      */
 082      protected function get_records_by_range_query($min_id, $max_id)
 083      {
 084          $columns = $this->get_columns();
 085          $fields  = array();
 086          foreach ($columns as $field_name => $column_name)
 087          {
 088              if ($column_name === $field_name)
 089              {
 090                  $fields[] = $column_name;
 091              }
 092              else
 093              {
 094                  $fields[] = $column_name . ' AS ' . $field_name;
 095              }
 096          }
 097   
 098          $sql = 'SELECT ' . implode(', ', $fields) . '
 099              FROM ' . $this->table . '
 100              WHERE ' . $columns['id'] . ' BETWEEN ' . $min_id . ' AND ' . $max_id;
 101   
 102          return $sql;
 103      }
 104   
 105      /**
 106      * {@inheritdoc}
 107      */
 108      protected function save_record(array $record)
 109      {
 110          $columns = $this->get_columns();
 111   
 112          $sql = 'UPDATE ' . $this->table . '
 113              SET ' . $columns['text'] . " = '" . $this->db->sql_escape($record['text']) . "'
 114              WHERE " . $columns['id'] . ' = ' . $record['id'];
 115          $this->db->sql_query($sql);
 116      }
 117  }
 118