<?php

/**
 * CodeIgniter library
 *
 * @category CodeIgniter
 * @license /_licenses/untermStrich/agb_normal.pdf
 * @author Michael Pfeilstöcker
 * @copyright 2009 untermStrich
 * @package us_libraries
 * @version $Id$
 */
if (!defined('BASEPATH')) {
    exit('No direct script access allowed');
}

require_once APPPATH . 'us_libraries/Value_object.php';

/**
 * Used to save a whatiswhere item
 *
 * @property    My_Controller           $CI                     The main CI object
 */
class Whatiswhere_filings_values extends Value_object {

    protected $filing;
    protected $parentid;

    /**
     * Init the whatiswhere values from $_POST
     *
     * @return  object  An Whatiswhere_filings_values object with all values out of the post array
     */
    public static function init_from_post() {

        $obj = new Whatiswhere_filings_values();
        $obj->CI = CI_Controller::get_instance();
        $obj->add_or_id = $obj->CI->input->post('whatiswhere_roratrfi_edit');
        $obj->filing = $obj->CI->input->post('whatiswhere_roratrfi_title');
        $obj->parentid = $obj->CI->input->post('whatiswhere_roratrfi_parentid');

        return $obj;
    }

    /**
     * Init the values from a given stdClass object
     *
     * @param   object  $values stdClass object with offers values to initialize a valid object out of it
     *
     * @return  object  An Whatiswhere_rooms_values object with all values out of the given stdClass object
     */
    public static function init_from_values(stdClass $values) {
        $obj = new Whatiswhere_filings_values();
        $obj->CI = CI_Controller::get_instance();

        $obj->add_or_id = $values->id;
        $obj->filing = $values->filing;
        $obj->parentid = $values->parent_id;

        return $obj;
    }

    /**
     * Validate and ensure all values are appropriate
     *
     * @return  mixed   false on success, else the error message
     *
     * @todo    implement!!
     */
    public function validate() {
        if ($this->add_or_id !== 'add' && !is_numeric($this->add_or_id)) {
            return 'Whatiswere_filings ID has to be "add" or an ID';
        }
        return false;
    }

    /**
     * Get task to save
     *
     * @return  array
     */
    public function get_filings_items_to_save() {

        $data = array(
            'title' => $this->filing,
            'tray_id' => $this->parentid,
        );

        return $data;
    }
}

