Пример #1
0
 /**
  * @author Thuanth6589 <*****@*****.**>
  * delete media
  * @param $media_id
  * @return bool
  */
 public function delete_media($media_id)
 {
     $media = Model_Mmedia::find_by_pk($media_id);
     if ($media) {
         try {
             $media_in_job = Model_Job::count('job_id', false, array(array('media_list', 'like', '%,' . $media_id . ',%')));
             $media_in_order = Model_Orders::count('order_id', false, array(array('media_list', 'like', '%,' . $media_id . ',%')));
             if ($media_in_job || $media_in_order) {
                 return false;
             }
             \Fuel\Core\DB::start_transaction();
             $post = new Model_Mpost();
             $delete_post = $post->delete_by_media($media_id);
             if (!isset($delete_post)) {
                 \Fuel\Core\DB::rollback_transaction();
                 return false;
             }
             if ($media->delete() != 1) {
                 \Fuel\Core\DB::rollback_transaction();
                 return false;
             }
             \Fuel\Core\DB::commit_transaction();
             return true;
         } catch (Exception $e) {
             \Fuel\Core\DB::rollback_transaction();
         }
     }
     return false;
 }
Пример #2
0
 public static function query($sql, $type = NULL)
 {
     //TODO: unsatisfactory implementation now.
     //		$query = new Query();
     //		return $query->parse_sql($sql);
     return parent::query($sql, $type);
 }
Пример #3
0
 /**
  * Create yaml files from database data.
  *
  * Usage (from command line):
  *
  * php oil r dbfixt:generate [-n=5] [-o=/tmp] <table1> [<table2> [...]]
  *
  * @return string
  */
 public static function generate()
 {
     $num = Cli::option('n') ? (int) Cli::option('n') : 5;
     $dir = Cli::option('o');
     if (is_null($dir)) {
         $dir = APPPATH . 'tests/fixture';
         if (!is_dir($dir)) {
             mkdir($dir);
         }
     } else {
         if (!is_dir($dir)) {
             return Cli::color('No such directory: ' . $dir, 'red');
         }
     }
     $args = func_get_args();
     foreach ($args as $table) {
         if (DBUtil::table_exists($table)) {
             $result = DB::select('*')->from($table)->limit($num)->execute();
             $data = $result->as_array();
             static::setToYaml($dir, $data, $table);
         } elseif (Mongo_Db::instance()->get_collection($table)) {
             $mongo = Mongo_Db::instance();
             $data = $mongo->limit($num)->get($table);
             static::setToYaml($dir, $data, $table);
         } else {
             echo Cli::color('No such table: ' . $table, 'red') . PHP_EOL;
         }
     }
 }
Пример #4
0
 public static function breadcum_base_type($type)
 {
     //Name
     $dbResult = DB::select('TypeName')->from(self::$TABLE)->where('ID', $type);
     // Parent name
     $dbResult = DB::select('TypeName')->from(self::$TABLE)->where('ParentID', $type);
 }
Пример #5
0
 public function connectDB()
 {
     $userData = null;
     $query = DB::select()->from('users');
     $userData = $query->execute();
     return $userData;
 }
Пример #6
0
 public static function load_data($type)
 {
     $dbResult = DB::SELECT('name', 'content')->from('about')->where('type', $type)->execute();
     $data = $dbResult->as_array();
     $retData['Data']['content'] = $data[0]['content'];
     return $retData;
 }
Пример #7
0
 /**
  * @author Thuanth6589 <*****@*****.**>
  * action delete ss
  * @param null $ss_id
  * @return bool
  */
 public static function delete_ss($ss_id = null)
 {
     if (!isset($ss_id)) {
         return false;
     }
     $ss = Model_Mss::find_by_pk($ss_id);
     if (!isset($ss)) {
         return false;
     }
     try {
         \Fuel\Core\DB::start_transaction();
         $sssale = new Model_Sssale();
         $delete = $sssale->delete_by_ss($ss_id);
         if (!isset($delete)) {
             return false;
         }
         if (!$ss->delete()) {
             \Fuel\Core\DB::rollback_transaction();
             return false;
         }
         \Fuel\Core\DB::commit_transaction();
         return true;
     } catch (Exception $e) {
         \Fuel\Core\DB::rollback_transaction();
         return false;
     }
 }
Пример #8
0
 public function updateView()
 {
     try {
         $dbObj = DB::update($this->TABLE)->set(array("Views" => $this->Views + 1))->where('ID', $this->ID);
         $dbResult = $dbObj->execute();
     } catch (\Exception $e) {
     }
 }
Пример #9
0
 private function _get_where($filters = array())
 {
     $query = \Fuel\Core\DB::select('emcall.*')->from('emcall');
     if (isset($filters['person_id']) && $filters['person_id']) {
         $query->where('person_id', '=', $filters['person_id']);
     }
     return $query;
 }
Пример #10
0
 public static function load_admissions_data()
 {
     $dbResult = DB::SELECT('name', 'content')->from('admissions_faculty')->where('faculty_id', 2)->execute();
     $data = $dbResult->as_array();
     foreach ($data as $item) {
         $retData['Data'][$item['name']] = $item['content'];
     }
     return $retData;
 }
Пример #11
0
 public static function up()
 {
     $table_exists = DBUtil::table_exists(self::$_table_name);
     if ($table_exists) {
         return false;
     }
     DBUtil::create_table(self::$_table_name, ['id' => ['constraint' => 11, 'type' => 'int', 'auto_increment' => true], 'maintenance' => ['constraint' => 1, 'type' => 'tinyint', 'default' => 0], 'email' => ['constraint' => 255, 'type' => 'varchar', 'null' => true], 'telephone' => ['constraint' => 12, 'type' => 'varchar', 'null' => true], 'address' => ['constraint' => 255, 'type' => 'varchar', 'null' => true], 'fb_url' => ['constraint' => 255, 'type' => 'varchar', 'null' => true], 'shop_name' => ['constraint' => 255, 'type' => 'varchar', 'null' => true], 'created_at' => ['type' => 'timestamp', 'default' => DB::expr('CURRENT_TIMESTAMP')], 'updated_at' => ['type' => 'timestamp', 'default' => '0000-00-00 00:00:00']], ['id'], true, 'InnoDB', 'utf8_general_ci');
     DBUtil::create_index(self::$_table_name, 'maintenance', 'maintenance');
 }
Пример #12
0
 public function post_add()
 {
     $model = Model_Blog::forge();
     $model->set(Input::post());
     $model->set(BLOG_CREATED_DATE, DB::expr('now()'));
     $model->set(DELETE_FLG, '0');
     $model->save();
     Response::redirect(Config::get('base_url'));
 }
Пример #13
0
 public static function delete($id)
 {
     $result = DB::delete(Staff::$TABLE)->where('ID', $id)->execute();
     if ($result > 0) {
         // Success
     } else {
         // Fail
     }
 }
Пример #14
0
 public static function up()
 {
     $table_exists = DBUtil::table_exists(self::$_table_name);
     if ($table_exists) {
         return false;
     }
     DBUtil::create_table(self::$_table_name, ['id' => ['constraint' => 11, 'type' => 'int', 'auto_increment' => true], 'group_id' => ['constraint' => 50, 'type' => 'varchar'], 'group_name' => ['constraint' => 50, 'type' => 'varchar'], 'privacy' => ['constraint' => 255, 'type' => 'varchar'], 'created_at' => ['type' => 'timestamp', 'default' => DB::expr('CURRENT_TIMESTAMP')], 'updated_at' => ['type' => 'timestamp', 'default' => '0000-00-00 00:00:00']], ['id'], true, 'InnoDB', 'utf8_general_ci');
     DBUtil::create_index(self::$_table_name, 'group_id', 'group_id');
 }
Пример #15
0
 public function getListBaseType($type)
 {
     try {
         $dbResult = DB::select('*')->from('News')->where('Type', $type)->execute();
         return $this->format($dbResult->as_array());
     } catch (\Exception $e) {
         ErrorMsg::_log($e);
         return null;
     }
 }
Пример #16
0
 public static function up()
 {
     $table_exists = DBUtil::table_exists(self::$_table_name);
     if ($table_exists) {
         return false;
     }
     DBUtil::create_table(self::$_table_name, ['order_item_id' => ['constraint' => 11, 'type' => 'int', 'auto_increment' => true], 'order_id' => ['constraint' => 11, 'type' => 'int'], 'product_id' => ['constraint' => 11, 'type' => 'int'], 'product_price' => ['constraint' => 11, 'type' => 'int'], 'quantity' => ['constraint' => 11, 'type' => 'int'], 'created_at' => ['type' => 'timestamp', 'default' => DB::expr('CURRENT_TIMESTAMP')]], ['order_item_id'], true, 'InnoDB', 'utf8_general_ci');
     DBUtil::create_index(self::$_table_name, 'order_id', 'order_id');
     DBUtil::create_index(self::$_table_name, 'product_id', 'product_id');
 }
Пример #17
0
 public static function up()
 {
     $table_exists = DBUtil::table_exists(self::$_table_name);
     if ($table_exists) {
         return false;
     }
     DBUtil::create_table(self::$_table_name, ['id' => ['constraint' => 11, 'type' => 'int', 'auto_increment' => true], 'code' => ['constraint' => 50, 'type' => 'varchar'], 'product_name' => ['type' => 'text'], 'product_description' => ['type' => 'text', 'null' => true], 'product_info' => ['type' => 'text', 'null' => true], 'note' => ['type' => 'text', 'null' => true], 'product_photo' => ['constraint' => 50, 'type' => 'varchar', 'null' => true], 'status' => ['constraint' => 1, 'type' => 'tinyint', 'default' => 2], 'highlight' => ['constraint' => 1, 'type' => 'tinyint', 'default' => 0], 'created_at' => ['type' => 'timestamp', 'default' => DB::expr('CURRENT_TIMESTAMP')], 'updated_at' => ['type' => 'timestamp', 'default' => '0000-00-00 00:00:00']], ['id'], true, 'InnoDB', 'utf8_general_ci');
     DBUtil::create_index(self::$_table_name, 'code', 'code');
     DBUtil::create_index(self::$_table_name, 'status', 'status');
     DBUtil::create_index(self::$_table_name, 'highlight', 'highlight');
 }
Пример #18
0
 /**
  * @author Bui Dang <*****@*****.**>
  * action check group name exits
  */
 public static function check_name($group_id = null, $group_name = null)
 {
     $select_group = \Fuel\Core\DB::select('*')->from(self::$_table_name);
     if (isset($group_id)) {
         $select_group->where('m_group_id', '!=', $group_id);
     }
     if (isset($group_name)) {
         $select_group->where('name', '=', $group_name);
     }
     return count($select_group->execute());
 }
Пример #19
0
 public static function load_highlight()
 {
     try {
         $dbResult = DB::SELECT('ID', 'Title', 'Description')->from('News')->where('Type', 2)->order_by('DateCreate', 'dsc')->limit(1)->execute();
         $dbData = $dbResult->as_array();
         return $dbData;
     } catch (\Exception $e) {
         Log::error($e);
         // Redirect to 500 server error;
         return Response::redirect(500);
     }
 }
Пример #20
0
 public static function getStaffBaseID($id)
 {
     try {
         $dbObj = DB::select('*')->from("Employee")->where('ID', $id);
         $dbResult = $dbObj->execute();
         print_r($dbResult);
         exit;
     } catch (\Exception $e) {
         print_r($e);
         exit;
     }
 }
Пример #21
0
 public static function buildListFaculty()
 {
     try {
         /** @var Database_Query $dbObj  */
         $dbObj = DB::select('*')->from('Faculty');
         $dbResult = $dbObj->execute();
         return $dbResult->as_array();
     } catch (\Exception $e) {
         ErrorCode::dbLog($e);
         return null;
     }
 }
Пример #22
0
 public static function up()
 {
     $table_exists = DBUtil::table_exists(self::$_table_name);
     if ($table_exists) {
         return false;
     }
     DBUtil::create_table(self::$_table_name, ['order_id' => ['constraint' => 11, 'type' => 'int', 'auto_increment' => true], 'user_id' => ['constraint' => 11, 'type' => 'int'], 'message' => ['type' => 'text', 'null' => true], 'order_email' => ['type' => 'text', 'null' => true], 'order_gender' => ['type' => 'text', 'null' => true], 'order_last_name' => ['type' => 'text', 'null' => true], 'order_first_name' => ['type' => 'text', 'null' => true], 'order_last_name_kana' => ['type' => 'text', 'null' => true], 'order_first_name_kana' => ['type' => 'text', 'null' => true], 'order_tel' => ['type' => 'text', 'null' => true], 'order_fax' => ['type' => 'text', 'null' => true], 'order_zip' => ['type' => 'text', 'null' => true], 'order_addr' => ['type' => 'text', 'null' => true], 'payment_total' => ['constraint' => 11, 'type' => 'int'], 'payment_method' => ['constraint' => 1, 'type' => 'int'], 'payment_status' => ['constraint' => 1, 'type' => 'int', 'default' => 1], 'payment_date' => ['type' => 'timestamp', 'default' => '0000-00-00 00:00:00'], 'del_flg' => ['constraint' => 1, 'type' => 'tinyint', 'default' => 0], 'created_at' => ['type' => 'timestamp', 'default' => DB::expr('CURRENT_TIMESTAMP')], 'updated_at' => ['type' => 'timestamp', 'default' => '0000-00-00 00:00:00']], ['order_id'], true, 'InnoDB', 'utf8_general_ci');
     DBUtil::create_index(self::$_table_name, 'user_id', 'user_id');
     DBUtil::create_index(self::$_table_name, 'payment_method', 'payment_method');
     DBUtil::create_index(self::$_table_name, 'payment_status', 'payment_status');
     DBUtil::create_index(self::$_table_name, 'del_flg', 'del_flg');
 }
Пример #23
0
 public static function up()
 {
     $table_exists = DBUtil::table_exists(self::$_table_name);
     if ($table_exists) {
         return false;
     }
     DBUtil::create_table(self::$_table_name, ['id' => ['constraint' => 11, 'type' => 'int', 'auto_increment' => true], 'username' => ['constraint' => 32, 'type' => 'varchar'], 'email' => ['constraint' => 255, 'type' => 'varchar'], 'password' => ['constraint' => 255, 'type' => 'varchar'], 'login_hash' => ['constraint' => 255, 'type' => 'varchar', 'null' => true], 'last_login' => ['constraint' => 11, 'type' => 'int', 'default' => 0], 'group' => ['constraint' => 11, 'type' => 'int', 'default' => 1], 'password_code' => ['constraint' => 32, 'type' => 'varchar', 'null' => true], 'full_name' => ['constraint' => 255, 'type' => 'varchar', 'null' => true], 'gender' => ['constraint' => 1, 'type' => 'int', 'default' => 0], 'birthday' => ['constraint' => 10, 'type' => 'varchar', 'null' => true], 'address' => ['constraint' => 255, 'type' => 'varchar', 'null' => true], 'telephone' => ['constraint' => 12, 'type' => 'varchar', 'null' => true], 'user_photo' => ['constraint' => 50, 'type' => 'varchar', 'null' => true], 'created_at' => ['type' => 'timestamp', 'default' => DB::expr('CURRENT_TIMESTAMP')], 'updated_at' => ['type' => 'timestamp', 'default' => '0000-00-00 00:00:00']], ['id'], true, 'InnoDB', 'utf8_general_ci');
     DBUtil::create_index(self::$_table_name, 'username', 'username');
     DBUtil::create_index(self::$_table_name, 'email', 'email');
     DBUtil::create_index(self::$_table_name, 'password', 'password');
     DBUtil::create_index(self::$_table_name, 'login_hash', 'login_hash');
     DBUtil::create_index(self::$_table_name, 'group', 'group');
 }
Пример #24
0
 public static function in_pages($page, $section_id)
 {
     // Start query with main section ID
     try {
         $dbResult = DB::SELECT('ID', 'Title', 'Description')->from('News')->where('Type', $section_id)->order_by('DateCreate', 'dsc')->limit(5)->offset($page * 5)->execute();
         $dbData = $dbResult->as_array();
         return $dbData;
     } catch (\Exception $e) {
         Log::error($e);
         // Redirect to 500 server error;
         return Response::redirect(500);
     }
 }
Пример #25
0
 public static function get_content($data)
 {
     $type = $data['type'];
     $query = "\n            SELECT content FROM recruitment\n            WHERE type = '{$type}'\n        ";
     $dbResult = DB::query($query)->execute();
     $data = $dbResult->as_array();
     if (empty($data)) {
         $data['content'] = '';
         return $data;
     } else {
         return $data[0];
     }
 }
Пример #26
0
 public static function get_content($data)
 {
     $faculty = $data['faculty'];
     $type = $data['type'];
     $query = "\n            SELECT content FROM admissions_faculty\n            WHERE faculty_id      = '{$faculty}' AND\n                  name  = '{$type}'\n\n        ";
     $dbResult = DB::query($query)->execute();
     $data = $dbResult->as_array();
     if (empty($data)) {
         $data['content'] = '';
         return $data;
     } else {
         return $data[0];
     }
 }
Пример #27
0
 public static function insert($props)
 {
     try {
         $query = DB::insert(static::$_table_name)->columns(static::$_properties);
         foreach ($props as $prop) {
             $query->values($prop);
         }
         if ($query->execute()) {
             return true;
         }
     } catch (Exception $e) {
         Log::write('ERROR', $e->getMessage());
         return false;
     }
     return false;
 }
Пример #28
0
 public static function _get_where($filter = array(), $keyword = array())
 {
     $query = \Fuel\Core\DB::select('*')->from(self::$_table_name)->order_by('created_at', 'desc');
     if (isset($filter['start_date']) and isset($filter['end_date'])) {
         $query->where_open();
         $query->where('created_at', '>=', $filter['start_date']);
         $query->where('created_at', '<=', $filter['end_date']);
         $query->where_close();
     }
     if (isset($filter['start_date']) and !isset($filter['end_date'])) {
         $query->where('created_at', '>=', $filter['start_date']);
     }
     if (isset($filter['end_date']) and !isset($filter['start_date'])) {
         $query->where('created_at', '<=', $filter['end_date']);
     }
     if (!empty($keyword)) {
         $query->and_where_open();
         $query->or_where_open();
         foreach ($keyword as $word) {
             $query->where('name', 'like', '%' . $word . '%');
         }
         $query->or_where_close();
         $query->or_where_open();
         foreach ($keyword as $word) {
             $query->where('name_kana', 'like', '%' . $word . '%');
         }
         $query->or_where_close();
         $query->or_where_open();
         foreach ($keyword as $word) {
             $query->where('mobile', 'like', '%' . $word . '%');
         }
         $query->or_where_close();
         $query->or_where_open();
         foreach ($keyword as $word) {
             $query->where('mail', 'like', '%' . $word . '%');
         }
         $query->or_where_close();
         $query->and_where_close();
     }
     if (isset($filter['offset'])) {
         $query->offset($filter['offset']);
     }
     if (isset($filter['limit'])) {
         $query->limit($filter['limit']);
     }
     return $query;
 }
Пример #29
0
 protected function getLetters()
 {
     $numSymbol = \Arr::get($this->config, 'numeric-symbol');
     $lettersQuery = DB::select(array(\DB::expr('LOWER(SUBSTR(' . Model_Word::title_property() . ',1,1)) collate utf8_general_ci '), 'initial'))->from(Model_Word::table())->group_by('initial')->order_by('initial', 'asc')->execute();
     $letters = array();
     foreach ($lettersQuery as $let) {
         $let['initial'] = iconv('UTF-8', 'ASCII//TRANSLIT', $let['initial']);
         if (!preg_match('/[a-z]/i', $let['initial'])) {
             $let['initial'] = $numSymbol;
         }
         if (in_array($let['initial'], $letters)) {
             continue;
         }
         $letters[] = $let['initial'];
     }
     return $letters;
 }
Пример #30
0
    public static function get_auto_complete_list()
    {
        $table_name = Model_Project::table();
        $sql = <<<SQL
SELECT name 
FROM {$table_name}
ORDER BY name ASC
SQL;
        $result = \Fuel\Core\DB::query($sql)->execute();
        $auto_complete_list = array();
        foreach ($result->as_array() as $index => $array) {
            foreach ($array as $project_name) {
                $auto_complete_list[] = $project_name;
            }
        }
        return $auto_complete_list;
    }