Esempio n. 1
0
 public function getSearch($r)
 {
     $t = new Dase_Template($r);
     $q = $r->get('q');
     $dbh = $this->db->getDbh();
     $lists = array();
     $texts = array();
     $sth = $dbh->prepare('select list.name,item.list_id, item.text from item, list where item.list_id = list.id  and text like ?');
     $sth->execute(array('%' . $q . '%'));
     while ($row = $sth->fetch()) {
         if (!isset($texts[$row['list_id']])) {
             $texts[$row['list_id']] = array();
         }
         $texts[$row['list_id']][] = $row['text'];
         $list = new Dase_DBO_List($this->db);
         $list->load($row['list_id']);
         $list->getCount();
         $lists[$row['list_id']] = $list;
     }
     $sth2 = $dbh->prepare("select id,name from list where name like ?");
     $sth2->execute(array('%' . $q . '%'));
     while ($row = $sth2->fetch()) {
         $list = new Dase_DBO_List($this->db);
         $list->load($row['id']);
         $list->getCount();
         $lists[$row['id']] = $list;
     }
     $t->assign('lists', $lists);
     $t->assign('texts', $texts);
     $t->assign('q', $q);
     $r->renderResponse($t->fetch('search.tpl'));
 }