function getTotalPopularComments($component = 'all', $cid = 'all', $options = array()) { // define default values $defaultOptions = array('start' => 0, 'limit' => 10, 'userid' => 'all', 'sticked' => 'all', 'published' => 1, 'minimumlikes' => 0, 'random' => 0); $querySelect = ''; $queryWhere = array(); $queryGroup = ''; $queryOrder = ''; $queryLimit = ''; // take the input values and clear unexisting keys $options = Komento::mergeOptions($defaultOptions, $options); $querySelect = 'SELECT comments.*, COUNT(actions.comment_id) AS likes FROM ' . $this->db->nameQuote('#__komento_comments') . ' AS comments'; $querySelect .= ' LEFT JOIN ' . $this->db->nameQuote('#__komento_actions') . ' AS actions ON comments.id = actions.comment_id'; if ($component !== 'all') { $queryWhere[] = 'comments.component = ' . $this->db->quote($component); } if ($cid !== 'all') { if (is_array($cid)) { $cid = implode(',', $cid); } if (empty($cid)) { $queryWhere[] = 'comments.cid = 0'; } else { $queryWhere[] = 'comments.cid IN (' . $cid . ')'; } } if ($options['userid'] !== 'all') { $queryWhere[] = 'comments.created_by = ' . $this->db->quote($options['userid']); } if ($options['published'] !== 'all') { $queryWhere[] = 'comments.published = ' . $this->db->quote($options['published']); } if ($options['sticked'] !== 'all') { $queryWhere[] = 'comments.sticked = ' . $this->db->quote(1); } $queryWhere[] = 'actions.type = ' . $this->db->quote('likes'); if (count($queryWhere) > 0) { $queryWhere = ' WHERE ' . implode(' AND ', $queryWhere); } else { $queryWhere = ''; } $queryGroup = ' GROUP BY actions.comment_id'; if ($options['minimumlikes'] > 0) { $queryGroup .= ' HAVING likes >= ' . $options['minimumlikes']; } $query = 'SELECT COUNT(1) FROM (' . $querySelect . $queryWhere . $queryGroup . ') AS x'; $this->db->setQuery($query); return $this->db->loadResult(); }
public static function addJomSocialActivity( $options = array() ) { $defaultOptions = array( 'comment' => '', 'title' => '', 'content' => '', 'cmd' => '', 'actor' => '', 'target' => 0, 'app' => '', 'cid' => '', 'comment_id' => '', 'comment_type' => '', 'like_id' => '', 'like_type' => '' ); $options = Komento::mergeOptions( $defaultOptions, $options ); $jsCoreFile = JPATH_ROOT . DIRECTORY_SEPARATOR . 'components' . DIRECTORY_SEPARATOR . 'com_community' . DIRECTORY_SEPARATOR . 'libraries' . DIRECTORY_SEPARATOR . 'core.php'; $config = Komento::getConfig(); if( !JFile::exists( $jsCoreFile ) ) { return false; } require_once( $jsCoreFile ); $obj = (object) $options; // add JomSocial activities CFactory::load ( 'libraries', 'activities' ); CActivityStream::add( $obj ); }
function getCommentCount($options = array()) { $query = 'SELECT COUNT(1) FROM `#__easyblog_comment`'; $defaultOptions = array('post_id' => 'all'); $options = Komento::mergeOptions($defaultOptions, $options); $queryWhere = array(); if (!empty($options['post_id']) && $options['post_id'] !== 'all') { $options['post_id'] = (array) $options['post_id']; $queryWhere[] = $this->_db->namequote('post_id') . ' IN (' . implode(',', $options['post_id']) . ')'; } if (count($queryWhere) > 0) { $query .= ' WHERE ' . implode(' AND ', $queryWhere); } $this->_db->setQuery($query); return $this->_db->loadResult(); }