Giter Site home page Giter Site logo

rotator-baner's Introduction

Ротатор баннеров

Task description:

Требуется написать систему вывода рекламы. Класс, либо расширение для Yii

Имеется множество шаблонов html/js

Возьмем для примера superbanner.php с текстом:

Кликни меня

Требования к приложению:

  • Приложение должно уметь подключать подобные шаблоны без указания типа файла, а только его имени, т.е "superbanner" ( возвращается код файла )

  • Возможность задавать количество возвращаемых кодов ( подключаю "superbanner" 3 раза и т.д )

  • Должен быть конфиг приложения для возможности задать кол-во возвращаемых кодов по умолчанию

  • Возможность задавать процентное отображение количества кодов. Например в конфиге для баннера "superbanner" указано по умолчанию 50 шт. Вызывая приложение мы сообщаем что нам нужно 50% от указанного количества в конфиге и нам возвращается 25 кодов. При этом запоминается для этого типа остаточное число баннеров. Забрали 25. Осталось 25. При следующем запросе в % или кол-ве приложение уже будет расчитывать из остатка кодов. Т.е вызов на странице что то типа

echo Banners::get("superbanner", '50%') // вернулось 25 кодов

// вызываем второй раз на странице

echo Banners::get("superbanner", '20%') // вернулось 5 кодов и еще осталось 20

====================== Вывод баннеров с учетом ограничения по количеству

Installation

The preferred way to install this extension is through composer.

Either run

php composer.phar require --prefer-dist yii2-gambit/yii2-banner "*"

or add

"yii2-gambit/yii2-banner": "*"

to the require section of your composer.json file.

Usage

Once the extension is installed, simply use it in your code by :

$config = [
    'superbanner' => [
        'default' => 10,
        'banner' => [
            'file' => '@app/web/img/banners/superbanner/superbanner_1.php',
            'id' => '54447',
            'url' => 'http://yandex.ru',
        ],
    ],
    'superbanner2' => [
        'default' => 5,
        'banner' => [
            'file' => '@app/web/img/banners/superbanner2/superbanner2_1.js',
            'id' => '54454',
            'url' => 'http://wordstat.yandex.ru',
        ],
    ],
    'superbanner3' => [
        'default' => 50,
        'banner' => [
            'file' => '@app/web/img/banners/superbanner3/superbanner.html',
            'id' => '54461',
            'url' => 'http://wordstat.yandex.ru',
        ],
    ],
];

<?=               
        \gambit\banner\rotator\ShowBanner::widget([
            'name' => 'superbanner',
            'config' => \Yii::getAlias('@frontend') . '/config/banners.php',
            'count' => '5%',
            'default' => '50',
        ]); 
?>```

file log example record 
{"superbanner":{"value":5}}
{"superbanner2":{"value":12}}

```php

    Переопределяемые свойства 

    /**
     * Наименование группы баннеров
     */
    public $name;

    /**
     * Переопределение значения опции 'default' в конфигурационном файле баннеров
     * @var integer
     */
    public $default;

    /**
     * Structure elements 
     *      [
     *           'file' => '@app/web/img/banners/superbanner/superbanner_1.php',
     *           'url' => 'http://yandex.ru',
     *           'id' => '54447',
     *      ],
     * @var array
     */
    public $banner;

    /**
     * Путь к конфигу
     * @var string
     */
    public $configPath = '@app/config/banners.php';

    /**
     * @var конфигурация баннеров
     */
    public $config = [];

    /**
     * @var integer
     */
    public $count = 0;

    /**
     * Рассчитанное ротатором кол-во
     * @var integer 
     */
    public $counterRotate;
    public $logPath = '@app/runtime/';

    /**
     * class path rotator
     */
    public $classPathRotator = '\gambit\banner\rotator\Rotator';

    /**
     * @var object Rotator
     */
    public $rotate = null;

    /**
     * Html attributes 
     * @var array
     */
    public $option = [];

    /**
     * Баннеры
     * @var array
     */
    public $items = [];

    /**
     * наименование view (шаблона)
     * @var array
     */
    public $viewName = 'show_banner';

rotator-baner's People

Stargazers

Negruzzi Cristian avatar

Watchers

Gambit avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.