Exemple #1
0
 public static function nameAvailable($name, $id = null)
 {
     global $application;
     $db = $application->getBootstrap()->getResource('db');
     $db->setFetchMode(Zend_Db::FETCH_OBJ);
     if ($id != '') {
         $where = " WHERE id <> {$id}";
     } else {
         $where = '';
     }
     $res = $db->query("SELECT * FROM app_name_available(E'" . pg_escape_string($name) . "'){$where}")->fetchAll();
     if (count($res) == 0) {
         return true;
     } else {
         $a = new Default_Model_Application();
         $m = new Default_Model_ApplicationsMapper();
         $m->populate($a, $res[0]);
         return $a;
     }
 }
Exemple #2
0
 /**
  * @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;
     }
 }