Inheritance: use trait erLhcoreClassDBTrait
コード例 #1
0
ファイル: edit.php プロジェクト: remdex/livehelperchat
<?php

$tpl = erLhcoreClassTemplate::getInstance('lhdepartment/edit.tpl.php');
$Departament = erLhcoreClassDepartament::getSession()->load('erLhcoreClassModelDepartament', (int) $Params['user_parameters']['departament_id']);
$DepartamentCustomWorkHours = erLhcoreClassModelDepartamentCustomWorkHours::getList(array('filter' => array('dep_id' => $Departament->id), 'sort' => 'date_from ASC'));
$userDepartments = true;
/**
 * Append user departments filter
* */
if ($currentUser->hasAccessTo('lhdepartment', 'manageall') !== true) {
    $userDepartments = erLhcoreClassUserDep::parseUserDepartmetnsForFilter($currentUser->getUserID());
    if ($userDepartments !== true) {
        if (!in_array($Departament->id, $userDepartments)) {
            erLhcoreClassModule::redirect('department/departments');
            exit;
        }
    }
}
if (isset($_POST['Cancel_departament'])) {
    erLhcoreClassModule::redirect('department/departments');
    exit;
}
if (isset($_POST['Delete_departament'])) {
    if (!isset($_POST['csfr_token']) || !$currentUser->validateCSFRToken($_POST['csfr_token']) || !$currentUser->hasAccessTo('lhdepartment', 'delete') || !$Departament->can_delete) {
        erLhcoreClassModule::redirect('department/departments');
        exit;
    }
    $Departament->removeThis();
    erLhcoreClassModule::redirect('department/departments');
    exit;
}
コード例 #2
0
 /**
  * validate and saves/removes department custom work hours, and return result of current custom work hours
  *
  * @param erLhcoreClassModelDepartament $departament
  * @param erLhcoreClassModelDepartamentCustomWorkHours[] $departamentCustomWorkHours
  * @return erLhcoreClassModelDepartamentCustomWorkHours[]
  */
 public static function validateDepartmentCustomWorkHours(erLhcoreClassModelDepartament $departament, $departamentCustomWorkHours = array())
 {
     $availableCustomWorkHours = array();
     $definition = array('customPeriodId' => new ezcInputFormDefinitionElement(ezcInputFormDefinitionElement::OPTIONAL, 'unsafe_raw', null, FILTER_REQUIRE_ARRAY), 'customPeriodDateFrom' => new ezcInputFormDefinitionElement(ezcInputFormDefinitionElement::OPTIONAL, 'unsafe_raw', null, FILTER_REQUIRE_ARRAY), 'customPeriodDateTo' => new ezcInputFormDefinitionElement(ezcInputFormDefinitionElement::OPTIONAL, 'unsafe_raw', null, FILTER_REQUIRE_ARRAY), 'customPeriodStartHour' => new ezcInputFormDefinitionElement(ezcInputFormDefinitionElement::OPTIONAL, 'unsafe_raw', null, FILTER_REQUIRE_ARRAY), 'customPeriodStartHourMin' => new ezcInputFormDefinitionElement(ezcInputFormDefinitionElement::OPTIONAL, 'unsafe_raw', null, FILTER_REQUIRE_ARRAY), 'customPeriodEndHour' => new ezcInputFormDefinitionElement(ezcInputFormDefinitionElement::OPTIONAL, 'unsafe_raw', null, FILTER_REQUIRE_ARRAY), 'customPeriodEndHourMin' => new ezcInputFormDefinitionElement(ezcInputFormDefinitionElement::OPTIONAL, 'unsafe_raw', null, FILTER_REQUIRE_ARRAY));
     $form = new ezcInputForm(INPUT_POST, $definition);
     if ($form->hasValidData('customPeriodId') && !empty($form->customPeriodId)) {
         foreach ($form->customPeriodId as $key => $customPeriodId) {
             if (!$customPeriodId) {
                 // if id is not defined save new custom departament work hours
                 $newDepartamentCustomWorkHours = new erLhcoreClassModelDepartamentCustomWorkHours();
                 $newDepartamentCustomWorkHours->setState(array('dep_id' => $departament->id, 'date_from' => strtotime($form->customPeriodDateFrom[$key]), 'date_to' => strtotime($form->customPeriodDateTo[$key]), 'start_hour' => $form->customPeriodStartHour[$key] . ($form->customPeriodStartHourMin[$key] > 0 ? str_pad($form->customPeriodStartHourMin[$key], 2, '0', STR_PAD_LEFT) : '00'), 'end_hour' => $form->customPeriodEndHour[$key] . ($form->customPeriodEndHourMin[$key] > 0 ? str_pad($form->customPeriodEndHourMin[$key], 2, '0', STR_PAD_LEFT) : '00')));
                 erLhcoreClassDepartament::getSession()->save($newDepartamentCustomWorkHours);
                 $availableCustomWorkHours[$key] = $newDepartamentCustomWorkHours;
                 unset($departamentCustomWorkHours[$customPeriodId]);
             } elseif ($customPeriodId && !empty($departamentCustomWorkHours) && isset($departamentCustomWorkHours[$customPeriodId])) {
                 // if id isset, unset from provided array
                 $availableCustomWorkHours[$key] = $departamentCustomWorkHours[$customPeriodId];
                 unset($departamentCustomWorkHours[$customPeriodId]);
             }
         }
     }
     // if there are left elements, remove them from DB
     if (!empty($departamentCustomWorkHours)) {
         foreach ($departamentCustomWorkHours as $departamentCustomWorkHour) {
             erLhcoreClassDepartament::getSession()->delete($departamentCustomWorkHour);
         }
     }
     return $availableCustomWorkHours;
 }