示例#1
0
 public function ajax_move($type, $id_card, $id_deck)
 {
     if (!in_array($type, ['add', 'remove'])) {
         $ajax_response = new Ajax_response_standard('NOK', 'Incorrect request');
         echo $ajax_response->produce();
         return;
     }
     $this->load->model('Card_move');
     $result = Card_move::move($type, $id_card, $id_deck);
     if ($result === true) {
         $ajax_response = new Ajax_response_standard('OK', 'Your request has been processed.');
     } elseif ($result instanceof Standard_error) {
         $ajax_response = new Ajax_response_standard('NOK', $result->message);
     }
     echo $ajax_response->produce();
     return;
 }
示例#2
0
文件: Card.php 项目: vmoulin77/DVB
 public static function delete($id)
 {
     $CI = get_instance();
     $CI->load->model('Card_move');
     $CI->load->model('Version');
     $CI->load->model('Deck');
     if (self::card_is_deleted($id)) {
         $CI->transaction->set_as_rollback();
         return new Standard_error('DELETE_ERROR', 'The card has already been deleted.');
     }
     if (self::never_versioned($id)) {
         $CI->db->where('id', $id);
         if ($CI->db->delete('card')) {
             return true;
         } else {
             $CI->transaction->set_as_rollback();
             return new Standard_error();
         }
     } else {
         $current_version = Version::retrieve_current_version();
         /********************************************************/
         $CI->db->where('id_card', $id);
         if (!$CI->db->delete('campaign_card')) {
             $CI->transaction->set_as_rollback();
             return new Standard_error();
         }
         /********************************************************/
         /********************************************************/
         $CI->db->select('id_deck')->from('card_deck_version')->where('id_card', $id)->where('id_version', $current_version->get_id())->where('type', 'add');
         $query = $CI->db->get();
         $ids_decks = array();
         foreach ($query->result() as $row) {
             $ids_decks[] = $row->id_deck;
         }
         $CI->db->where('id_card', $id)->where('id_version', $current_version->get_id())->where('type', 'add');
         if (!$CI->db->delete('card_deck_version')) {
             $CI->transaction->set_as_rollback();
             return new Standard_error();
         }
         foreach ($ids_decks as $id_deck) {
             if (!Card_move::set_last_move($id, $id_deck, true)) {
                 $CI->transaction->set_as_rollback();
                 return new Standard_error();
             }
         }
         /********************************************************/
         /********************************************************/
         $finder_manager = new Finder_manager('Deck', 'find_with_contains_current_card', FIND_MANY, ['id_card' => $id]);
         $decks = $finder_manager->get();
         foreach ($decks as $deck) {
             if ($deck->contains_current_card) {
                 if (!Card_move::set_last_move($id, $deck->get_id(), false)) {
                     $CI->transaction->set_as_rollback();
                     return new Standard_error();
                 }
                 $data = array('id_card' => $id, 'id_deck' => $deck->get_id(), 'id_version' => $current_version->get_id(), 'type' => 'remove', 'is_last' => true);
                 if (!$CI->db->insert('card_deck_version', $data)) {
                     $CI->transaction->set_as_rollback();
                     return new Standard_error();
                 }
             }
         }
         /********************************************************/
         $CI->db->where('id_card', $id)->where('id_version', $current_version->get_id());
         if (!$CI->db->delete('card_content')) {
             $CI->transaction->set_as_rollback();
             return new Standard_error();
         }
         $CI->db->select('id')->from('card_content')->where('id_card', $id)->order_by('id_version', 'DESC')->limit(1);
         $query = $CI->db->get();
         if ($query->num_rows() == 0) {
             $CI->transaction->set_as_rollback();
             return new Standard_error();
         } else {
             $row = $query->row();
             $CI->db->set(array('is_last' => true))->where('id', $row->id);
             if (!$CI->db->update('card_content')) {
                 $CI->transaction->set_as_rollback();
                 return new Standard_error();
             }
         }
         $data = array('is_deleted' => true, 'id_version_when_deleted' => $current_version->get_id());
         $CI->db->set($data)->where('id', $id);
         if ($CI->db->update('card')) {
             return true;
         } else {
             $CI->transaction->set_as_rollback();
             return new Standard_error();
         }
     }
 }