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();
    }
Example #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.'));
     }
 }
Example #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;
 }
Example #4
0
 public function render($value = false)
 {
     $color = '';
     if ($value) {
         $color = $value->toStyleString();
     }
     $inputName = $this->getVariable();
     $r = Request::getInstance();
     if ($r->request->has($inputName)) {
         $color = h($r->request->get($inputName));
     }
     $view = View::getInstance();
     $view->requireAsset('core/colorpicker');
     $json = new Json();
     print "<input type=\"text\" name=\"{$inputName}[color]\" value=\"{$color}\" id=\"ccm-colorpicker-{$inputName}\" />";
     print "<script type=\"text/javascript\">";
     print "\$(function() { \$('#ccm-colorpicker-{$inputName}').spectrum({\n            showInput: true,\n            showInitial: true,\n            preferredFormat: 'rgb',\n            allowEmpty: true,\n            className: 'ccm-widget-colorpicker',\n            showAlpha: true,\n            value: " . $json->encode($color) . ",\n            cancelText: " . $json->encode(t('Cancel')) . ",\n            chooseText: " . $json->encode(t('Choose')) . ",\n            clearText: " . $json->encode(t('Clear Color Selection')) . ",\n            change: function() {ConcreteEvent.publish('StyleCustomizerControlUpdate');}\n        });});";
     print "</script>";
 }
<?php

use Concrete\Core\Application\Service\Dashboard;
use Concrete\Core\Http\Service\Json;
use Concrete\Core\Marketplace\RemoteItemList as MarketplaceRemoteItemList;
$dh = new Dashboard();
if ($dh->canRead()) {
    session_write_close();
    $js = new Json();
    $mri = new MarketplaceRemoteItemList();
    $mri->setItemsPerPage(5);
    $mri->setIncludeInstalledItems(false);
    $mri->setType('addons');
    $keywords = $_REQUEST['q'];
    $mri->filterByKeywords($keywords);
    $mri->execute();
    $items = $mri->getPage();
    $r = array();
    foreach ($items as $it) {
        $obj = new stdClass();
        $obj->mpID = $it->getMarketplaceItemID();
        $obj->name = $it->getName();
        $obj->img = $it->getRemoteIconURL();
        $obj->href = $it->getRemoteURL();
        $r[] = $obj;
    }
    print $js->encode($r);
    exit;
}
 private function installSampleData($pkg)
 {
     $db = \Database::get();
     $json = new Json();
     $q = "insert into TutorialDbTableDemoAttribute (keyID, displayTitle, data) values (?,?,?)";
     for ($i = 1; $i <= 10; $i++) {
         if ($i < 10) {
             $displayNum = "0" . $i;
         } else {
             $displayNum = $i;
         }
         $item = array();
         // keyID
         $item[] = $i;
         // displayTitle
         $item[] = t("Display Title (Key = " . $displayNum . ")");
         // data
         $itemData = array();
         $itemData["Department Name"] = "Facility Name (Key = " . $displayNum . ")";
         $itemData["Address 1"] = "Address 1 (Key = " . $displayNum . ")";
         $itemData["Address 2"] = "Address 2 (Key = " . $displayNum . ")";
         $itemData["City"] = "City (Key = " . $displayNum . ")";
         $itemData["State"] = "State (Key = " . $displayNum . ")";
         $itemData["Zip"] = "Zip (Key = " . $displayNum . ")";
         $item[] = $json->encode($itemData);
         $db->query($q, $item);
     }
 }