/**
 * Return all LEDCOIN mined by attendants.
 * @return double LEDCOIN sum.
 */
function operations_ledcoin_mined()
{
    return operations_ledcoin_added_in_day('ALL', Operation::ADDITION_TYPE_MINING);
}
Esempio n. 2
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();
     }
 }