Created
February 28, 2018 22:44
-
-
Save muskie9/a71983adf20d563004add18c88b7990e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Class DynamicManyManyList | |
*/ | |
class DynamicManyManyList extends ManyManyList { | |
/** | |
* Remove the given item from this list. | |
* | |
* Note that for a ManyManyList, the item is never actually deleted, only | |
* the join table is affected | |
* | |
* @param int $itemID The item ID | |
*/ | |
public function removeByID($itemID) { | |
if(!is_numeric($itemID)) throw new InvalidArgumentException("ManyManyList::removeById() expecting an ID"); | |
$query = new SQLDelete("\"{$this->joinTable}\""); | |
$foreignID = $this->getForeignID(); | |
$this->extend('onBeforeRemoveByID', $itemID, $this->joinTable, $foreignID); | |
if($filter = $this->foreignIDWriteFilter($foreignID)) { | |
$query->setWhere($filter); | |
} else { | |
user_error("Can't call ManyManyList::remove() until a foreign ID is set", E_USER_WARNING); | |
} | |
$query->addWhere(array("\"{$this->localKey}\"" => $itemID)); | |
$query->execute(); | |
$this->extend('onAfterRemoveByID', $itemID, $this->joinTable, $foreignID); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment