function approve($comment_ids)
 {
     if (!is_array($comment_ids) || empty($comment_ids)) {
         $this->setError('COM_JUDIRECTORY_NO_ITEM_SELECTED');
         return false;
     }
     JTable::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_judirectory/tables');
     $comment_table = JTable::getInstance("Comment", "JUDirectoryTable");
     $count = 0;
     $comment_ids = (array) $comment_ids;
     $rootComment = JUDirectoryFrontHelperComment::getRootComment();
     $listingIds = 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) {
             $listingIds[$comment_table->listing_id] = $comment_table->listing_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++;
         JUDirectoryFrontHelperMail::sendEmailByEvent('comment.approve', $comment_id);
         $logData = array('user_id' => $comment_table->user_id, 'event' => 'comment.approve', 'item_id' => $comment_id, 'listing_id' => $comment_table->listing_id, 'value' => 0, 'reference' => '');
         JUDirectoryFrontHelperLog::addLog($logData);
     }
     foreach ($listingIds as $listingId) {
         JUDirectoryHelper::rebuildRating($listingId);
     }
     return $count;
 }
Exemple #2
0
 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());
     }
     $listingIds = $this->getListingsForRating($cats, $criteriaGroups, $limit, $start);
     if (!empty($listingIds)) {
         foreach ($listingIds as $listingId) {
             JUDirectoryHelper::rebuildRating($listingId);
         }
         $result = array('processed' => count($listingIds) + $start, 'total' => $app->getUserState('total_listings', 0));
     } else {
         $result = array('processed' => 100, 'total' => $app->getUserState('total_listings', 0));
     }
     return json_encode($result);
 }