polls_table = $polls_table; $this->options_table = $options_table; } function get_title() { return $this->title; } function get_options() { $options = array(); $raw_options = $this->options_table->get_options($this->poll_id); if ( count( $raw_options ) ) { foreach ( $raw_options as $option ) : array_push($options, new pollpress_poll_option($this->options_table, $this, $option) ); endforeach; } return $options; } function get_option($option_id) { $raw_option = $this->options_table->get_option($option_id); return new pollpress_poll_option($this->options_table, $this, $raw_option); } function get_id() { return $this->poll_id; } function get_post_id() { return $this->post_id; } function get_post() { return $this->polls_table->get_post($this->post_id); } function set_title($title) { $this->title = $title; } function set_id($poll_id) { $this->poll_id = $poll_id; } function set_post_id($post_id) { $this->post_id = $post_id; } function create_option($title) { // Create a new option and set the text $new_option = new pollpress_poll_option($this->options_table, $this); $new_option->set_text($title); // We need to determine the order it should be at, so hit // the db, and figure out what the next one is $options = $this->get_options(); $order = 0; foreach ( $options as $option ) : if ( $option->get_order() >= $order ) { $order = $option->get_order() + 1; } endforeach; $new_option->set_order($order); // Return the new option return $new_option; } function save() { return $this->polls_table->save_poll($this); } function destroy() { wp_delete_post($this->post_id); $this->polls_table->destroy_poll($this); $this->options_table->destroy_poll($this); } } ?>