public function compare_to(Version $version_before) { $this->load->model('Card_content'); if ($this->get_id() <= $version_before->get_id()) { return array(); } $this->db->select('id AS "card_content:id",' . 'id_card AS "card_content:id_card",' . 'word_english AS "card_content:word_english",' . 'word_french AS "card_content:word_french",' . 'is_active_english AS "card_content:is_active_english",' . 'is_active_french AS "card_content:is_active_french",' . 'id_version AS "card_content:id_version",' . 'is_last AS "card_content:is_last"')->from('card_content')->where('id_version <= ', $this->id)->order_by('id_card ASC, id_version ASC'); $query = $this->db->get(); $card_contents = array(); foreach ($query->result() as $row) { cast_row($row); if ($row->{'card_content:id_version'} <= $version_before->id) { $card_contents[$row->{'card_content:id_card'}] = array(); } $card_content = Card_content::make($row->{'card_content:id'}, $row->{'card_content:word_english'}, $row->{'card_content:word_french'}, $row->{'card_content:is_active_english'}, $row->{'card_content:is_active_french'}, $row->{'card_content:is_last'}); $card_content->id_version = $row->{'card_content:id_version'}; $card_contents[$row->{'card_content:id_card'}][] = $card_content; } $retour = array(); foreach ($card_contents as $value) { if (count($value) > 1 || $value[0]->id_version > $version_before->id) { $retour[] = $value; } } return $retour; }
public function with_card_contents_history() { $this->load->model('Card_content'); $this->db->select('card_content.id AS card_content:id,' . 'card_content.word_english AS card_content:word_english,' . 'card_content.word_french AS card_content:word_french,' . 'card_content.is_active_english AS card_content:is_active_english,' . 'card_content.is_active_french AS card_content:is_active_french,' . 'card_content.is_last AS card_content:is_last')->from('card')->join('card_content', 'card.id = card_content.id_card')->where('card.id', $this->id); $query = $this->db->get(); $card_contents_history = array(); foreach ($query->result() as $row) { cast_row($row); $card_content = Card_content::make($row->{'card_content:id'}, $row->{'card_content:word_english'}, $row->{'card_content:word_french'}, $row->{'card_content:is_active_english'}, $row->{'card_content:is_active_french'}, $row->{'card_content:is_last'}); $card_contents_history[] = $card_content; } $this->set_card_contents_history($card_contents_history); return $this; }