<?php
namespace App;

use \MyListing\Src\Forms;

class ToMyListingJob extends \MyListing\Src\Forms\Add_Listing_Form {
    protected static $_instance;

    protected $mdFields = array();
    protected $mdErrors = array();

    public function __construct()
    {
        $this->mdGetFields();
    }


    public static function print_r($a, $e=1) {
        echo('<pre>');
        print_r($a);
        echo('</pre>');
        if($e)exit();
    }

    protected function mdGetPostId() {
        $args = array(
            'post_type'        => 'case27_listing_type',
        );
        $posts = get_posts( $args );
        foreach($posts AS $k => $post) {
            if($post->post_title == 'Job') {
                return $post->ID;
            }
        }
        return false;
    }

    protected function mdGetFields() {
        $idForJob = $this->mdGetPostId();
        if($idForJob) {
            $fields = get_post_meta($idForJob, 'case27_listing_type_fields', true);
            if($fields) {
                $fields = unserialize($fields);
            }
            //self::print_r($fields);
            foreach($fields AS $k => $v) {
                //echo($k."\n");
                //if(in_array($k, $autorizedFields)) {
                if($v['show_in_admin'] == 1) {
                    $this->mdFields[$k] = $v;
                }
            }
        }
    }
}