Пример #1
0
 public function delete_person($person_id = NULL)
 {
     if (is_null($person_id)) {
         add_error_flash_message('Osoba sa nenašla.');
         redirect(site_url('persons'));
     }
     $person = new Person();
     $person->get_by_id((int) $person_id);
     if (!$person->exists()) {
         add_error_flash_message('Osoba sa nenašla.');
         redirect(site_url('persons'));
     }
     if ($person->id == auth_get_id()) {
         add_error_flash_message('Nemôžete vymazať vlastný účet.');
         redirect(site_url('persons'));
     }
     $success_message = 'Osoba <strong>' . $person->name . ' ' . $person->surname . '</strong> s loginom <strong>' . $person->login . '</strong>, a s ID <strong>' . $person->id . '</strong> bola úspešne vymazaná.';
     $error_message = 'Osobu <strong>' . $person->name . ' ' . $person->surname . '</strong> s loginom <strong>' . $person->login . '</strong>, a s ID <strong>' . $person->id . '</strong> sa nepodarilo vymazať.';
     if ($person->delete()) {
         unlink_recursive('user/photos/data/' . (int) $person_id . '/', TRUE);
         add_success_flash_message($success_message);
     } else {
         add_error_flash_message($error_message);
     }
     redirect(site_url('persons'));
 }
Пример #2
0
 /**
  * @return Questionnaire
  */
 protected function get_questionnaires()
 {
     $person = new Person();
     $person->get_by_id(auth_get_id());
     $questionnaire_answers = new Questionnaire_answer();
     $questionnaire_answers->select_func('MAX', '@answer_number', 'max_answer');
     $questionnaire_answers->group_by('person_id');
     $questionnaire_answers->where_related($person);
     $questionnaire_answers->where_related_questionnaire('id', '${parent}.id');
     $questonnaires = new Questionnaire();
     $questonnaires->select('*');
     $questonnaires->select_subquery($questionnaire_answers, 'max_answer_number');
     $questonnaires->where('published', 1);
     $questonnaires->get_iterated();
     return $questonnaires;
 }
Пример #3
0
 public function do_batch_ledcoin_addition()
 {
     $this->load->helper('operations');
     $this->db->trans_begin();
     build_validator_from_form($this->get_batch_ledcoin_addition_form());
     if ($this->form_validation->run()) {
         $batch_amount_data = $this->input->post('batch_amount');
         $person_amount_data = $this->input->post('person_amount');
         $workplace = new Workplace();
         if ((int) $batch_amount_data['workplace_id'] > 0) {
             $workplace->get_by_id((int) $batch_amount_data['workplace_id']);
             if (!$workplace->exists()) {
                 $this->db->trans_rollback();
                 add_error_flash_message('Zamestnanie sa nenašlo.');
                 redirect(site_url('operations/batch_ledcoin_addition'));
             }
         }
         $persons = new Person();
         $persons->where('admin', 0);
         $persons->get_iterated();
         $total_added = 0;
         foreach ($persons as $person) {
             if (array_key_exists($person->id, $person_amount_data) && (double) $person_amount_data[$person->id] > 0) {
                 $total_added += (double) $person_amount_data[$person->id];
             }
         }
         $remaining = 0;
         if ($total_added > 0 && $batch_amount_data['addition_type'] == Operation::ADDITION_TYPE_TRANSFER && !operations_ledcoin_addition_possible($total_added, $remaining)) {
             $this->db->trans_rollback();
             add_error_flash_message('Nedá sa prideliť <strong>' . $total_added . '</strong> ' . get_inflection_ledcoin($total_added) . ', na účte vedúcich zostáva iba <strong>' . $remaining . '</strong> ' . get_inflection_ledcoin($remaining) . '.');
             redirect('operations');
             return;
         }
         $persons = new Person();
         $persons->where('admin', 0);
         $persons->get_iterated();
         $successful_count = 0;
         $error_count = 0;
         $successful_messages = array();
         $error_messages = array();
         $total_added = 0;
         foreach ($persons as $person) {
             if (array_key_exists($person->id, $person_amount_data) && (double) $person_amount_data[$person->id] > 0) {
                 $operation = new Operation();
                 $operation->admin_id = auth_get_id();
                 $operation->amount = (double) $person_amount_data[$person->id];
                 $operation->type = Operation::TYPE_ADDITION;
                 $operation->subtraction_type = Operation::SUBTRACTION_TYPE_DIRECT;
                 $operation->addition_type = $batch_amount_data['addition_type'];
                 $operation->comment = @$batch_amount_data['comment'];
                 if ($operation->save(array('person' => $person, 'workplace' => $workplace))) {
                     $total_added += (double) $operation->amount;
                     $successful_messages[] = 'Účastník <strong>' . $person->name . ' ' . $person->surname . '</strong> dostal <strong>' . (double) $operation->amount . '</strong> ' . get_inflection_ledcoin((double) $operation->amount) . '.';
                     $successful_count++;
                 } else {
                     $error_count++;
                     $error_messages[] = 'Účastníkovi <strong>' . $person->name . ' ' . $person->surname . '</strong> sa nepodarilo prideliť LEDCOIN.';
                 }
             }
         }
         if ($total_added > 0 && $batch_amount_data['addition_type'] == Operation::ADDITION_TYPE_TRANSFER && !operations_ledcoin_limit_check($total_added)) {
             add_common_flash_message('Pozor, celkovým pridaním ' . $total_added . ' LEDCOIN-ov bol prekročený denný limit. Pred pridaním už bolo pridaných ' . operations_ledcoin_added_in_day() . ' z ' . operations_ledcoin_daily_limit() . ' LEDCOIN-ov!');
         }
         if ($successful_count == 0 && $error_count == 0) {
             $this->db->trans_rollback();
             add_error_flash_message('Nikomu nebol pridelený LEDCOIN, nakoľko bol odoslaný prázdny formulár.');
             redirect(site_url('operations'));
         } elseif ($successful_count == 0 && $error_count > 0) {
             $this->db->trans_rollback();
             add_error_flash_message('Nepodarilo sa nikomu pridať LEDCOIN:<br /><br />' . implode('<br />', $error_messages));
         } else {
             $this->db->trans_commit();
             if ($successful_count > 0) {
                 add_success_flash_message('LEDCOIN bol pridelený <strong>' . $successful_count . '</strong> ' . get_inflection_by_numbers($successful_count, 'účastníkom', 'účastníkovi', 'účastníkom', 'účastníkom', 'účastníkom', 'účastníkom') . ':<br /><br />' . implode('<br />', $successful_messages));
             }
             if ($error_count > 0) {
                 add_error_flash_message('LEDCOIN sa nepodarilo udeliť <strong>' . $error_count . '</strong> ' . get_inflection_by_numbers($error_count, 'účastníkom', 'účastníkovi', 'účastníkom', 'účastníkom', 'účastníkom', 'účastníkom') . ':<br /><br />' . implode('<br />', $error_messages));
             }
             redirect(site_url('operations'));
         }
     } else {
         $this->db->trans_rollback();
         $this->batch_ledcoin_addition();
     }
 }