Ejemplo n.º 1
0
 /**
  * แสดงผล
  *
  * @return string
  */
 public function render()
 {
     // อ่านข้อมูลสมาชิก
     $rs = Recordset::create('Index\\User\\Model');
     $user = $rs->where((int) $_SESSION['login']['id'])->first('id');
     $template = Template::create('member', 'member', 'password');
     $contents = array('/{ACCEPT}/' => Mime::getEccept(self::$cfg->user_icon_typies), '/{USER_ICON_TYPIES}/' => sprintf(Language::get('Upload a picture of %s resize automatically'), empty(self::$cfg->user_icon_typies) ? 'jpg' : implode(', ', self::$cfg->user_icon_typies)));
     // ข้อมูลฟอร์ม
     foreach ($user as $key => $value) {
         if ($key == 'sex') {
             $source = Language::get('SEXES');
             $datas = array();
             foreach ($source as $k => $v) {
                 $sel = $k == $value ? ' selected' : '';
                 $datas[] = '<option value="' . $k . '"' . $sel . '>' . $v . '</option>';
             }
             $contents['/{' . strtoupper($key) . '}/'] = implode('', $datas);
         } elseif ($key === 'subscrib') {
             $contents['/{' . strtoupper($key) . '}/'] = $value == 1 ? 'checked' : '';
         } elseif ($key === 'icon') {
             if (is_file(ROOT_PATH . self::$cfg->usericon_folder . $value)) {
                 $icon = WEB_URL . self::$cfg->usericon_folder . $value;
             } else {
                 $icon = WEB_URL . 'skin/img/noicon.jpg';
             }
             $contents['/{ICON}/'] = $icon;
         } else {
             $contents['/{' . strtoupper($key) . '}/'] = $value;
         }
     }
     $template->add($contents);
     return $template->render();
 }
 /**
  * action
  */
 public static function action()
 {
     $ret = array();
     // referer, session, admin
     if (self::$request->initSession() && self::$request->isReferer() && ($login = Login::isAdmin())) {
         if ($login['email'] == 'demo') {
             $ret['alert'] = Language::get('Unable to complete the transaction');
         } else {
             if (self::$request->post('action')->toString() === 'delete') {
                 $id = self::$request->post('action')->toInt();
                 $rs = Recordset::create(get_called_class());
                 $index = $rs->find($id);
                 if ($index) {
                     $index->delete();
                 }
                 // คืนค่า
                 $ret['delete_id'] = self::$request->post('src')->toString() . '_' . $id;
                 $ret['alert'] = Language::get('Deleted successfully');
             }
         }
     } else {
         $ret['alert'] = Language::get('Unable to complete the transaction');
     }
     // คืนค่าเป็น JSON
     echo json_encode($ret);
 }
Ejemplo n.º 3
0
 /**
  * แสดงผล
  *
  * @return string
  */
 public function render()
 {
     // อ่านข้อมูลสมาชิก
     $rs = Recordset::create('Index\\User\\Model');
     $user = $rs->where((int) $_SESSION['login']['id'])->first('id', 'provinceID', 'country', 'fname', 'lname', 'address1', 'address2', 'province', 'zipcode');
     $template = Template::create('member', 'member', 'address');
     $contents = array();
     // ข้อมูลฟอร์ม
     foreach ($user as $key => $value) {
         if ($key === 'provinceID' || $key === 'country') {
             // select
             if ($key == 'provinceID') {
                 $source = Province::all();
             } elseif ($key == 'country') {
                 $source = Country::all();
             }
             $datas = array();
             foreach ($source as $k => $v) {
                 $sel = $k == $value ? ' selected' : '';
                 $datas[] = '<option value="' . $k . '"' . $sel . '>' . $v . '</option>';
             }
             $contents['/{' . strtoupper($key) . '}/'] = implode('', $datas);
         } else {
             $contents['/{' . strtoupper($key) . '}/'] = $value;
         }
     }
     $template->add($contents);
     return $template->render();
 }
Ejemplo n.º 4
0
 /**
  * Recordset Performance (select and update)
  * ทดสอบการเรียกข้อมูลและอัปเดทข้อมูลด้วย Recordset
  */
 public function recordset()
 {
     $rs = \Kotchasan\Orm\Recordset::create('Index\\World\\Model');
     $rs->updateAll(array('name' => ''));
     for ($i = 0; $i < 2; $i++) {
         $rnd = mt_rand(1, 10000);
         $result = $rs->find($rnd);
         $result->name = 'Hello World!';
         $result->save();
     }
     $result = $rs->find($result->id);
     echo $result->name;
 }
Ejemplo n.º 5
0
 /**
  * แสดงผล
  *
  * @param Request $request
  */
 public function index(Request $request)
 {
     // อ่านรายชื่อฟิลด์ของตาราง
     $rs = Recordset::create('Index\\World\\Model');
     $result = $rs->find(100);
     $fields = $rs->getFields();
     echo implode(', ', array_keys($fields)) . '<br>';
     // ลบข้อมูลทั้งตาราง
     $rs->emptyTable();
     // insert new record
     for ($i = 0; $i < 10000; $i++) {
         $query = World::create();
         $query->updated_at = Date::mktimeToSqlDateTime();
         $query->save();
     }
     // อัปเดททุก record
     $rs->updateAll(array('created_at' => Date::mktimeToSqlDateTime()));
     // อ่านจำนวนข้อมูลทั้งหมดในตาราง
     echo 'All ' . $rs->count() . ' records.<br>';
     // สุ่ม record มาแก้ไข
     for ($i = 0; $i < 5; $i++) {
         $rnd = rand(1, 10000);
         $world = $rs->find($rnd);
         $world->name = 'Hello World!';
         $world->save();
     }
     // query รายการที่มีการแก้ไข
     $rs->where(array('name', '!=', ''));
     // อ่านจำนวนข้อมูลที่พบ
     echo 'Found ' . $rs->count() . ' records.<br>';
     // แสดงผลรายการที่พบ
     foreach ($rs->all('id', 'name') as $item) {
         echo $item->id . '=' . $item->name . '<br>';
         // ลบรายการที่กำลังแสดงผล
         $item->delete();
     }
     // อ่านรายชื่อฟิลด์ของ query
     $fields = $rs->getFields();
     echo implode(', ', array_keys($fields)) . '<br>';
     // อ่านจำนวนข้อมูลที่เหลือ
     echo 'Remain ' . Recordset::create('Index\\World\\Model')->count() . ' records.<br>';
 }