<?php

namespace GriffinForms\Admin\Secure;

class Lists extends \GriffinForms\Admin\Secure\Format
{
    protected function secureListColumns($columns)
    {
        if(!is_array($columns)) {
            return array('name');
        }
        
        $final_columns = array_map('sanitize_text_field', $columns);
        return $final_columns;
    }
    
    protected function secureListPerpage($item_count) {
        $per_page = absint($item_count);
        if (is_int($per_page) and $per_page > 0) {
            return $per_page;
        } else {
            return 10;
        }
    }
    
    protected function secureListOrderBy($order_by)
    {
        $choices = $this->choices->getOrderBy();
        if (in_array($order_by, $choices)) {
            return $order_by;
        } else {
            return 'id';
        }
    }
    
    protected function secureListSortOrder($order)
    {
        if ($order == 'asc' or $order == 'desc') {
            return $order;
        } else {
            return 'asc';
        }
    }
}