mambax7/marquee

View on GitHub
class/MarqueexHandler.php

Summary

Maintainability
A
0 mins
Test Coverage
<?php declare(strict_types=1);

namespace XoopsModules\Marquee;

use XoopsDatabase;
use XoopsPersistableObjectHandler;

/**
 * ****************************************************************************
 * marquee - MODULE FOR XOOPS
 * Copyright (c) Hervé Thouzard (https://www.herve-thouzard.com)
 *
 * You may not change or alter any portion of this comment or credits
 * of supporting developers from this source code or any supporting source code
 * which is considered copyrighted (c) material of the original comment or credit authors.
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 *
 * @copyright          Hervé Thouzard (https://www.herve-thouzard.com)
 * @license            GNU GPL 2.0 or later (https://www.gnu.org/licenses/gpl-2.0.html)
 * @author             Hervé Thouzard (https://www.herve-thouzard.com)
 * ****************************************************************************
 */
//require_once XOOPS_ROOT_PATH . '/kernel/object.php';
//require_once XOOPS_ROOT_PATH . '/modules/marquee/class/Utility.php';
//if (!class_exists('MarqueePersistableObjectHandler')) {
//    require_once XOOPS_ROOT_PATH . '/modules/marquee/class/PersistableObjectHandler.php';
//}
//class MarqueeHandler extends MarqueePersistableObjectHandler

/**
 * Class MarqueeHandler
 */
class MarqueexHandler extends XoopsPersistableObjectHandler //MarqueePersistableObjectHandler
{
    /**
     * @param \XoopsDatabase|null $db
     */
    public function __construct(XoopsDatabase $db = null)
    {
        parent::__construct($db, 'marquee', Marqueex::class, 'marquee_marqueeid');
    }

    /**
     * @param int $selectedmarquee
     *
     * @return string
     */
    public function getHtmlMarqueesList($selectedmarquee = 0)
    {
        $ret         = '';
        $tbl_marquee = $this->getObjects();
        foreach ($tbl_marquee as $oneMarquee) {
            $selected = '';
            if ($oneMarquee->getVar('marquee_marqueeid') == $selectedmarquee) {
                $selected = ' selected';
            }
            $content = '' !== \xoops_trim(\strip_tags($oneMarquee->getVar('marquee_content'))) ? \xoops_substr(\strip_tags($oneMarquee->getVar('marquee_content')), 0, 50) : $oneMarquee->getVar('marquee_source');
            $ret     .= '<option ' . $selected . " value='" . $oneMarquee->getVar('marquee_marqueeid') . "'>" . $content . '</option>';
        }

        return $ret;
    }

    /**
     * Quickly insert a record like this $myobjectHandler->quickInsert('field1' => field1value, 'field2' => $field2value)
     *
     * @param array $vars  Array containing the fields name and value
     * @param bool  $force whether to force the query execution despite security settings
     *
     * @return bool @link insert's value
     */
    public function quickInsert($vars = null, $force = false)
    {
        $object = $this->create(true);
        $object->setVars($vars);
        $retval = $this->insert($object, $force);
        unset($object);

        return $retval;
    }
}