<?php
namespace App\Model;


class Canal extends GenericObject
{
    static $table_name = 'canal';

    static $primary_key = 'can_codigo';

    public function cargar($data){
        $this->can_codigo = $data->id;
        $this->can_descri = $data->descripcion;
    }

    public static function toJSON($result, $cn=null)
    {
        return json_encode(Canal::toArray($result, $cn));
    }

    public static function toArray($result, $cn=1)
    {
        if ($result === null) return $result;
        $temp = array();
        if(!isset($result->can_codigo)){
            foreach($result as $item){
                $object = array(
                    "id" => $item->can_codigo,
                    "descripcion" => $item->can_descri,
                    "canalNumero" => $cn,
                    "activo" => !isset($item->can_inacti) ? true : ($item->can_inacti == 0)
                );
                $temp[] = $object;
                $cn++;
            }
        }else{
            $temp = array(
                "id" => $result->can_codigo,
                "descripcion" => $result->can_descri,
                "canalNumero" => $cn
            );
        }
        return $temp;
    }

}