repository->getById($training_id); if(!is_null($training)) return $this->repository->getCoursesByDate($training,$date); return false; } public function register(ICompanyService &$training){ $training->setMarketplace($this->getMarketPlaceType()); return parent::register($training); } /** * @param $current_date * @return null */ public function getActives($current_date=null){ $trainings = null; $ordering_set = false; if($order = $this->cache_service->getSingleValue("Trainings.Ordering")){ $str_order = implode(', ',$order); $trainings_count = $this->repository->countActives($current_date); if(intval($trainings_count)!= count($order)){ //select random order $trainings = $this->repository->getActivesRandom($current_date); } else{ $ordering_set = true; $trainings = $this->repository->getActivesByList($current_date, $str_order); } } else{ $trainings = $this->repository->getActivesRandom($current_date); } if (!is_null( $trainings)) { $ordering = array(); $to_remove = array(); foreach ($trainings as $t){ if(!$this->show_policy->canShow($t->getIdentifier())){ array_push($to_remove,$t); } array_push($ordering,$t->getIdentifier()); } $trainings = array_diff($trainings,$to_remove); if(!$ordering_set)//store random order for next time to maintain consistency { $this->cache_service->setSingleValue("Trainings.Ordering",$ordering); } } return $trainings; } /** * @param int $training_id * @return bool */ public function isActive($training_id){ $training = $this->repository->getById($training_id); if(!$training->isActive()) return false; if(!$this->show_policy->canShow($training->getIdentifier())) return false; return true; } /** * @param ITrainingAdministrator $user * @return ITraining[] */ public function getAllowedTrainings(ITrainingAdministrator $user){ $res = array(); //get all companies on where member is training admin $companies = $user->getAdministeredTrainingCompanies(); foreach($companies as $company){ $trainings = $company->getTrainings(); foreach($trainings as $training){ if($training->isActive()) array_push($res,$training); } } //then on each company get all active trainings return $res; } /** * @return IMarketPlaceType * @throws NotFoundEntityException */ protected function getMarketPlaceType() { $marketplace_type = $this->marketplace_type_repository->getByType(ITraining::MarketPlaceType); if(!$marketplace_type) throw new NotFoundEntityException('MarketPlaceType',sprintf("type %s ",ITraining::MarketPlaceType)); return $marketplace_type; } }