示例#1
0
 public function notify($type, TableInterface $table, RecordInterface $record)
 {
     $message = Json::encode($record->getData());
     $headers = array('amun-table' => $table->getName(), 'amun-type' => $type, 'amun-user-id' => $this->user->id);
     $stomp = new Stomp($this->registry['stomp.broker'], $this->registry['stomp.user'], $this->registry['stomp.pw']);
     $stomp->send($this->registry['stomp.destination'], $message, $headers);
     unset($stomp);
 }
示例#2
0
 public function notify($type, TableInterface $table, RecordInterface $record)
 {
     $handler = $this->hm->getHandler('AmunService\\Log', $this->user);
     $log = $handler->getRecord();
     $log->setRefId(isset($record->id) ? $record->id : 0);
     $log->setType(RecordAbstract::getType($type));
     $log->setTable($table->getName());
     $handler->create($log);
 }
示例#3
0
    private function handleDefault($type, TableInterface $table, RecordInterface $record)
    {
        // get template message
        $sql = <<<SQL
SELECT
\t`template`.`verb`,
\t`template`.`path`,
\t`template`.`summary`
FROM 
\t{$this->registry['table.user_activity_template']} `template`
WHERE 
\t`template`.`table` = ?
AND 
\t`template`.`type` = ?
SQL;
        $row = $this->sql->getRow($sql, array($table->getName(), RecordAbstract::getType($type)));
        if (!empty($row)) {
            // get object
            $className = $this->registry->getClassNameFromTable($table->getName());
            $handler = $this->hm->getHandler($className, $this->user);
            $object = $handler->get($record->id, array(), Sql::FETCH_OBJECT);
            // build object url
            if (isset($object->pagePath) && !empty($row['path'])) {
                $url = $this->config['psx_url'] . '/' . $this->config['psx_dispatch'] . $object->pagePath . '/' . $row['path'];
                $url = $this->substituteVars($object, $url);
            } else {
                $url = '#';
            }
            // get activity stream object. If the record does not support jas
            // an exception is thrown
            $jas = null;
            try {
                $jas = $object->export(new WriterResult(WriterInterface::JAS, new Writer\Jas()));
            } catch (\Exception $e) {
            }
            // insert activity
            $handler = $this->hm->getHandler('AmunService\\User\\Activity', $this->user);
            $activity = $handler->getRecord();
            $activity->verb = $row['verb'];
            $activity->object = $jas instanceof ActivityStream\Activity ? json_encode($jas->getData()) : null;
            $activity->summary = $this->substituteVars($object, $row['summary'], $url);
            $handler->create($activity);
        }
    }