public function setTableInfo($key_array) { if (!Util_Array::IsArrayValue($key_array)) { return false; } $th_array = array(); $td_array = array(); foreach ($key_array as $index => $one) { if (is_numeric($index)) { $index = $one; } $th_array[$index] = $one; $td_array[$index] = $index; } $this->th_array = $th_array; $this->td_array = $td_array; }
public function getHtml() { $html = ""; $showPage = $this->getShowPage(); if (Util_Array::IsArrayValue($showPage)) { $url = $this->getUrl(); foreach ($showPage as $pageInfo) { $currentUrl = $url . "&page_no={$pageInfo['page_no']}"; $class = ''; if ($pageInfo['current']) { $html .= "<button class='btn btn-success'>{$pageInfo['title']}</button>"; } else { $html .= "<a href='{$currentUrl}'><button class='btn btn-default'>{$pageInfo['title']}</button></a>"; } } } $html = "<div style=''>{$html}</div>"; return $html; }
public static function BuildXML($data, $parentTag) { if (!Util_Array::IsArrayValue($data)) { return $data; } $xml = ''; foreach ($data as $index => $one) { if (is_array($one)) { if ($one['attribute']) { $attribute = ''; foreach ($one['attribute'] as $akey => $aval) { $attribute .= " {$akey}=\"{$aval}\""; } } $value = strval($one['value']); $xml .= "<{$index}{$attribute}>{$value}</{$index}>"; } else { $xml .= "<{$index}>{$one}</{$index}>"; } } $xml = "<?xml version=\"1.0\" encoding=\"UTF-8\" ?><{$parentTag}> {$xml} </{$parentTag}>"; return $xml; }
/** * 在树形数组中寻找指定元素 * * @param array $tree 输入树形数组 * @param str $keyValue 寻找Key值 * @param string $keyName 键值名称 默认为 id * @param string $subName 子树名称 * @return 找到的元素 */ public static function FindNodeInTree($tree, $keyValue, $keyName = 'id', $subName = 'sub') { if (!Util_Array::IsArrayValue($tree)) { return false; } foreach ($tree as $index => $one) { if ($one[$keyName] == $keyValue) { return $one; } if ($one[$subName]) { $subResult = self::FindNodeInTree($one[$subName], $keyValue, $keyName, $subName); if ($subResult) { return $subResult; } } } return false; }
/** * 判断是否是json对象 * @param array $obj */ public static function IsJsonObj($obj) { if (is_object($obj)) { return true; } if (!Util_Array::IsArrayValue($obj)) { return false; } $index = 0; foreach ($obj as $key => $value) { if (!is_numeric($index)) { return true; } if ($key !== $index) { return true; } $index++; } return false; }
public static function BuildUpdateCondition($condition = array(), $dbType = null) { if (is_string($condition)) { return $condition; } if (!Util_Array::IsArrayValue($condition)) { return ''; } $conditionStr = ''; foreach ($condition as $key => $value) { if (is_numeric($value)) { $value = "'{$value}'"; } else { if (is_null($value)) { $value = 'NULL'; } else { if (is_array($value)) { $value = implode(',', $value); $value = self::EscapeString($value, $dbType); $value = "'{$value}'"; } else { $value = self::EscapeString($value, $dbType); $value = "'{$value}'"; } } } $conditionStr .= "`{$key}` = {$value},"; } $conditionStr = trim($conditionStr, ','); return $conditionStr; }
public function fetch($id, $key = null) { if (!$id) { return false; } $key = $key ? $key : $this->primaryKey; if (Util_Array::IsArrayValue($id)) { $id = array_values($id); $one = false; } else { $one = true; } $condition = array($key => $id); $option = array('one' => $one); $result = DB::LimitQuery($this->tableName, $condition, $option, $this->readDB); if (!$result) { $this->error = DB::$error; } if (is_array($id) && $this->primaryKey) { $result = Util_Array::AssColumn($result, $this->primaryKey); } return $result; }