/** * Returns the array of CustomFieldValue objects * * @return An array of CustomFieldValue objects */ function getFields() { if ($this->_fields == null) { // get the custom fields $customFields = new CustomFieldsValues(); $fields = $customFields->getArticleCustomFieldsValues($this->getId(), $this->getBlog()); $this->setFields($fields); } return $this->_fields; }
/** * removes a custom field, but also all the values that have been created * based on this field and that have been assigned to different articles. * Otherwise, we would have data which is not linked to any article... but if still * needed, set the second parameter to false * * @param id * @param deleteValues * @return Returns true if successful or false otherwise */ function removeCustomField($id, $deleteValues = true) { $query = "DELETE FROM " . $this->getPrefix() . "custom_fields_definition\n\t\t\t WHERE id = {$id}"; $result = $this->Execute($query); if (!$result) { return false; } if (!$deleteValues) { return true; } // remove the values that were associated to this field $fieldValues = new CustomFieldsValues(); return $fieldValues->removeCustomFieldValues($id); }
/** * Removes an article from the database * * If forever == true, the article is physically removed from the database. * Otherwise, the 'status' field is set to 'deleted' * * Problem is, that MySQL will automatically update the 'date' field because he feels * like it... even if we explicitely say date = old_date... grrreat :P * * Valid article identifier, blog identifier and user identifier are required to remove an * article. It was done for security reasons and to make perfectly clear that we are removing * an article (so that we wouldn't be deleting the wrong one if there was any bug!) * * @param artId A valid article identifier * @param userid A valid user identifier * @param blogId A valid blog identifier * @param forever A boolean meaning whether the post should be removed forever or simply its status * should be set to 'deleted' * @return Returns true if successful or false otherwise. */ function deleteArticle($artId, $userId, $blogId, $forever = false) { if ($forever) { $query = "DELETE FROM " . $this->getPrefix() . "articles WHERE id = " . $artId . " AND user_id = " . $userId . " AND blog_id = " . $blogId . ";"; // -- text -- $this->deleteArticleText($artId); // we also have to remove its comments and trackbacks if the article is being deleted forever // -- comments -- $comments = new ArticleComments(); $comments->deletePostComments($artId); // -- trackbacks -- $trackbacks = new Trackbacks(); $trackbacks->deletePostTrackbacks($artId); // -- post-to-categories mappings -- $this->deletePostCategoriesLink($artId); // -- custom fields -- $customFields = new CustomFieldsValues(); $customFields->removeArticleCustomFields($artId); } else { $query = "UPDATE " . $this->getPrefix() . "articles SET date = date, status = 3 WHERE id = " . $artId . " AND user_id = " . $userId . " AND blog_id = " . $blogId . ";"; } $result = $this->Execute($query); if (!$result) { return false; } if ($this->_db->Affected_Rows() == 0) { return false; } return true; }