Exemplo n.º 1
0
 /**
  * @overrides get() from RestResource
  */
 public function get($extraFilter = null)
 {
     if (parent::get() !== false) {
         global $application;
         $isAdmin = $this->userIsAdmin();
         $mapper = new Default_Model_SitesMapper();
         $db = $application->getBootstrap()->getResource('db');
         $flt = $this->getParam("flt");
         $select = $mapper->getDbTable()->getAdapter()->select()->distinct()->from('sites');
         $from = '';
         $where = '';
         $orderby = '';
         $limit = '';
         $filter = FilterParser::getSites($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 (!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 site_logistics(?,?,?)', array($flt, $from, $where))->fetchAll();
         if (count($rs) > 0) {
             $rs = $rs[0];
             $x = $rs['site_logistics'];
         } else {
             $x = '';
         }
         return new XMLFragmentRestResponse($x, $this);
     } else {
         return false;
     }
 }