PHP code example of mrcnpdlk / grandstream-xmlapp

1. Go to this page and download the library: Download mrcnpdlk/grandstream-xmlapp library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

mrcnpdlk / grandstream-xmlapp example snippets


use mrcnpdlk\Grandstream\XMLApp\AddressBook\View;

123123123', 'John');
$oView->addContact('Nowak', '456456456');

header('Content-type: application/xml; charset="utf-8"');

echo $oView->asTxt();

use mrcnpdlk\Grandstream\XMLApp\Application\Model\Components\ElemBitmap;
use mrcnpdlk\Grandstream\XMLApp\Application\Model\Components\ElemRectangle;
use mrcnpdlk\Grandstream\XMLApp\Application\Model\Components\ElemSelect;
use mrcnpdlk\Grandstream\XMLApp\Application\Model\Components\ElemString;
use mrcnpdlk\Grandstream\XMLApp\Application\Model\Container;
use mrcnpdlk\Grandstream\XMLApp\Application\Model\Event;
use mrcnpdlk\Grandstream\XMLApp\Application\Model\SoftKey;
use mrcnpdlk\Grandstream\XMLApp\Application\Model\Styles;
use mrcnpdlk\Grandstream\XMLApp\Application\ModelConstant;
use mrcnpdlk\Grandstream\XMLApp\Application\View;
use mrcnpdlk\Grandstream\XMLApp\Helper\Color;
use mrcnpdlk\Grandstream\XMLApp\Helper\Rectangle;

etColor(new Color(0))
    ->setColorBorder(new Color(30))
)
          ->addItem('one', 1)
          ->addItem('two', 2)
          ->addItem('three', 3)
;


$oSelect_2 = new ElemSelect('select_2');
$oSelect_2->setStyles(new  Styles(100))
          ->addItem('apple', 1)
          ->addItem('orange', 2)
          ->addItem('lemon', 3)
          ->move(0, 20)
;

$oContainer_2
    ->addElement($oSelect_1)
    ->addElement($oSelect_2)
    ->move(0, 20)
;
$oView->addContainer($oContainer_2);

/**
 * Elements can be added directly on the View without using Container
 */
$oView->addElem(new ElemRectangle(10, 10));

/**
 * You can also define SoftKey
 */
$oView->addSoftkey(new SoftKey(ModelConstant::ACTION_QUIT_APP, 'Exit'));

/**
 * And define Events
 */
$oEvent = new Event(ModelConstant::STATE_OFFHOOK, ModelConstant::ACTION_DIAL, '299');
$oView->addEvent($oEvent);
/**
 * Add picture (100x100) to screen
 */
$oBitmap = new ElemBitmap(
    __DIR__ . '/../devel/logo.png',
    new Rectangle(100)
);
$oView->addElem($oBitmap->move(120, 0));

/**
 * Last thing. Left status bar can be disabled (more space on screen)
 */
$oView->setVisibleStatusLine(false);

/**
 * Echo text for phone
 */
header('Content-type: application/xml; charset="utf-8"');
echo $oView->asTxt();
xml
<AddressBook>
    <Contact>
        <LastName>Doe</LastName>
        <FirstName/>
        <Email/>
        <Department/>
        <Company/>
        <Icon/>
        <Phone>
            <phonenumber>123123123</phonenumber>
            <accountindex>1</accountindex>
        </Phone>
    </Contact>
    <Contact>
        <LastName>Nowak</LastName>
        <FirstName/>
        <Email/>
        <Department/>
        <Company/>
        <Icon/>
        <Phone>
            <phonenumber>456456456</phonenumber>
            <accountindex>1</accountindex>
        </Phone>
    </Contact>
</AddressBook>
xml
<Screen>
    <Page ignoreCallUpdate="false">
        <ShowStatusLine>false</ShowStatusLine>
        <Contents>
            <DisplayString font="unifont" color="Black" bgcolor="None" halign="left">
                <X>0</X>
                <Y>60</Y>
                <DisplayStr>First line</DisplayStr>
            </DisplayString>
            <DisplayString font="unifont" color="Black" bgcolor="None" halign="left">
                <X>0</X>
                <Y>70</Y>
                <DisplayStr>Second line</DisplayStr>
            </DisplayString>
            <select name="select_1">
                <styles pos_x="0" pos_y="20" width="100" color="White" bgcolor="Black" border-color="Light3"/>
                <items>
                    <item value="1">one</item>
                    <item value="2">two</item>
                    <item value="3">three</item>
                </items>
            </select>
            <select name="select_2">
                <styles pos_x="0" pos_y="40" width="100" color="Black" bgcolor="Light4" border-color="Black"/>
                <items>
                    <item value="1">apple</item>
                    <item value="2">orange</item>
                    <item value="3">lemon</item>
                </items>
            </select>
            <DisplayRectangle x="0" y="0" width="10" height="10" bgcolor="None" border-color="Black"/>
            <DisplayBitmap isfile="false" isflash="false">
                <X>120</X>
                <Y>0</Y>
                <Bitmap>..BASE_64_STRING..</Bitmap>
            </DisplayBitmap>
        </Contents>
        <SoftKeys>
            <SoftKey action="QuitApp" label="Exit"/>
        </SoftKeys>
    </Page>
    <Events>
        <Event state="offhook">
            <Action action="Dial" commandArgs="299"/>
        </Event>
    </Events>
</Screen>