/** * Should return everything - Full rating, list of reviews and add review form * * @param object $row DJ-Catalog2 Object * @param JRegistry $params * @param int $page * @return boolean|Ambigous <boolean, string> */ public function onAfterDJCatalog2DisplayContent(&$row, &$params, $page = 0, $context = 'item') { $app = JFactory::getApplication(); $view = $app->input->get('view'); if ($view != 'item') { return false; } $excluded_categories = $this->params->get('exclude_categories', array()); if (in_array($row->cat_id, $excluded_categories)) { return false; } $excluded_products = explode(',', $this->params->get('exclude_items', '')); if (in_array($row->id, $excluded_products)) { return false; } $group_id = $this->params->get('rating_group', false); if (!$group_id) { return false; } require_once JPath::clean(JPATH_ROOT . '/components/com_djreviews/lib/api.php'); require_once JPath::clean(JPATH_ROOT . '/components/com_djcatalog2/helpers/route.php'); $review = DJReviewsAPI::getInstance(array('group' => $group_id, 'type' => 'com_djcatalog2.item', 'name' => $row->name, 'link' => DJCatalogHelperRoute::getItemRoute($row->slug, $row->catslug), 'id' => $row->id)); return $review->getFullReview(); }
public function onAfterDJClassifiedsDisplayProfile(&$profile, $params, $view) { $app = JFactory::getApplication(); if (!$profile['id']) { return false; } $group_id = $this->params->get('rating_group_author', false); if (!$group_id) { return false; } require_once JPath::clean(JPATH_ROOT . '/components/com_djreviews/lib/api.php'); require_once JPath::clean(JPATH_ROOT . '/administrator/components/com_djclassifieds/lib/djseo.php'); $uid_slug = $profile['id'] . ':' . DJClassifiedsSEO::getAliasName($profile['name']); $name = $profile['name'] ? $profile['name'] : $profile['id']; $review = DJReviewsAPI::getInstance(array('group' => $group_id, 'type' => 'com_djclassifieds.author', 'name' => $name, 'link' => 'index.php?option=com_djclassifieds&view=profile&uid=' . $uid_slug, 'id' => $profile['id'])); return $review->getFullReview(); }
public function save($key = null, $urlVar = null) { // Check for request forgeries. JSession::checkToken() or jexit(JText::_('JINVALID_TOKEN')); $app = JFactory::getApplication(); $model = $this->getModel(); $table = $model->getTable(); $data = $app->input->post->get('jform', array(), 'array'); $context = "{$this->option}.edit.{$this->context}"; $task = $this->getTask(); $checkin = property_exists($table, 'checked_out'); // Determine the name of the primary key for the data. if (empty($key)) { $key = $table->getKeyName(); } // To avoid data collisions the urlVar may be different from the primary key. if (empty($urlVar)) { $urlVar = $key; } $recordId = $app->input->getInt($urlVar); // Populate the row id from the session. $data[$key] = $recordId; // Access check. if (!$this->allowSave($data, $key)) { $this->setError(JText::_('JLIB_APPLICATION_ERROR_SAVE_NOT_PERMITTED')); return false; } // Validate the posted data. // Sometimes the form needs some posted data, such as for plugins and modules. $form = $model->getForm($data, true); if (!$form) { $this->setError($model->getError()); return false; } // Test whether the data is valid. $validData = $model->validate($form, $data); // Check for validation errors. if ($validData === false) { // Get the validation messages. $errors = $model->getErrors(); $messages = array(); // Push up to three validation messages out to the user. for ($i = 0, $n = count($errors); $i < $n && $i < 3; $i++) { if ($errors[$i] instanceof Exception) { $this->setError($errors[$i]->getMessage()); } else { $this->setError($errors[$i]); } } // Save the data in the session. $app->setUserState($context . '.data', $data); return false; } // Attempt to save the data. if (!$model->save($validData)) { // Save the data in the session. $app->setUserState($context . '.data', $validData); // Redirect back to the edit screen. $this->setError(JText::sprintf('JLIB_APPLICATION_ERROR_SAVE_FAILED', $model->getError())); return false; } // Save succeeded, so check-in the record. if ($checkin && $model->checkin($validData[$key]) === false) { // Save the data in the session. $app->setUserState($context . '.data', $validData); // Check-in failed, so go back to the record and display a notice. $this->setError(JText::sprintf('JLIB_APPLICATION_ERROR_CHECKIN_FAILED', $model->getError())); return false; } $this->setMessage(JText::_('COM_DJREVIEWS_REVIEW_SUCCESSFULLY_ADDED')); $this->releaseEditId($context, $recordId); $app->setUserState($context . '.data', null); // Invoke the postSave method to allow for the child class to access the model. $this->postSaveHook($model, $validData); require_once JPath::clean(JPATH_ROOT . '/components/com_djreviews/lib/api.php'); DJReviewsAPI::recalculate(); return true; }
/** * Should return everything - Full rating, list of reviews and add review form * * @param object $row DJ-Catalog2 Object * @param JRegistry $params * @param int $page * @return boolean|Ambigous <boolean, string> */ public function onContentAfterDisplay($context, &$item, $params, $offset = 0) { if (!in_array($context, array('com_content.article', 'com_content.category', 'com_content.featured'))) { return false; } $app = JFactory::getApplication(); $view = $app->input->get('view'); if ($view != 'article' && !($view == 'featured' && $app->input->getInt('id', false))) { return false; } $excluded_categories = $this->params->get('exclude_categories', array()); if (in_array($item->catid, $excluded_categories)) { return false; } $excluded_articles = explode(',', $this->params->get('exclude_articles', '')); if (in_array($item->id, $excluded_articles)) { return false; } $group_id = $this->params->get('rating_group', false); if (!$group_id) { return false; } require_once JPath::clean(JPATH_ROOT . '/components/com_djreviews/lib/api.php'); require_once JPath::clean(JPATH_ROOT . '/components/com_content/helpers/route.php'); $review = DJReviewsAPI::getInstance(array('group' => $group_id, 'type' => 'com_content.article', 'name' => $item->title, 'link' => ContentHelperRoute::getArticleRoute($item->id . ':' . $item->alias, $item->catid . ':' . $item->category_alias), 'id' => $item->id)); return $review->getFullReview(); }
protected function initialise() { // already initialised if ((int) $this->id > 0) { return true; } $db = JFactory::getDbo(); $query = $db->getQuery(true); $query->select('*'); $query->from('#__djrevs_objects'); $query->where('entry_id=' . (int) $this->entry_id); $query->where('object_type=' . $db->quote($this->object_type)); // not sure about this $query->where('rating_group_id=' . (int) $this->rating_group_id); $db->setQuery($query); $object = $db->loadObject(); $update_needed = false; $is_new = true; if ($object) { $is_new = false; $this->id = $object->id; if ($this->name != $object->name) { //$this->name = $object->name; $update_needed = true; } if ($this->link != $object->link) { //$this->link = $object->link; $update_needed = true; } if ($this->rating_group_id != $object->rating_group_id) { //$this->rating_group_id = $object->rating_group_id; $update_needed = true; } $this->avg_rate = $object->avg_rate; } if ($is_new || $update_needed) { $row = new stdClass(); $row->id = $this->id; $row->object_type = $this->object_type; $row->entry_id = $this->entry_id; $row->rating_group_id = $this->rating_group_id; $row->name = $this->name; $row->link = $this->link; $row->avg_rate = $this->avg_rate; if ($is_new) { try { $db->insertObject('#__djrevs_objects', $row, 'id'); } catch (RuntimeException $e) { if (defined('JDEBUG') && JDEBUG) { JLog::add('DJ-Reviews - Cannot initialise object', JLOG::ERROR); } return false; } $this->id = $row->id; } else { if ($update_needed) { try { $db->updateObject('#__djrevs_objects', $row, 'id', false); } catch (RuntimeException $e) { if (defined('JDEBUG') && JDEBUG) { JLog::add('DJ-Reviews - Cannot update object', JLOG::ERROR); } return false; } } } } if (!self::$js_core) { $version = new JVersion(); $document = JFactory::getDocument(); if ($this->params->get('jquery', '0') != '3') { if ($this->params->get('jquery', '0') == '0' && JFile::exists(JPath::clean(JPATH_ROOT . '/libraries/cms/html/jquery.php'))) { JHtml::_('jquery.framework', true); } else { if ($this->params->get('jquery') == '1') { $document->addScript(JUri::base() . '/components/com_djreviews/assets/js/jquery.min.js'); } else { $document->addScript('//ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js'); } } } $document->addScript(JUri::base() . 'components/com_djreviews/assets/js/core.js'); $options = array('url' => JUri::base(false), 'object_url' => $this->link, 'object_id' => $this->id); JFactory::getDocument()->addScriptDeclaration(' jQuery(document).ready(function(){ DJReviewsCore.init(' . json_encode($options) . '); }); '); self::$js_core = true; } return true; }
public function delete(&$cid) { if (count($cid)) { // mark other reviews to be recalculated first $query = ' UPDATE #__djrevs_reviews AS r ' . ' INNER JOIN (SELECT DISTINCT object_id FROM #__djrevs_reviews WHERE id IN (' . implode(',', $cid) . ')) as r2 ON r2.object_id = r.object_id' . ' SET r.recalculate = 2 '; $this->_db->setQuery($query); $this->_db->query(); $this->_db->setQuery('DELETE FROM #__djrevs_reviews_items WHERE review_id IN (' . implode(',', $cid) . ')'); if ($this->_db->query() == false) { $this->setError($this->_db->getErrorMsg()); return false; } } require_once JPath::clean(JPATH_ROOT . '/components/com_djreviews/lib/api.php'); DJReviewsAPI::recalculate(); $deleted = parent::delete($cid); return $deleted; }