/**
  * Will return an array of 2:
  * 1. an object (usually string) representing the response
  * 2. a string representing the recommended content type header
  */
 public function renderDataInRequestedFormat($response_params, $response_type, $escape_text = false)
 {
     if ($this->cached_content) {
         return $this->cached_content;
     }
     $this->escape_text = $escape_text;
     $this->response_type = $response_type;
     if ($this->response_type == self::RESPONSE_TYPE_XML) {
         $content_type = "text/xml; charset=utf-8";
         $response = '<?xml version="1.0" encoding="ISO-8859-1"?><xml>' . $this->array2xml($response_params) . '</xml>';
     } elseif ($this->response_type == self::RESPONSE_TYPE_PHP) {
         $content_type = "text/html; charset=utf-8";
         $response = $this->array2phpserialize($response_params);
     } elseif ($this->response_type == self::RESPONSE_TYPE_PHP_ARRAY || $this->response_type == self::RESPONSE_TYPE_PHP_OBJECT) {
         $content_type = "text/html; charset=utf-8";
         $response = objectWrapperBase::toArrayImpl($response_params);
     } elseif ($this->response_type == self::RESPONSE_TYPE_RAW) {
         $content_type = "text/html; charset=utf-8";
         $response = $response_params;
     } elseif ($this->response_type == self::RESPONSE_TYPE_HTML) {
         $content_type = "text/html; charset=utf-8";
         $response = $response_params;
     } elseif ($this->response_type == self::RESPONSE_TYPE_MRSS) {
         $content_type = "text/xml; charset=utf-8";
         //$response =  kalturaRssRenderer::renderMrssFeed( objectWrapperBase::toArrayImpl ( $response_params  ) );
         $mrss_renderer = new kalturaRssRenderer(kalturaRssRenderer::TYPE_YAHOO);
         $response = $mrss_renderer->renderMrssFeed($response_params);
     } else {
         $content_type = "text/html; charset=utf-8";
         $response = self::json_serialize($response_params);
     }
     $res = array($response, $content_type);
     // we reached here and there is a $this->cachekey - store in the cahce for the next time
     if ($this->cachekey) {
         if (!$this->my_cache) {
             $this->my_cache = new myCache("kwr", $this->cachekey->expiry);
         }
         $this->cached_content = $this->my_cache->put($response_type . "_" . $this->cachekey->toString(), $res);
         // the cache is per $response_type
     }
     return $res;
 }
Example #2
0
 /**
  * This is not a regular service.
  * Because the caller is not a partner but rather a 3rd party provider that wishs to query our system,
  * The security is slightly different and the respons is in the format of mRss which is related to entries only.
  */
 public function executeImpl($partner_id, $subp_id, $puser_id, $partner_prefix, $puser_kuser)
 {
     myDbHelper::$use_alternative_con = myDbHelper::DB_HELPER_CONN_PROPEL2;
     header("Content-Type: text/xml; charset=utf-8");
     // TODO -  verify permissions for viewing lists
     // validate the ks of the caller
     $code = $this->getP("code");
     if ($code != 'fsalh5423a43g') {
         return "<xml></xml>";
         die;
     }
     $detailed = $this->getP("detailed", false);
     $limit = $this->getP("page_size", 100);
     $limit = $this->maxPageSize($limit);
     $operated_partner_id = $this->getP("operated_partner_id");
     $page = $this->getP("page", 1);
     $offset = ($page - 1) * $limit;
     //		kuserPeer::setUseCriteriaFilter( false );
     if ($operated_partner_id) {
         entryPeer::setUseCriteriaFilter(true);
     } else {
         entryPeer::setUseCriteriaFilter(false);
     }
     // FOR now - display only 2 partners
     // 2460 - dorimedia
     $partner_list = array(593, 2460);
     $c = KalturaCriteria::create(entryPeer::OM_CLASS);
     $c->addAnd(entryPeer::STATUS, entryStatus::READY);
     // for now display only entries that are part of the kaltura network
     //		$c->addAnd ( entryPeer::DISPLAY_IN_SEARCH , mySearchUtils::DISPLAY_IN_SEARCH_KALTURA_NETWORK );
     // filter
     $filter = new entryFilter();
     $fields_set = $filter->fillObjectFromRequest($this->getInputParams(), "filter_", null);
     $this->setExtraFilters($filter);
     $offset = ($page - 1) * $limit;
     $c->setLimit($limit);
     if ($offset > 0) {
         $c->setOffset($offset);
     }
     $filter->attachToCriteria($c);
     //if ($order_by != -1) entryPeer::setOrder( $c , $order_by );
     $c->addAnd(entryPeer::PARTNER_ID, $partner_list, Criteria::IN);
     $start_1 = microtime(true);
     if ($detailed) {
         // for some entry types - there are no kshow or kusers - don't join even when detailed
         if ($this->joinOnDetailed()) {
             $list = entryPeer::doSelectJoinAll($c);
         } else {
             $list = entryPeer::doSelect($c);
         }
         $level = objectWrapperBase::DETAIL_LEVEL_DETAILED;
     } else {
         $list = entryPeer::doSelect($c);
         $level = objectWrapperBase::DETAIL_LEVEL_REGULAR;
     }
     $count = $c->getRecordsCount();
     $end_1 = microtime(true);
     KalturaLog::log("benchmark db: [" . ($end_1 - $start_1) . "]");
     $result_count = count($list);
     $start_2 = microtime(true);
     $mrss_renderer = new kalturaRssRenderer(kalturaRssRenderer::TYPE_TABOOLA);
     $str = $mrss_renderer->renderMrssFeed($list, $page, $result_count);
     $end_2 = microtime(true);
     KalturaLog::log("benchmark render: [" . ($end_2 - $start_2) . "]");
     echo $str;
     // don't return to the rest of the implementation - the base class manipulates the content.
     die;
 }