Exemple #1
0
 public function render($bEcho = true)
 {
     $str = '';
     if ($this->page) {
         $str .= "<table><tr><th>Product Name</th>";
         $displayedElements = App::Get()->settings['browser_products_met'];
         foreach ($displayedElements as $elementName) {
             $str .= "<th>{$elementName}</th>";
         }
         $str .= "</tr>";
         if (!App::Get()->settings['browser_private_products_visibility']) {
             // Get a CAS-Browser XML/RPC client
             $browser = new CasBrowser();
             $client = $browser->getClient();
             foreach ($this->pageMetadata as $key => $value) {
                 if ($browser->getProductVisibilityLevel($key) == "deny") {
                     unset($this->pageMetadata[$key]);
                     foreach ($this->pageProducts as $product) {
                         if ($product->id == $key) {
                             $productKey = array_search($product, $this->pageProducts);
                             unset($this->pageProducts[$productKey]);
                         }
                     }
                 }
             }
         }
         foreach ($this->pageProducts as $product) {
             $str .= "<tr><td><a href=\"" . $this->urlBase . "/product/{$product->getId()}/{$this->returnPage}\">" . urlDecode(basename($product->getName())) . "</a></td>";
             foreach ($displayedElements as $elementName) {
                 $str .= "<td>" . $this->pageMetadata[$product->getId()]->getMetadata($elementName) . "</td>";
             }
             $str .= "</tr>";
         }
         $str .= "</table>";
     }
     if ($bEcho) {
         echo $str;
     } else {
         return $str;
     }
 }
Exemple #2
0
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
$module = App::Get()->loadModule();
require_once $module->modulePath . "/classes/CasBrowser.class.php";
require_once $module->modulePath . "/scripts/widgets/MetadataDisplayWidget.php";
require_once $module->modulePath . "/scripts/widgets/ProductDownloadWidget.php";
// Get a CAS-Browser XML/RPC client
$browser = new CasBrowser();
$client = $browser->getClient();
// Get the specified product
$productId = App::Get()->request->segments[0];
$product = $client->getProductById($productId);
$productName = $product->getName();
$productTypeName = $product->getType()->getName();
$productTypeId = $product->getType()->getId();
$productMetadata = $client->getMetadata($product);
// Get metadata for product and productType as associative arrays
$productTypeInfo = $product->getType()->toAssocArray();
$productInfo = $productMetadata->toAssocArray();
$productVisibilityLevel = $browser->getProductVisibilityLevel($productId);
// Redirect the user if they are not authorized
if ($productVisibilityLevel == CasBrowser::VIS_NONE) {
    App::Get()->redirect(SITE_ROOT . '/errors/403');
}
Exemple #3
0
 */
$module = App::Get()->loadModule();
require_once dirname(dirname(__FILE__)) . '/classes/CasBrowser.class.php';
// Extract desired output format from POST
if (isset($_POST['OutputFormat'])) {
    try {
        $outputFormat = Utils::getRequestedReturnType($_POST['OutputFormat']);
    } catch (Exception $e) {
        Utils::reportError($e->getMessage(), 'html');
    }
} else {
    $outputFormat = 'html';
}
// Get client handle
$cb = new CasBrowser();
$client = $cb->getClient();
// Extract ProductType from POST
if (!isset($_POST['Type'])) {
    Utils::reportError("POST does not contain 'Type' ProductType", $outputFormat);
}
$typeName = $_POST['Type'];
try {
    $allTypes = $client->getProductTypes();
    $allTypeNames = array_map(create_function('$t', 'return $t->getName();'), $allTypes);
    if (!in_array($typeName, $allTypeNames)) {
        $errStr = "The type " . $typeName . " is not used in the repository.  Please use one of: ";
        for ($i = 0; $i < count($allTypeNames) - 1; $i++) {
            $errStr .= $allTypeNames[i] . ", ";
        }
        $errStr .= $allTypeNames[count($allTypeNames) - 1];
        Utils::reportError($errStr, $outputFormat);
Exemple #4
0
 public static function formatResults($products)
 {
     $cb = new CasBrowser();
     $client = $cb->getClient();
     $results = array();
     foreach ($products as $product) {
         try {
             $p = array('id' => $product['product']->getId(), 'name' => urlDecode($product['product']->getName()), 'metadata' => $client->getMetadata($product['product'])->toAssocArray());
             if (isset($product['typeName'])) {
                 $p['type'] = $product['typeName'];
             }
             array_push($results, $p);
         } catch (Exception $e) {
             throw new CasBrowserException("An error occured while formatting product [" . $product['product']->getId() . "] metadata: " . $e->getMessage());
         }
     }
     return $results;
 }