<?php

namespace Internetgalerie\IgDatapoolFe\Domain\Model;

/**
 * This FileReference Class is used because the original one is not finished in TYPO3 6.2
 * THIS IS USED FOR THE UPLOAD VIEWHELPER!!
 *
 * @see Configuration/TypoScript/Setup.txt
 *
 * Class FileReference
 */


class FileReference extends \TYPO3\CMS\Extbase\Domain\Model\FileReference
{
    /**
     * Uid of a sys_file
     *
     * @var integer
     */
    protected $originalFileIdentifier;

    /**
     * Name of the table
     *
     * @var string
     */
    //protected $tablenames = '';

    /**
     * Title
     *
     * @var string
     */
    protected $title;

    /**
     * description
     *
     * @var string
     */
    protected $description;

    /**
     * sorting_foreign
     *
     * @var integer
     */
    protected $sortingForeign;

    /**
     * uid_local
     *
     * @var \TYPO3\CMS\Core\Resource\FileReference
     */
    protected $uidLocal;


    /**
     * uid_foreign
     *
     * @var integer
     */
    protected $uidForeign;


    public function delete()
    {
        echo('DELETE FROM sys_file_reference WHERE uid=' . $this->getUid());
    }

    /*
    //
    // @param \TYPO3\CMS\Core\Resource\FileReference $originalResource
    //
    public function setOriginalResource(\TYPO3\CMS\Core\Resource\FileReference $originalResource) {
       $this->originalResource = $originalResource;
       $this->originalFileIdentifier = (int)$originalResource->getOriginalFile()->getUid();
       $this->uidLocal = (int)$originalResource->getOriginalFile()->getUid();
    }
    */

    /**
     * @param \TYPO3\CMS\Core\Resource\ResourceInterface $originalResource
     */
    public function setOriginalResource(\TYPO3\CMS\Core\Resource\ResourceInterface $originalResource)
    {
        $this->originalResource = $originalResource;
        if ($originalResource) {
            $this->originalFileIdentifier = (int)$originalResource->getOriginalFile()->getUid();
            $this->uidLocal = (int)$originalResource->getOriginalFile()->getUid();
        }
    }


    public function setUidLocalInt($uidLocal)
    {
        $this->uidLocal = (int)$uidLocal;
    }

    /*    public function setTablenames($tablenames = NULL) {
      $this->tablenames = $tablenames;
    }


    public function getTablenames() {
      return $this->tablenames;
    }
    */


    public function setTitle($title)
    {
        $this->title = $title;
    }
    public function getTitle()
    {
        return $this->title;
    }

    public function setDescription($description)
    {
        $this->description = $description;
    }
    public function getDescription()
    {
        return $this->description;
    }

    public function setSortingForeign($sortingForeign)
    {
        $this->sortingForeign = $sortingForeign;
    }
    public function getSortingForeign()
    {
        return $this->sortingForeign;
    }

    public function setUid($uid)
    {
        $this->uid = $uid;
    }

    /*    public function setUidLocal( \TYPO3\CMS\Core\Resource\FileReference $uidLocal ) {
      echo('SET='.get_class($uidLocal) .'<br />');
      $this->uidLocal = $uidLocal;
      }*/
    public function getUidLocal()
    {
        $originalResource = $this->getOriginalResource();
        return is_null($originalResource) ? null : $originalResource->getOriginalFile();
    }
    public function getUidLocalResource()
    {
        return $this->uidLocal->getOriginalResource();//$this->uidLocal;
    }

    public function getPublicUrl()
    {
        return $this->getOriginalResource()->getPublicUrl();//getUid();//PublicUrl();//$this->uidLocal;
    }


    public function setUidForeign($uidForeign)
    {
        $this->uidForeign = $uidForeign;
    }
    public function getUidForeign()
    {
        return $this->uidForeign;//->getOriginalResource();//$this->uidForeign;
    }

    /**
     * @param  int $_languageUid
     * @return void
     */
    public function set_languageUid($_languageUid)
    {
        $this->_languageUid = $_languageUid;
    }

    /**
     * @return int
     */
    public function get_languageUid()
    {
        return $this->_languageUid;
    }



    /**
     * @param  int $_localizedUid
     * @return void
     */
    public function set_localizedUid($_localizedUid)
    {
        $this->_localizedUid = $_localizedUid;
    }

    /**
     * @return int
     */
    public function get_localizedUid()
    {
        return $this->_localizedUid;
    }
}
