public function with_next_id_card() { $this->db->select('id_card AS campaign_card:id_card')->from('campaign_card')->where('id_campaign', $this->id)->where('is_done', false)->limit(1); $query = $this->db->get(); if ($query->num_rows() == 0) { $this->next_id_card = null; } else { $row = $query->row(); cast_row($row); $this->next_id_card = $row->{'campaign_card:id_card'}; } return $this; }
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_version_when_created() { $this->load->model('Version'); $this->db->select('version.id AS version:id,' . 'version.database_version AS version:database_version,' . 'version.app_version_code AS version:app_version_code,' . 'version.app_version_name AS version:app_version_name,' . 'version.created_at AS version:created_at')->from('deck')->join('version', 'version.id = deck.id_version_when_created')->where('deck.id', $this->id); $query = $this->db->get(); if ($query->num_rows() == 1) { $row = $query->row(); cast_row($row); $version_when_created = Version::make($row->{'version:id'}, $row->{'version:database_version'}, $row->{'version:app_version_code'}, $row->{'version:app_version_name'}, $row->{'version:created_at'}); } else { return new Standard_error(); } $this->set_version_when_created($version_when_created); return $this; }
public static function review_record_is_done($id_campaign, $id_card) { $CI = get_instance(); $CI->db->select('is_done AS campaign_card:is_done')->from('campaign_card')->where('id_campaign', $id_campaign)->where('id_card', $id_card); $query = $CI->db->get(); if ($query->num_rows() == 0) { return new Standard_error('ERROR', "The review record doesn't exist anymore."); } $row = $query->row(); cast_row($row); return $row->{'campaign_card:is_done'}; }
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; }