Alert::displayLastAlert PHP Метод

displayLastAlert() статический публичный Метод

static public displayLastAlert ( $itemtype, $items_id ) : nothing
$itemtype
$items_id
Результат nothing
    static function displayLastAlert($itemtype, $items_id)
    {
        global $DB;
        if ($items_id) {
            $iter = $DB->request(self::getTable(), ['FIELDS' => 'date', 'ORDER' => 'date DESC', 'LIMIT' => 1, 'itemtype' => $itemtype, 'items_id' => $items_id]);
            if ($row = $iter->next()) {
                //TRANS: %s is the date
                echo sprintf(__('Alert sent on %s'), Html::convDateTime($row['date']));
            }
        }
    }

Usage Example

Пример #1
0
 public function testAddDelete()
 {
     $alert = new Alert();
     $nb = countElementsInTable($alert->getTable());
     $comp = getItemByTypeName('Computer', '_test_pc01');
     $date = '2016-09-01 12:34:56';
     // Add
     $id = $alert->add(['itemtype' => $comp->getType(), 'items_id' => $comp->getID(), 'type' => Alert::END, 'date' => $date]);
     $this->assertGreaterThan(0, $id);
     $this->assertGreaterThan($nb, countElementsInTable($alert->getTable()));
     // Getters
     $this->assertFalse(Alert::alertExists($comp->getType(), $comp->getID(), Alert::NOTICE));
     $this->assertEquals($id, Alert::alertExists($comp->getType(), $comp->getID(), Alert::END));
     $this->assertEquals($date, Alert::getAlertDate($comp->getType(), $comp->getID(), Alert::END));
     // Display
     $this->expectOutputString(sprintf('Alert sent on %s', Html::convDateTime($date)));
     Alert::displayLastAlert($comp->getType(), $comp->getID());
     // Delete
     $this->assertTrue($alert->clear($comp->getType(), $comp->getID(), Alert::END));
     $this->assertEquals($nb, countElementsInTable($alert->getTable()));
     // Still true, nothing to delete but no error
     $this->assertTrue($alert->clear($comp->getType(), $comp->getID(), Alert::END));
 }
All Usage Examples Of Alert::displayLastAlert