mirror of
https://github.com/Oreolek/ifhub.club.git
synced 2024-07-03 06:55:03 +03:00
47 lines
1.5 KiB
PHP
47 lines
1.5 KiB
PHP
<?php
|
||
/**
|
||
* Класс. представляющий собой обёертку для связей MANY_TO_MANY.
|
||
* Позволяет оперровать коллекцией загруженных по связи эдементов через имя связи
|
||
* Например, $oTopic->Tags->add($oTag) или $oTopic->Tags->delete($oTag->getId()) при
|
||
* наличии настроенной MANY_TO_MANY связи 'tags'
|
||
*/
|
||
class LS_ManyToManyRelation
|
||
{
|
||
// Ссылка на $oEntityORM->aRelationsData[<relation_name>],
|
||
// где relation_name - имя сязи, которую представляет объект
|
||
protected $_aCollection = array();
|
||
|
||
public function __construct(&$aCollection)
|
||
{
|
||
$this->_aCollection = &$aCollection;
|
||
}
|
||
|
||
/**
|
||
* Добавление объекта в коллекцию
|
||
* @param <type> $oEntity
|
||
*/
|
||
public function add($oEntity)
|
||
{
|
||
$this->_aCollection[$oEntity->_getPrimaryKeyValue()] = $oEntity;
|
||
}
|
||
|
||
/**
|
||
* Удаление объекта из коллекции по его id или массиву id
|
||
* @param <type> $iId
|
||
*/
|
||
public function delete($iId)
|
||
{
|
||
if (is_array($iId)) {
|
||
foreach ($iId as $id) {
|
||
if (isset($this->_aCollection[$id])) {
|
||
unset($this->_aCollection[$id]);
|
||
}
|
||
}
|
||
} elseif (isset($this->_aCollection[$iId])) {
|
||
unset($this->_aCollection[$iId]);
|
||
}
|
||
}
|
||
}
|
||
|
||
?>
|