Skip to content

Commit 5f33793

Browse files
authored
Merge branch 'n1crack:master' into bugfix
2 parents 1b3559d + 8c83cce commit 5f33793

14 files changed

+259
-50
lines changed

.github/FUNDING.yml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# These are supported funding model platforms
2+
3+
github: n1crack # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2]
4+
patreon: # Replace with a single Patreon username
5+
open_collective: # Replace with a single Open Collective username
6+
ko_fi: # Replace with a single Ko-fi username
7+
tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel
8+
community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry
9+
liberapay: # Replace with a single Liberapay username
10+
issuehunt: # Replace with a single IssueHunt username
11+
otechie: # Replace with a single Otechie username
12+
lfx_crowdfunding: # Replace with a single LFX Crowdfunding project-name e.g., cloud-foundry
13+
custom: # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2']

README.md

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Datatables library for PHP
22
[![Latest Stable Version](https://poser.pugx.org/ozdemir/datatables/v/stable)](https://packagist.org/packages/ozdemir/datatables) [![PHP Composer](https://github.com/n1crack/datatables/actions/workflows/tests.yml/badge.svg)](https://github.com/n1crack/datatables/actions/workflows/tests.yml) [![license](https://img.shields.io/github/license/mashape/apistatus.svg)](https://github.com/n1crack/datatables/blob/master/LICENCE)
33

4-
PHP Library to handle server-side processing for Datatables, in a fast and simple way. [Live Demo](https://datatables.ozdemir.be/)
4+
Simplify your Datatables server-side processing effortlessly using our lightning-fast PHP library, streamlining your workflow seamlessly. [Live Demo](https://datatables.ozdemir.be/)
55

66
## Features
77
* Easy to use. Generates json using only a few lines of code.
@@ -127,20 +127,22 @@ use Ozdemir\Datatables\DB\LaravelAdapter;
127127

128128
Route::get('/ajax/laravel', function () {
129129

130-
$sqlBuilder = Track::select([
131-
'TrackId',
132-
'Track.Name',
133-
'Title as Album',
134-
'MediaType.Name as MediaType',
135-
'UnitPrice',
136-
'Milliseconds',
137-
'Bytes',
138-
])
139-
->join('Album', 'Album.AlbumId', 'Track.AlbumId')
140-
->join('MediaType', 'MediaType.MediaTypeId', 'Track.MediaTypeId');
141-
142130
$dt = new Datatables(new LaravelAdapter);
143-
$dt->query($sqlBuilder); // same as the previous example, sql statement can be used.
131+
132+
$dt->query(
133+
Track::query()
134+
->select([
135+
'TrackId',
136+
'Track.Name',
137+
'Title as Album',
138+
'MediaType.Name as MediaType',
139+
'UnitPrice',
140+
'Milliseconds',
141+
'Bytes',
142+
])
143+
->join('Album', 'Album.AlbumId', 'Track.AlbumId')
144+
->join('MediaType', 'MediaType.MediaTypeId', 'Track.MediaTypeId')
145+
); // same as the previous example, sql statement can be used.
144146

145147
return $dt->generate();
146148
});

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "ozdemir/datatables",
3-
"description": "PHP Library to handle server-side processing for Datatables, in a fast and simple way.",
3+
"description": "Simplify your Datatables server-side processing effortlessly using our lightning-fast PHP library, streamlining your workflow seamlessly.",
44
"license": "MIT",
55
"config": {
66
"bin-dir": "vendor/bin"

src/Column.php

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,19 @@ class Column
5050
* Custom filter
5151
* @var \Closure
5252
*/
53-
public $customFilter;
53+
public $customIndividualFilter;
54+
55+
/**
56+
* Custom filter
57+
* @var \Closure
58+
*/
59+
public $customGlobalFilter;
60+
61+
/**
62+
*
63+
* @var string
64+
*/
65+
public $customFilterType;
5466

5567
/**
5668
* Column constructor.
@@ -82,7 +94,7 @@ public function value($row): string
8294
* Set visibility of the column.
8395
* @param bool $searchable
8496
*/
85-
public function hide($searchable = false): void
97+
public function hide(bool $searchable = false): void
8698
{
8799
$this->hidden = true;
88100
$this->forceSearch = $searchable;
@@ -91,9 +103,17 @@ public function hide($searchable = false): void
91103
/**
92104
* @return bool
93105
*/
94-
public function hasFilter(): bool
106+
public function hasCustomIndividualFilter(): bool
107+
{
108+
return $this->customIndividualFilter instanceof \Closure;
109+
}
110+
111+
/**
112+
* @return bool
113+
*/
114+
public function hasCustomGlobalFilter(): bool
95115
{
96-
return $this->customFilter instanceof \Closure;
116+
return $this->customGlobalFilter instanceof \Closure;
97117
}
98118

99119
/**

src/CustomFilterType.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?php
2+
3+
namespace Ozdemir\Datatables;
4+
5+
class CustomFilterType
6+
{
7+
const INDIVIDUAL = 'individual';
8+
const GLOBALLY = 'globally';
9+
const ALL = 'all';
10+
}

src/DB/Codeigniter4Adapter.php

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,19 +18,22 @@ class Codeigniter4Adapter extends DBAdapter
1818
protected $db;
1919

2020
/**
21-
* @var $config
21+
* @var array
2222
*/
23+
protected $config;
24+
2325
public function __construct($config = null)
2426
{
25-
27+
$this->config = $config ?? ['DBGroup' => 'default'];
28+
$this->config['DBGroup'] = $this->config['DBGroup'] ?? 'default';
2629
}
2730

2831
/**
2932
* @return $this
3033
*/
3134
public function connect()
3235
{
33-
$this->db = \Config\Database::connect();
36+
$this->db = \Config\Database::connect($this->config['DBGroup']);
3437

3538
return $this;
3639
}
@@ -87,7 +90,7 @@ public function makeQueryString(string $query, ColumnCollection $columns): strin
8790
* @param $query
8891
* @return string
8992
*/
90-
public function getQueryString($query)
93+
public function getQueryString($query): string
9194
{
9295
if ($query instanceof \CodeIgniter\Database\BaseBuilder) {
9396
return $query->getCompiledSelect();

src/DB/DBAdapter.php

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
abstract class DBAdapter implements DatabaseInterface
1212
{
13+
public $exactMatch = false;
1314

1415
/**
1516
* @return void
@@ -64,17 +65,46 @@ public function makeWhereString(array $filter)
6465
return ' WHERE '.implode(' AND ', $filter);
6566
}
6667

68+
69+
/**
70+
* @return bool
71+
*/
72+
public function isExactMatch()
73+
{
74+
return $this->exactMatch;
75+
}
76+
77+
/**
78+
* @param bool $value
79+
* @return void
80+
*/
81+
public function setExactMatch(bool $value)
82+
{
83+
$this->exactMatch = $value;
84+
}
85+
6786
/**
6887
* @param Query $query
6988
* @param Column $column
70-
* @param $word
89+
* @param string $word
7190
* @return string
7291
*/
7392
public function makeLikeString(Query $query, Column $column, string $word)
7493
{
7594
return $column->name.' LIKE '.$this->escape('%'.$word.'%', $query);
7695
}
7796

97+
/**
98+
* @param Query $query
99+
* @param Column $column
100+
* @param string $word
101+
* @return string
102+
*/
103+
public function makeEqualString(Query $query, Column $column, string $word)
104+
{
105+
return $column->name.' = '.$this->escape( $word, $query);
106+
}
107+
78108
/**
79109
* @param array $o
80110
* @return string
@@ -98,7 +128,7 @@ public function makeLimitString(int $take, int $skip)
98128
* @param $query
99129
* @return string
100130
*/
101-
public function getQueryString($query)
131+
public function getQueryString($query): string
102132
{
103133
return $query;
104134
}

src/DB/DatabaseInterface.php

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,17 @@ public function makeDistinctQueryString(Query $query, string $column);
5454
*/
5555
public function makeWhereString(array $filter);
5656

57+
/**
58+
* @param bool $value
59+
* @return void
60+
*/
61+
public function setExactMatch(bool $value);
62+
63+
/**
64+
* @return mixed
65+
*/
66+
public function isExactMatch();
67+
5768
/**
5869
* @param Query $query
5970
* @param Column $column
@@ -62,6 +73,15 @@ public function makeWhereString(array $filter);
6273
*/
6374
public function makeLikeString(Query $query, Column $column, string $word);
6475

76+
77+
/**
78+
* @param Query $query
79+
* @param Column $column
80+
* @param string $word
81+
* @return mixed
82+
*/
83+
public function makeEqualString(Query $query, Column $column, string $word);
84+
6585
/**
6686
* @param array $o
6787
* @return mixed
@@ -74,4 +94,10 @@ public function makeOrderByString(array $o);
7494
* @return mixed
7595
*/
7696
public function makeLimitString(int $take, int $skip);
97+
98+
/**
99+
* @param $query
100+
* @return string
101+
*/
102+
public function getQueryString($query): string;
77103
}

src/DB/LaravelAdapter.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ public function escape($string, Query $query)
7171
* @param $query
7272
* @return string
7373
*/
74-
public function getQueryString($query)
74+
public function getQueryString($query): string
7575
{
7676
if ($query instanceof \Illuminate\Database\Eloquent\Builder) {
7777
return vsprintf(str_replace('?', '%s', $query->toSql()),

0 commit comments

Comments
 (0)