public function post() { $post = JRequest::get('post'); $data = json_decode($post['JSON_object']); $table = JTable::getInstance('Comment', 'JTable'); $table->created = gmdate("Y-m-d H:i:s"); $table->name = $this->plugin->get('user')->name; $table->username = $this->plugin->get('user')->username; $table->userid = $this->plugin->get('user')->id; $table->email = $this->plugin->get('user')->email; $table->comments = $data->comments; $table->pid = $data->listing_id; $table->store(); // Create rating record here $rating = JTable::getInstance('Rating', 'JTable'); $rating->reviewid = $table->id; $rating->ratings = isset($post['rating']) ? (double) $post['rating'] : 'na'; $rating->ratings_sum = is_numeric($rating->ratings) ? $rating->ratings : 0; $rating->ratings_qty = $rating->ratings == 'na' ? 0 : 1; $rating->store(); require_once JPATH_SITE . '/components/com_jreviews/jreviews/framework.php'; require_once JPATH_SITE . '/components/com_jreviews/jreviews/models/review.php'; $model = new ReviewModel(); $model->saveListingTotals($data->listing_id, 'com_content'); $this->addStream($table); if ($table->email) { $this->sendEmail($table); } JRequest::setVar('id', $table->id); $this->get(); }
function onPhotoComment($photoid, $message) { // when users comment on a photo that is related to a catch report, // add that comment to the catch report as well $db =& JFactory::getDBO(); $user =& JFactory::getUser(); // get related listings $sql = "SELECT rp.listing_id FROM #__relate_photos rp " . "LEFT JOIN #__content c ON rp.listing_id = c.id " . "WHERE rp.photo_id = '" . $photoid . "' " . "AND rp.listing_id != 0 AND c.state > 0 AND c.catid IN (13,14,15) "; $db->setQuery($sql); $listings = $db->loadResultArray(); foreach ($listings as $listing_id) { $jr_comment = array('pid' => $listing_id, 'mode' => 'com_content', 'created' => gmdate("Y-m-d H:i:s"), 'userid' => $user->id, 'name' => $user->name, 'username' => $user->username, 'email' => $user->email, 'comments' => $message, 'published' => '1', 'ipaddress' => $_SERVER['REMOTE_ADDR'], 'posts' => '0', 'vote_helpful' => '0', 'vote_total' => '0'); $sql = "INSERT INTO #__jreviews_comments (" . implode(",", array_keys($jr_comment)) . ") VALUES ('" . implode("','", $jr_comment) . "')"; $db->setQuery($sql); $db->query(); $jr_ratings = array('reviewid' => $db->insertid(), 'ratings' => 'na', 'ratings_sum' => 0, 'ratings_qty' => 0); $sql = "INSERT INTO #__jreviews_ratings (" . implode(",", array_keys($jr_ratings)) . ") VALUES ('" . implode("','", $jr_ratings) . "')"; $db->setQuery($sql); $db->query(); require_once JPATH_SITE . '/components/com_jreviews/jreviews/framework.php'; require_once JPATH_SITE . '/components/com_jreviews/jreviews/models/review.php'; $model = new ReviewModel(); $model->saveListingTotals($listing_id, 'com_content'); } }