/** * Handles * a) the adding of new Tags to the database, * b) the deleting of all existing Tag2All for this Model|Set|Image|Video and * c) inserting the appropriate Tag2All records for this Model|Set|Image|Video * @param array(string) $newTags * @param array(Tag2All) $Tag2AllsThisItem * @param array(Tag) $TagsInDB, passed by reference * @param User $CurrentUser * @param int $ModelID * @param int $SetID * @param int $ImageID * @param int $VideoID * @param bool $DeleteOldTag2Alls determines whether to delete or merge existing Tag2Alls */ public static function HandleTags($newTags, $Tag2AllsThisItem, &$TagsInDB, $CurrentUser, $ModelID = NULL, $SetID = NULL, $ImageID = NULL, $VideoID = NULL, $DeleteOldTag2Alls = TRUE) { global $db; foreach (array_unique($newTags) as $string) { $tInDB = Tag::Filter($TagsInDB, NULL, $string); if (!$tInDB) { $tNew = new Tag(); $tNew->setName(trim($string)); if (Tag::Insert($tNew, $CurrentUser)) { $TagsInDB[] = $tNew; } } } if ($DeleteOldTag2Alls) { self::DeleteMulti($Tag2AllsThisItem, $CurrentUser); } foreach (array_unique($newTags) as $string) { $tInDB = Tag::Filter($TagsInDB, NULL, $string); if (!$DeleteOldTag2Alls) { $ttits = self::Filter($Tag2AllsThisItem, $tInDB[0]->getID(), $ModelID, $SetID, $ImageID, $VideoID); if ($ttits) { continue; } } $t2a = new Tag2All(); $t2a->setTag($tInDB[0]); if (!is_null($ModelID)) { $t2a->setModelID($ModelID); } if (!is_null($SetID)) { $t2a->setSetID($SetID); } if (!is_null($ImageID)) { $t2a->setImageID($ImageID); } if (!is_null($VideoID)) { $t2a->setVideoID($VideoID); } if ($t2a->getModelID() || $t2a->getSetID() || $t2a->getImageID() || $t2a->getVideoID()) { Tag2All::Insert($t2a, $CurrentUser); } } }