public function getSubscribers($obj = null, $action = 127, $delivery = 15) { if (is_null($obj)) { return array(); } $cls = get_class($obj); switch ($cls) { case "Default_Model_Researcher": $type = 'app'; break; case "Default_Model_Applciation": $type = 'ppl'; break; default: return array(); } $act = array(); if (NewsEventType::has($action, NewsEventType::E_INSERT)) { $act[] = "insert"; } if (NewsEventType::has($action, NewsEventType::E_UPDATE)) { $act[] = "update"; } if (NewsEventType::has($action, NewsEventType::E_INSERT_COMMENT)) { $act[] = "insertcmm"; } if (NewsEventType::has($action, NewsEventType::E_INSERT_CONTACT)) { $act[] = "insertcnt"; } $subs = new Default_Model_MailSubscriptions(); $subs->filter->type->equals($type)->and($subs->filter->events->hasbit($event))->and($subd->filter->delivery->hasbit($delivery)); if ($subs->count() == 0) { return array(); } $subs = $subs->items; foreach ($subs as $sub) { switch ($type) { case "app-entry": $f = FilterParser::getApplications($sub->flt); break; case "app": $f = FilterParser::getApplications($sub->flt); break; case "ppl": $f = FilterParser::getPeople($sub->flt); break; } $news = new Default_Model_AggregateNews(); $nf = new Default_Model_AggregateNewsFilter(); if (count($act) > 0) { for ($i = 0; $i < count($act); $i += 1) { if (isset($a)) { $a = $a->or($nf->action->equals(trim($act[$i]))); } else { $a = $nf->action->equals(trim($act[$i])); } } $news->filter = $news->filter->chain($nf, "AND"); } $nf->subjecttype->equals(trim($type)); $news->filter = $news->filter->chain($nf, "AND"); $news->filter->orderBy('timestamp DESC'); $news->refresh(); } return array(); }
/** * @overrides get() from RestResource */ public function get($extraFilter = null) { if (parent::get() !== false) { global $application; $isAdmin = $this->userIsAdmin(); $mapper = new Default_Model_ApplicationsMapper(); $db = $application->getBootstrap()->getResource('db'); $flt = $this->getParam("flt"); $select = $mapper->getDbTable()->getAdapter()->select()->distinct()->from('applications'); $from = ''; $where = ''; $orderby = ''; $limit = ''; $filter = FilterParser::getApplications($flt); if (is_array($filter->expr())) { $ex = implode(" ", $filter->expr()); } else { $ex = $filter->expr(); } if (strpos($ex, 'applications.moderated) IS FALSE') === false || strpos($ex, 'applications.deleted) IS FALSE') === false) { $f = new Default_Model_ApplicationsFilter(); $f->moderated->equals(false)->and($f->deleted->equals(false)); $filter->chain($f, "AND"); } if (is_array($filter->expr())) { foreach ($filter->expr() as $x) { getZendSelectParts($select, $from, $where, $orderby, $limit); if (strpos($from, ' researchers ') !== false && strpos($ex, 'researchers.deleted) IS FALSE') === false) { $f = new Default_Model_ResearchersFilter(); $f->deleted->equals(false); $filter->chain($f, "AND"); } if (strpos($from, ' vos ') !== false && strpos($ex, 'vos.deleted) IS FALSE') === false) { $f = new Default_Model_VOsFilter(); $f->deleted->equals(false); $filter->chain($f, "AND"); } } } else { getZendSelectParts($select, $from, $where, $orderby, $limit); if (strpos($from, ' researchers ') !== false && strpos($ex, 'researchers.deleted) IS FALSE') === false) { $f = new Default_Model_ResearchersFilter(); $f->deleted->equals(false); $filter->chain($f, "AND"); } if (strpos($from, ' vos ') !== false && strpos($ex, 'vos.deleted) IS FALSE') === false) { $f = new Default_Model_VOsFilter(); $f->deleted->equals(false); $filter->chain($f, "AND"); } } if (!is_null($extraFilter)) { $filter->chain($extraFilter, "AND"); } $mapper->joins($select, $filter); if (is_array($filter->expr())) { $from = array(); $where = array(); foreach ($filter->expr() as $x) { $s = clone $select; $s->where($x); getZendSelectParts($s, $f, $w, $orderby, $limit); $from[] = $f; $where[] = $w; } $flt = str_replace("''", "\\'", php_to_pg_array($filter->fltstr, false)); $from = str_replace("''", "\\'", php_to_pg_array($from, false)); $where = str_replace("''", "\\'", php_to_pg_array($where, false)); } else { $select->where($filter->expr()); getZendSelectParts($select, $from, $where, $orderby, $limit); } $db->setFetchMode(Zend_Db::FETCH_BOTH); debug_log($db->quoteInto('SELECT * FROM app_logistics(?,?,?)', array($flt, $from, $where))); $rs = $db->query('SELECT * FROM app_logistics(?,?,?)', array($flt, $from, $where))->fetchAll(); if (count($rs) > 0) { $rs = $rs[0]; $x = $rs['app_logistics']; } else { $x = ''; } return new XMLFragmentRestResponse($x, $this); } else { return false; } }
public function exportAction() { $this->_helper->layout->disableLayout(); $this->_helper->viewRenderer->setNoRender(); if (array_key_exists("type", $_GET)) { $type = $_GET['type']; } else { $type = 'xml'; } $apps = new Default_Model_Applications(); $apps->filter = FilterParser::getApplications($this->_getParam("flt")); if ($type === "xml") { $apps->refresh("xmlexport"); } else { $apps->refresh("csvexport"); } $s = ''; foreach ($apps->items as $item) { $s = $s . preg_replace("/[\n\r]/", '', $item) . "\n"; } header('Content-Description: File Transfer'); header('Content-Disposition: attachment; filename=apps' . time() . '.' . $type); header('Content-type: text/' . ($type === "xml" ? "xml" : "x-csv")); header("Pragma: no-cache"); header("Expires: 0"); header('Content-Length: ' . strlen($s)); if ($type === "xml") { echo '<applications>' . $s . '</applications>'; } else { echo '"Name","Description","Abstract","Date Added","Added By","Owner","Status","Categories","Middlewares","VOs","Disciplines","Countries","URLs","Researchers"' . "\n"; echo $s; } }
private function appindex($mode, $paging = true, $format = '') { if ($format == '') { $format = $this->_getParam("format"); } if ($format == "json") { $format = "xml"; } if ($this->session->viewMode === null) { $this->session->viewMode = 1; } $this->view->viewMode = $this->session->viewMode; $this->_helper->layout->disableLayout(); $offset = $this->_getParam('ofs'); $length = $this->_getParam('len'); if ($length == "-1") { $paging = false; } if ($offset === null) { $offset = 0; } if ($length === null) { $length = 23; } if (array_key_exists("filter", $_GET)) { $this->session->appFlt = null; } $fltstr = $this->getFltStr(); $apps = new Default_Model_Applications(); $this->session->appFlt = $fltstr; $apps->filter = FilterParser::getApplications($fltstr, $this->_getParam("fuzzySearch") == '1'); if ($mode == 1) { $f = new Default_Model_ApplicationsFilter(); $f->addedby->equals($this->session->userid); $apps->filter->chain($f, "AND"); } if ($mode == 2) { $f = new Default_Model_ResearchersFilter(); $f->id->equals($this->session->userid); $apps->filter->chain($f, "AND"); } if ($mode == 3) { $f = new Default_Model_AppBookmarksFilter(); $f->researcherid->equals($this->session->userid); $apps->filter->chain($f, "AND"); } if ($mode == 4) { $f = new Default_Model_PermissionsFilter(); $f->actor->equals($this->session->userguid)->and($f->actionid->between(array(3, 17))->or($f->actionid->equals(20))); $apps->filter->chain($f, "AND"); } if ($mode == 5) { $f = new Default_Model_ApplicationsFilter(); $f->moderated->equals(true)->and($f->deleted->equals(false)); $apps->filter->chain($f, "AND"); } if ($mode == 6) { $f = new Default_Model_ApplicationsFilter(); $f->deleted->equals(true); $apps->filter->chain($f, "AND"); } if ($this->_getParam("orderby") != '') { $orderby = $this->_getParam("orderby"); } else { $orderby = "name"; } if ($this->_getParam("orderbyOp") != '') { $orderbyop = $this->_getParam("orderbyOp"); } else { $orderbyop = "ASC"; } if ($orderby != '') { if ($orderby != "unsorted") { $apps->filter->orderBy($orderby . " " . $orderbyop); } $this->view->orderby = $orderby; $this->view->orderbyOp = $orderbyop; } if ($paging) { $apps->filter->limit($length + 1); $apps->filter->offset($offset); } $t1 = microtime(true); $total = $apps->count(); $apps->refresh($format, $this->_getParam('details')); $entries = $apps->items; if ($format == '') { $this->cachelogos($entries); } if ($paging) { $this->view->offset = $offset; $this->view->length = $length; $this->view->pageCount = ceil($total / ($length + 1)); $this->view->currentPage = floor($offset / ($length + 1)); } else { $this->view->offset = 0; $this->view->length = $total; if ($total != 0) { $this->view->pageCount = ceil($total / $total); $this->view->currentPage = floor($offset / $total); } else { $this->view->pageCount = 1; $this->view->currentPage = 1; } } $this->view->entries = $entries; $this->view->total = $total; $this->view->gid = null; $t2 = microtime(true); $dt = $t2 - $t1; $this->view->searchTime = round($dt, 2); if ($this->_getParam("fuzzySearch") == '1') { $this->view->fuzzySearch = '1'; } return $apps->items; }