/source/components/com_pfcomments/site/models/form.php
https://github.com/projectfork/Projectfork · PHP · 137 lines · 58 code · 25 blank · 54 comment · 8 complexity · 0a4414cb12c66ab769f142d330d7cce2 MD5 · raw file
- <?php
- /**
- * @package Projectfork
- * @subpackage Comments
- *
- * @author Tobias Kuhn (eaxs)
- * @copyright Copyright (C) 2006-2012 Tobias Kuhn. All rights reserved.
- * @license http://www.gnu.org/licenses/gpl.html GNU/GPL, see LICENSE.txt
- */
- defined('_JEXEC') or die();
- // Base this model on the backend version.
- JLoader::register('PFcommentsModelComment', JPATH_ADMINISTRATOR . '/components/com_pfcomments/models/comment.php');
- /**
- * Projectfork Component Comment Form Model
- *
- */
- class PFcommentsModelForm extends PFcommentsModelComment
- {
- /**
- * Constructor.
- *
- * @param array $config An optional associative array of configuration settings.
- *
- * @see jcontroller
- */
- public function __construct($config = array())
- {
- // Call parent constructor
- parent::__construct($config);
- }
- /**
- * Method to get item data.
- *
- * @param integer $id The id of the item.
- * @return mixed $value Item data object on success, false on failure.
- */
- public function getItem($id = null)
- {
- // Initialise variables.
- $id = (int) (!empty($id)) ? $id : $this->getState($this->getName() . '.id');
- // Get a row instance.
- $table = $this->getTable();
- // Attempt to load the row.
- $return = $table->load($id);
- // Check for a table object error.
- if ($return === false && $table->getError()) {
- $this->setError($table->getError());
- return false;
- }
- $properties = $table->getProperties(1);
- $value = JArrayHelper::toObject($properties, 'JObject');
- // Convert attrib field to Registry.
- $value->params = new JRegistry;
- $value->params->loadString($value->attribs);
- // Count parent replies
- $value->parent_replies = $this->countReplies($value->parent_id);
- // Count replies of this item
- $value->replies = $this->countReplies($value->id);
- // Compute selected asset permissions.
- $uid = JFactory::getUser()->get('id');
- $access = PFcommentsHelper::getActions($value->id);
- // Check general edit permission first.
- if ($access->get('core.edit')) {
- $value->params->set('access-edit', true);
- }
- // Now check if edit.own is available.
- elseif (!empty($uid) && $access->get('core.edit.own')) {
- // Check for a valid user and that they are the owner.
- if ($uid == $value->created_by) {
- $value->params->set('access-edit', true);
- }
- }
- // Check edit state permission.
- if ($id) {
- // Existing item
- $value->params->set('access-change', $access->get('core.edit.state'));
- }
- else {
- // New item
- $access = PFcommentsHelper::getActions();
- $value->params->set('access-change', $access->get('core.edit.state'));
- }
- return $value;
- }
- /**
- * Get the return URL.
- *
- * @return string The return URL.
- */
- public function getReturnPage()
- {
- return base64_encode($this->getState('return_page'));
- }
- /**
- * Method to auto-populate the model state.
- * Note. Calling getState in this method will result in recursion.
- *
- * @return void
- */
- protected function populateState()
- {
- // Load state from the request.
- $pk = JRequest::getInt('id');
- $this->setState($this->getName() . '.id', $pk);
- $return = JRequest::getVar('return', null, 'default', 'base64');
- $this->setState('return_page', base64_decode($return));
- // Load the parameters.
- $params = JFactory::getApplication()->getParams();
- $this->setState('params', $params);
- $this->setState('layout', JRequest::getCmd('layout'));
- }
- }