Lifestyle.php 1.23 KB
<?php

namespace WebPlugin\DataProcess\Channel;
use WebPlugin\Helpers;
class Lifestyle extends AbstractChannel
{

    /**
     * 格式化数据
     * 
     * @param array $resource
     * @return 
     */
    public static function format($resource)
    {
        $result = array();
        $result += self::getFormatNewArrivals($resource);
        foreach ($resource as $key => $val) {//老版处理
            if (isset($resource[$key]) && isset($resource[$key + 1])) {
                $temp = array('newArrivls' => array('name' => '', 'navs' => array()));
                //newArrivals
                if ($resource[$key]['template_name'] == 'textNav' && $resource[$key + 1]['template_name'] == 'link') {
                    //text模版
                    $temp['newArrivls']['name'] = '最新上架 NEW ARRIVALS';
                    //textNav模版
                    foreach ($resource[$key]['data'] as $val) {
                        $temp['newArrivls']['navs'][] = array('href' => Helpers::getUrlSafe($val['url']), 'name' => $val['name']);
                    }
                    unset($resource[$key], $resource[$key + 1]);
                    $result[$key] = $temp;
                }
            }
        }
        return $result;
    }

}