| 1 |
<?php |
| 2 |
|
| 3 |
namespace WeDevs\ERP\Framework; |
| 4 |
|
| 5 |
/** |
| 6 |
* Class Model |
| 7 |
*/ |
| 8 |
class Model extends \WeDevs\ORM\Eloquent\Model { |
| 9 |
protected $prefixed_table = null; |
| 10 |
|
| 11 |
/** |
| 12 |
* Get the table name with WP prefix |
| 13 |
* |
| 14 |
* @return string |
| 15 |
*/ |
| 16 |
public function getTable() { |
| 17 |
if ( ! $this->prefixed_table ) { |
| 18 |
$this->prefixed_table = $this->getConnection()->db->prefix . $this->table; |
| 19 |
} |
| 20 |
|
| 21 |
return $this->prefixed_table; |
| 22 |
} |
| 23 |
|
| 24 |
/** |
| 25 |
* Set the value of the "created at" attribute. |
| 26 |
* |
| 27 |
* @param mixed $value |
| 28 |
* |
| 29 |
* @return void |
| 30 |
*/ |
| 31 |
public function setCreatedAt( $value ) { |
| 32 |
$this->{static::CREATED_AT} = current_time( 'mysql' ); |
| 33 |
} |
| 34 |
|
| 35 |
/** |
| 36 |
* Set the value of the "updated at" attribute. |
| 37 |
* |
| 38 |
* @param mixed $value |
| 39 |
* |
| 40 |
* @return void |
| 41 |
*/ |
| 42 |
public function setUpdatedAt( $value ) { |
| 43 |
$this->{static::UPDATED_AT} = current_time( 'mysql' ); |
| 44 |
} |
| 45 |
|
| 46 |
/** |
| 47 |
* Set the table associated with the model. |
| 48 |
* |
| 49 |
* @param string $table |
| 50 |
* |
| 51 |
* @return $this |
| 52 |
*/ |
| 53 |
public function setTable( $table ) { |
| 54 |
if ( ! empty( $this->table ) ) { |
| 55 |
$table = $this->table; |
| 56 |
} |
| 57 |
|
| 58 |
if ( ! $this->prefixed_table ) { |
| 59 |
$this->prefixed_table = $this->getConnection()->db->prefix . $table; |
| 60 |
} |
| 61 |
|
| 62 |
return $this; |
| 63 |
} |
| 64 |
} |
| 65 |
|