protected function select(array $selectFields, array $param, $tables) { $limit = $order = $where = $fromTables = $like = ''; $fields = implode(',', $selectFields); //处理筛选条件 if (!Validate::isNullArray($param)) { $limit = isset($param['limit']) ? ' LIMIT ' . $param['limit'] : ''; $order = isset($param['order']) ? ' ORDER BY ' . $param['order'] : ''; if (isset($param['where'])) { $isAnd = ''; foreach ($param['where'] as $value) { $isAnd .= $value . ' AND '; } $where = ' WHERE ' . substr($isAnd, 0, -4); } if (isset($param['like'])) { foreach ($param['like'] as $key => $value) { $like = " WHERE {$key} LIKE '%{$value}%'"; } } } //处理多表联查 foreach ($tables as $value) { $fromTables .= $value . ' ,'; } $fromTables = substr($fromTables, 0, -1); $sql = "SELECT {$fields} FROM {$fromTables} {$where} {$like} {$order} {$limit} "; $stmt = $this->execute($sql); $result = array(); while (!!($obj = $stmt->fetchObject())) { $result[] = $obj; } return Tool::setHtmlString($result); }
public function filter(array $fields) { $selectDate = array(); if (Validate::isArray($_POST) && !Validate::isNullArray($_POST)) { foreach ($_POST as $key => $value) { if (Validate::inArray($key, $fields)) { $selectDate[$key] = $value; } } } return $selectDate; }
public function filter(array $_fields) { $_selectData = array(); if (Validate::isArray($_POST) && !Validate::isNullArray($_POST)) { //筛选准备入库的字段和数据 foreach ($_POST as $_key => $_value) { if (Validate::inArray($_key, $_fields)) { $_selectData[$_key] = $_value; } } } return $_selectData; }
public static function setHtmlString($_data) { $_string = null; if (Validate::isArray($_data)) { if (Validate::isNullArray($_data)) { return $_data; } foreach ($_data as $_key => $_value) { $_string[$_key] = self::setHtmlString($_value); } } elseif (is_object($_data)) { foreach ($_data as $_key => $_value) { $_string->{$_key} = self::setHtmlString($_value); } } else { $_string = htmlspecialchars($_data); } return $_string; }
public function fileUser($file) { foreach ($file as $key => $value) { if (!is_object($value)) { $user = parent::select(array('id,user,thumb'), array('where' => array("thumb='upload/{$_GET['file']}/{$value}'"))); if (!Validate::isNullArray($user)) { $user[0]->pic = $value; $user[0]->link = 'user'; $user[0]->name = $user[0]->user . '[<strong style="color:green;font-size:12px;">会员头像</strong>]'; $file[$key] = $user[0]; } } } return $file; }
protected function select($_tables, array $_field, array $_param = array()) { $_limit = ''; $_order = ''; $_where = ''; $_like = ''; if (Validate::isArray($_param) && !Validate::isNullArray($_param)) { $_limit = isset($_param['limit']) ? 'LIMIT ' . $_param['limit'] : ''; $_order = isset($_param['order']) ? 'ORDER BY ' . $_param['order'] : ''; $_where = ''; if (isset($_param['where'])) { foreach ($_param['where'] as $_key => $_value) { $_where .= $_value . ' AND '; } $_where = 'WHERE ' . substr($_where, 0, -4); } if (isset($_param['like'])) { foreach ($_param['like'] as $_key => $_value) { $_like = "WHERE {$_key} LIKE '%{$_value}%'"; } } } $_selectFields = implode(',', $_field); $_table = isset($_tables[1]) ? $_tables[0] . ',' . $_tables[1] : $_tables[0]; $_sql = "SELECT {$_selectFields} FROM {$_table} {$_where} {$_like} {$_order} {$_limit} "; $_stmt = $this->execute($_sql); $_result = array(); while (!!($_objs = $_stmt->fetchObject())) { $_result[] = $_objs; } return Tool::setHtmlString($_result); }
private function getNavId() { $this->_tables = array(DB_PREFIX . 'nav'); //商品副类id数组 $_idArr = parent::select(array('id'), array('where' => array("sid='{$this->_R['navid']}'"))); $_id = ''; //副类处理 if (Validate::isNullArray($_idArr)) { $_id = $this->_R['navid']; } else { foreach ($_idArr as $_key => $_value) { $_id .= $_value->id . ','; } $_id = substr($_id, 0, -1); } $this->_tables = array(DB_PREFIX . 'goods'); return $_id; }
private function getNavId() { //商品副类id数组 $_idArr = parent::select(array('id'), array('where' => array("sid='{$this->_R['navid']}'"))); $_id = array(); //副类处理 if (Validate::isNullArray($_idArr)) { $_id[] = $this->_R['navid']; } else { foreach ($_idArr as $_key => $_value) { $_id[] .= $_value->id; } } return $_id; }
public function fileRotator($file) { foreach ($file as $key => $value) { if (!is_object($value)) { $rotator = parent::select(array('id,thumb,name'), array('where' => array("thumb='upload/{$_GET['file']}/{$value}'"))); if (!Validate::isNullArray($rotator)) { $rotator[0]->pic = $value; $rotator[0]->link = 'index'; $rotator[0]->name = $rotator[0]->name . '[<strong style="color:green;font-size:12px;">轮播器</strong>]'; $file[$key] = $rotator[0]; } } } return $file; }
public function fileGoods($file) { foreach ($file as $key => $value) { if (!is_object($value)) { $goods = parent::select(array('id,nav,name'), array('where' => array("thumb='upload/{$_GET['file']}/{$value}' OR\r\n\t\t\t\t\t\tthumb_small='upload/{$_GET['file']}/{$value}' OR\r\n\t\t\t\t\t\t\t\tcontent LIKE '%upload/{$_GET['file']}/{$value}%'"))); if (!Validate::isNullArray($goods)) { $goods[0]->pic = $value; $goods[0]->name = $goods[0]->name . '[<strong style="color:green;font-size:12px;">商品</strong>]'; $file[$key] = $goods[0]; } } } return $file; }
public function getFrontAttr() { //用于存放所有的符合查询条件的导航信息id $array = array(); //获得全部的导航 $allNav = parent::select(array('id', 'sid')); foreach ($allNav as $key => $value) { //通过主导航保存子导航id if ($value->sid == $this->R['navid']) { $array[] = $value->id; } else { //保存子导航id $array[] = $this->R['navid']; } } $this->tables = array(DB_FREFIX . 'attr'); //查询属性信息 $allAttr = parent::select(array('name', 'item', 'id', 'nav')); //用于保存最终生成的属性信息 $frontAttr = array(); foreach ($allAttr as $key => $value) { //属性中的nav字段转为数组 $value->nav = explode(',', $value->nav); //如果导航id与属性nav集合之间有交集则证明该导航有相关属性信息 if (array_intersect($array, $value->nav)) { //转属性为数组 $value->item = explode('|', $value->item); //转url属性为数组 $getAttr = explode('-', $this->R['attr']); //用于存放每组属性与url的交集,属性每组只有一个位于url中,所以该数组永远只有一个元素 $attrArray = array_intersect($getAttr, $value->item); //显示“全部”是否被选中,用flag做判定,如果URL中已有信息为该属性的则证明已有属性被选中,flag为TRUE $value->flag = $attrArray ? true : false; //存放前台显示全部按钮的具体href信息 显示全部即为去掉当前属性中的相关信息 $value->all = implode('-', array_diff($getAttr, $value->item)) ? '&attr=' . implode('-', array_diff($getAttr, $value->item)) : null; //该循环用于过滤url中由于多次点击而重复出现的attr属性 foreach ($value->item as $k => $v) { if (!Validate::isNullArray($attrArray)) { //该处$attrArray永远只有一个元素,因为attr中相关属性只能有一个 foreach ($attrArray as $val) { $attrArray[0] = $val; } //如果url中已有相关属性值用最新的替换之,temp用于存放生成的url地址栏信息 $value->temp[] = $temp = str_replace($attrArray[0], $v, $this->R['attr']); } elseif (!isset($this->R['attr']) || empty($this->R['attr'])) { //初次加载URL中没有相关attr时 $value->temp[] = $v; } elseif (Validate::isNullArray($attrArray)) { //用于不同属性之间的链接 $value->temp[] = $this->R['attr'] . '-' . $v; } } //将item与temp链接item为key,temp为值 $value->attr = array_combine($value->item, $value->temp); $frontAttr[] = $value; } } return $frontAttr; }