-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
342 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/* | ||
* This file is part of PHP CS Fixer. | ||
* (c) Fabien Potencier <[email protected]> | ||
* Dariusz Rumiński <[email protected]> | ||
* This source file is subject to the MIT license that is bundled | ||
* with this source code in the file LICENSE. | ||
*/ | ||
|
||
enum SqlEnumCondition: string | ||
{ | ||
case Equal = ' = '; | ||
|
||
case Bigger = ' > '; | ||
|
||
case Less = ' < '; | ||
|
||
case BiggerEqual = ' >= '; | ||
|
||
case LessEqual = ' =< '; | ||
|
||
case IsNull = ' IS NULL '; | ||
|
||
case NotNull = 'IS NOT NULL'; | ||
|
||
case Not = ' != '; | ||
|
||
case Like = ' LIKE '; | ||
|
||
case Descending = ' DESC '; | ||
|
||
case Ascending = ' ASC '; | ||
|
||
case Between = ' BETWEEN '; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
<?php | ||
namespace GemFramework\Traits\Table; | ||
|
||
/** | ||
* @method delete() | ||
* @method restore() | ||
*/ | ||
trait SafeDeleteTrait | ||
{ | ||
/** | ||
* @param int|null $id | ||
* @return int|null | ||
* @description : if id = null then use $this->id | ||
* return 1 if successful and null if not | ||
*/ | ||
public function delete(int $id = null): int|null | ||
{ | ||
$table = $this->setTable(); | ||
if(!$table) | ||
{ | ||
$this->setError('table is not setted in function setTable'); | ||
return null; | ||
} | ||
if (!$id) { | ||
$id = $this->id; | ||
} | ||
if(!$id || $id < 1) | ||
{ | ||
$this->setError('property id does existed or not setted in object'); | ||
return null; | ||
} | ||
$query = "UPDATE $table SET deleted_at = NOW() WHERE id = :id"; | ||
|
||
return $this->updateQuery($query, [':id' => $id]); | ||
} | ||
|
||
/** | ||
* @param int|null $id | ||
* @return int|null | ||
* @description : if id = null then use $this->id | ||
* return 1 if successful and null if not | ||
*/ | ||
public function restore(int $id = null): int|null | ||
{ | ||
$table = $this->setTable(); | ||
if(!$table) | ||
{ | ||
$this->setError('table is not setted in function setTable'); | ||
return null; | ||
} | ||
if (!$id) { | ||
$id = $this->id; | ||
} | ||
if(!$id || $id < 1) | ||
{ | ||
$this->setError('property id does existed or not setted in object'); | ||
return null; | ||
} | ||
$query = "UPDATE {$this->table} SET deleted_at = NULL WHERE id = :id"; | ||
|
||
return $this->updateQuery($query, []); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.