} // Something is wrong, abort // --------------------------------------------------------------------------- // Create $body based on $link type // --------------------------------------------------------------------------- $body = getBody($link, $id); if ($body === false) { failure('No $body, nothing to train.'); } // Something is wrong, abort. // --------------------------------------------------------------------------- // Go! // --------------------------------------------------------------------------- // Get all the bayes_documents linked to this message where user is trainer // Also get associated vectors $link_table = $suxLink->buildTableName($link, 'bayes_documents'); $innerjoin = "\nINNER JOIN {$link_table} ON {$link_table}.bayes_documents_id = bayes_documents.id\nINNER JOIN {$link} ON {$link_table}.{$link}_id = {$link}.id\nINNER JOIN bayes_categories ON bayes_categories.id = bayes_documents.bayes_categories_id\nINNER JOIN bayes_auth ON bayes_categories.bayes_vectors_id = bayes_auth.bayes_vectors_id\n"; $query = "\nSELECT bayes_documents.id, bayes_auth.bayes_vectors_id FROM bayes_documents\n{$innerjoin}\nWHERE {$link}.id = ?\nAND bayes_auth.users_id = ? AND (bayes_auth.owner = true OR bayes_auth.trainer = true)\n"; // Note: bayes_auth WHERE condition equivilant to nb->isCategoryTrainer() $db = suxDB::get(); $st = $db->prepare($query); $st->execute(array($id, $_SESSION['users_id'])); $tmp = $st->fetchAll(PDO::FETCH_ASSOC); // Since we are only training one category/vector at a time, we need to make // sure we don't untrain other unrelated vectors here. $vec_id = $nb->getVectorByCategory($cat_id); foreach ($tmp as $val) { if (isset($vec_id[$val['bayes_vectors_id']])) { $nb->untrainDocument($val['id']); } }