public function getDisplayValue()
    {
        $db = \Database::get();
        $q = "select * from TutorialDbTableDemoAttribute where keyID = ?";
        $row = $db->getRow($q, array($this->getValue()));
        $json = new Json();
        $jsonData = $json->decode($row['data']);
        ob_start();
        ?>
<h4><?php 
        echo $row['displayTitle'];
        ?>
</h4>
<dl>
    <?php 
        foreach ($jsonData as $handle => $value) {
            ?>
    <dt><?php 
            echo $handle;
            ?>
</dt>
    <dd><?php 
            echo $value;
            ?>
</dd>
    <?php 
        }
        ?>
</dl>
        <?php 
        return ob_get_clean();
    }
Ejemplo n.º 2
0
 /**
  * @param string $response A JSON encoded array. Expected format of:
  * <code>
  * {
  *  'id': value,
  *  'title': value,
  *  'content': value,
  *  'date': value,
  *  'description': value
  * }
  * </code>
  * @return NewsflowItem Returns a new NewsflowItem if one could be created from the response, otherwise throws an exception
  * @throws \Exception
  */
 public function parseResponse($response)
 {
     try {
         $json = new Json();
         $obj = $json->decode($response);
         if (is_object($obj) && isset($obj->id) && isset($obj->title) && isset($obj->content) && isset($obj->date) && isset($obj->description)) {
             return new NewsflowItem($obj->id, $obj->title, $obj->content, $obj->date, $obj->description);
         } else {
             throw new \Exception(t('Unable to parse news response.'));
         }
     } catch (\Exception $e) {
         throw new \Exception(t('Unable to parse news response.'));
     }
 }
Ejemplo n.º 3
0
 /**
  * @param string $response Parses a JSON response that looks similar to below
  * <code>
  * {
  *     'slots': {
  *          'slotKey1': 'content',
  *          'slotKey2': 'other content',
  *          ...
  *      }
  * }
  * </code>
  * @return NewsflowSlotItem[] Returns an associative array of NewsflowSlotItems
  */
 public function parseResponse($response)
 {
     $slots = array();
     try {
         $json = new Json();
         $obj = $json->decode($response);
         if (is_object($obj)) {
             if (is_object($obj->slots)) {
                 foreach ($obj->slots as $key => $content) {
                     $cn = new NewsflowSlotItem($content);
                     $slots[$key] = $cn;
                 }
             }
         }
     } catch (\Exception $e) {
     }
     return $slots;
 }