View file upload/src/addons/XenCentral/Feedback/Repository/ImportSource/ImportPhotopostClassifieds.php

File size: 4.03Kb
<?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
 */

namespace XenCentral\Feedback\Repository\ImportSource;


class ImportPhotopostClassifieds extends ImportAbstract
{
    /**
     * @var Array
     * Handles user ID cache for imported users
     */
    protected $_dataCache;

    /**
     * @var array
     * Mapping of iTrader type numbers to buy/sell/trade
     */

    public function getImporterTitle()
    {
        return 'Photopost Classifieds Feedback';
    }

    /**
     * @param $db Zend_Db_Adapter_Abstract
     * @param $prefix String
     * Throws exception if table prefix is not valid for the system
     */
    public function assertTablePrefix($db, $prefix)
    {
        // simply query database for a user
        $db->query('
                SELECT id
                FROM ' . $prefix . 'feedback
                LIMIT 1
        ');
    }

    /**
     * @param $db Zend_Db_Adapter_Abstract
     * @param $config
     * @param $errors
     */
    public function preImport($db, &$config, &$errors)
    {
        if (!$config['charset']) {
            $config['charset'] = 'utf8';
        }

        $this->_config = $config;
    }

    public function getAllFeedback($start, $perpage)
    {
        return $this->_sourceDb->fetchAll("
			SELECT feedback.* FROM {$this->_config['prefix']}feedback AS feedback
			WHERE feedback.approved=1
			ORDER BY id ASC
			LIMIT $start, $perpage
		");
    }

    public function getForUserId($feedback)
    {
        return $this->_getFromCache('userid', $feedback['foruser']);
    }

    public function getFromUserId($feedback)
    {
        return $this->_getFromCache('userid', $feedback['fromuser']);
    }

    public function getAmount($feedback)
    {
        if(intval($feedback['rating'])==1) {
            return -1;
        } else if(intval($feedback['rating'])==3) {
            return 1;
        }
        return 0;
    }

    public function getType($feedback)
    {
        return 'trade';
    }

    public function getDealUrl($feedback)
    {
        return '';
    }

    public function getThreadId($feedback)
    {
        return 0;
    }

    public function getDateline($feedback)
    {
        return $feedback['postdate'];
    }

    public function getOriginalId($feedback)
    {
        return $feedback['id'];
    }

    public function getFeedbackText($feedback)
    {
        return $feedback['comment'];
    }

    public function getIPAddress($feedback)
    {
        return $feedback['ip'];
    }

    public function getAllComments($originalId)
    {
        return array();
    }

    public function getCommentUserId($comment)
    {
        throw new XenForo_Exception("Comments are not implemented for Photopost Classifieds");
    }

    public function getCommentText($comment)
    {
        throw new XenForo_Exception("Comments are not implemented for Photopost Classifieds");
    }

    public function getCommentDateline($comment)
    {
        throw new XenForo_Exception("Comments are not implemented for Photopost Classifieds");
    }

    protected function _getFromCache($type, $oldid)
    {
        if (isset($this->_dataCache[$type][$oldid])) {
            return $this->_dataCache[$type][$oldid];
        }

        switch ($type) {
            case 'userid':
                $data = $this->db()->fetchOne("
						SELECT new_id FROM " . $this->_config['archive_table'] . "
						WHERE content_type='user'
						AND old_id=$oldid
					");
                break;
            case 'threadid':
                $data = $this->db()->fetchOne("
						SELECT new_id FROM " . $this->_config['archive_table'] . "
						WHERE content_type='thread'
						AND old_id=$oldid
					");
                break;
            default:
                throw new XenForo_Exception("Content type $type is not implemented.");
                break;
        }

        $this->_dataCache[$type][$oldid] = $data;

        return $data;
    }
}