convertSortMode($sort_mode); $query_cant = "select count(*) from `tiki_polls` $mid"; $result = $this->query($query, $bindvars, $maxRecords, $offset); $cant = $this->getOne($query_cant, $bindvars); $ret = []; while ($res = $result->fetchRow()) { $query = "select count(*) from `tiki_poll_options` where `pollId`=?"; $res["options"] = $this->getOne($query, [$res["pollId"]]); $ret[] = $res; } $retval = []; $retval["data"] = $ret; $retval["cant"] = $cant; return $retval; } /** * @param $offset * @param $maxRecords * @param $sort_mode * @param $find * @return array */ public function list_active_polls($offset, $maxRecords, $sort_mode, $find) { if ($find) { $findesc = '%' . $find . '%'; $mid = " where (`active`=? or `active`=? or `active`=?) and `publishDate`<=? and (`title` like ?)"; $bindvars = ['a', 'c', 'o', (int) $this->now, $findesc]; } else { $mid = " where (`active`=? or `active`=? or `active`=?) and `publishDate`<=? "; $bindvars = ['a', 'c', 'o', (int) $this->now]; } $query = "select * from `tiki_polls` $mid order by " . $this->convertSortMode($sort_mode); $query_cant = "select count(*) from `tiki_polls` $mid"; $result = $this->query($query, $bindvars, $maxRecords, $offset); $cant = $this->getOne($query_cant, $bindvars); $ret = []; while ($res = $result->fetchRow()) { $ret[] = $res; } $retval = []; $retval["data"] = $ret; $retval["cant"] = $cant; return $retval; } /** * @param $offset * @param $maxRecords * @param $sort_mode * @param $find * @return array */ public function list_all_polls($offset, $maxRecords, $sort_mode, $find) { if ($find) { $findesc = '%' . $find . '%'; $mid = " where `publishDate`<=? and (`title` like ?)"; $bindvars = [(int) $this->now, $findesc]; } else { $mid = " where `publishDate`<=? "; $bindvars = [(int) $this->now]; } $query = "select * from `tiki_polls` $mid order by " . $this->convertSortMode($sort_mode); $query_cant = "select count(*) from `tiki_polls` $mid"; $result = $this->query($query, $bindvars, $maxRecords, $offset); $cant = $this->getOne($query_cant, $bindvars); $ret = []; while ($res = $result->fetchRow()) { $ret[] = $res; } $retval = []; $retval["data"] = $ret; $retval["cant"] = $cant; return $retval; } /** * @return TikiDb_Pdo_Result|TikiDb_Adodb_Result */ public function set_last_poll() { $query = "select max(`publishDate`) from `tiki_polls` where `publishDate`<=?"; $last = $this->getOne($query, [(int) $this->now]); $query = "update `tiki_polls` set `active`=? where `publishDate`=?"; return $this->query($query, ['c', $last]); } /** * @return TikiDb_Pdo_Result|TikiDb_Adodb_Result */ public function close_all_polls() { $query = "select max(`publishDate`) from `tiki_polls` where `publishDate`<=?"; $last = $this->getOne($query, [(int) $this->now]); $query = "update `tiki_polls` set `active`=? where `publishDate`query($query, ['x', (int) $last]); } /** * @return TikiDb_Pdo_Result|TikiDb_Adodb_Result */ public function active_all_polls() { $query = "update `tiki_polls` set `active`=? where `publishDate`<=?"; return $this->query($query, ['a', (int) $this->now]); } /** * @param $optionId * * @return TikiDb_Pdo_Result|TikiDb_Adodb_Result */ public function remove_poll_option($optionId) { $query = "delete from `tiki_poll_options` where `optionId`=?"; return $this->query($query, [$optionId]); } /** * @param $optionId * @return bool */ public function get_poll_option($optionId) { $query = "select * from `tiki_poll_options` where `optionId`=?"; $result = $this->query($query, [$optionId]); if (! $result->numRows()) { return false; } $res = $result->fetchRow(); return $res; } }