UserModel.php 1.93 KB
<?php
/**
 *
 * @author Adhidarma <adhisimon@gmail.com>
 */
class UserModel extends Model {
    protected $table_name = 'users';
    protected $table_fields = array(
        'email' => array(
            'type' => \DB\SQL\Schema::DT_VARCHAR128,
            'nullable' => false,
            'index' => true,
            'unique' => true,
        ),

        'fullname' => array(
            'type' => \DB\SQL\Schema::DT_VARCHAR128,
            'nullable' => true,
            'index' => false,
            'unique' => false,
        ),

        'phone' => array(
            'type' => \DB\SQL\Schema::DT_VARCHAR128,
            'nullable' => true,
            'index' => false,
            'unique' => false,
        ),

        'password' => array(
            'type' => \DB\SQL\Schema::DT_VARCHAR512,
            'nullable' => true,
            'index' => false,
            'unique' => false,
        ),

        'enable' => array(
            'type' => \DB\SQL\Schema::DT_BOOLEAN,
            'nullable' => true,
            'index' => false,
            'unique' => false,
            'default' => 1,
        ),

        'created' => array(
            'type' => \DB\SQL\Schema::DT_DATETIME,
            'nullable' => false,
            'index' => false,
            'unique' => false,
        ),

        'modified' => array(
            'type' => \DB\SQL\Schema::DT_TIMESTAMP,
            'nullable' => true,
            'index' => false,
            'unique' => false,
            'default' => \DB\SQL\Schema::DF_CURRENT_TIMESTAMP,
        ),
    );

    protected $initial_rows = array(
        array(
            'email' => 'admin@example.com',
            'fullname' => 'Administrator',
            'password' => '$1$xl5Amydz$YZVaSpUFkOlVGaoNUAtBa.', // crypt('admin')
            'enable' => 1,
            'created' => self::DB_FUNCTION_NOW
        ),
    );

    public function getByEmail($email) {
        return $this->getItemByFieldValue('email', $email);
    }
}