Skip to content

Instantly share code, notes, and snippets.

@nickdunn
Created December 16, 2009 14:48
Show Gist options
  • Save nickdunn/257872 to your computer and use it in GitHub Desktop.
Save nickdunn/257872 to your computer and use it in GitHub Desktop.
<?php
require_once(TOOLKIT . '/class.datasource.php');
Class datasourceblog_post_moderated_comment_count extends Datasource{
var $dsParamROOTELEMENT = 'blog-post-moderated-comment-count';
var $dsParamORDER = 'desc';
var $dsParamLIMIT = '9999';
var $dsParamREDIRECTONEMPTY = 'no';
var $dsParamSORT = 'system:id';
var $dsParamSTARTPAGE = '1';
function __construct(&$parent, $env=NULL, $process_params=true){
parent::__construct($parent, $env, $process_params);
$this->dsParamFILTERS = array(
'posts' => '{$ds-blog-posts}',
'posts-by-tag' => '{$ds-blog-posts-by-tag}',
'post' => '{$ds-blog-post}',
'posts-search' => '{$ds-blog-posts-search}'
);
$this->_dependencies = array('$ds-blog-posts', '$ds-blog-posts-by-tag', '$ds-blog-post', '$ds-blog-posts-search');
}
function about(){
return array(
'name' => 'Blog Post Moderated Comment Count',
'author' => array(
'name' => 'Nick Dunn',
'website' => 'http://dev.ema.mtv.co.uk',
'email' => '[email protected]'),
'version' => '1.0',
'release-date' => '2008-09-30T14:40:58+00:00');
}
function grab(&$param_pool){
$result = new XMLElement("post-comments");
$posts = array();
if (is_array($this->dsParamFILTERS['posts'])) {
foreach($this->dsParamFILTERS['posts'] as $post) {
array_push($posts, $post);
}
}
if (is_array($this->dsParamFILTERS['posts-by-tag'])) {
foreach($this->dsParamFILTERS['posts-by-tag'] as $post) {
array_push($posts, $post);
}
}
if (is_array($this->dsParamFILTERS['post'])) {
foreach($this->dsParamFILTERS['post'] as $post) {
array_push($posts, $post);
}
}
if (is_array($this->dsParamFILTERS['posts-search'])) {
foreach($this->dsParamFILTERS['posts-search'] as $post) {
array_push($posts, $post);
}
}
foreach($posts as $post) {
$post_xml = new XMLElement("post");
$section_link_id = 32;
$moderation_id = 34;
$comments = $this->_Parent->Database->fetchRow(0, "SELECT COUNT(sym_entries_data_$section_link_id.relation_id) FROM sym_entries_data_$moderation_id INNER JOIN sym_entries_data_$section_link_id ON sym_entries_data_$moderation_id.entry_id = sym_entries_data_$section_link_id.entry_id WHERE (sym_entries_data_$moderation_id.handle = 'approved' OR sym_entries_data_$moderation_id.value = 'Approved') AND sym_entries_data_$section_link_id.relation_id = " . $post);
$post_xml->setAttributeArray(array("id" => $post, "approved-comments" => $comments["COUNT(sym_entries_data_$section_link_id.relation_id)"]));
$result->appendChild($post_xml);
}
return $result;
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment