Back to PhocaDownloadTag class

Method storeTags

public static
storeTags
(mixed $tagsArray, mixed $fileId)

Method storeTags - Source code

public static function storeTags($tagsArray, $fileId)
{
    if ((int) $fileId > 0) {
        $db = Factory::getDBO();
        $query = ' DELETE ' . ' FROM #__phocadownload_tags_ref' . ' WHERE fileid = ' . (int) $fileId;
        $db->setQuery($query);
        if (!$db->execute()) {
            echo PhocaDownloadException::renderErrorInfo('Database Error - Deleting FileId Tags');
            return false;
        }
        if (!empty($tagsArray)) {
            $values = array();
            $valuesString = '';
            foreach ($tagsArray as $k => $v) {
                $values[] = ' (' . (int) $fileId . ', ' . (int) $v . ')';
            }
            if (!empty($values)) {
                $valuesString = implode(',', $values);
                $query = ' INSERT INTO #__phocadownload_tags_ref (fileid, tagid)' . ' VALUES ' . (string) $valuesString;
                $db->setQuery($query);
                if (!$db->execute()) {
                    echo PhocaDownloadException::renderErrorInfo('Database Error - Insert FileId Tags');
                    return false;
                }
            }
        }
    }
}