/** * @method GET */ function get() { // get token $token = Utilities::ValidateJWTToken(); // check if token is not null if ($token != NULL) { $list = MenuType::GetMenuTypes($token->SiteId); // return a json response $response = new Tonic\Response(Tonic\Response::OK); $response->contentType = 'application/json'; $response->body = json_encode($list); return $response; } else { return new Tonic\Response(Tonic\Response::UNAUTHORIZED); } }
/** * @method GET */ function get() { // get an authuser $authUser = new AuthUser(); if (isset($authUser->UserUniqId)) { // check if authorized $list = MenuType::GetMenuTypes($authUser->SiteId); // return a json response $response = new Tonic\Response(Tonic\Response::OK); $response->contentType = 'application/json'; $response->body = json_encode($list); return $response; } else { return new Tonic\Response(Tonic\Response::UNAUTHORIZED); } }
public static function PublishMenuJSON($site) { $types = MenuType::GetMenuTypes($site['SiteId']); // create types for primary, footer $primary = array('MenuTypeId' => -1, 'FriendlyId' => 'primary'); $footer = array('MenuTypeId' => -1, 'FriendlyId' => 'footer'); // push default types array_push($types, $primary); array_push($types, $footer); // walk through types foreach ($types as $type) { // get items for type $list = MenuItem::GetMenuItemsForType($site['SiteId'], $type['FriendlyId']); // encode to json $encoded = json_encode($list); $dest = SITES_LOCATION . '/' . $site['FriendlyId'] . '/data/'; Utilities::SaveContent($dest, 'menu-' . $type['FriendlyId'] . '.json', $encoded); } }
public static function PublishMenuJSON($siteId) { $site = Site::GetBySiteId($siteId); $types = MenuType::GetMenuTypes($site['SiteId']); // create types for primary, footer $primary = array('MenuTypeId' => -1, 'FriendlyId' => 'primary'); $footer = array('MenuTypeId' => -1, 'FriendlyId' => 'footer'); // push default types array_push($types, $primary); array_push($types, $footer); // walk through types foreach ($types as $type) { echo $type['FriendlyId']; // get items for type $list = MenuItem::GetMenuItemsForType($site['SiteId'], $type['FriendlyId']); // create array for menu $menu = array(); // walk through menu items foreach ($list as $row) { $isInternal = false; $state = ''; $url = ''; // push non nested items onto the array if ($row['IsNested'] == 0) { // create an array item $item = array('MenuItemId' => $row['MenuItemId'], 'Name' => $row['Name'], 'CssClass' => $row['CssClass'], 'Url' => $row['Url'], 'PageId' => $row['PageId'], 'HasChildren' => false, 'Children' => array()); // push item onto the array array_push($menu, $item); } else { // create an array item $item = array('MenuItemId' => $row['MenuItemId'], 'Name' => $row['Name'], 'CssClass' => $row['CssClass'], 'Url' => $row['Url'], 'PageId' => $row['PageId']); // get a reference to the parent $parent = array_pop($menu); // make sure the parent exists if ($parent != NULL) { // push item to the children array array_push($parent['Children'], $item); // set that it has children $parent['HasChildren'] = true; // push item onto the array array_push($menu, $parent); } } } // encode to json $encoded = json_encode($menu); $dest = SITES_LOCATION . '/' . $site['FriendlyId'] . '/data/'; echo $dest . 'menu-' . $type['FriendlyId'] . '.json'; Utilities::SaveContent($dest, 'menu-' . $type['FriendlyId'] . '.json', $encoded); } }