예제 #1
0
파일: report.php 프로젝트: Gerold103/lgmis
 public static function FetchBy($kwargs)
 {
     extract($kwargs, EXTR_PREFIX_ALL, 't');
     $select_list = '*';
     $eq_conds = array();
     $order_by = '';
     $limit = '';
     $offset = '';
     $where_addition = '';
     $is_assoc = false;
     $is_unique = false;
     $special = array();
     if (isset($t_select_list)) {
         $select_list = $t_select_list;
     }
     if (isset($t_eq_conds)) {
         $eq_conds = $t_eq_conds;
     }
     if (isset($t_order_by)) {
         $order_by = $t_order_by;
     }
     if (isset($t_limit)) {
         $limit = $t_limit;
     }
     if (isset($t_offset)) {
         $offset = $t_offset;
     }
     if (isset($t_where_addition)) {
         $where_addition = $t_where_addition;
     }
     if (isset($t_is_assoc)) {
         $is_assoc = $t_is_assoc;
     }
     if (isset($t_is_unique)) {
         $is_unique = $t_is_unique;
     }
     if (isset($t_special)) {
         $special = $t_special;
     }
     global $db_connection;
     $where_clause = '';
     $i = 0;
     $size = count($eq_conds);
     $need_where_word = $size !== 0 || StringNotEmpty($where_addition);
     foreach ($eq_conds as $key => $value) {
         $value_tmp = $db_connection->real_escape_string($value);
         if (is_string($value_tmp)) {
             $value_tmp = '"' . $value_tmp . '"';
         }
         $where_clause .= ' (' . $key . ' = ' . $value_tmp . ') ';
         if ($i < $size - 1) {
             $where_clause .= 'OR';
         }
         ++$i;
     }
     if ($need_where_word) {
         if (StringNotEmpty($where_clause) && StringNotEmpty($where_addition)) {
             $where_clause = '(' . $where_clause . ') AND ';
             $where_addition = '(' . $where_addition . ')';
         }
         $where_clause = "WHERE " . $where_clause . ' ' . $where_addition;
     }
     if (StringNotEmpty($order_by)) {
         $where_clause .= ' ORDER BY ' . $order_by;
     }
     if (StringNotEmpty($limit)) {
         $where_clause .= ' LIMIT ' . $limit;
     }
     if (StringNotEmpty($offset)) {
         $where_clause .= ' OFFSET ' . $offset;
     }
     if (!StringNotEmpty($lang)) {
         $lang = GetLanguage();
     }
     $from_table = self::$table;
     $res = $db_connection->query("SELECT " . $select_list . " FROM " . $from_table . " " . $where_clause);
     if (!$res) {
         return new Error($db_connection->error, Error::db_error);
     }
     $res = self::ArrayFromDBResult($res, $is_assoc);
     $res_count = count($res);
     if ($is_unique) {
         if ($res_count > 1) {
             return Error::ambiguously;
         }
         if ($res_count === 0) {
             return Error::not_found;
         }
     }
     for ($i = 0, $count = count($special); $i < $count; ++$i) {
         switch ($special[$i]) {
             default:
                 break;
         }
     }
     if (!$is_unique) {
         return $res;
     } else {
         return $res[0];
     }
 }
예제 #2
0
파일: myfile.php 프로젝트: Gerold103/lgmis
 public static function FetchBy($kwargs)
 {
     extract($kwargs, EXTR_PREFIX_ALL, 't');
     $select_list = '*';
     $eq_conds = array();
     $order_by = '';
     $limit = '';
     $offset = '';
     $where_addition = '';
     $is_assoc = false;
     $is_unique = false;
     $special = array();
     if (isset($t_select_list)) {
         $select_list = $t_select_list;
     }
     if (isset($t_eq_conds)) {
         $eq_conds = $t_eq_conds;
     }
     if (isset($t_order_by)) {
         $order_by = $t_order_by;
     }
     if (isset($t_limit)) {
         $limit = $t_limit;
     }
     if (isset($t_offset)) {
         $offset = $t_offset;
     }
     if (isset($t_where_addition)) {
         $where_addition = $t_where_addition;
     }
     if (isset($t_is_assoc)) {
         $is_assoc = $t_is_assoc;
     }
     if (isset($t_is_unique)) {
         $is_unique = $t_is_unique;
     }
     if (isset($t_special)) {
         $special = $t_special;
     }
     global $db_connection;
     $where_clause = '';
     $i = 0;
     $size = count($eq_conds);
     $need_where_word = $size !== 0 || StringNotEmpty($where_addition);
     foreach ($eq_conds as $key => $value) {
         $value_tmp = $db_connection->real_escape_string($value);
         if (is_string($value)) {
             $value_tmp = '"' . $value_tmp . '"';
         }
         $where_clause .= ' (' . $key . ' = ' . $value_tmp . ') ';
         if ($i < $size - 1) {
             $where_clause .= 'OR';
         }
         ++$i;
     }
     if ($need_where_word) {
         if (StringNotEmpty($where_clause) && StringNotEmpty($where_addition)) {
             $where_clause = '(' . $where_clause . ') AND ';
             $where_addition = '(' . $where_addition . ')';
         }
         $where_clause = "WHERE " . $where_clause . ' ' . $where_addition;
     }
     if (StringNotEmpty($order_by)) {
         $where_clause .= ' ORDER BY ' . $order_by;
     }
     if (StringNotEmpty($limit)) {
         $where_clause .= ' LIMIT ' . $limit;
     }
     if (StringNotEmpty($offset)) {
         $where_clause .= ' OFFSET ' . $offset;
     }
     if (!StringNotEmpty($lang)) {
         $lang = GetLanguage();
     }
     $from_table = self::$table;
     $res = $db_connection->query("SELECT " . $select_list . " FROM " . $from_table . " " . $where_clause);
     if (!$res) {
         return new Error($db_connection->error, Error::db_error);
     }
     $res = self::ArrayFromDBResult($res, $is_assoc);
     $res_count = count($res);
     if ($is_unique) {
         if ($res_count > 1) {
             return Error::ambiguously;
         }
         if ($res_count === 0) {
             return Error::not_found;
         }
     }
     for ($i = 0, $count = count($special); $i < $count; ++$i) {
         switch ($special[$i]) {
             case 'file_type':
                 if ($is_assoc === false) {
                     break;
                 }
                 global $valid_extensions;
                 for ($j = 0; $j < $res_count; ++$j) {
                     if (isset($res[$j]['name'])) {
                         $type = fileExtension($res[$j]['name']);
                         if (!in_array($type, $valid_extensions)) {
                             $type = 'file';
                         }
                         $res[$j]['file_type'] = $type;
                     }
                 }
                 break;
             case 'link_to_download':
                 if ($is_assoc === false) {
                     break;
                 }
                 for ($j = 0; $j < $res_count; ++$j) {
                     if (isset($res[$j]['path_to_file']) && isset($res[$j]['name']) && isset($res[$j]['is_directory'])) {
                         $tmp = self::FetchFromAssoc(['path_to_file' => $res[$j]['path_to_file'], 'name' => $res[$j]['name'], 'is_directory' => $res[$j]['is_directory']]);
                         $res[$j]['link_to_download'] = $tmp->GetLinkToFile();
                     }
                 }
                 break;
             case 'link_to_delete':
                 if ($is_assoc === false) {
                     break;
                 }
                 for ($j = 0; $j < $res_count; ++$j) {
                     if (isset($res[$j]['id']) && isset($res[$j]['owner_id'])) {
                         $tmp = self::FetchFromAssoc(['id' => $res[$j]['id'], 'owner_id' => $res[$j]['owner_id']]);
                         $res[$j]['link_to_delete'] = $tmp->GetLinkToDelete();
                     }
                 }
                 break;
             case 'link_to_edit':
                 if ($is_assoc === false) {
                     break;
                 }
                 for ($j = 0; $j < $res_count; ++$j) {
                     if (isset($res[$j]['id']) && isset($res[$j]['owner_id'])) {
                         $tmp = self::FetchFromAssoc(['id' => $res[$j]['id'], 'owner_id' => $res[$j]['owner_id']]);
                         $res[$j]['link_to_edit'] = $tmp->GetLinkToEdit();
                     }
                 }
                 break;
             case 'link_to_link_to_download':
                 if ($is_assoc === false) {
                     break;
                 }
                 for ($j = 0; $j < $res_count; ++$j) {
                     if (isset($res[$j]['id']) && isset($res[$j]['owner_id'])) {
                         $tmp = self::FetchFromAssoc(['path_to_file' => $res[$j]['path_to_file'], 'name' => $res[$j]['name'], 'id' => $res[$j]['id']]);
                         $link = $tmp->CreateDownloadLink();
                         $res[$j]['link_to_link_to_download'] = SecretLink::WrapLinkToButton($link->GetPublicLink());
                     }
                 }
                 break;
             default:
                 break;
         }
     }
     if (!$is_unique) {
         return $res;
     } else {
         return $res[0];
     }
 }