<?php

namespace Push\Lib;

use Dever;

class Manage
{
    //{source_id} > 0 ? ("{name}" ? "{name}" : Dever::load("sad/supply-one#name", {source_id})) : "{name}"
    public function name($id)
    {
        $info = Dever::db('push/data')->one($id);

        if ($info['name']) {
            return $info['name'];
        }

        if ($info['type'] < 10) {
            $table = Dever::config('base')->type_table[$info['type']];
            $audit = array
            (
                //'audit' => 2,
                //'status' => 2,
                'state' => 1,
            );
            if ($info['type'] == 1) {
                $audit['id'] = $info['article_id'];
                $data = Dever::db($table)->one($audit);
            } elseif ($info['type'] == 2) {
                $audit['id'] = $info['vod_id'];
                $data = Dever::db($table)->one($audit);
            } elseif ($info['type'] == 3) {
                $audit['id'] = $info['live_id'];
                $data = Dever::db($table)->one($audit);
            } elseif ($info['type'] == 4) {
                $audit['id'] = $info['journal_id'];
                $data = Dever::db($table)->one($audit);
            } elseif ($info['type'] == 6) {
                $audit['id'] = $info['feature_id'];
                $data = Dever::db($table)->one($audit);
            } elseif ($info['type'] == 7) {
                $data = Dever::db($table)->one(array('state' => 1, 'id' => $info['applet_id']));
            }

            if (isset($data) && $data && isset($data['name'])) {
                return $data['name'];
            }
        }

        return $info['name'];
    }
}