Пример #1
0
 public static function createConnections(\PDO $pdo, $user_id, $group_id)
 {
     $table = DbPdoConnector::getTableNameWithPrefix('user_fiche');
     $tableFiche = DbPdoConnector::getTableNameWithPrefix('fiche');
     $query = "SELECT id FROM `{$tableFiche}` WHERE group_id='{$group_id}' AND id NOT IN (SELECT fiche_id FROM `{$table}` WHERE user_id='{$user_id}' AND group_id='{$group_id}') LIMIT " . FicheLevelValue::FICHES_COUNT_AT_FIRST_LEVEL;
     $fichesIds = FetchData::executeFetchAllStatement($pdo->prepare($query));
     $data = [];
     foreach ($fichesIds as $ficheId) {
         $dateTime = date("Y-m-d H:i:s") . substr((string) microtime(), 1, 8);
         $id = $ficheId['id'];
         $data[] = "('{$user_id}', '{$id}', '{$group_id}', 1, '{$dateTime}', 0)";
     }
     $query = "INSERT INTO `{$table}` (user_id, fiche_id, group_id, level, last_modified, archived) VALUES " . implode(', ', $data);
     return self::execute($pdo->prepare($query));
 }
Пример #2
0
 public static function innerJoin(\PDO $pdo, array $columns, string $tableName, string $joinTable, array $onCondition = null, array $whereCondition = null)
 {
     $joinTable = $table = DbPdoConnector::getTableNameWithPrefix($joinTable);
     $query = self::baseQuery($columns, $tableName);
     $query .= " AS t1 INNER JOIN `{$joinTable}` AS t2";
     if ($onCondition !== null) {
         $query .= " ON t1.{$onCondition['0']}=t2.{$onCondition['1']}";
     }
     if ($whereCondition !== null) {
         $query .= " WHERE t1.{$whereCondition['0']}='{$whereCondition['1']}'";
     }
     return self::executeFetchAllStatement($pdo->prepare($query));
 }