*/ class JobFormCommonFunctions { /** * Vrátí pole kategorii roznělené na skupiny * @return array */ public static function getCategoryGroupedChoices($add_empty = false) { $categories = Doctrine::getTable('JobCategory')->createQuery() ->addWhere('parent_id IS NULL') ->orderBy('priority DESC') ->execute(); if($add_empty) { return array('' => '') + self::getCategoryGroupedArrayRecursively($categories); } return self::getCategoryGroupedArrayRecursively($categories); } /** * Vrátí pole kategorii roznělené na skupiny pomocí oddělovače * @return array */ public static function getCategoryFakeGroupedChoices($add_empty = false) { $categories = Doctrine::getTable('JobCategory')->createQuery() ->addWhere('parent_id IS NULL') ->orderBy('priority DESC') ->execute(); if($add_empty) { return array('' => '') + self::getCategoryFakeGroupedArrayRecursively($categories); } return self::getCategoryFakeGroupedArrayRecursively($categories); } public static function getCategoryFakeGroupedArrayRecursively(Doctrine_Collection $categories, $prefix = '') { $result = array(); foreach($categories as $category) { if(strlen($prefix) > 0) { $result[$category->getId()] = ' '.$prefix.' '.$category->getName(); } else { $result[$category->getId()] = $category->getName(); } $result = $result + self::getCategoryFakeGroupedArrayRecursively($category->getChildren(), $prefix.'--'); } return $result; } /** * Získá pole názvů kategorií rekurzivně * * @param Doctrine_Collection $categories * @return array */ public static function getCategoryGroupedArrayRecursively(Doctrine_Collection $categories) { $result = array(); foreach($categories as $category) { if($category->hasChildren()) { $result[$category->getName()] = self::getCategoryGroupedArrayRecursively($category->getChildren()); } else { $result[$category->getId()] = $category->getName(); } } return $result; } /** * Vrátí pole specializacích rozdělené do skupin podle kategorie * * @param string $form_name * @return array */ public static function getSpecializationsListGroupedChoices($form_name) { $result = array(); $specs = Doctrine::getTable('JobSpecialization')->createQuery()->orderBy('priority DESC, name ASC')->execute(); foreach($specs as $spec) { $result['group_'.$form_name.'_category_id_'.$spec->getCategoryId()][$spec->getId()] = $spec->getName(); } return $result; } /** * Odstraní specializace ktere nepatří k vybrané kategorii * * @param array $taintedValues */ public static function checkSpecializations(&$taintedValues) { if(isset($taintedValues['specializations_list'])) { if(isset($taintedValues['category_id']) && $taintedValues['category_id'] > 0) { $specs = Doctrine::getTable('JobSpecialization')->createQuery() ->select('id') ->addWhere('category_id = ?', $taintedValues['category_id']) ->orderBy('priority DESC, name ASC') ->setHydrationMode(Doctrine_Core::HYDRATE_SINGLE_SCALAR) ->execute(); foreach($taintedValues['specializations_list'] as $key => $spec) { if(!in_array($spec, $specs)) { unset($taintedValues['specializations_list'][$key]); } } } else { $taintedValues['specializations_list'] = array(); } } } }