<?php

defined('_JEXEC') or die('Restricted access');

/**
* @package OS CCK
* @copyright 2020 OrdaSoft.
* @author Andrey Kvasnevskiy(akbet@mail.ru),Vladislav Prikhodko(vlados.vp1@gmail.com)
* @link http://ordasoft.com/cck-content-construction-kit-for-joomla.html
* @description OrdaSoft Content Construction Kit
*/

class os_cckAPIInstance extends os_cckEntityInstance
{

  private $contentInstance;
  private $eid;
  /** @var array with all fields */
  //first table fileds 
  // var $eiid = null;
  // var $fk_lid = null;
  // var $fk_eid = null;
  // var $title = null;
  // var $asset_id = null;
  // var $fk_userid = null;
  // var $published = null;
  // var $approved = null;
  // var $created = null;
  // var $changed = null;
  // var $last_review = null;
  // var $checked_out = null;
  // var $checked_out_time = null;
  // var $teid = null;
  // var $hits = null;
  // var $instance_price = 0;
  // var $instance_currency = null;
  // var $notreaded = null;
  // var $featured_clicks = null;
  // var $featured_shows = null;
  // var $access = null;
  // var $meta_title = '';
  // var $meta_description = '';
  // var $meta_keywords = '';
  // var $meta_robots = '';
  // var $language = '';
  // var $layout_type = '';
  // var $associate_instances = '';
  
  

  /**
   * @param database - A database connector object
   */
  function __construct(&$db, $eid)
  {
      $this->eid = $eid;
      $this->contentInstance = new os_cckContentInstance($db, $eid);
      parent::__construct($db);
  }
  
  

  /**
   * Binds a named array/hash to this object
   *
   * Can be overloaded/supplemented by the child class
   *
   * @access  public
   * @param $from mixed An associative array or object
   * @param $ignore mixed An array or space separated list of fields not to bind
   * @return  boolean
   */
  function bind($from, $ignore = array()){
    // echo $aaaa;
    // var_dump($from);
    $fromArray = is_array($from);
    $fromObject = is_object($from);
    if (!$fromArray && !$fromObject) {
      $this->setError(get_class($this) . '::bind failed. Invalid from argument');
      return false;
    }
    if (!is_array($ignore)) {
      $ignore = explode(' ', $ignore);
    }
    foreach ($this->getProperties() as $k => $v) {
      // internal attributes of an object are ignored
      if (!in_array($k, $ignore)) {
        if ($fromArray && isset($from[$k])) {
            $this->$k = $from[$k];
        } else if ($fromObject && isset($from->$k)) {
            $this->$k = $from->$k;
        }
      }
    }
    // var_dump($from);
    $this->contentInstance->bind($from);
    return true;
  }
  
    
  /**
   * Inserts a new row if id is zero or updates an existing row in the database table
   *
   * Can be overloaded/supplemented by the child class
   *
   * @access public
   * @param boolean If false, null object variables are not updated
   * @return null|string null if successful otherwise returns and error message
   */
  function store($updateNulls = false){
    global $app, $global_settings, $input;

    parent::store();

    $this->contentInstance->store($updateNulls, $this->eiid);
    
    
  }
  
  

  
  

}


