Duffer Derek

Current Path : /var/www/podiomigration.bitkit.dk/httpdocs/src/classes/Repository/Copy/
Upload File :
Current File : /var/www/podiomigration.bitkit.dk/httpdocs/src/classes/Repository/Copy/CommentRepo.php

<?php namespace App\Repository\Copy;

use App\Repository\General\DB;
use App\Repository\General\Log;


/**
 * Created by PhpStorm.
 * User: jis
 * Date: 31/3/17
 * Time: 11:46 AM
 */
class CommentRepo
{

    public function saveComments($identifier, $comments)
    {
        try {
            $sql = "INSERT IGNORE INTO `comments` (`identifier`, `src_ref_type`, `src_ref_id`,`comment_id`, `file_count`,`rich_value`, `question`, `embed`,
        `like_count`, `created_on`, `created_by_user_id`, `created_by_name`, `created_by_url`) VALUES (:identifier,
         :src_ref_type, :src_ref_id,:comment_id,:file_count,:rich_value,:question, :embed,:like_count,:created_on,:created_by_user_id,:created_by_name,:created_by_url)";
            $STH = DB::prepare($sql);
            $fileRepo = new FileCopyRepo();
            foreach ($comments as $comment) {
                $fileCount = count($comment['files']);

                $data = array("identifier" => $identifier, 'src_ref_type' => $comment['ref']['type'],
                    'src_ref_id' => $comment['ref']['id'], 'file_count' => $fileCount, 'comment_id' => $comment['comment_id'],
                    'question' => $this->getQuestion($comment), 'embed' => $this->getEmbed($comment),
                    'like_count' => $comment['like_count'], 'created_on' => $comment['created_on'],
                    'created_by_user_id' => $comment['created_by']['user_id'], 'rich_value' => $comment['rich_value'],
                    'created_by_name' => $comment['created_by']['name'], 'created_by_url' => $comment['created_by']['url']
                );

                if ($fileCount > 0) {
                    // add files to db
                    $fileRepo->saveFilesToDB(array("identifier" => $identifier, 'src_ref_type' => "comment",
                        'src_ref_id' => $comment['comment_id']), $comment['files']);
                }
                $STH->execute($data);
            }
        } catch (\Exception $e) {
            Log::logError($e . "", $comments, "saveComments");
        }
    }

    public function getEmbed($comment)
    {
        $embed = NULL;
        if (isset($comment['embed']) && isset($comment['embed']['original_url']))
            $embed = $comment['embed']['original_url'];
        return $embed;
    }

    public function getQuestion($comment)
    {
        $questions = NULL;
        try {
            if (isset($comment['questions']) && is_array($comment['questions']) && count($comment['questions']) > 0) {
                $commentQuestion = $comment['questions'][0];
                $questions = array('text' => $commentQuestion['text'], "options" => $commentQuestion['options'],
                    'answer_counts' => $commentQuestion['answer_counts']);
                $answers = array();
                foreach ($commentQuestion['answers'] as $answer) {
                    $answers[] = array("question_option_id" => $answer['question_option_id'],
                        "user_id" => $answer['user']['user_id'], 'user_name' => $answer['user']['name'],
                        'user_link' => $answer['user']['link'], 'profile_id' => $answer['user']['profile_id']);
                }

                $questions['answers'] = $answers;
                $questions = json_encode($questions);
            }
        } catch (\Exception $e) {
            Log::logError($e . "", $comment, "getQuestion");
        }
        return $questions;
    }

}

Sindbad File Manager Version 1.0, Coded By Sindbad EG ~ The Terrorists