-
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
1 changed file
with
25 additions
and
29 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 |
---|---|---|
|
@@ -8,7 +8,7 @@ | |
* @author Ali Güçlü (Mirarus) <[email protected]> | ||
* @link https://github.com/mirarus/bmvc-libs | ||
* @license http://www.php.net/license/3_0.txt PHP License 3.0 | ||
* @version 0.1 | ||
* @version 0.2 | ||
*/ | ||
|
||
namespace BMVC\Libs\Model; | ||
|
@@ -92,45 +92,49 @@ public function all(array $sort = [null, "ASC"], string $query = null) | |
/** | ||
* @param array $data | ||
* @param bool $time | ||
* @param bool $uuid | ||
* @return int | ||
*/ | ||
public function add(array $data, bool $time = true): int | ||
public function add(array $data, bool $time = true, bool $uuid = true): int | ||
{ | ||
return $this->DB() | ||
$_time = ($time ? ['time' => time()] : []); | ||
$_uuid = ($uuid && class_exists(\Ramsey\Uuid\Uuid::class) ? ['uuid' => \Ramsey\Uuid\Uuid::uuid6()->toString()] : []); | ||
|
||
return $this | ||
->DB() | ||
->insert($this->tableName) | ||
->set(array_merge($data, $time ? [ | ||
'time' => time() | ||
] : [])); | ||
->set(array_merge($data, $_time, $_uuid)); | ||
} | ||
|
||
/** | ||
* @param string $key | ||
* @param $val | ||
* @param array $data | ||
* @param bool $time | ||
* @param bool $uuid | ||
* @return bool | ||
*/ | ||
public function edit(string $key, $val, array $data, bool $time = true): int | ||
public function edit(string $key, $val, array $data, bool $time = true, bool $uuid = true): int | ||
{ | ||
return $this->wEdit([$key => $val], $data, $time); | ||
return $this->wEdit([$key => $val], $data, $time, $uuid); | ||
} | ||
|
||
/** | ||
* @param $where | ||
* @param array $data | ||
* @param bool $time | ||
* @param bool $uuid | ||
* @return bool | ||
*/ | ||
public function wEdit($where, array $data, bool $time = true): int | ||
public function wEdit($where, array $data, bool $time = true, bool $uuid = true): int | ||
{ | ||
//if ($this->wGet($where)) { | ||
$_time = ($time ? ['time' => time()] : []); | ||
$_uuid = ($uuid && class_exists(\Ramsey\Uuid\Uuid::class) ? ['uuid' => \Ramsey\Uuid\Uuid::uuid6()->toString()] : []); | ||
|
||
$sql = $this->DB()->update($this->tableName); | ||
$this->_where($sql, $where); | ||
$sql = $this->DB()->update($this->tableName); | ||
$this->_where($sql, $where); | ||
|
||
return $sql->set(array_merge($data, $time ? ['edit_time' => time()] : [])); | ||
// } | ||
return false; | ||
return $sql->set(array_merge($data, $_time, $_uuid)); | ||
} | ||
|
||
/** | ||
|
@@ -149,14 +153,10 @@ public function delete(string $key, $val): bool | |
*/ | ||
public function wDelete($where): bool | ||
{ | ||
//if ($this->wGet($where)) { | ||
|
||
$sql = $this->DB()->delete($this->tableName); | ||
$this->_where($sql, $where); | ||
$sql = $this->DB()->delete($this->tableName); | ||
$this->_where($sql, $where); | ||
|
||
return $sql->done(); | ||
//} | ||
return false; | ||
return $sql->done(); | ||
} | ||
|
||
/** | ||
|
@@ -175,14 +175,10 @@ public function count(string $key = null, $val = null): int | |
*/ | ||
public function wCount($where): int | ||
{ | ||
//if ($this->wGet($where)) { | ||
|
||
$sql = $this->DB()->from($this->tableName); | ||
$this->_where($sql, $where); | ||
$sql = $this->DB()->from($this->tableName); | ||
$this->_where($sql, $where); | ||
|
||
return $sql->rowCount(); | ||
//} | ||
return false; | ||
return $sql->rowCount(); | ||
} | ||
|
||
/** | ||
|