1
0
Fork 0
mirror of https://github.com/Oreolek/ifhub.club.git synced 2024-06-29 04:55:02 +03:00
ifhub.club/engine/classes/ManyToManyRelation.class.php
2011-05-31 13:04:05 +00:00

60 lines
1.7 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?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();
protected $bUpdated = false;
public function __construct($aCollection)
{
$this->_aCollection = $aCollection;
}
/**
* Добавление объекта в коллекцию
* @param <type> $oEntity
*/
public function add($oEntity)
{
$this->bUpdated = true;
$this->_aCollection[$oEntity->_getPrimaryKeyValue()] = $oEntity;
}
/**
* Удаление объекта из коллекции по его id или массиву id
* @param <type> $iId
*/
public function delete($iId)
{
$this->bUpdated = true;
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]);
}
}
public function getCollection()
{
return $this->_aCollection;
}
public function isUpdated()
{
return $this->bUpdated;
}
}
?>