PHP Classes

File: src/Models/Dialog.php

Recommend this page to a friend!
  Classes of Joseluis Laso   PHP Telegram CLI Wrapper   src/Models/Dialog.php   Download  
File: src/Models/Dialog.php
Role: Class source
Content type: text/plain
Description: Class source
Class: PHP Telegram CLI Wrapper
Send messages and other commands to Telegram users
Author: By
Last change:
Date: 8 years ago
Size: 1,953 bytes
 

Contents

Class file image Download
<?php

namespace TelegramCliWrapper\Models;


class
Dialog extends BasicObject
{

    public
$event;
    public
$id;
   
/** @var Flags */
   
public $flags;
    public
$service;
    public
$out;
   
/** @var User */
   
public $from;
   
/** @var string */
   
public $text;
   
/** @var User */
   
public $to;
    public
$unread;
    public
$date;

   
/**
     * Transform an stdClass Object returned by history into a HistoryItem
     * @param $item
     */
   
public function __construct($item)
    {
       
parent::__construct($item);
       
$this->flags = new Flags($item->flags);
       
$this->from = new User($item->from);
       
$this->to = new User($item->to);
    }

    public static function
getTitles()
    {
        return
sprintf(
           
"|%-10s|%-10s|%-10s|%-10s|%-20s|%-20s|%-30s|%-10s|%s|",
           
"id",
           
"service",
           
"event",
           
"flags",
           
"from",
           
"to",
           
"text",
           
"date",
           
"unread"
       
);
    }

    public function
__toString()
    {
        return
sprintf(
           
"|%-10d|%-10s|%-10s|%-10s|%-20s|%-20s|%-30s|%-10s|%s|",
           
$this->id,
           
$this->service,
           
$this->event,
           
$this->flags,
           
$this->from->print_name,
           
$this->to->print_name,
           
$this->text,
           
date("y.m.d-H:j:s", $this->date),
           
$this->unread
       
);
    }


   
/**
     * Converts an array returned by history into a Dialog[]
     * @param array $items
     * @return Dialog[]
     */
   
public static function fromArray($items = array())
    {
       
$result = array();
        if (
$items && count($items)) {
            foreach (
$items as $item) {
               
$result[] = new Dialog($item);
            }
        }

        return
$result;
    }

   
/**
     * @return string
     */
   
public function getId()
    {
        return
$this->id;
    }


}