Пример #1
0
 /**
  * 
  * @param string $type image type
  * @return orm object
  * 
  * @access public
  * @author Dao Anh Minh
  */
 public static function get_img($type)
 {
     $img = Model_Img::query()->where('type', $type)->where('active', true);
     if ($type == IMG_GALLERY) {
         // return multi images
         return $img->get();
     } else {
         // return one image
         return $img->get_one();
     }
 }
Пример #2
0
 /**
  * Update active
  *
  * @param integer $img_id
  *
  * @access public
  * @author Dao Anh Minh
  */
 public function action_active($img_id, $type)
 {
     $up_active = Model_Img::query()->where('id', $img_id)->where('type', IMG_GALLERY)->get_one();
     if (empty($up_active)) {
         Session::set_flash('error', 'Không cập nhật được hình này');
         Response::redirect('admin/gallery');
     } else {
         $active = $type == 'display' ?: false;
         // update spcicifed id to active
         Model_Img::query()->where('id', $img_id)->where('type', IMG_GALLERY)->set('active', $active)->update();
         Session::set_flash('success', 'Cập nhật hình thành công');
         Response::redirect('admin/gallery');
     }
 }
Пример #3
0
 /**
  * Register background
  * 
  * @param integer $logo_id
  * 
  * @access public
  * @author Dao Anh Minh
  */
 public function action_register()
 {
     $view = View::forge('admin/mainlogo/register');
     $view->err = array();
     if (Input::method() == 'POST') {
         if (count(Input::file()) == 0) {
             Session::set_flash('error', 'Chưa chọn hình');
             Response::redirect('admin/mainlogo/register');
         }
         Upload::process($this->config);
         if (Upload::is_valid()) {
             Upload::save();
         } else {
             Session::set_flash('error', 'Chỉ chấp nhận file hình');
             Response::redirect('admin/mainlogo/register');
         }
         $file_name = Upload::get_files(0)['saved_as'];
         if (!empty($file_name)) {
             $img = Model_Img::forge();
             $active = Input::post('active', false);
             if ($active != false) {
                 // update all background images to non-active
                 Model_Img::query()->where('type', IMG_LOGO)->set('active', false)->update();
             }
             $img->name = $file_name;
             $img->active = $active;
             $img->type = IMG_LOGO;
             $img->info = null;
             $img->save();
             Session::set_flash('success', 'Đăng ký logo thành công');
             Response::redirect('admin/mainlogo');
         } else {
             Session::set_flash('error', 'Có lỗi xảy ra, vui lòng thử lại');
             Response::redirect('admin/mainlogo');
         }
     }
     $this->template->title = 'Đăng ký logo chính';
     $this->template->content = $view;
 }