Ejemplo n.º 1
0
 public static function get_user_info($id)
 {
     $user = Model_User::find($id);
     if ($user) {
         $user_config = Model_Service_Util::get_app_config('user');
         return array('username' => $user->username, 'email' => $user->email, 'group' => $user->group, 'group_display' => $user_config['group'][$user->group], 'full_name' => $user->full_name, 'gender' => $user->gender, 'gender_display' => $user_config['gender'][$user->gender], 'birthday' => $user->birthday, 'address' => $user->address, 'telephone' => $user->telephone, 'user_photo' => $user->user_photo, 'user_photo_display' => empty($user->user_photo) ? _PATH_NO_ICON_ : _PATH_ICON_ . $user->user_photo);
     }
     return false;
 }
Ejemplo n.º 2
0
 public static function insert($data)
 {
     try {
         $props = ['code' => Model_Service_Util::gen_code(), 'parent_category_id' => !empty($data['parent_category_id']) ? $data['parent_category_id'] : 0, 'category_name' => $data['category_name'], 'rank' => Model_Category::query()->max('rank') + 1, 'level' => $data['level'], 'created_at' => date('Y-m-d H:i:s', Date::forge()->get_timestamp())];
         $new = Model_Category::forge($props);
         $new->save();
         return $new->id;
     } catch (Exception $e) {
         Log::write('ERROR', $e->getMessage());
         return false;
     }
 }
Ejemplo n.º 3
0
 public static function insert($data)
 {
     try {
         $props = ['code' => Model_Service_Util::gen_code(), 'product_name' => $data['product_name'], 'product_description' => $data['product_description'], 'product_info' => $data['product_info'], 'status' => 2, 'created_at' => date('Y-m-d H:i:s', Date::forge()->get_timestamp())];
         $new = Model_Product::forge($props);
         $new->save();
         return $new->id;
     } catch (Exception $e) {
         Log::write('ERROR', $e->getMessage());
         return false;
     }
 }
Ejemplo n.º 4
0
 public function post_contact()
 {
     $val = Validation::forge();
     $val->add_callable('MyRules');
     $val->add_field('name', 'Name', 'required|max_length[100]');
     $val->add_field('email', 'Email', 'required|valid_email|max_length[255]');
     $val->add_field('subject', 'Subject', 'required|max_length[255]');
     $val->add_field('message', 'Message', 'required|max_length[1000]');
     if ($val->run()) {
         $props = array('to' => $val->validated('email'), 'subject' => Model_Service_Util::mb_trim($val->validated('subject')), 'content' => array('name' => Model_Service_Util::mb_trim($val->validated('name')), 'body' => Model_Service_Util::mb_trim($val->validated('message'))), 'view' => 'contact');
         Model_Service_Mail::send_mail($props);
         $this->data['success'] = 'Gửi tin nhắn thành công';
     } else {
         $this->data['errors'] = $val->error_message();
     }
     return $this->response($this->data);
 }
Ejemplo n.º 5
0
 public function post_create()
 {
     $val = Validation::forge();
     $val->add_callable('MyRules');
     $val->add_field('category_name', Lang::get('label.category_name'), 'required|max_length[255]');
     $val->add_field('id', Lang::get('label.category'), 'trim|valid_numeric|valid_category');
     $val->add_field('parent_category_id', Lang::get('label.parent_category'), 'trim|valid_numeric|valid_category');
     if ($val->run()) {
         DB::start_transaction();
         $category_id = $val->validated('id');
         $parent_category_id = (int) $val->validated('parent_category_id');
         $category_props = array('category_name' => Model_Service_Util::mb_trim($val->validated('category_name')), 'parent_category_id' => $parent_category_id, 'level' => !empty($parent_category_id) ? Model_Category::find($parent_category_id)->level + 1 : 1);
         $create_id = !empty($category_id) ? Model_Base_Category::update($category_id, $category_props) : Model_Base_Category::insert($category_props);
         if ($create_id) {
             $type = !empty($category_id) ? 'update' : 'new';
             $category_id = !empty($category_id) ? $category_id : $create_id;
             $photo_props = array('type' => $type, 'category_id' => $category_id);
             if ($type === 'new' || Input::file('category_photo')) {
                 $upload = Model_Service_Upload::run('category', $photo_props);
             }
             if (empty($upload['error'])) {
                 DB::commit_transaction();
                 $this->data['category'] = array('type' => $type, 'id' => $category_id, 'parent_category_id' => $parent_category_id, 'category_name' => $val->validated('category_name'), 'category_name_display' => Model_Base_Category::get_parent($category_id), 'category_photo_display' => empty($upload['photo_name']) ?: $upload['photo_name'], 'no_image' => _PATH_NO_IMAGE_);
                 $this->data['success'] = true;
                 $this->data['msg'] = Lang::get($this->controller . '.' . $this->action . '.success');
             } else {
                 DB::rollback_transaction();
                 $this->data['msg'] = $upload['error'];
             }
         } else {
             DB::rollback_transaction();
             $this->data['msg'] = Lang::get($this->controller . '.' . $this->action . '.error');
         }
     } else {
         $this->data['errors'] = $val->error_message();
     }
     return $this->response($this->data);
 }
Ejemplo n.º 6
0
 public static function _validation_valid_product_highlight($val)
 {
     if (self::_empty($val)) {
         return true;
     }
     $_config = Model_Service_Util::get_app_config('product', array('highlight'));
     return array_key_exists($val, $_config['highlight']);
 }
Ejemplo n.º 7
0
 public static function hash_password($password)
 {
     is_null(self::$hasher) and self::$hasher = new \PHPSecLib\Crypt_Hash();
     return base64_encode(self::$hasher->pbkdf2($password, Config::get('auth.salt'), Config::get('auth.iterations', 10000), 32));
 }
Ejemplo n.º 8
0
 public function post_update()
 {
     $val = Validation::forge();
     $val->add_callable('MyRules');
     $val->add_field('id', Lang::get('label.product'), 'required|valid_product');
     $val->add_field('category_ids', Lang::get('label.category'), 'required');
     $val->add_field('product_name', Lang::get('label.product_name'), 'required|max_length[255]');
     $val->add_field('product_description', Lang::get('label.description'), 'trim|max_length[1024]');
     $val->add_field('product_info', Lang::get('label.information'), 'trim|max_length[10000]');
     if ($val->run()) {
         DB::start_transaction();
         $product_id = $val->validated('id');
         $category_ids = implode(',', $val->validated('category_ids'));
         $category_name = Model_Service_Util::mb_trim($val->validated('product_name'));
         $product_description = Model_Service_Util::mb_trim($val->validated('product_description'));
         $product_info = $val->validated('product_info');
         $product_props = array('product_name' => $category_name, 'product_description' => $product_description, 'product_info' => $product_info);
         if (Model_Base_Product::update($product_id, $product_props) && Model_Base_ProductCategory::update($product_id, $category_ids)) {
             DB::commit_transaction();
             $this->data['success'] = Lang::get($this->controller . '.' . $this->action . '.success');
         } else {
             DB::rollback_transaction();
             $this->data['error'] = Lang::get($this->controller . '.' . $this->action . '.error');
         }
     } else {
         $this->data['errors'] = $val->error_message();
     }
     return $this->response($this->data);
 }
Ejemplo n.º 9
0
 public function post_update_password()
 {
     $val = Validation::forge();
     $val->add_callable('MyRules');
     $val->add_field('password', Lang::get('label.password'), 'required|valid_password|min_length[8]|max_length[50]');
     $val->add_field('confirm_password', Lang::get('label.confirm_password'), 'match_field[password]');
     if ($val->run()) {
         $props = array('password' => Model_Service_Util::hash_password($val->validated('password')));
         if (Model_Base_User::update($this->user_id, $props)) {
             $this->data['success'] = Lang::get($this->controller . '.' . $this->action . '.success');
         } else {
             $this->data['error'] = Lang::get($this->controller . '.' . $this->action . '.error');
         }
     } else {
         $this->data['errors'] = $val->error_message();
     }
     return $this->response($this->data);
 }
Ejemplo n.º 10
0
 public static function add_user()
 {
     $user_props = ['username' => 'wjshop', 'email' => 'admin@wjshop.com', 'password' => Model_Service_Util::hash_password('11111111'), 'group' => 100, 'customer_name' => 'wjshop', 'created_at' => date('Y-m-d H:i:s', Date::forge()->get_timestamp())];
     $user = Model_User::forge($user_props);
     $user->save();
 }