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(); }
public function exportAction() { $this->_helper->layout->disableLayout(); $this->_helper->viewRenderer->setNoRender(); if (array_key_exists("type", $_GET)) { $type = $_GET['type']; } else { $type = 'xml'; } $ppl = new Default_Model_Researchers(); $ppl->filter = FilterParser::getPeople($this->_getParam("flt")); if ($type == "xml") { $ppl->refresh("xmlexport", false, $this->session->userid); } else { $ppl->refresh("csvexport", false, $this->session->userid); } $s = ''; foreach ($ppl->items as $item) { $s = $s . preg_replace("/[\n\r]/", '', $item) . "\n"; } header('Content-Description: File Transfer'); header('Content-Disposition: attachment; filename=ppl' . 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 '<researchers>'; echo $s; echo '</researchers>'; } else { echo '"Firstname","Lastname","Gender","Registered","Institution","Country","Role","Permalink","Software","Contacts"' . "\n"; echo $s; } }
/** * @overrides get() from RestResource */ public function get($extraFilter = null) { if (parent::get() !== false) { global $application; $isAdmin = $this->userIsAdmin(); $mapper = new Default_Model_ResearchersMapper(); $db = $application->getBootstrap()->getResource('db'); $flt = $this->getParam("flt"); $select = $mapper->getDbTable()->getAdapter()->select()->distinct()->from('researchers'); $from = ''; $where = ''; $orderby = ''; $limit = ''; $filter = FilterParser::getPeople($flt); if (is_array($filter->expr())) { $ex = implode(" ", $filter->expr()); } else { $ex = $filter->expr(); } $fltexp = $filter->expr(); if (!is_array($fltexp)) { $fltexp = array($fltexp); } foreach ($fltexp as $x) { getZendSelectParts($select, $from, $where, $orderby, $limit); if (!$isAdmin) { if (strpos($from, ' applications ') !== false && (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 (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); $rs = $db->query('SELECT * FROM ppl_logistics(?,?,?)', array($flt, $from, $where))->fetchAll(); if (count($rs) > 0) { $rs = $rs[0]; $x = $rs['ppl_logistics']; } else { $x = ''; } debug_log($from); debug_log($where); return new XMLFragmentRestResponse($x, $this); } else { return false; } }
public function pplindex($paging = true, $format = '') { if ($format == '') { $format = $this->_getParam("format"); } $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->pplFlt = null; } $fltstr = $this->getFltStr(); $ppl = new Default_Model_Researchers(); $this->session->pplFlt = $fltstr; $ppl->filter = FilterParser::getPeople($fltstr, $this->_getParam("fuzzySearch") == '1'); if ($this->_getParam("orderby") != '') { $orderby = $this->_getParam("orderby"); } else { $orderby = "firstname"; } if ($this->_getParam("orderbyOp") != '') { $orderbyop = $this->_getParam("orderbyOp"); } else { $orderbyop = "ASC"; } if ($orderby != '') { if ($orderby != "unsorted") { if ($orderby == "firstname") { $ppl->filter->orderBy(array("firstname " . $orderbyop, "lastname " . $orderbyop)); } elseif ($orderby == "lastname") { $ppl->filter->orderBy(array("lastname " . $orderbyop, "firstname " . $orderbyop)); } else { $ppl->filter->orderBy($orderby . " " . $orderbyop); } } $this->view->orderby = $orderby; $this->view->orderbyOp = $orderbyop; } if ($paging) { $ppl->filter->limit($length + 1); $ppl->filter->offset($offset); } $t1 = microtime(true); $total = $ppl->count(); $listType = $this->_getParam("details"); $ppl->refresh($format, '', $listType); $entries = $ppl->items; if ($format == '') { $this->cacheimages($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; include 'pplaccounting.php'; $t2 = microtime(true); $dt = $t2 - $t1; $this->view->searchTime = round($dt, 2); if ($this->_getParam("fuzzySearch") == '1') { $this->view->fuzzySearch = '1'; } return $ppl->items; }