Source of file api.contractdates.php
Size: 6,551 Bytes - Last Modified: 2024-04-27T15:26:05+03:00
/tmp/current_snapshot/api/libs/api.contractdates.php
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203 | <?php /** * Contract dates manipulation class */ class ContractDates { /** * Contract dates database abstraction layer * * @var object */ protected $contractDatesDb = ''; /** * some predefined stuff */ const TABLE_CONDATES = 'contractdates'; const PROUTE_RUNEDIT = 'newcontractnum'; const PROUTE_DATE = 'newcontractdate'; const PROUTE_FROM = 'newcontractfrom'; const PROUTE_TILL = 'newcontracttill'; public function __construct() { $this->initDb(); } /** * Inits database abstraction layer * * @return void */ protected function initDb() { $this->contractDatesDb = new NyanORM(self::TABLE_CONDATES); } /** * Creates new contract date database record * * @param $contract - existing contract num * @param $date - contract creation date * @param $from - optional start of contract date * @param $till - optional end of contract date * * @return void */ protected function create($contract, $date, $from = '', $till = '') { $contract = ubRouting::filters($contract, 'mres'); $date = ubRouting::filters($date, 'mres'); $from = ubRouting::filters($from, 'mres'); $till = ubRouting::filters($till, 'mres'); //not empty contract and valid date? if (!empty($contract) AND zb_checkDate($date)) { $this->contractDatesDb->data('contract', $contract); $this->contractDatesDb->data('date', $date); $this->contractDatesDb->data('from', $from); $this->contractDatesDb->data('till', $till); $this->contractDatesDb->create(); log_register('CREATE UserContractDate [' . $contract . '] D`' . $date . '` F`' . $from . '` T`' . $till . '`'); } } /** * Updates some existing contract date database record * * @param $contract - existing contract num * @param $date - contract creation date * @param $from - optional start of contract date * @param $till - optional end of contract date * * @return void */ protected function update($contract, $date, $from = '', $till = '') { $contract = ubRouting::filters($contract, 'mres'); $date = ubRouting::filters($date, 'mres'); $from = ubRouting::filters($from, 'mres'); $till = ubRouting::filters($till, 'mres'); //not empty contract and valid date? if (!empty($contract) AND zb_checkDate($date)) { $this->contractDatesDb->data('date', $date); $this->contractDatesDb->data('from', $from); $this->contractDatesDb->data('till', $till); $this->contractDatesDb->where('contract', '=', $contract); $this->contractDatesDb->save(); log_register('CHANGE UserContractDate [' . $contract . '] D`' . $date . '` F`' . $from . '` T`' . $till . '`'); } } /** * Sets some contract date in database * * @param $contract - existing contract num * @param $date - contract creation date * @param $from - optional start of contract date * @param $till - optional end of contract date * * @return void */ public function set($contract, $date, $from = '', $till = '') { if (!empty($contract)) { $currentDatabaseRecord = $this->getAllDatesFull($contract); //create new if (empty($currentDatabaseRecord)) { $this->create($contract, $date, $from, $till); } else { //or update existing? $this->update($contract, $date, $from, $till); } } } /** * Get all or selected existing contract basic dates as contract=>date * * @return array */ public function getAllDatesBasic($contract = '') { $contract = ubRouting::filters($contract, 'mres'); $result = array(); if (!empty($contract)) { $this->contractDatesDb->where('contract', '=', $contract); } $all = $this->contractDatesDb->getAll(); if (!empty($all)) { foreach ($all as $io => $each) { $result[$each['contract']] = $each['date']; } } return ($result); } /** * Get all or selected existing contract basic dates as contract=>datesData[id,date,from,till] * * @return array */ public function getAllDatesFull($contract = '') { $contract = ubRouting::filters($contract, 'mres'); $result = array(); if (!empty($contract)) { $this->contractDatesDb->where('contract', '=', $contract); } $result = $this->contractDatesDb->getAll('contract'); return ($result); } /** * Shows contract create date modify form * * @param string $contract * * @return string */ public function renderChangeForm($contract = '') { $result = ''; $curDate = ''; $curFrom = ''; $curTill = ''; if (!empty($contract)) { $currentData = $this->getAllDatesFull($contract); if (!empty($currentData)) { $curDate = $currentData[$contract]['date']; $curFrom = $currentData[$contract]['from']; $curTill = $currentData[$contract]['till']; } } $curDateLabel = ($curDate) ? $curDate : __('None'); $curFromLabel = ($curFrom) ? $curFrom : __('None'); $curTillLabel = ($curTill) ? $curTill : __('None'); $rows = wf_HiddenInput(self::PROUTE_RUNEDIT, $contract); $cells = wf_TableCell($curDateLabel, '30%', 'row2'); $cells .= wf_TableCell(wf_DatePickerPreset(self::PROUTE_DATE, $curDate) . ' ' . __('User contract date'), '', 'row3'); $rows .= wf_tablerow($cells); $cells = wf_TableCell($curFromLabel, '', 'row2'); $cells .= wf_TableCell(wf_DatePickerPreset(self::PROUTE_FROM, $curFrom) . ' ' . __('Start date'), '', 'row3'); $rows .= wf_tablerow($cells); $cells = wf_TableCell($curTillLabel, '', 'row2'); $cells .= wf_TableCell(wf_DatePickerPreset(self::PROUTE_TILL, $curTill) . ' ' . __('End date'), '', 'row3'); $rows .= wf_tablerow($cells); $form = wf_TableBody($rows, '100%', 0); $form .= wf_Submit('Save'); $result .= wf_Form("", 'POST', $form, ''); return ($result); } } |