XOOPS  2.6.0
TableLoad.php
Go to the documentation of this file.
1 <?php
2 /*
3  You may not change or alter any portion of this comment or credits
4  of supporting developers from this source code or any supporting source code
5  which is considered copyrighted (c) material of the original comment or credit authors.
6 
7  This program is distributed in the hope that it will be useful,
8  but WITHOUT ANY WARRANTY; without even the implied warranty of
9  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10  */
11 
12 namespace Xmf\Database;
13 
14 use Xoops\Core\Yaml;
15 
29 class TableLoad
30 {
31 
42  public static function loadTableFromArray($table, $data)
43  {
44  $db = \Xoops::getInstance()->db();
45  $count = 0;
46  $db->beginTransaction();
47  foreach ($data as $row) {
48  $count += $db->insertPrefix($table, $row);
49  }
50  $db->commit();
51  return $count;
52  }
53 
62  public static function loadTableFromYamlFile($table, $yamlFile)
63  {
64  $count = 0;
65 
66  $data = Yaml::read($yamlFile);
67  if ($data) {
68  $count = self::loadTableFromArray($table, $data);
69  }
70 
71  return $count;
72  }
73 
81  public static function truncateTable($table)
82  {
83  $db = \Xoops::getInstance()->db();
84  $platform = $db->getDatabasePlatform();
85  $sql = $platform->getTruncateTableSQL($db->prefix($table));
86 
87  return $db->exec($sql);
88  }
89 
98  public static function rowCount($table, $criteria = null)
99  {
100  $db = \Xoops::getInstance()->db();
101  $qb = $db->createXoopsQueryBuilder();
102  $qb ->select('COUNT(*)')
103  ->fromPrefix($table, '');
104  if (isset($criteria) && is_subclass_of($criteria, 'Xoops\Core\Kernel\CriteriaElement')) {
105  $qb = $criteria->renderQb($qb, '');
106  }
107  $result = $qb->execute();
108  $count = $result->fetchColumn();
109  return $count;
110  }
111 }
static rowCount($table, $criteria=null)
Definition: TableLoad.php:98
static getInstance()
Definition: Xoops.php:160
$result
Definition: pda.php:33
if($_SERVER['REQUEST_METHOD']== 'POST') $platform
static loadTableFromArray($table, $data)
Definition: TableLoad.php:42
$sql
Definition: pda.php:32
static read($yamlFile)
Definition: Yaml.php:87
$criteria
static truncateTable($table)
Definition: TableLoad.php:81
static loadTableFromYamlFile($table, $yamlFile)
Definition: TableLoad.php:62