<?php

/*
 * Copyright (c) 2018 Earworks.
 * Codeigniter Project Template Modification
 * Please contact our email for more information :
 *  contact@earworks.co.id
 */
defined('BASEPATH') OR exit('No direct script access allowed');

/**
 * Description of Admins_lib
 *
 * @author Fajar Dwi Rianto <fajar@earworks.co.id>
 * @since 1.0
 */
class Admins_lib {

    public function get($userid = null) {
        $CI = & get_instance();
        $CI->load->model('admins_model');
        return $CI->admins_model->get($userid);
    }
    public function check($userid = null) {
        $CI = & get_instance();
        $CI->load->model('admins_model');
        return $CI->admins_model->check($userid);
    }
    public function create($input = array()) {
        $CI = & get_instance();
        $CI->load->model('admins_model');
        $CI->load->helper('hash');
        $input['profilename'] = ucwords(strtolower($input['profilename']));
        $input['userpassword'] = hash_data($input['userpassword']);
        unset($input['confirm']);
        return $CI->admins_model->create($input);
    }
    public function update($input = array(), $userid = null) {
        $CI = & get_instance();
        $CI->load->model('admins_model');
        if(!$CI->admins_model->check($userid)){
            return false;
        }
        if($input['profilename']){
            $input['profilename'] = ucwords(strtolower($input['profilename']));
        }
        if($input['userpassword']) {
            $CI->load->helper('hash');
            $input['userpassword'] = hash_data($input['userpassword']);
        }
        return $CI->admins_model->update($input, $userid);
    }
    public function delete($userid = null) {
        $CI = & get_instance();
        $CI->load->model('admins_model');
        if(!$CI->admins_model->check($userid)){
            return false;
        }
        return $CI->admins_model->delete($userid);
    }
    public function suspend($userid = null, $status = 1){
        $CI = & get_instance();
        $CI->load->model('admins_model');
        if(!$CI->admins_model->check($userid)){
            return false;
        }
        return $CI->admins_model->suspend($userid, $status);
    }
}
