Skip to content

Commit

Permalink
Update Tree.php
Browse files Browse the repository at this point in the history
  • Loading branch information
mirarus committed Nov 27, 2023
1 parent a6940d6 commit d6eeb98
Showing 1 changed file with 25 additions and 29 deletions.
54 changes: 25 additions & 29 deletions src/Model/Tree.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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));
}

/**
Expand All @@ -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();
}

/**
Expand All @@ -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();
}

/**
Expand Down

0 comments on commit d6eeb98

Please sign in to comment.