Skip to content

Commit 9bd3d9b

Browse files
authored
Merge pull request #34 from Planetbiru/feature/2.7.1
Feature/2.7.1
2 parents 0c999b8 + 4889b2d commit 9bd3d9b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+555
-178
lines changed

manual/includes/_entity.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -991,7 +991,7 @@ class SpecificationUtil
991991
* $@param array|null $additional
992992
* @return PicoSpecification
993993
*/
994-
public static function createSongSpecification($inputGet, $additional = null) //NOSONAR
994+
public static function createSongSpecification($inputGet, $additional = null) // NOSONAR
995995
{
996996
$spesification = new PicoSpecification();
997997

@@ -1212,7 +1212,7 @@ class SpecificationUtil
12121212
* $@param array|null $additional
12131213
* @return PicoSpecification
12141214
*/
1215-
public static function createSongDraftSpecification($inputGet, $additional = null) //NOSONAR
1215+
public static function createSongDraftSpecification($inputGet, $additional = null) // NOSONAR
12161216
{
12171217
$spesification = new PicoSpecification();
12181218

manual/includes/_secret-object.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -610,11 +610,11 @@ $cfg->loadYamlFile(dirname(__DIR__)."/.cfg/app.yml", true, true, true);
610610
$databaseCredentials = new PicoDatabaseCredentials($cfg->getDatabase());
611611

612612
$database = new PicoDatabase($databaseCredentials,
613-
function($sql, $type) //NOSONAR
613+
function($sql, $type) // NOSONAR
614614
{
615615
// callback when execute query that modify data
616616
},
617-
function($sql) //NOSONAR
617+
function($sql) // NOSONAR
618618
{
619619
// callback when execute all query
620620
}

manual/index.html

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1305,11 +1305,11 @@ <h3>Secure Config from DynamicObject</h3>
13051305
$databaseCredentials = new PicoDatabaseCredentials($cfg-&gt;getDatabase());
13061306

13071307
$database = new PicoDatabase($databaseCredentials,
1308-
function($sql, $type) //NOSONAR
1308+
function($sql, $type) // NOSONAR
13091309
{
13101310
// callback when execute query that modify data
13111311
},
1312-
function($sql) //NOSONAR
1312+
function($sql) // NOSONAR
13131313
{
13141314
// callback when execute all query
13151315
}
@@ -3254,7 +3254,7 @@ <h3>Find By Specification</h3>
32543254
* $@param array|null $additional
32553255
* @return PicoSpecification
32563256
*/
3257-
public static function createSongSpecification($inputGet, $additional = null) //NOSONAR
3257+
public static function createSongSpecification($inputGet, $additional = null) // NOSONAR
32583258
{
32593259
$spesification = new PicoSpecification();
32603260

@@ -3475,7 +3475,7 @@ <h3>Find By Specification</h3>
34753475
* $@param array|null $additional
34763476
* @return PicoSpecification
34773477
*/
3478-
public static function createSongDraftSpecification($inputGet, $additional = null) //NOSONAR
3478+
public static function createSongDraftSpecification($inputGet, $additional = null) // NOSONAR
34793479
{
34803480
$spesification = new PicoSpecification();
34813481

src/DataLabel/PicoDataLabels.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public function append($data)
4141
*/
4242
public function generate()
4343
{
44-
foreach ($this->data as $data) //NOSONAR
44+
foreach ($this->data as $data) // NOSONAR
4545
{
4646
// Implementation for processing each data label goes here
4747
}

src/DataTable.php

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -63,38 +63,54 @@ class DataTable extends SetterGetter
6363

6464
/**
6565
* Current language code.
66+
*
67+
* The property name starts with an underscore to prevent child classes
68+
* from overriding its value.
6669
*
6770
* @var string
6871
*/
69-
private $_currentLanguage; //NOSONAR
72+
private $_currentLanguage; // NOSONAR
7073

7174
/**
7275
* Language instances.
76+
*
77+
* The property name starts with an underscore to prevent child classes
78+
* from overriding its value.
7379
*
7480
* @var PicoLanguage[]
7581
*/
76-
private $_lableLanguage = array(); //NOSONAR
82+
private $_lableLanguage = array(); // NOSONAR
7783

7884
/**
7985
* Table identity.
86+
*
87+
* The property name starts with an underscore to prevent child classes
88+
* from overriding its value.
8089
*
8190
* @var PicoGenericObject
8291
*/
83-
private $_tableIdentity; //NOSONAR
92+
private $_tableIdentity; // NOSONAR
8493

8594
/**
8695
* Table information.
96+
*
97+
* The property name starts with an underscore to prevent child classes
98+
* from overriding its value.
8799
*
88100
* @var PicoTableInfo
89101
*/
90-
private $_tableInfo; //NOSONAR
102+
private $_tableInfo; // NOSONAR
91103

92104
/**
93105
* Labels for the table.
106+
*
107+
* The property name starts with an underscore to prevent child classes
108+
* from overriding its value.
94109
*
95110
* @var array
96111
*/
97-
private $_labels = array(); //NOSONAR
112+
private $_labels = array(); // NOSONAR
113+
98114

99115
/**
100116
* Constructor

src/Database/PicoDatabase.php

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
* @package MagicObject\Database
3838
* @link https://github.com/Planetbiru/MagicObject
3939
*/
40-
class PicoDatabase //NOSONAR
40+
class PicoDatabase // NOSONAR
4141
{
4242
const QUERY_INSERT = "insert";
4343
const QUERY_UPDATE = "update";
@@ -735,22 +735,13 @@ public function fetchAll($sql, $tentativeType = PDO::FETCH_ASSOC, $defaultValue
735735
*
736736
* @param string $sql SQL query to be executed.
737737
* @param array|null $params Optional parameters to bind to the SQL query.
738+
* @return PDOStatement|false Returns the PDOStatement object if successful, or `false` on failure.
738739
* @throws NullPointerException If the database connection is null.
740+
* @throws PDOException If an error occurs while executing the query.
739741
*/
740742
public function execute($sql, $params = null)
741743
{
742-
if ($this->databaseConnection == null) {
743-
throw new NullPointerException(self::DATABASE_NONECTION_IS_NULL);
744-
}
745-
746-
$this->executeDebug($sql, $params);
747-
$stmt = $this->databaseConnection->prepare($sql);
748-
749-
try {
750-
$stmt->execute($params);
751-
} catch (PDOException $e) {
752-
// Handle exception as needed
753-
}
744+
return $this->executeQuery($sql, $params);
754745
}
755746

756747
/**
@@ -898,8 +889,7 @@ private function executeDebug($query, $params = null)
898889
else
899890
{
900891
call_user_func($this->callbackDebugQuery, $query);
901-
}
902-
892+
}
903893
}
904894
}
905895

src/Database/PicoDatabaseCredentials.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -53,14 +53,14 @@ class PicoDatabaseCredentials extends SecretObject
5353
* @DecryptOut
5454
* @var string
5555
*/
56-
protected $host = 'localhost';
56+
protected $host;
5757

5858
/**
5959
* Database server port.
6060
*
6161
* @var int
6262
*/
63-
protected $port = 3306;
63+
protected $port;
6464

6565
/**
6666
* Database username.
@@ -69,7 +69,7 @@ class PicoDatabaseCredentials extends SecretObject
6969
* @DecryptOut
7070
* @var string
7171
*/
72-
protected $username = "";
72+
protected $username;
7373

7474
/**
7575
* Database user password.
@@ -78,7 +78,7 @@ class PicoDatabaseCredentials extends SecretObject
7878
* @DecryptOut
7979
* @var string
8080
*/
81-
protected $password = "";
81+
protected $password;
8282

8383
/**
8484
* Database name.
@@ -87,7 +87,7 @@ class PicoDatabaseCredentials extends SecretObject
8787
* @DecryptOut
8888
* @var string
8989
*/
90-
protected $databaseName = "";
90+
protected $databaseName;
9191

9292
/**
9393
* Database schema (default: 'public').
@@ -96,14 +96,14 @@ class PicoDatabaseCredentials extends SecretObject
9696
* @DecryptOut
9797
* @var string
9898
*/
99-
protected $databaseSchema = "public";
99+
protected $databaseSchema;
100100

101101
/**
102102
* Application time zone.
103103
*
104104
* @var string
105105
*/
106-
protected $timeZone = "Asia/Jakarta";
106+
protected $timeZone;
107107

108108
/**
109109
* Get the database driver.

src/Database/PicoPage.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,21 @@ public function setPageSize($pageSize)
109109
$this->pageSize = max(1, intval($pageSize));
110110
return $this;
111111
}
112+
113+
/**
114+
* Calculates and retrieves the offset for database queries.
115+
*
116+
* The offset is used to determine the starting point for fetching data
117+
* in paginated queries, based on the current page number and page size.
118+
*
119+
* @return int The calculated offset for database queries.
120+
*/
121+
public function getOffset()
122+
{
123+
$limit = $this->getPageSize();
124+
$offset = ($this->getPageNumber() - 1) * $limit;
125+
return max(0, $offset);
126+
}
112127

113128
/**
114129
* Calculates the limit and offset for database queries.

0 commit comments

Comments
 (0)