[TYPO3-mvc] How to get repository name?

Ревенко С.В. dedsemen at gmail.com
Mon May 3 19:43:25 CEST 2010


Hi list.

I am currently working on the extension which  allow to connect any types of
entities with each other. For storing relationships between two entities I
use a table with structure like this:

CREATE TABLE th_rsrelatedentties_relationship (
   ............
   first_entity_uid int (11) unsigned NOT NULL
   first_entity_type varchar (255) NOT NULL,
   second_entity_uid int (11) unsigned NOT NULL,
   second_entiti_type varchar (255) NOT NULL
   ..............
)
In fields first_entity_type and second_entity_type i store table name in
which related entities persisted.
For relationship entity i use model like this:

class Tx_RsRelatedEntities_Domain_Model_Relationship extends
Tx_Extbase_DomainObject_AbstractEntity {
    /**
     * First entity id
     *
     * @var int
     * @validate Integer
     */
    protected $first_entity_uid;
    /**
     * Type of first entity
     *
     * @var string
     * @validate NotEmpty
     */
    protected $first_entity_type;
    /**
     * First entity
     *
     * @var Tx_Extbase_DomainObject_AbstractEntity
     */
    protected $first_entity = null;
    /**
     * Second entity id
     *
     * @var int
     * @validate Integer
     */
    protected $second_entity_uid;
    /**
     * Type of second entity
     *
     * @var string
     * @validate NotEmpty
     */
    protected $second_entity_type;

    /**
     * Second entity
     *
     * @var Tx_Extbase_DomainObject_AbstractEntity
     */
    protected $second_entity = null;

    /**
     * Return first entity
     *
     * @return Tx_Extbase_DomainObject_AbstractEntity
     */
    public function getFirstEntity() {
        if (is_null($this->first_entity) &&
(!is_null($this->first_entity_uid)) && (!is_null($this->first_entity_type)))
{

        }
        return $this->first_entity;
    }

    /**
     * Sets first entity
     *
     * @param Tx_Extbase_DomainObject_AbstractEntity
     */
    public function setFirstEntity(Tx_Extbase_DomainObject_AbstractEntity
$first_entity) {
        $this->first_entity_uid = $first_entity->getUid();
        $this->first_entity_type = self::getEntityTable($first_entity);
        $this->first_entity = $first_entity;
    }

    /**
     * Return second entity
     *
     * @return Tx_Extbase_DomainObject_AbstractEntity
     */
    public function getSecondEntity() {
        return $this->second_entity;
    }

    /**
     * Sets second entity
     *
     * @param Tx_Extbase_DomainObject_AbstractEntity $second_entity
     */
    public function setSecondEntity(Tx_Extbase_DomainObject_AbstractEntity
$second_entity) {
        $this->second_entity_uid = $second_entity->getUid();
        $this->second_entity_type = self::getEntityTable($second_entity);
        $this->second_entity = $second_entity;
    }

    /**
     * Return related entity
     *
     * @param Tx_Extbase_DomainObject_AbstractEntity $entity
     * @return Tx_Extbase_DomainObject_AbstractEntity
     */
    public function getRelatedEntity(Tx_Extbase_DomainObject_AbstractEntity
$entity) {
        if ((self::getEntityTable($entity) == $this->first_entity) &&
($entity->getUid() == $this->getFirstEntity()->getId())) {
            return $this->getFirstEntity();
        }

        return $this->getSecondEntity();
    }

    /**
     * Return table name in which specified entity stored
     *
     * @param Tx_Extbase_DomainObject_AbstractEntity $entity
     * @return string
     */
    static protected function
getEntityTable(Tx_Extbase_DomainObject_AbstractEntity $entity) {
        $dataMapper =
t3lib_div::makeInstance('Tx_Extbase_Persistence_Mapper_DataMapper');
        return $dataMapper->convertClassNameToTableName(get_class($entity));
    }
}
So, for methods getFirstEntity() end getSecondEntity() I need to get
repository class based on table name in which entity persisted.
Please show me how I can get the class of repository  based on the table
name in which related entity stored.
-- 
С уважением,
Ревенко Сергей.


More information about the TYPO3-project-typo3v4mvc mailing list