Esempio n. 1
0
 public static function Del($resource_type, $resource_id, $keyword_word)
 {
     if (!($id = Keywords::GetID($keyword_word))) {
         message_die(GENERAL_ERROR, "Keyword not found : {$keyword_word}", 'Keywords::Del fatal error');
     }
     if (Keywords::IsLinked($id, $resource_type, $resource_id)) {
         global $db;
         $sql = "DELETE FROM " . TABLE_RELATIONS . " WHERE parent_type = '{$resource_type}' AND parent_id = '{$resource_id}' AND children_type = 'K' AND children_id = {$id}";
         if (!($result = $db->sql_query($sql))) {
             message_die(SQL_ERROR, "Can't link keyword to specified resource {$resource_type} {$resource_id}", '', __LINE__, __FILE__, $sql);
         }
         //If keyword count = 1, the keyword is not used anymore so we can erase it
         //Just decrements keyword count without any other consideration, so:
         $sql = "UPDATE " . TABLE_KEYWORDS . " SET keyword_count = keyword_count - 1 WHERE keyword_id = {$id}";
         if (!($result = $db->sql_query($sql))) {
             message_die(SQL_ERROR, "Can't decrement keyword count", '', __LINE__, __FILE__, $sql);
         }
     }
 }