View file upload/src/addons/XenCentral/Feedback/Behavior/Comment.php

File size: 1.69Kb
<?php
/**
 * @package XenCentral Feedback System
 * @author DNF Technology
 * @copyright Drnoyan & Nalyan LDA, Portugal, EU
 * @license http://dnf.technology/terms/
 * @link http://customers.dnf.technology
 * @version 2.0.0 Beta 10
 * @revision 12
 */


/**
 * Data writer for feedback comments
 *
 * @package XenCentral_Feedback
 */

namespace XenCentral\Feedback\Behavior;

use XF\Mvc\Entity\Behavior;

class Comment extends Behavior
{
    use FeedbackAbstractBehavior;

	public function preSave()
	{
		// check if comment length is okay
		if($this->_getOptionsModel()->getCommentMinimumLength() && strlen(strip_tags($this->entity->get('message'))) < $this->_getOptionsModel()->getCommentMinimumLength())
		{
			$this->entity->error(\XF::phrase('xcfs_comment_length_x', array (
					'length' => $this->_getOptionsModel()->getCommentMinimumLength() 
			)));
		}
	}
	
	public function postSave() {
		if ( $this->entity->isInsert() && ! $this->entity->get( 'ip_id' ) || $this->entity->getOption( 'saveip' ) ) {
			$ipAddress = $this->entity->getOption( 'saveip' );
			$ipId      = \XF::app()->repository( 'XF:Ip' )->logIp( $this->entity->get( 'user_id' ), $ipAddress, 'feedback_comment', $this->entity->get( 'fb_id' ), 'insert' );
			if ( isset( $ipId['ip_id'] ) ) {
				$this->entity->set( 'ip_id', $ipId['ip_id'], array(
					'setAfterPreSave' => true,
					'forceSet'        => true
				) );
			}

			if ( isset( $ipId['ip_id'] ) ) {
				$this->entity->db()->update( 'xf_xc_feedback_comment', array(
					'ip_id' => $ipId['ip_id']
				), 'comment_id = ' . $this->entity->db()->quote( $this->entity->get( 'comment_id' ) ) );
			}
		}
	}
	
	protected function _getDefaultOptions()
	{
		return array (
				'saveip' => true
		);
	}
}