Exemplo n.º 1
0
 public static function ad_simple_list(\ApiParam $params)
 {
     if (!$params->exists('activeOnly')) {
         $params->activeOnly = 1;
     }
     //没有参数,则默认返回active ad,保证兼容
     list($resultCount, $adsSearched) = self::searchAds($params);
     $ads = self::loadRealtimeAds($params->newAdIds, $adsSearched);
     $resultCount += count($ads);
     $ads = array_merge($ads, $adsSearched);
     if ($params->rows) {
         $ads = array_slice($ads, 0, $params->rows);
     }
     $newAds = array();
     foreach ($ads as $ad) {
         $newAd = array();
         $newAd['id'] = $ad->get('id');
         $newAd['title'] = $ad->get('title');
         $newAd['imageFlag'] = $ad->get('imageFlag');
         $newAd['createdTime'] = $ad->get('createdTime');
         $newAds[] = $newAd;
     }
     return array('count' => $resultCount, 'data' => $newAds);
 }
Exemplo n.º 2
0
 public static function mobile_get_favourites(\ApiParam $params)
 {
     $user = new \User();
     $user->load($params->userId);
     $follower = \Follower::create($user);
     if ($follower) {
         $favs = $follower->favovites();
         $originFavs = $favs;
         if ($favs && is_array($favs)) {
             $query = '(';
             foreach ($favs as $fav) {
                 if ($fav->identity) {
                     if ($query != '(') {
                         $query .= ' OR ';
                     }
                     $query .= 'id:' . $fav->identity;
                 }
             }
             if ($query != '(') {
                 $query .= ')';
                 $ary = $params->getArrayCopy();
                 $ary['query'] = $query;
                 $newParams = \Api::paramFactory($ary);
                 $response = self::mobile_ad_list($newParams);
                 $existingAds = $response['data'];
                 if ($existingAds) {
                     foreach ($existingAds as $ad) {
                         foreach ($favs as $key => $fav) {
                             if ($ad['id'] == $fav->identity) {
                                 unset($favs[$key]);
                                 break;
                             }
                         }
                     }
                 }
                 if (sizeof($favs) > 0) {
                     foreach ($favs as $fav) {
                         array_push($existingAds, array('id' => $fav->identity, 'title' => $fav->attris['title'], 'status' => '3'));
                         ++$response['num'];
                     }
                 }
                 $adsMap = array();
                 foreach ($existingAds as $ad) {
                     $adsMap[$ad['id']] = $ad;
                 }
                 //					var_dump('ads map');
                 //					var_dump($adsMap);
                 $sortAds = array();
                 foreach ($originFavs as $fav) {
                     array_push($sortAds, $adsMap[$fav->identity]);
                 }
                 //					var_dump('sorted ads');
                 //					var_dump($sortAds);
                 $response['data'] = $sortAds;
                 return $response;
             }
         } else {
             return self::composeResponse(0, '没有已收藏信息', array('count' => 0, 'data' => array(), 'num' => 0));
         }
     }
     return self::composeResponse(1, 'fail');
 }