dmBridge PHP API
DMAPICommentController.php
00001 <?php
00002 #
00003 # dmBridge: a data access framework for CONTENTdm(R)
00004 #
00005 # Copyright © 2009, 2010, 2011 Board of Regents of the Nevada System of Higher
00006 # Education, on behalf of the University of Nevada, Las Vegas
00007 #
00008 
00013 class DMAPICommentController extends DMAbstractController {
00014 
00020    public function index() {
00021       $uri = DMHTTPRequest::getCurrent()->getURI();
00022       $page = abs((int) substr($uri->getQueryValue("page"), 0, 7));
00023       $page = ($page < 1) ? 1 : $page;
00024 
00025       $rpp = abs((int) substr($uri->getQueryValue("rpp"), 0, 4));
00026       $rpp = ($rpp > 100) ? 100 : $rpp;
00027       $rpp = ($rpp == 1) ? 50 : ($rpp < 10) ? 10 : $rpp;
00028 
00029       $term = substr($uri->getQueryValue("term"), 0, 100);
00030       $collections = explode(",", $uri->getQueryValue("collections"));
00031       $objects = explode(",", $uri->getQueryValue("objects"));
00032 
00033       $ds = DMDataStoreFactory::getDataStore();
00034       $cq = new DMCommentQuery($ds);
00035       $cq->setApproved(1);
00036       $cq->setPage($page);
00037       $cq->setNumResultsPerPage($rpp);
00038       if ($term) {
00039          $predicate = new DMQueryPredicate();
00040          $predicate->setString($term);
00041          $cq->setPredicates(array($predicate));
00042       }
00043       foreach ($collections as $alias) {
00044          if ($alias) {
00045             $col = DMCollectionFactory::getCollection(
00046                   DMCollection::getSanitizedAlias($alias));
00047             $cq->addCollection($col);
00048          }
00049       }
00050       foreach ($objects as $aliasptr) {
00051          $split = explode("/", $aliasptr);
00052          if (count($split) == 3 && $split[1] && $split[2]) {
00053             $col = DMCollectionFactory::getCollection(
00054                   DMCollection::getSanitizedAlias($split[1]));
00055             $obj = DMObjectFactory::getObject($col, (int) $split[2]);
00056             $cq->addObject($obj);
00057          }
00058       }
00059 
00060       $results = $cq->getSearchResults();
00061       $total = $cq->getNumResults();
00062 
00063       $response = new DMHTTPResponse();
00064       $rep = DMHTTPResponseFactory::getRepresentation();
00065       $trans = DMHTTPResponseFactory::getTransformer();
00066       $rep->setBody($trans->transformComments($results, $page, $rpp, $total));
00067       $response->setRepresentation($rep);
00068       $response->send();
00069       die;
00070    }
00071 
00075    public function view($id) {
00076       $ds = DMDataStoreFactory::getDataStore();
00077       $comment = $ds->loadComment($id);
00078       if (!$comment->isApproved()) {
00079          throw new DMUnavailableModelException("Access denied.", 401);
00080       }
00081 
00082       $response = new DMHTTPResponse();
00083       $rep = DMHTTPResponseFactory::getRepresentation();
00084       $trans = DMHTTPResponseFactory::getTransformer();
00085       $rep->setBody($trans->transformComment($comment));
00086       $response->setRepresentation($rep);
00087       $response->send();
00088       die;
00089    }
00090 
00091 }
 All Data Structures Functions Variables