@param int $character_id

@return mixed
@throws \Exception
973518
public function getTopMailFromData(int $character_id)
    {
        if (! request()->has('all_linked_characters'))
            return abort(500);

        $character_ids = collect($character_id);

        $user_group = User::find($character_id)->group->users
            ->filter(function ($user) {
                return $user->name !== 'admin' && $user->id !== 1;
            })
            ->pluck('id');

        if (request('all_linked_characters') === 'true')
            $character_ids = $user_group;

        $top = $this->characterTopMailInteractions($character_ids);

        return DataTables::of($top)
            ->editColumn('character_id', function ($row) {

                return $this->getIntelView('character', $row->character_id, $row->from);
            })
            ->editColumn('corporation_id', function ($row) {

                return $this->getIntelView('corporation', $row->character_id, $row->from);
            })
            ->editColumn('alliance_id', function ($row) {

                return $this->getIntelView('alliance', $row->character_id, $row->from)
                    . view('web::character.intel.partials.mailcontentbutton', compact('row'));
            })
            ->rawColumns(['character_id', 'corporation_id', 'alliance_id'])
            ->make(true);
    }
892345
private function getIntelView(string $type, int $character_id, int $first_other_id, int $second_other_id = null) : string
    {
        $universe_name = $this->getUniverseNameResolved($character_id, $first_other_id, $second_other_id);

        if($type === 'character')
            return $this->getCharacterIntelView($universe_name, $character_id);

        if($type === 'corporation')
            return $this->getCorporationIntelView($universe_name, $character_id);

        if($type === 'alliance')
            return $this->getAllianceIntelView($universe_name, $character_id);

        return '';

    }
969145
public function getCharacterPlanetaryExtractors(int $character_id): Collection
    {

        $extractors = CharacterPlanet::where('character_planets.character_id', $character_id)
            ->join('character_planet_extractors', function ($join) {
                $join->on('character_planet_extractors.planet_id', '=', 'character_planets.planet_id')
                    ->on('character_planet_extractors.character_id', '=', 'character_planets.character_id');
            })
            ->join('character_planet_pins', function ($join) {
                $join->on('character_planet_pins.pin_id', '=', 'character_planet_extractors.pin_id')
                    ->on('character_planet_pins.planet_id', '=', 'character_planet_extractors.planet_id')
                    ->on('character_planet_pins.character_id', '=', 'character_planet_extractors.character_id');
            })
            ->join('mapDenormalize as planet',
                'planet.itemID', '=', 'character_planets.planet_id')
            ->join('mapDenormalize as system',
                'system.itemID', '=', 'character_planets.solar_system_id')
            ->join('invTypes',
                'invTypes.typeID', '=', 'character_planet_extractors.product_type_id')
            ->select(
                'character_planet_extractors.product_type_id', // Extractor Product Name f.e. Aqueous Liquids
                'planet.celestialIndex', // arabic planet index
                'planet.itemName', // Planet Name
                'planet.typeID', // Planet Type ID
                'system.itemName', // System Name
                'character_planet_pins.install_time', //UTC Time of start
                'character_planet_pins.expiry_time', // UTC Time of expiry
                'character_planets.planet_type', // barren, temperate, gas
                'invTypes.typeName' // Extractor Product Name
            )
            ->get();

        return $extractors->map(function ($item) {

            $item->celestialIndex = number_roman($item->celestialIndex);

            return $item;
        });
    }
128456
public function getTopMailContent(int $character_id, int $from)
    {

        $mail = $this->getMailContent($character_id, $from);

        return DataTables::of($mail)
            ->editColumn('from', function ($row) {

                $character_id = $row->character_id;

                $character = CharacterInfo::find($row->from) ?: $row->from;

                return view('web::partials.character', compact('character', 'character_id'));
            })
            ->editColumn('subject', function ($row) {

                return view('web::character.partials.mailtitle', compact('row'));
            })
            ->editColumn('tocounts', function ($row) {

                return view('web::character.partials.mailtocounts', compact('row'));
            })
            ->addColumn('read', function ($row) {

                return view('web::character.partials.topmailread', compact('row'));
            })
            ->rawColumns(['from', 'subject', 'tocounts', 'read'])
            ->make(true);

    }
583185
public function getTransactionsData(int $character_id)
    {

        if (! request()->has('all_linked_characters'))
            return abort(500);

        if (request('all_linked_characters') === 'false')
            $character_ids = collect($character_id);

        $user_group = User::find($character_id)->group->users
            ->filter(function ($user) {

                return $user->name !== 'admin' && $user->id !== 1;
            })
            ->pluck('id');

        if (request('all_linked_characters') === 'true')
            $character_ids = $user_group;

        $transactions = $this->getCharacterWalletTransactions($character_ids);

        return DataTables::of($transactions)
            ->editColumn('is_buy', function ($row) {

                return view('web::partials.transactionbuysell', compact('row'));
            })
            ->editColumn('unit_price', function ($row) {

                return number($row->unit_price);
            })
            ->addColumn('item_view', function ($row) {
                return view('web::partials.transactiontype', compact('row'));
            })
            ->addColumn('total', function ($row) {

                return number($row->unit_price * $row->quantity);
            })
            ->addColumn('client_view', function ($row) {

                $character_id = $row->character_id;

                $character = CharacterInfo::find($row->client_id) ?: $row->client_id;

                return view('web::partials.character', compact('character', 'character_id'));
            })
            ->rawColumns(['is_buy', 'client_view', 'item_view'])
            ->make(true);

    }
856668
public function getJournalGraphBalance(int $character_id)
    {

        $data = $this->getCharacterWalletJournal(collect($character_id))
            ->orderBy('date', 'desc')
            ->take(150)
            ->get();

        return response()->json([
            'labels'   => $data->map(function ($item) {

                return $item->date;
            })->toArray(),
            'datasets' => [
                [
                    'label'           => 'Balance',
                    'fill'            => false,
                    'lineTension'     => 0.1,
                    'backgroundColor' => 'rgba(60,141,188,0.9)',
                    'borderColor'     => 'rgba(60,141,188,0.8)',
                    'data'            => $data->map(function ($item) {

                        return $item->balance;
                    })->toArray(),
                ],
                [
                    'label'           => 'Amount',
                    'fill'            => false,
                    'lineTension'     => 0.1,
                    'backgroundColor' => 'rgba(210, 214, 222, 1)',
                    'borderColor'     => 'rgba(210, 214, 222, 1)',
                    'data'            => $data->map(function ($item) {

                        return $item->amount;
                    })->toArray(),
                ],
            ],
        ]);
    }
868543
public function getCharacterContacts(Collection $character_ids, array $standings): Builder
    {

        return CharacterContact::whereIn('character_contacts.character_id', $character_ids->toArray())
            ->whereIn('standing', $standings);
    }
1280970
public function getJournalData(int $corporation_id)
    {
        if (! request()->has('division'))
            return abort(500);

        $journal = $this->getCorporationWalletJournal($corporation_id, (int) request('division'));

        return DataTables::of($journal)
            ->editColumn('ref_type', function ($row) {

                return view('web::partials.journaltranstype', compact('row'));
            })
            ->editColumn('first_party_id', function ($row) {

                $character_id = $row->character_id;

                if (optional($row->first_party)->category === 'character') {

                    $character = CharacterInfo::find($row->first_party_id) ?: $row->first_party_id;

                    return view('web::partials.character', compact('character', 'character_id'));
                }

                if (optional($row->first_party)->category === 'corporation'){

                    $corporation = CorporationInfo::find($row->first_party_id) ?: $row->first_party_id;

                    return view('web::partials.corporation', compact('corporation', 'character_id'));
                }

                return view('web::partials.unknown', [
                    'unknown_id' => $row->first_party_id,
                    'character_id' => $character_id,
                ]);
            })
            ->editColumn('second_party_id', function ($row) {

                $character_id = $row->character_id;

                if (optional($row->second_party)->category === 'character') {

                    $character = CharacterInfo::find($row->second_party_id) ?: $row->second_party_id;

                    return view('web::partials.character', compact('character', 'character_id'));
                }

                if (optional($row->second_party)->category === 'corporation') {

                    $corporation = CorporationInfo::find($row->second_party_id) ?: $row->second_party_id;

                    return view('web::partials.corporation', compact('corporation', 'character_id'));
                }

                return view('web::partials.unknown', [
                    'unknown_id' => $row->second_party_id,
                    'character_id' => $character_id,
                ]);
            })
            ->editColumn('amount', function ($row) {

                return number($row->amount);
            })
            ->editColumn('balance', function ($row) {

                return number($row->balance);
            })
            ->rawColumns(['ref_type', 'first_party_id', 'second_party_id'])
            ->make(true);

    }
977195
public function getDetailedLedger(int $character_id, $date, int $system_id, int $type_id): JsonResponse
    {
        if (! request()->has('all_linked_characters'))
            return abort(500);

        $character_ids = collect($character_id);

        $entries = $this->getCharacterLedger($character_ids)
            ->addSelect('time', 'quantity')
            ->where('character_minings.date', $date)
            ->where('solar_system_id', $system_id)
            ->where('character_minings.type_id', $type_id)
            ->get();

        return DataTables::of($entries)
            ->removeColumn('solar_system_id')
            ->removeColumn('date')
            ->removeColumn('type_id')
            ->removeColumn('average_price')
            ->removeColumn('type')
            ->editColumn('quantity', function ($row) {

                return view('web::partials.miningquantity', compact('row'));
            })
            ->editColumn('volume', function ($row) {

                return view('web::partials.miningvolume', compact('row'));
            })
            ->addColumn('value', function ($row) {

                $value = $row->average_price * $row->quantity;

                if(empty($value))
                    // If historical price has not been set, get historical price.
                    $value = $this->getHistoricalPrice($row->type_id, $row->date)->average_price;

                return view('web::partials.miningvalue', compact('value'));
            })
            ->rawColumns(['value', 'volume'])
            ->make(true);
    }
254104
public function getTopTransactionsData(int $character_id)
    {
        if (! request()->has('all_linked_characters'))
            return abort(500);

        $character_ids = collect($character_id);

        $user_group = User::find($character_id)->group->users
            ->filter(function ($user) {
                return $user->name !== 'admin' && $user->id !== 1;
            })
            ->pluck('id');

        if (request('all_linked_characters') === 'true')
            $character_ids = $user_group;

        $top = $this->characterTopWalletTransactionInteractions($character_ids);

        return DataTables::of($top)
            ->addColumn('character', function ($row) {

                return $this->getIntelView('character', $row->character_id, $row->client_id);
            })
            ->addColumn('corporation', function ($row) {

                return $this->getIntelView('corporation', $row->character_id, $row->client_id);
            })
            ->addColumn('alliance', function ($row) {

                return $this->getIntelView('alliance', $row->character_id, $row->client_id)
                    . view('web::character.intel.partials.transactioncontentbutton', compact('row'));
            })
            ->rawColumns(['character', 'corporation', 'alliance'])
            ->make(true);

    }
407396
public function randomId($random_id_length = 10)
    {
        //generate a random id encrypt it and store it in $rnd_id 
        $rnd_id = crypt(uniqid(rand(), 1), uniqid(rand(), 1));

        //to remove any slashes that might have come 
        $rnd_id = strip_tags(stripslashes($rnd_id));

        //Removing any . or / and reversing the string 
        $rnd_id = strrev(str_replace("/", "", str_replace(".", "", $rnd_id)));

        if (strlen($rnd_id) < $random_id_length) {
            $rnd_id = $rnd_id . $this->randomId($random_id_length - strlen($rnd_id));
        }

        //finally I take the first 10 characters from the $rnd_id 
        $rnd_id = substr($rnd_id, 0, $random_id_length);
        $this->BackyardError->log(5, "Random id is " . $rnd_id, array(16));
        return $rnd_id;
    }
797122
public function getCharacterApi()
    {
        if (!$this->apis->has('character')) {
            $this->apis->set('character', new Character($this));
        }

        return $this->apis->get('character');
    }
772228
public function postUpdateNote(UpdateIntelNote $request, int $character_id)
    {

        CharacterInfo::updateNote(
            $character_id, $request->input('note_id'),
            $request->input('title'),
            $request->input('note'));

        return redirect()->back()
            ->with('success', 'Note updated!');

    }
154121
public function postAddNew(NewIntelNote $request, int $character_id)
    {

        CharacterInfo::addNote(
            $character_id, $request->input('title'), $request->input('note'));

        return redirect()->back()
            ->with('success', 'Note Added');

    }
332545
public function getFittingItems(int $character_id, int $fitting_id)
    {

        $fitting = $this->getCharacterFitting($character_id, $fitting_id);
        $items = $this->getCharacterFittingItems($fitting_id);

        return view('web::character.fittingitems', compact('fitting', 'items'));
    }
346255
public function getCharacter4Id($id)
    {
        /** @var \GameBackend\Entity\SRO\Shard\Repository\Character $repository */
        $repository = $this->getShardEntityManager()->getRepository($this->getGameOptions()->getEntityShardCharacter());
        return $repository->getCharacter4Id($id, $this->getNotListedJIDList());
    }
694542
protected function getCharacterFromArray()
    {
        $character = $this->characters[rand(0, count($this->characters) - 1)];

        if ($this->unique) {
            $this->removeFromArray($character);
        }

        return $character;
    }