public static function getUrl($url, $params) { if ($url != '') { $delimiter = '/'; $url = rtrim($url, $delimiter); if (!empty($params)) { $url .= $delimiter . str_replace(array('&', '='), $delimiter, http_build_query($params)); } $url .= '.html'; } else { $url = Util_Common::getUrl($url, $params, true); } return $url; }
public static function getUrl($url, $params) { if ($url != '') { $url = rtrim($url, '/'); if (!empty($params)) { $delimiter = '/'; foreach ($params as $k => $v) { if (false !== stripos($url, '{' . $k . '}')) { $url = str_replace('{' . $k . '}', $v, $url); } else { $url .= $delimiter . urlencode($k) . $delimiter . urlencode($v); } } } } else { $url = Util_Common::getUrl($url, $params, true); } return $url; }
/** * 获取列表 * * @param array $aParam * @param string $sOrder * @return array */ public static function getList($aWhere, $iPage, $sOrder = '', $iPageSize = 20, $sUrl = '', $aArg = array(), $bReturnPager = true) { $iPage = max($iPage, 1); $aRet = array(); $aParam = array('where' => $aWhere, 'limit' => ($iPage - 1) * $iPageSize . ',' . $iPageSize, 'order' => $sOrder); $aRet['aList'] = self::getOrm()->fetchAll($aParam); if ($iPage == 1 && count($aRet['aList']) < $iPageSize) { $aRet['iTotal'] = count($aRet['aList']); if ($bReturnPager) { $aRet['aPager'] = null; } } else { unset($aParam['limit'], $aParam['order']); $aRet['iTotal'] = self::getOrm()->fetchCnt($aParam); if ($bReturnPager) { if (empty($sUrl)) { $sUrl = Util_Common::getUrl(); } if (empty($aArg)) { $aArg = $_REQUEST; } $aRet['aPager'] = Util_Page::getPage($aRet['iTotal'], $iPage, $iPageSize, $sUrl, $aArg); } } return $aRet; }
/** * 搜索自媒体 * * @param unknown $aParam * @param string $sOrder * @param number $iPageSize * @return Ambigous <NULL, boolean, string, multitype:multitype: Ambigous <> , multitype:, array/string, int/false, number, unknown, unknown> */ public static function search($aParam, $sOrder = '', $iPageSize = 20) { $aRule = array(); $aTable = array('t_media m'); $aWhere = array('m.iStatus=1', 'm.iPut=1', 'm.iMediaType=' . intval($aParam['type'])); if (!empty($aParam['name'])) { $aWhere[] = '(m.sMediaName LIKE "%' . $aParam['name'] . '%" OR m.sOpenName LIKE "%' . $aParam['name'] . '%")'; } if (!empty($aParam['catid'])) { $aTable[] = 't_media_category c'; $aWhere[] = 'c.iMediaID=m.iMediaID'; $aWhere[] = 'c.iCategoryID=' . intval($aParam['catid']); //$aWhere[] = 'c.iCategoryID IN(' . join(',', $aParam['catid']) . ')'; } if (!empty($aParam['price'])) { $aPrice = Model_Price::parsePrice($aParam['price']); $aWhere[] = '(m.iPrice1>=' . $aPrice[0] . ' AND m.iPrice1<' . $aPrice[1] . ' OR m.iPrice2>=' . $aPrice[0] . ' AND m.iPrice2<' . $aPrice[1] . ')'; } if (!empty($aParam['follower'])) { $aFollower = explode('~', $aParam['follower']); $aWhere[] = '(m.iFollowerNum>=' . $aFollower[0] . ' AND m.iFollowerNum<' . $aFollower[1] . ')'; } if (!empty($aParam['city'])) { $aTable[] = 't_media_city ct'; $aWhere[] = 'ct.iMediaID=m.iMediaID'; $aWhere[] = 'ct.iCityID IN(' . join(',', $aParam['city']) . ')'; } if (!empty($aParam['readnum0'])) { $aWhere[] = 'm.iReadAvgNum >=' . intval($aParam['readnum0']); } if (!empty($aParam['readnum1'])) { $aWhere[] = 'm.iReadAvgNum <=' . intval($aParam['readnum1']); } if (!empty($aParam['score'])) { $aWhere[] = 'm.iScore >=' . intval($aParam['score']); } if (!empty($aParam['tag'])) { $aTable[] = 't_media_tag t'; $aWhere[] = 't.iMediaID=m.iMediaID'; $aWhere[] = 't.iTagID IN(' . join(',', $aParam['tag']) . ')'; } /* if (! empty($aParam['aCriceID'])) { $aTable[] = 't_media_cricle cr'; $aWhere[] = 'cr.iMediaID=m.iMediaID'; $aWhere[] = 'cr.iCricleID IN(' . join(',', $aParam['aCriceID']) . ')'; } */ $iPage = max(intval($aParam['page']), 1); $sLimit = ' LIMIT ' . ($iPage - 1) * $iPageSize . ',' . $iPageSize; $sOrder = empty($sOrder) ? '' : ' ORDER BY ' . $sOrder; $sSQL = 'SELECT m.* FROM ' . join(',', $aTable) . ' WHERE ' . join(' AND ', $aWhere) . ' GROUP BY m.iMediaID' . $sOrder . $sLimit; $aRet['aList'] = self::query($sSQL); if ($iPage == 1 && count($aRet['aList']) < $iPageSize) { $aRet['iTotal'] = count($aRet['aList']); $aRet['aPager'] = null; } else { unset($aParam['limit'], $aParam['order']); $sSQL = 'SELECT COUNT(DISTINCT m.iMediaID) FROM ' . join(',', $aTable) . ' WHERE ' . join(' AND ', $aWhere); $aRet['iTotal'] = self::query($sSQL, 'one'); $sUrl = Util_Common::getUrl(); $aRet['aPager'] = Util_Page::getPage($aRet['iTotal'], $iPage, $iPageSize, $sUrl, $aParam); } return $aRet; }