webservice = $webservice; $this->deviceGetUrl = $deviceGetUrl; $this->deviceLogGetUrl = $deviceLogGetUrl; } /** * @return array */ public function getFunctions() { return array( new \Twig_SimpleFunction('device_log', array($this, 'getDeviceLog')), ); } /** * @param Entity $object * @param int $limit * @param int $offset * * @return array */ public function getDeviceLog($object, $limit = 50, $offset = 0) { $filters = array( 'deviceType' => get_class($object), 'deviceId' => $object->getId(), 'disableTenancy' => true ); $device = $this->webservice->getData($this->deviceGetUrl, $filters); $log = ''; if (count($device) && isset($device[0])) { $filters = array( 'device' => $device[0]['id'], ); // $order = array( // 'created' => 'DESC' // ); $deviceLogs = $this->webservice->getData($this->deviceLogGetUrl, $filters, array(), $limit, $offset); foreach ($deviceLogs as $deviceLog) { unset($deviceLog['device']); $created = new \DateTime($deviceLog['created']); $log .= $created->format('d/m/Y H:i') . ' - ' . $deviceLog['message'] . PHP_EOL; } } return $log; } /** * @return string */ public function getName() { return 'device_log_extension'; } }