Kids.php 1.23 KB
<?php

namespace WebPlugin\DataProcess\Channel;
use WebPlugin\Helpers;
class Kids 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'] == 'text' && $resource[$key + 1]['template_name'] == 'textNav') {
                    //text模版
                    $temp['newArrivls']['name'] = $resource[$key]['data']['text'];
                    //textNav模版
                    foreach ($resource[$key + 1]['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;
    }

}