コード例 #1
0
 public function save(Default_Model_UserAccount $value)
 {
     $rec = $value->IDPTrace;
     $value->IDPTrace = php_to_pg_array($value->IDPTrace, true);
     parent::save($value);
     $value->IDPTrace = $rec;
 }
コード例 #2
0
 public function save(Default_Model_DisseminationEntry $value)
 {
     $rec = $value->recipients;
     $value->recipients = php_to_pg_array($value->recipients, true);
     parent::save($value);
     $value->recipients = $rec;
 }
コード例 #3
0
ファイル: restapi_vo.php プロジェクト: IASA-GR/appdb-core
 /**
  * @overrides get() from RestResource
  */
 public function get($extraFilter = null)
 {
     if (parent::get() !== false) {
         global $application;
         $isAdmin = $this->userIsAdmin();
         $mapper = new Default_Model_VOsMapper();
         $db = $application->getBootstrap()->getResource('db');
         $flt = $this->getParam("flt");
         $select = $mapper->getDbTable()->getAdapter()->select()->distinct()->from('vos');
         $from = '';
         $where = '';
         $orderby = '';
         $limit = '';
         $filter = FilterParser::getVOs($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($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($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 vo_logistics(?,?,?)', array($flt, $from, $where))->fetchAll();
         if (count($rs) > 0) {
             $rs = $rs[0];
             $x = $rs['vo_logistics'];
         } else {
             $x = '';
         }
         return new XMLFragmentRestResponse($x, $this);
     } else {
         return false;
     }
 }
コード例 #4
0
ファイル: harvest.php プロジェクト: IASA-GR/appdb-core
 private static function doSearchLocalData($archiveid, $keywords = array(), $keyfields = array(), $limit = 50)
 {
     $q = "SELECT harvest.search_local_records_to_xml((?)::TEXT[],(?)::TEXT[],?,?)";
     $stmt = db()->query($q, array(php_to_pg_array($keywords, false), php_to_pg_array($keyfields, false), $archiveid, $limit));
     $rows = $stmt->fetchAll();
     $res = array();
     if (count($rows) > 0) {
         foreach ($rows as $r) {
             $res[] = $r["search_local_records_to_xml"];
         }
     }
     return $res;
 }
コード例 #5
0
 public function fetchAll($filter = null, $format = '', $userid = '', $xmldetailed = false)
 {
     $select = $this->getDbTable()->select();
     $executor = $this->getDbTable();
     if ($filter !== null) {
         $orderby = $filter->orderBy;
         if (is_array($orderby)) {
             $orderby = end($orderby);
         }
     } else {
         $orderby = null;
     }
     if ($filter !== null && $filter->expr() != '') {
         $select = $this->getDbTable()->getAdapter()->select()->distinct()->from('researchers');
         $this->joins($select, $filter);
         if (!is_array($filter->expr())) {
             $select->where($filter->expr());
         }
         $executor = $this->getDbTable()->getAdapter();
         $executor->setFetchMode(Zend_Db::FETCH_OBJ);
     }
     if ($filter !== null) {
         $select->limit($filter->limit, $filter->offset);
     }
     if ($filter !== null) {
         $inv = false;
         if (substr($orderby, 0, 16) === "researchers.rank") {
             //				$orderby = substr($orderby,12);
             //				if ( strpos($_orderby," DESC") === false ) {
             //					$orderby = str_replace(" ASC"," DESC", $orderby);
             //				} else {
             //					$orderby = str_replace(" DESC"," ASC", $orderby);
             //					$inv = true;
             //				}
             //				$orderby = array($orderby, 'name'.($inv?' DESC':''));
             /** 
              * NOTE: Ordering by rank is handled by the database, so trust DB order
              */
             $orderby = "rank DESC, name ASC";
         }
         $select->order($orderby);
         if (is_array($orderby)) {
             $_orderby = implode(",", $orderby);
         } else {
             $_orderby = $orderby;
         }
     }
     if (str_replace('export', '', $format) === 'xml' || str_replace('export', '', $format) === 'csv') {
         $this->getDbTable()->getAdapter()->setFetchMode(Zend_Db::FETCH_OBJ);
         if ($userid != '') {
             $userid = ", {$userid}";
         } else {
             $userid = '';
         }
         $simpleList = ", ''";
         if ($xmldetailed === "-1") {
             $xmldetailed = false;
             $simpleList = ", 'simpleindex'";
         }
         if ($format === 'xml') {
             $func = "researcher_to_xml";
         } else {
             $func = "export_researcher";
             $simpleList = ',\'' . str_replace('export', '', $format) . '\'';
         }
         if ($xmldetailed) {
             $func = $func . "_ext";
         }
         if (is_array($filter->expr())) {
             $where = array();
             $from = array();
             foreach ($filter->expr() as $x) {
                 $sss = clone $select;
                 $sss->where($x);
                 getZendSelectParts($sss, $f, $w, $orderby, $limit);
                 $f = fixuZenduBuguru($f);
                 $where[] = $w;
                 $from[] = $f;
             }
         } else {
             getZendSelectParts($select, $from, $where, $orderby, $limit);
             $from = fixuZenduBuguru($from);
         }
         if (isset($_orderby)) {
             $orderby = 'ORDER BY ' . $_orderby;
         }
         # TODO: FIX NULLS FIRST/LAST bypass
         if ($from == '') {
             $from = 'FROM researchers';
         }
         if ($func == "researcher_to_xml") {
             //				debug_log(var_export($filter->fltstr,true));
             //				debug_log(var_export($from, true));
             //				debug_log(var_export($where,true));
             //				debug_log($orderby);
             if (is_array($filter->expr())) {
                 noDBSeqScan(db());
                 $resultSet = db()->query("SELECT " . $func . "(array_agg(id {$orderby})) as researcher FROM filterppl((?)::text[],(?)::text[],(?)::text[]) AS researchers {$limit}", array(php_to_pg_array($filter->fltstr, false), php_to_pg_array($from, false), str_replace("''", "\\'", php_to_pg_array($where, false))))->fetchAll();
             } else {
                 noDBSeqScan(db());
                 $resultSet = db()->query("SELECT " . $func . "(array_agg(id {$orderby})" . $simpleList . $userid . ") AS researcher FROM filterppl(?,?,?) AS researchers {$limit}", array($filter->fltstr, $from, $where))->fetchAll();
             }
         } else {
             $select = fixuZenduBuguru("" . $select);
             noDBSeqScan($this->getDbTable()->getAdapter());
             $resultSet = $this->getDbTable()->getAdapter()->query("SELECT " . $func . "(id" . $simpleList . $userid . ") as researcher FROM (" . $select . ") AS t;")->fetchAll();
         }
     } else {
         $select = fixuZenduBuguru("" . $select);
         noDBSeqScan($executor);
         $resultSet = $executor->fetchAll($select);
     }
     $entries = array();
     foreach ($resultSet as $row) {
         if (str_replace('export', '', $format) === 'xml' || str_replace('export', '', $format) === 'csv') {
             $entry = $row->researcher;
         } else {
             $entry = new Default_Model_Researcher();
             $this->populate($entry, $row);
         }
         $entries[] = $entry;
     }
     return $entries;
 }
コード例 #6
0
ファイル: DatasetsMapper.php プロジェクト: IASA-GR/appdb-core
 public function save(Default_Model_Dataset $value)
 {
     $oldTags = $value->tags;
     if (!is_array($value->tags) || count($value->tags) == 0 || trim($value->tags[0]) == "") {
         $value->setTags("NULL");
     } else {
         $value->setTags(php_to_pg_array($value->tags));
     }
     //		parent::save($value);
     global $application;
     $data = array();
     if (!isnull($value->getId())) {
         $data['id'] = $value->getId();
     }
     if (!isnull($value->getName())) {
         $data['name'] = $value->getName();
     }
     if (!isnull($value->getCategory())) {
         $data['category'] = $value->getCategory();
     }
     if (!isnull($value->getDescription())) {
         $data['description'] = $value->getDescription();
     }
     if (!isnull($value->getHomepage())) {
         $data['homepage'] = $value->getHomepage();
     }
     if (!isnull($value->getElixirURL())) {
         $data['elixir_url'] = $value->getElixirURL();
     }
     if (!isnull($value->getDisciplineID())) {
         $data['disciplineid'] = $value->getDisciplineID();
     }
     if (!isnull($value->getAddedByID())) {
         $data['addedby'] = $value->getAddedByID();
     }
     if (!isnull($value->getAddedon())) {
         $data['addedon'] = $value->getAddedon();
     }
     if (!isnull($value->getTags())) {
         $data['tags'] = $value->getTags();
     }
     if (!isnull($value->getGuID())) {
         $data['guid'] = $value->getGuID();
     }
     if (!isnull($value->getParentID())) {
         $data['parentid'] = $value->getParentID();
     }
     if ($value->getParentID() == "0") {
         $data['parentid'] = null;
     }
     if (trim($value->getHomepage()) === "") {
         $data['homepage'] = null;
     }
     if (trim($value->getElixirURL()) === "") {
         $data['elixir_url'] = null;
     }
     if (trim($value->getDescription()) === "") {
         $data['description'] = null;
     }
     if ($value->getTags() === "NULL") {
         $data['tags'] = null;
     }
     $q1 = 'id = ?';
     $q2 = $value->id;
     if (null === ($id = $value->id)) {
         unset($data['id']);
         $value->id = $this->getDbTable()->insert($data);
     } else {
         $s = $this->getDbTable()->getAdapter()->quoteInto($q1, $q2);
         $this->getDbTable()->update($data, $s);
     }
     $value->setTags($oldTags);
 }
コード例 #7
0
ファイル: VoController.php プロジェクト: IASA-GR/appdb-core
 public function syncEBIVOMembers()
 {
     db()->setFetchMode(Zend_Db::FETCH_OBJ);
     $rs = db()->query("SELECT id, name, enabled, members_url FROM vo_sources WHERE name = 'EBI-Perun'")->fetchAll();
     $enabled = false;
     $uri = null;
     if (count($rs) > 0) {
         $rs = $rs[0];
         if (filter_var($rs->enabled, FILTER_VALIDATE_BOOLEAN) === true) {
             $enabled = true;
         }
         $uri = $rs->members_url;
     }
     if (!$enabled) {
         error_log("EBI-Perun VO source is disabled; will not sync VO members");
         ExternalDataNotification::sendNotification('VO::syncEBIVOMembers', "EBI-Perun VO source is disabled; will not sync VO members", ExternalDataNotification::MESSAGE_TYPE_ERROR);
         return false;
     }
     $inTransaction = false;
     try {
         if (APPLICATION_ENV == "production") {
             $ch = curl_init();
             if (is_null($uri)) {
                 $uri = "https://perun.cesnet.cz/external/appdb/users";
             }
             curl_setopt($ch, CURLOPT_URL, $uri);
             curl_setopt($ch, CURLOPT_HEADER, false);
             curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
             curl_setopt($ch, 181, 1 | 2);
             curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
             curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
             curl_setopt($ch, CURLOPT_SSLCERT, APPLICATION_PATH . '/../bin/sec/usercert.pem');
             curl_setopt($ch, CURLOPT_SSLKEY, APPLICATION_PATH . '/../bin/sec/userkey.pem');
             curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
             $headers = apache_request_headers();
             curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
             $xml = curl_exec($ch);
             if ($xml === false) {
                 $err = var_export(curl_error($ch), true);
                 error_log("error in syncEBIVOMembers: " . $err);
                 ExternalDataNotification::sendNotification('VO::syncEBIVOMembers', 'Could not sync VO members from EBI-Perun. Error was:\\n\\n' . $err);
                 return;
             } else {
                 $xml = "<results>{$xml}</results>";
             }
             @curl_close($ch);
             @exec("rm " . APPLICATION_PATH . "/../cache/ebivo_users.xml.old");
             @exec("mv " . APPLICATION_PATH . "/../cache/egivo_users.xml " . APPLICATION_PATH . "/../cache/ebivo_users.xml.old");
             $f = fopen(APPLICATION_PATH . "/../cache/ebivo_users.xml", "w");
             fwrite($f, $xml);
             fclose($f);
         }
         if (@md5_file(APPLICATION_PATH . "/../cache/ebivo_users.xml") !== @md5_file(APPLICATION_PATH . "/../cache/ebivo_users.xml.old")) {
             $xmldata = file_get_contents(APPLICATION_PATH . "/../cache/ebivo_users.xml");
             if (mb_detect_encoding($xmldata, "UTF-8", true) === false) {
                 $xmldata = recode_string("iso8859-1..utf8", $xmldata);
             }
             $xml = new SimpleXMLElement($xmldata);
             $rows = $xml->xpath("//result/row");
             if (count($rows) > 0) {
                 error_log("Sync'ing EBI VO members...");
                 db()->beginTransaction();
                 $inTransaction = true;
                 db()->query("ALTER TABLE perun.vo_members DISABLE TRIGGER tr_perun_vo_members_99_refresh_permissions;");
                 db()->query("DELETE FROM perun.vo_members;");
                 foreach ($rows as $row) {
                     $lastup = trim($row->last_update);
                     $firstup = trim($row->first_update);
                     if ($lastup == "") {
                         $lastup = null;
                     }
                     if ($firstup == "") {
                         $firstup = null;
                     }
                     $xdns = $row->dn;
                     $dns = array();
                     $cas = array();
                     foreach ($xdns as $xdn) {
                         $dnatt = $xdn->attributes();
                         $dns[] = str_replace("'", '’', trim(strval($xdn)));
                         $cas[] = trim(strval($dnatt["ca"]));
                     }
                     $dns = php_to_pg_array($dns, false);
                     $cas = php_to_pg_array($cas, false);
                     if ($dns === '{}') {
                         $dns = null;
                     }
                     if ($cas === '{}') {
                         $cas = null;
                     }
                     error_log("dn: " . var_export($dns, true));
                     error_log("ca: " . var_export($cas, true));
                     $xeppns = $row->eppn;
                     $eppns = array();
                     foreach ($xeppns as $xeppn) {
                         $eppns[] = strval($xeppn);
                     }
                     $eppns = php_to_pg_array($eppns, false);
                     if ($eppns === '{}') {
                         $eppns = null;
                     }
                     db()->query("INSERT INTO perun.vo_members (uservo, certdn, ca, vo, last_update, first_update, sso, eppn) VALUES (?,(?)::text[],(?)::text[],?,?,?,?,(?)::text[]);", array(str_replace("'", '’', trim($row->uservo)), $dns, $cas, trim($row->vo), $lastup, $firstup, trim($row->sso), $eppns));
                 }
                 db()->commit();
                 db()->query("ALTER TABLE perun.vo_members ENABLE TRIGGER tr_perun_vo_members_99_refresh_permissions;");
                 db()->query("SELECT request_permissions_refresh();");
                 db()->query("UPDATE config SET data = NOW()::text WHERE var = 'ebi_vo_members_synced'");
                 error_log("EBI VO members sync'ed");
             } else {
                 ExternalDataNotification::sendNotification('VO::syncEBIVOMembers', 'Could not sync VO members from EBI-Perun. Probably got currupt or empty data');
             }
         } else {
             error_log("Sync EBI VO members: nothing to do (MD5 unchanged)");
             db()->query("UPDATE config SET data = NOW()::text WHERE var = 'ebi_vo_members_synced'");
         }
     } catch (Exception $e) {
         if ($inTransaction) {
             $db = db();
             @$db->rollBack();
         }
         db()->query("ALTER TABLE perun.vo_members ENABLE TRIGGER tr_perun_vo_members_99_refresh_permissions;");
         db()->query("SELECT request_permissions_refresh();");
         error_log("error in syncEBIVOMembers: {$e}");
         ExternalDataNotification::sendNotification('VO::syncEBIVOMembers', 'Could not sync VO members from EBI-Perun. Error was:\\n\\n' . $e->getMessage());
     }
 }
コード例 #8
0
 public function fetchAll($filter = null, $format = '', $xmldetailed = false)
 {
     $select = $this->getDbTable()->select()->from('applications');
     $select->columns('applications.keywords');
     $executor = $this->getDbTable();
     if ($filter !== null) {
         $orderby = $filter->orderBy;
         if (is_array($orderby)) {
             $orderby = end($orderby);
         }
     } else {
         $orderby = null;
     }
     if ($filter !== null && $filter->expr() != '' || substr($orderby, 0, 27) === "applications.app_popularity") {
         $select = $this->getDbTable()->getAdapter()->select()->distinct()->from('applications');
         $select->columns('applications.keywords');
         if (substr($orderby, 0, 27) === "applications.app_popularity") {
             $select->columns('app_popularity(applications.id)');
         }
         if ($filter !== null) {
             if ($filter->expr() != '') {
                 $this->joins($select, $filter);
                 if (!is_array($filter->expr())) {
                     $select->where($filter->expr());
                 }
                 $executor = $this->getDbTable()->getAdapter();
                 $executor->setFetchMode(Zend_Db::FETCH_OBJ);
             }
         }
     }
     if ($filter !== null) {
         $select->limit($filter->limit, $filter->offset);
     }
     if ($filter !== null) {
         if (substr($orderby, 0, 17) === "applications.rank") {
             //				$orderby = substr($orderby,13);
             //				if ( strpos($orderby," DESC") !== false ) {
             //					$orderby = str_replace(" DESC"," DESC NULLS LAST", $orderby);
             //				} else {
             //					$orderby = str_replace(" ASC"," ASC NULLS FIRST", $orderby);
             //				}
             //				$orderby = array($orderby, "name");
             /**
              * NOTE: Ordering by rank is handled by the database, so trust DB order
              */
             $orderby = "applications.rank DESC, applications.name ASC";
         } elseif (substr($orderby, 0, 27) === "applications.app_popularity") {
             $orderby = substr($orderby, 13);
             if (strpos($orderby, " DESC") !== false) {
                 $orderby = str_replace(" DESC", " DESC NULLS LAST", $orderby);
             } else {
                 $orderby = str_replace(" ASC", " ASC NULLS FIRST", $orderby);
             }
             $orderby = array($orderby, "applications.name");
         } elseif (substr($orderby, 0, 19) === 'applications.rating') {
             if (strpos($orderby, " DESC") !== false) {
                 $orderby = str_replace(" DESC", " DESC NULLS LAST", $orderby);
             } else {
                 $orderby = str_replace(" ASC", " ASC NULLS FIRST", $orderby);
             }
             $orderby = array($orderby, "applications.ratingcount DESC", "applications.name");
         } elseif (substr($orderby, 0, 21) === 'applications.hitcount') {
             if (strpos($orderby, " DESC") !== false) {
                 $orderby = str_replace(" DESC", " DESC NULLS LAST", $orderby);
             } else {
                 $orderby = str_replace(" ASC", " ASC NULLS FIRST", $orderby);
             }
             //				$orderby = str_replace("applications.hitcount","hitcount",$orderby);
             $orderby = array($orderby, "applications.name");
         }
         /** freshness app order HACK start **/
         $orderby = str_replace("applications.lastupdated", "CASE WHEN applications.id IN (SELECT appid FROM app_order_hack) THEN '2000-01-01 00:00:00'::timestamp ELSE applications.lastupdated END", $orderby);
         $orderby = str_replace("applications.dateadded", "CASE WHEN applications.id IN (SELECT appid FROM app_order_hack) THEN '2000-01-01 00:00:00'::timestamp ELSE applications.dateadded END", $orderby);
         /** freshness app order HACK end **/
         $select->order($orderby);
         if (is_array($orderby)) {
             $_orderby = implode(",", $orderby);
         } else {
             $_orderby = $orderby;
         }
     }
     if (str_replace('export', '', $format) === 'xml' || str_replace('export', '', $format) === 'csv') {
         $this->getDbTable()->getAdapter()->setFetchMode(Zend_Db::FETCH_OBJ);
         $userid = '';
         if ($format === 'xml') {
             $func = "app_to_xml";
         } else {
             $func = "export_app";
             $userid = ", '" . str_replace('export', '', $format) . "'";
         }
         if ($xmldetailed === true) {
             $func = $func . "_ext";
             if ($this->_userid != '') {
                 $userid = ", {$this->_userid}";
             }
         } elseif ($xmldetailed === "listing") {
             $func = $func . "_list";
         }
         if (is_array($filter->expr())) {
             $where = array();
             $from = array();
             foreach ($filter->expr() as $x) {
                 $sss = clone $select;
                 $sss->where($x);
                 getZendSelectParts($sss, $f, $w, $orderby, $limit);
                 $f = fixuZenduBuguru($f);
                 $where[] = $w;
                 $from[] = $f;
             }
         } else {
             getZendSelectParts($select, $from, $where, $orderby, $limit);
             $from = fixuZenduBuguru($from);
         }
         if (isset($_orderby) && trim($_orderby) !== "") {
             $orderby = 'ORDER BY ' . $_orderby;
         }
         # TODO: FIX NULLS FIRST/LAST bypass
         if (isset($orderby)) {
             $orderby = str_replace("applications.lastupdated", "apps.lastupdated", $orderby);
         }
         # FORCE current value of "lastupdated" instead of cached
         if ($from == '') {
             $from = 'FROM applications';
         }
         if ($func == "app_to_xml" || $func == "app_to_xml_list" || $func == "export_app") {
             //				debug_log(var_export($filter->fltstr,true));
             //				debug_log(var_export($from, true));
             //				debug_log(var_export($where,true));
             //				debug_log($orderby);
             $frmt = "";
             if ($func === "export_app") {
                 $frmt = str_replace('export', '', $format);
                 if (!$frmt || trim($frmt) === "") {
                     $frmt = "";
                 } else {
                     if ($frmt === 'xml') {
                         $frmt = ", 'xml'";
                     } else {
                         if ($frmt === 'csv') {
                             $frmt = ", 'csv'";
                         } else {
                             $frmt = "";
                         }
                     }
                 }
             }
             if (is_array($filter->expr())) {
                 noDBSeqScan(db());
                 $resultSet = db()->query("SELECT " . $func . "(array_agg(applications.id {$orderby}) {$frmt} ) as application FROM filterapps((?)::text[],(?)::text[],(?)::text[]) AS applications INNER JOIN applications AS apps ON apps.id = applications.id {$limit}", array(php_to_pg_array($filter->fltstr, false), php_to_pg_array($from, false), str_replace("''", "\\'", php_to_pg_array($where, false))))->fetchAll();
             } else {
                 noDBSeqScan(db());
                 $resultSet = db()->query("SELECT " . $func . "(array_agg(applications.id {$orderby}) {$frmt}) as application FROM filterapps(?,?,?) AS applications INNER JOIN applications AS apps ON apps.id = applications.id {$limit}", array($filter->fltstr, $from, $where))->fetchAll();
             }
         } else {
             //debug_log("########" . "".$select . "#########");
             $select = fixuZenduBuguru("" . $select);
             noDBSeqScan($this->getDbTable()->getAdapter());
             $resultSet = db()->query("SELECT " . $func . "(id" . $userid . ") as application FROM (" . $select . ") AS t")->fetchAll();
             //				$resultSet = $this->getDbTable()->getAdapter()->query("SELECT ".$func."(id".$userid.") as application FROM (".$select.") AS t")->fetchAll();
         }
     } else {
         $query = fixuZenduBuguru("" . $select);
         if (strpos(str_replace('"', '', $orderby), "applications.name") !== false && !is_array($orderby)) {
             $query = str_replace("DISTINCT \"applications", "DISTINCT ON (applications.name) \"applications", $query);
         }
         //			debug_log("########" . "".$query. "#########");
         noDBSeqScan($executor);
         $resultSet = $executor->fetchAll($query);
     }
     $entries = array();
     foreach ($resultSet as $row) {
         if (str_replace('export', '', $format) === 'xml' || str_replace('export', '', $format) === 'csv') {
             $entry = $row->application;
         } else {
             $entry = new Default_Model_Application();
             $this->populate($entry, $row);
         }
         $entries[] = $entry;
     }
     return $entries;
 }
コード例 #9
0
ファイル: VOsMapper.php プロジェクト: IASA-GR/appdb-core
 public function fetchAll($filter = null, $format = '', $xmldetailed = false)
 {
     $select = $this->getDbTable()->select();
     $executor = $this->getDbTable();
     if ($filter !== null) {
         $orderby = $filter->orderBy;
         if (is_array($orderby)) {
             $orderby = end($orderby);
         }
     } else {
         $orderby = null;
     }
     if ($filter !== null && $filter->expr() != '') {
         $select = $this->getDbTable()->getAdapter()->select()->distinct()->from('vos');
         $this->joins($select, $filter);
         if (!is_array($filter->expr())) {
             $select->where($filter->expr());
         }
         $executor = $this->getDbTable()->getAdapter();
         $executor->setFetchMode(Zend_Db::FETCH_OBJ);
     }
     if ($filter !== null) {
         $select->limit($filter->limit, $filter->offset);
     }
     if ($filter !== null) {
         $inv = false;
         if (substr($orderby, 0, 8) === "vos.rank") {
             //				$orderby = substr($orderby, 4);
             //				if ( strpos($orderby," DESC") === false ) {
             //					$orderby = str_replace(" ASC"," DESC", $orderby);
             //				} else {
             //					$orderby = str_replace(" DESC"," ASC", $orderby);
             //					$inv = true;
             //				}
             //				$orderby = array($orderby, 'name'.($inv?' DESC':''));
             /** 
              * NOTE: Ordering by rank is handled by the database, so trust DB order
              */
             $orderby = "rank DESC, name ASC";
         }
         $select->order($orderby);
         if (is_array($orderby)) {
             $_orderby = implode(",", $orderby);
         } else {
             $_orderby = $orderby;
         }
     }
     if (is_array($filter->expr())) {
         $where = array();
         $from = array();
         foreach ($filter->expr() as $x) {
             $sss = clone $select;
             $sss->where($x);
             getZendSelectParts($sss, $f, $w, $orderby, $limit);
             $f = fixuZenduBuguru($f);
             $where[] = $w;
             $from[] = $f;
         }
     } else {
         getZendSelectParts($select, $from, $where, $orderby, $limit);
         $from = fixuZenduBuguru($from);
     }
     if (isset($_orderby)) {
         $orderby = 'ORDER BY ' . $_orderby;
     }
     # TODO: FIX NULLS FIRST/LAST bypass
     if ($from == '') {
         $from = 'FROM vos';
     }
     if ($format === 'xml') {
         $func_name = "vo_to_xml";
         if ($xmldetailed) {
             $func_name .= "_ext";
         }
         //			debug_log(var_export($filter->fltstr,true));
         //			debug_log(var_export($from, true));
         //			debug_log(var_export($where,true));
         //			debug_log($orderby);
         $this->getDbTable()->getAdapter()->setFetchMode(Zend_Db::FETCH_OBJ);
         if (is_array($filter->expr())) {
             noDBSeqScan(db());
             //				$fff = fopen(APPLICATION_PATH . "/../cache/debuglog", "a+");
             //				$sss = db()->quoteInto("SELECT ".$func_name."(array_agg(id $orderby)) as vo FROM filtervos((?)::text[],", php_to_pg_array($filter->fltstr, false)) . db()->quoteInto("(?)::text[],", php_to_pg_array($from, false)) . db()->quoteInto("(?)::text[]) AS vos $limit", str_replace("''", "\'", php_to_pg_array($where, false)));
             //				fwrite($fff, $sss);
             //				fclose($fff);
             $resultSet = db()->query("SELECT " . $func_name . "(array_agg(id {$orderby})) as vo FROM filtervos((?)::text[],(?)::text[],(?)::text[]) AS vos {$limit}", array(php_to_pg_array($filter->fltstr, false), php_to_pg_array($from, false), str_replace("''", "\\'", php_to_pg_array($where, false))))->fetchAll();
         } else {
             noDBSeqScan(db());
             $resultSet = db()->query("SELECT " . $func_name . "(array_agg(id {$orderby})) AS vo FROM filtervos(?,?,?) AS vos {$limit}", array($filter->fltstr, $from, $where))->fetchAll();
         }
     } else {
         $select = fixuZenduBuguru("" . $select);
         noDBSeqScan($executor);
         $resultSet = $executor->fetchAll($select);
     }
     $entries = array();
     foreach ($resultSet as $row) {
         if ($format === 'xml') {
             $entry = $row->vo;
         } else {
             $entry = new Default_Model_VO();
             $this->populate($entry, $row);
         }
         $entries[] = $entry;
     }
     return $entries;
 }
コード例 #10
0
ファイル: SitesMapper.php プロジェクト: IASA-GR/appdb-core
 public function fetchAll($filter = null, $format = '', $xmldetailed = false)
 {
     $select = $this->getDbTable()->select()->from('sites');
     $executor = $this->getDbTable();
     if ($filter !== null) {
         $orderby = $filter->orderBy;
         if (is_array($orderby)) {
             $orderby = end($orderby);
         }
     } else {
         $orderby = null;
     }
     if ($format == '') {
         if ($filter !== null && is_array($filter->joins) && count($filter->joins) > 0) {
             return $this->fetchFilteredEntries($filter);
         } else {
             return parent::fetchAll($filter);
         }
     } else {
         if ($format === 'xml') {
             if ($filter !== null) {
                 $select = $this->getDbTable()->getAdapter()->select()->distinct()->from('sites');
                 if (is_array($filter->expr()) || trim($filter->expr()) != '') {
                     $this->joins($select, $filter);
                     if (!is_array($filter->expr())) {
                         $select->where($filter->expr());
                     }
                     $executor = $this->getDbTable()->getAdapter();
                     $executor->setFetchMode(Zend_Db::FETCH_OBJ);
                 }
             }
             $this->getDbTable()->getAdapter()->setFetchMode(Zend_Db::FETCH_OBJ);
             if ($filter !== null) {
                 $ord = $filter->orderBy;
                 //					if ( $ord == '' ) $ord = 'name ASC';
                 $select->limit($filter->limit, $filter->offset);
                 $select->order($ord);
             }
             if (is_array($filter->expr())) {
                 $where = array();
                 $from = array();
                 foreach ($filter->expr() as $x) {
                     $sss = clone $select;
                     $sss->where($x);
                     getZendSelectParts($sss, $f, $w, $orderby, $limit);
                     $f = fixuZenduBuguru($f);
                     $where[] = $w;
                     $from[] = $f;
                 }
             } else {
                 getZendSelectParts($select, $from, $where, $orderby, $limit);
                 $from = fixuZenduBuguru($from);
             }
             if ($from == '') {
                 $from = 'FROM sites';
             }
             if ($xmldetailed === true) {
                 $func = "site_to_xml_ext";
             } else {
                 $func = "site_to_xml";
             }
             db()->setFetchMode(Zend_Db::FETCH_OBJ);
             if (is_array($filter->expr())) {
                 noDBSeqScan(db());
                 $resultSet = db()->query("SELECT " . $func . "(array_agg(sites.guid::text {$orderby})) as site FROM filtersites((?)::text[],(?)::text[],(?)::text[]) AS sites INNER JOIN sites AS s ON s.id = sites.id {$limit}", array(php_to_pg_array($filter->fltstr, false), php_to_pg_array($from, false), str_replace("''", "\\'", php_to_pg_array($where, false))))->fetchAll();
             } else {
                 noDBSeqScan(db());
                 $resultSet = db()->query("SELECT " . $func . "(array_agg(sites.guid::text {$orderby})) as site FROM filtersites(?,?,?) AS sites INNER JOIN sites AS s ON s.id = sites.id {$limit}", array($filter->fltstr, $from, $where))->fetchAll();
             }
             $entries = array();
             foreach ($resultSet as $row) {
                 $entry = $row->site;
                 $entries[] = $entry;
             }
             return $entries;
         }
     }
 }