function approve($comment_ids) { if (!is_array($comment_ids) || empty($comment_ids)) { $this->setError('COM_JUDOWNLOAD_NO_ITEM_SELECTED'); return false; } JTable::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_judownload/tables'); $comment_table = JTable::getInstance("Comment", "JUDownloadTable"); $count = 0; $comment_ids = (array) $comment_ids; $rootComment = JUDownloadFrontHelperComment::getRootComment(); $docIds = array(); foreach ($comment_ids as $comment_id) { $comment_table->reset(); if ($comment_table->load($comment_id) && $comment_table->parent_id == $rootComment->id && $comment_table->approved == 0) { $docIds[$comment_table->doc_id] = $comment_table->doc_id; } $user = JFactory::getUser(); $date = JFactory::getDate(); $comment_table->approved = 1; $comment_table->published = 1; $comment_table->approved_by = $user->id; $comment_table->approved_time = $date->toSql(); $comment_table->store(); $count++; JUDownloadFrontHelperMail::sendEmailByEvent('comment.approve', $comment_id); $logData = array('user_id' => $comment_table->user_id, 'event' => 'comment.approve', 'item_id' => $comment_id, 'doc_id' => $comment_table->doc_id, 'value' => 0, 'reference' => ''); JUDownloadFrontHelperLog::addLog($logData); } foreach ($docIds as $docId) { JUDownloadHelper::rebuildRating($docId); } return $count; }
public function reBuildRating() { $app = JFactory::getApplication(); $start = $app->input->getInt("start", 0); $limit = $app->input->getInt("limit", 5); if ($start == 0) { $cats = $app->input->get('cats', array(), 'array'); $criteriaGroups = $app->input->get('criteriagroups', array(), 'array'); $app->setUserState('cats', $cats); $app->setUserState('criteria_groups', $criteriaGroups); } else { $cats = $app->getUserState('cats', array()); $criteriaGroups = $app->getUserState('criteria_groups', array()); } $docIds = $this->getDocsForRating($cats, $criteriaGroups, $limit, $start); if (!empty($docIds)) { foreach ($docIds as $docId) { JUDownloadHelper::rebuildRating($docId); } $result = array('processed' => count($docIds) + $start, 'total' => $app->getUserState('total_documents', 0)); } else { $result = array('processed' => 100, 'total' => $app->getUserState('total_documents', 0)); } return json_encode($result); }