<?php
defined('BASEPATH') OR exit('No direct script access allowed');

/**
 * Apprank
 */


class Apprank extends CI_Controller
{

    private $CI;

    function __construct()
    {
        $this->CI = & get_instance();

    }

	function main()
	{

		if ( ! $this->CI->input->post_get('token')) {
			$this->CI->apilib->make_error("토큰 값이 넘어오지 않았습니다");
        }
		$token = $this->CI->input->post_get('token');


        $app_id = (int) trim($this->CI->input->post_get('app_id'));
        if (empty($app_id)) {
			$this->CI->apilib->make_error("어플 아이디가 넘어오지 않았습니다");
        }

		$this->CI->load->model(array('Apps_model'));

        $where = array(
			'app_id' => $app_id,
		);
		$result = $this->CI->Apps_model->get_one('', '', $where);
		if ( ! element('app_id', $result)) {
			$this->CI->apilib->make_error("존재하지 않는 어플입니다");
		}

		$apprank = json_decode($result['app_rank'], true);

		

		$arr = array(
			'result' => 'ok',
			'token' => $token,
			'app_id' => $app_id,
			'app_rank_1_title' => html_escape(element('app_rank_1_title', $apprank)),
			'app_rank_1_desc' => html_escape(element('app_rank_1_desc', $apprank)),
			'app_rank_1_link' => html_escape(element('app_rank_1_link', $apprank)),
			'app_rank_1_image_url' => thumb_url('apprank', element('app_rank_1_image_url', $apprank), '50', '50'),
			'app_rank_2_title' => html_escape(element('app_rank_2_title', $apprank)),
			'app_rank_2_desc' => html_escape(element('app_rank_2_desc', $apprank)),
			'app_rank_2_link' => html_escape(element('app_rank_2_link', $apprank)),
			'app_rank_2_image_url' => thumb_url('apprank', element('app_rank_2_image_url', $apprank), '50', '50'),
			'app_rank_3_title' => html_escape(element('app_rank_3_title', $apprank)),
			'app_rank_3_desc' => html_escape(element('app_rank_3_desc', $apprank)),
			'app_rank_3_link' => html_escape(element('app_rank_3_link', $apprank)),
			'app_rank_3_image_url' => thumb_url('apprank', element('app_rank_3_image_url', $apprank), '50', '50'),
		);
		return $arr;

	}


}
