Example #1
0
 public static function getNews($request)
 {
     $t = $request;
     if ($t->type == "app-entry") {
         $t->type = "app";
     }
     $t->filter = str_replace("”", '"', $t->filter);
     if (trim($t->filter) !== '') {
         if ($t->type === 'ppl') {
             $t->filter = FilterParser::normalizeFilter($t->filter, FilterParser::NORM_PPL, $err);
             $f = FilterParser::getPeople($t->filter);
         } else {
             if ($t->type === 'app') {
                 $t->filter = FilterParser::normalizeFilter($t->filter, FilterParser::NORM_APP, $err);
                 $f = FilterParser::getApplications($t->filter);
             }
         }
     }
     $news = new Default_Model_AggregateNews();
     if ($t->length != '') {
         $news->filter->limit($t->length);
     }
     if ($t->offset != '') {
         $news->filter->offset($t->offset);
     }
     $nf = new Default_Model_AggregateNewsFilter();
     if (count($t->action) > 0) {
         if ($t->type == "app" && in_array("update", $t->action) == true) {
             $t->action[] = "updaterel";
         }
         for ($i = 0; $i < count($t->action); $i += 1) {
             if (isset($a)) {
                 $a = $a->or($nf->action->equals(trim($t->action[$i])));
             } else {
                 $a = $nf->action->equals(trim($t->action[$i]));
             }
         }
         $news->filter = $news->filter->chain($nf, "AND");
     }
     if (trim($t->type) != '') {
         $nf->subjecttype->equals(trim($t->type));
         $news->filter = $news->filter->chain($nf, "AND");
     }
     $nf->timestamp->between(array($t->from, $t->to));
     $news->filter = $news->filter->chain($nf, "AND");
     if (isset($f)) {
         if (is_array($f->expr())) {
             $f->SetExpr("(" . implode(") AND (", $f->expr()) . ")");
         }
         if ($f->expr() != '') {
             $nf = $nf->chain($f, "AND");
         }
     }
     $news->filter = $news->filter->chain($nf, "AND");
     debug_log($news->filter->expr());
     $news->filter->orderBy('timestamp DESC');
     $news->refresh();
     return $news;
 }
Example #2
0
function validateFilterActionHelper($flt, $type, $ver = null)
{
    if (is_null($ver)) {
        $api = Zend_Registry::get("api");
        $ver = $api["latestVersion"];
    }
    $origFlt = $flt;
    $error = '';
    $stype = '';
    $flds = array();
    $flt = FilterParser::normalizeFilter($flt, $type, $error, $flds, $ver);
    switch ($type) {
        case FilterParser::NORM_APP:
            $stype = "application";
            break;
        case FilterParser::NORM_PPL:
            $stype = "person";
            break;
        case FilterParser::NORM_VOS:
            $stype = "vo";
            break;
        case FilterParser::NORM_DISSEMINATION:
            $stype = "dissemination";
            break;
        case FilterParser::NORM_SITE:
            $stype = "site";
            break;
    }
    $s = '<' . $stype . ':filter xmlns:filter="http://appdb.egi.eu/api/' . $ver . '/filter" xmlns:' . $stype . '="http://appdb.egi.eu/api/' . $ver . '/' . $stype . '">';
    if ($error != '') {
        $s .= '<filter:error>';
        $s .= base64_encode($error);
        $s .= '</filter:error>';
    }
    $s .= '<filter:originalForm>';
    $s .= base64_encode($origFlt);
    $s .= '</filter:originalForm>';
    $s .= '<filter:normalForm>';
    $s .= base64_encode($flt);
    $s .= '</filter:normalForm>';
    $ref = array();
    foreach ($flds as $f) {
        if ($f["value"] != "") {
            if (!isset($ref[$f["ref"]])) {
                $ref[$f["ref"]] = '<filter:field level="0" name="' . $f["ref"] . '">';
            }
            $ref[$f["ref"]] .= '<filter:field level="1" name="' . $f["field"] . '" ' . ($f["operator"] == '' ? '' : 'operator="' . htmlentities($f["operator"]) . '" ') . ($f["required"] == false ? '' : 'required="true" ') . ($f["negated"] == false ? '' : 'negated="true" ') . '>' . base64_encode($f["value"]) . '</filter:field>';
        }
    }
    foreach ($ref as $r) {
        $r .= '</filter:field>';
        $s .= $r;
    }
    $s .= '</' . $stype . ':filter>';
    return $s;
}