AbstractChannel.php 1.48 KB
<?php

namespace WebPlugin\DataProcess\Channel;

abstract class AbstractChannel
{
    /*     * *
     * 处理数据
     * @param array $resource
     * @return array[以key方式存储数据]
     */

    public static function format($resource)
    {
        
    }

    /**
     * 获取格式化最新上架数据
     * 
     * @param array &$resource
     * @return array
     */
    public static function getFormatNewArrivals(&$resource)
    {
        $result = array();
        foreach ($resource as $key => $val) {
            if (isset($resource[$key]) && isset($resource[$key + 2])) {
                $temp = array('newArrivls' => array('name' => '', 'navs' => array()), 'href' => '');
                //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' => $val['url'], 'name' => $val['name']);
                    }
                    //link模版
                    $temp['href'] = $resource[$key + 2]['data'][0]['url'];
                    unset($resource[$key], $resource[$key + 1], $resource[$key + 2]);
                    $result[$key] = $temp;
                }
            }
        }
        return $result;
    }

}