/** * @return array */ public function __invoke() { // get the module manager $moduleManager = $this->serviceLocator->get('ModuleManager'); // get all loaded modules application wide $loadedModules = array_keys($moduleManager->getLoadedModules()); // remove default unwanted modules $loadedModules = array_diff($loadedModules, $this->config['skip_modules']); // loop through all the loaded modules foreach ($loadedModules as $loadedModule) { $moduleClass = '\\' . $loadedModule . '\\Module'; $moduleObject = new $moduleClass(); if (!$moduleObject->getConfig()) { continue; } // get all routes for current module $module = $moduleManager->getModule($loadedModule); $routes = $module->getConfig()['router']['routes']; // if the routes variable (array) is not empty if (!empty($routes)) { // loop through each route foreach ($routes as $key => $route) { // check for route type for the root route and act accordingly // $this->_setRootRoute($route, $key); // loop the children routes and act accordingly $this->_setResources($route, $key); } } } return $this->_resources; }
/** * @param bool $view determines if the routes should be properly formatted for views * @return array */ public function fetchAllRoutes($view = false) { // $this->_format_for_view = $view; // get the module manager $moduleManager = $this->serviceLocator->get('ModuleManager'); // get all loaded modules application wide $loadedModules = array_keys($moduleManager->getLoadedModules()); // remove default unwanted modules $loadedModules = array_diff($loadedModules, $this->config['skip_modules']); // loop through all the loaded modules foreach ($loadedModules as $loadedModule) { $moduleClass = '\\' . $loadedModule . '\\Module'; $moduleObject = new $moduleClass(); if (!$moduleObject->getConfig()) { continue; } // get all routes for current module $module = $moduleManager->getModule($loadedModule); if ($routes = $module->getConfig()['router']['routes']) { // if the routes variable (array) is not empty if (!empty($routes)) { // loop through each route foreach ($routes as $key => $route) { $this->_setResources($route, $key); } } } } return $this->_resources; }
/** * Получает сервис из локатора если он есть * или сначала помещает его туда * * @return object */ public function getService() { if (!$this->locator->checkService($this->service)) { $this->buildService(true); } return $this->locator->get($this->service); }
public function __construct(ServiceLocator $sl, $path) { $this->request = $sl->get('request'); $this->response = $sl->get('response'); $this->path = $path; // … }
/** * @return TestDbAcle; */ public static function create(\Pdo $pdo, $factoryOverrides = array(), $factories = null) { if (is_null($factories)) { $factories = new Config\DefaultFactories(); } $testDbAcle = new TestDbAcle(); $serviceLocator = new ServiceLocator($factories->getFactories($pdo->getAttribute(\PDO::ATTR_DRIVER_NAME))); $serviceLocator->addFactories($factoryOverrides); $serviceLocator->setService('pdo', $pdo); $testDbAcle->setServiceLocator($serviceLocator); return $testDbAcle; }
public function __construct() { parent::__construct(); $userRepository = new UserRepository(); $user = ServiceLocator::GetServer()->GetUserSession(); $this->_presenter = new ManageSchedulesPresenter($this, new ScheduleAdminManageScheduleService(new ScheduleAdminScheduleRepository($userRepository, $user), new ScheduleRepository(), new ResourceAdminResourceRepository($userRepository, $user)), new GroupRepository()); }
public function PageLoad() { ob_clean(); $this->presenter->PageLoad(); $config = Configuration::Instance(); $feed = new FeedWriter(ATOM); $title = $config->GetKey(ConfigKeys::APP_TITLE); $feed->setTitle("{$title} Reservations"); $url = $config->GetScriptUrl(); $feed->setLink($url); $feed->setChannelElement('updated', date(DATE_ATOM, time())); $feed->setChannelElement('author', array('name' => $title)); foreach ($this->reservations as $reservation) { /** @var FeedItem $item */ $item = $feed->createNewItem(); $item->setTitle($reservation->Summary); $item->setLink($reservation->ReservationUrl); $item->setDate($reservation->DateCreated->Timestamp()); $item->setDescription($this->FormatReservationDescription($reservation, ServiceLocator::GetServer()->GetUserSession())); // sprintf('<div><span>Start</span> %s</div> // <div><span>End</span> %s</div> // <div><span>Organizer</span> %s</div> // <div><span>Description</span> %s</div>', // $reservation->DateStart->ToString(), // $reservation->DateEnd->ToString(), // $reservation->Organizer, // $reservation->Description)); $feed->addItem($item); } $feed->genarateFeed(); }
/** * Returns a limited query based on page number and size * If nulls are passed for both $pageNumber, $pageSize then all results are returned * * @param SqlCommand $command * @param callback $listBuilder callback to for each row of results * @param int|null $pageNumber * @param int|null $pageSize * @param string|null $sortField * @param string|null $sortDirection * @return PageableData */ public static function GetList($command, $listBuilder, $pageNumber = null, $pageSize = null, $sortField = null, $sortDirection = null) { $total = null; $totalCounter = 0; $results = array(); $db = ServiceLocator::GetDatabase(); $pageNumber = intval($pageNumber); $pageSize = intval($pageSize); if (empty($pageNumber) && empty($pageSize) || $pageSize == PageInfo::All) { $resultReader = $db->Query($command); } else { $totalReader = $db->Query(new CountCommand($command)); if ($row = $totalReader->GetRow()) { $total = $row[ColumnNames::TOTAL]; } $pageNumber = empty($pageNumber) ? 1 : $pageNumber; $pageSize = empty($pageSize) ? 1 : $pageSize; $resultReader = $db->LimitQuery($command, $pageSize, ($pageNumber - 1) * $pageSize); } while ($row = $resultReader->GetRow()) { $results[] = call_user_func($listBuilder, $row); $totalCounter++; } $resultReader->Free(); return new PageableData($results, is_null($total) ? $totalCounter : $total, $pageNumber, $pageSize); }
protected function __construct($titleKey = '', $pageDepth = 0) { $this->SetSecurityHeaders(); $this->path = str_repeat('../', $pageDepth); $this->server = ServiceLocator::GetServer(); $resources = Resources::GetInstance(); ExceptionHandler::SetExceptionHandler(new WebExceptionHandler(array($this, 'RedirectToError'))); $this->smarty = new SmartyPage($resources, $this->path); $userSession = ServiceLocator::GetServer()->GetUserSession(); $this->smarty->assign('Charset', $resources->Charset); $this->smarty->assign('CurrentLanguage', $resources->CurrentLanguage); $this->smarty->assign('HtmlLang', $resources->HtmlLang); $this->smarty->assign('HtmlTextDirection', $resources->TextDirection); $appTitle = Configuration::Instance()->GetKey(ConfigKeys::APP_TITLE); $pageTile = $resources->GetString($titleKey); $this->smarty->assign('Title', (empty($appTitle) ? 'Booked' : $appTitle) . (empty($pageTile) ? '' : ' - ' . $pageTile)); $this->smarty->assign('CalendarJSFile', $resources->CalendarLanguageFile); $this->smarty->assign('LoggedIn', $userSession->IsLoggedIn()); $this->smarty->assign('Version', Configuration::VERSION); $this->smarty->assign('Path', $this->path); $this->smarty->assign('ScriptUrl', Configuration::Instance()->GetScriptUrl()); $this->smarty->assign('UserName', !is_null($userSession) ? $userSession->FirstName : ''); $this->smarty->assign('DisplayWelcome', $this->DisplayWelcome()); $this->smarty->assign('UserId', $userSession->UserId); $this->smarty->assign('CanViewAdmin', $userSession->IsAdmin); $this->smarty->assign('CanViewGroupAdmin', $userSession->IsGroupAdmin); $this->smarty->assign('CanViewResourceAdmin', $userSession->IsResourceAdmin); $this->smarty->assign('CanViewScheduleAdmin', $userSession->IsScheduleAdmin); $this->smarty->assign('CanViewResponsibilities', !$userSession->IsAdmin && ($userSession->IsGroupAdmin || $userSession->IsResourceAdmin || $userSession->IsScheduleAdmin)); $allowAllUsersToReports = Configuration::Instance()->GetSectionKey(ConfigSection::REPORTS, ConfigKeys::REPORTS_ALLOW_ALL, new BooleanConverter()); $this->smarty->assign('CanViewReports', $allowAllUsersToReports || $userSession->IsAdmin || $userSession->IsGroupAdmin || $userSession->IsResourceAdmin || $userSession->IsScheduleAdmin); $timeout = Configuration::Instance()->GetKey(ConfigKeys::INACTIVITY_TIMEOUT); if (!empty($timeout)) { $this->smarty->assign('SessionTimeoutSeconds', max($timeout, 1) * 60); } $this->smarty->assign('ShouldLogout', $this->GetShouldAutoLogout()); $this->smarty->assign('CssExtensionFile', Configuration::Instance()->GetKey(ConfigKeys::CSS_EXTENSION_FILE)); $this->smarty->assign('UseLocalJquery', Configuration::Instance()->GetKey(ConfigKeys::USE_LOCAL_JQUERY, new BooleanConverter())); $this->smarty->assign('EnableConfigurationPage', Configuration::Instance()->GetSectionKey(ConfigSection::PAGES, ConfigKeys::PAGES_ENABLE_CONFIGURATION, new BooleanConverter())); $this->smarty->assign('ShowParticipation', !Configuration::Instance()->GetSectionKey(ConfigSection::RESERVATION, ConfigKeys::RESERVATION_PREVENT_PARTICIPATION, new BooleanConverter())); $this->smarty->assign('LogoUrl', 'booked.png'); if (file_exists($this->path . 'img/custom-logo.png')) { $this->smarty->assign('LogoUrl', 'custom-logo.png'); } if (file_exists($this->path . 'img/custom-logo.gif')) { $this->smarty->assign('LogoUrl', 'custom-logo.gif'); } if (file_exists($this->path . 'img/custom-logo.jpg')) { $this->smarty->assign('LogoUrl', 'custom-logo.jpg'); } $this->smarty->assign('CssUrl', 'null-style.css'); if (file_exists($this->path . 'css/custom-style.css')) { $this->smarty->assign('CssUrl', 'custom-style.css'); } $logoUrl = Configuration::Instance()->GetKey(ConfigKeys::HOME_URL); if (empty($logoUrl)) { $logoUrl = $this->path . Pages::UrlFromId($userSession->HomepageId); } $this->smarty->assign('HomeUrl', $logoUrl); }
public function PageLoad() { $this->Set('DefaultTitle', Resources::GetInstance()->GetString('NoTitleLabel')); $this->presenter->SetSearchCriteria(ServiceLocator::GetServer()->GetUserSession()->UserId, ReservationUserLevel::ALL); $this->presenter->PageLoad(); $this->Display('upcoming_reservations.tpl'); }
/** * Update method to register message sending events. * * @access public * @param $args['news_id'] Newsletter identifier refferring to the event. * * @param $args['msg_id'] Message identifier refferring to the event. * @return false if something wrong. * @since 0.6 */ function update(&$args) { jincimport('utility.servicelocator'); $servicelocator = ServiceLocator::getInstance(); $logger = $servicelocator->getLogger(); if (!isset($args['news_id']) || !isset($args['msg_id'])) { return false; } $news_id = (int) $args['news_id']; $msg_id = (int) $args['msg_id']; $dbo =& JFactory::getDBO(); $query = 'UPDATE #__jinc_newsletter SET lastsent = now() ' . 'WHERE id = ' . (int) $news_id; $dbo->setQuery($query); $logger->debug('SentMsgEvent: executing query: ' . $query); if (!$dbo->query()) { $logger->error('SentMsgEvent: error updating last newsletter dispatch date'); return false; } $query = 'UPDATE #__jinc_message SET datasent = now() ' . 'WHERE id = ' . (int) $msg_id; $dbo->setQuery($query); $logger->debug('SentMsgEvent: executing query: ' . $query); if (!$dbo->query()) { $logger->error('SentMsgEvent: error updating last message dispatch date'); return false; } return true; }
public function __construct($user = null) { $this->user = $user; if ($this->user == null) { $this->user = ServiceLocator::GetServer()->GetUserSession(); } }
function setup() { $this->_db = new FakeDatabase(); ServiceLocator::SetDatabase($this->_db); $this->newEncryption = new PasswordEncryption(); $this->oldEncryption = new RetiredPasswordEncryption(); }
/** * @param IReservationViewRepository $reservationViewRepository * @param IReservationAuthorization $authorization * @param IReservationHandler $reservationHandler * @param IUpdateReservationPersistenceService $persistenceService */ public function __construct(IReservationViewRepository $reservationViewRepository, $authorization = null, $reservationHandler = null, $persistenceService = null) { $this->reservationViewRepository = $reservationViewRepository; $this->reservationAuthorization = $authorization == null ? new ReservationAuthorization(PluginManager::Instance()->LoadAuthorization()) : $authorization; $this->persistenceService = $persistenceService == null ? new UpdateReservationPersistenceService(new ReservationRepository()) : $persistenceService; $this->reservationHandler = $reservationHandler == null ? ReservationHandler::Create(ReservationAction::Update, $this->persistenceService, ServiceLocator::GetServer()->GetUserSession()) : $reservationHandler; }
function display($tpl = null) { $layout = $this->getLayout(); if ($layout == 'multisubscription') { $this->newsletters = array(); if (isset($this->mmsg)) { jincimport('utility.servicelocator'); $servicelocator = ServiceLocator::getInstance(); $logger = $servicelocator->getLogger(); jincimport('core.newsletterfactory'); $ninstance = NewsletterFactory::getInstance(); foreach ($this->mmsg as $news_id => $text) { if ($newsletter = $ninstance->loadNewsletter($news_id, true)) { $this->newsletters[$news_id] = $newsletter; } } } } else { $news_id = JRequest::getInt('id', 0); jincimport('core.newsletterfactory'); $ninstance = NewsletterFactory::getInstance(); if ($newsletter = $ninstance->loadNewsletter($news_id, true)) { $this->newsletter = $newsletter; } } parent::display($tpl); }
public function __construct() { parent::__construct(); $userRepository = new UserRepository(); $this->presenter = new ManageReservationsPresenter($this, new ScheduleAdminManageReservationsService(new ReservationViewRepository(), $userRepository, new ReservationAuthorization(PluginManager::Instance()->LoadAuthorization())), new ScheduleAdminScheduleRepository($userRepository, ServiceLocator::GetServer()->GetUserSession()), new ResourceAdminResourceRepository($userRepository, ServiceLocator::GetServer()->GetUserSession()), new AttributeService(new AttributeRepository()), new UserPreferenceRepository()); $this->SetPageId('manage-reservations-schedule-admin'); }
public function ProcessPageLoad() { $this->presenter->PageLoad(); $this->Set('priorities', range(1, 10)); $this->Set('timezone', ServiceLocator::GetServer()->GetUserSession()->Timezone); $this->Display('Admin/manage_announcements.tpl'); }
/** * @param ReservationSeries $reservationSeries * @return void */ public function Notify($reservationSeries) { $resourceAdmins = array(); $applicationAdmins = array(); $groupAdmins = array(); if ($this->SendForResourceAdmins($reservationSeries)) { $resourceAdmins = $this->userViewRepo->GetResourceAdmins($reservationSeries->ResourceId()); } if ($this->SendForApplicationAdmins($reservationSeries)) { $applicationAdmins = $this->userViewRepo->GetApplicationAdmins(); } if ($this->SendForGroupAdmins($reservationSeries)) { $groupAdmins = $this->userViewRepo->GetGroupAdmins($reservationSeries->UserId()); } $admins = array_merge($resourceAdmins, $applicationAdmins, $groupAdmins); if (count($admins) == 0) { // skip if there is nobody to send to return; } $owner = $this->userRepo->LoadById($reservationSeries->UserId()); $resource = $reservationSeries->Resource(); $adminIds = array(); /** @var $admin UserDto */ foreach ($admins as $admin) { $id = $admin->Id(); if (array_key_exists($id, $adminIds) || $id == $owner->Id()) { // only send to each person once continue; } $adminIds[$id] = true; $message = $this->GetMessage($admin, $owner, $reservationSeries, $resource); ServiceLocator::GetEmailService()->Send($message); } }
/** * The newsletter importer. It imports newsletter subscribers from a CSV file. * * @access public * @param integer $newsletter a newsletter object. * @param string $csvfile_name the CSV file name. * @return array containing import results. * @since 0.6 * @see Newsletter */ function ImportFromCSV($newsletter, $csvfile_name) { jincimport('utility.jincjoomlahelper'); jincimport('utility.servicelocator'); $servicelocator = ServiceLocator::getInstance(); $logger = $servicelocator->getLogger(); if (!($handle = @fopen($csvfile_name, "r"))) { $logger->finer('NewsletterImporter: unable to open ' . $csvfile_name); return false; } $result = array(); while (($data = fgetcsv($handle, $this->_LINE_MAX_LENGTH, ",")) !== FALSE) { $logger->finer('NewsletterImporter: importing ' . implode(', ', $data)); $info = $newsletter->getSubscriptionInfo(); $subscriber_info = array(); $attributes = array(); for ($i = 0; $i < count($info); $i++) { $prefix = substr($info[$i], 0, 5); if ($prefix == 'attr_') { $suffix = substr($info[$i], 5); $attributes[$suffix] = isset($data[$i]) ? $data[$i] : ''; } else { $subscriber_info[$info[$i]] = $data[$i]; } } $sub_result = array(); $sub_result['data'] = implode(', ', $subscriber_info); switch ($newsletter->getType()) { case NEWSLETTER_PUBLIC_NEWS: $subscriber_info['noptin'] = true; break; case NEWSLETTER_PRIVATE_NEWS: $user_id = $subscriber_info['user_id']; $user_info = JINCJoomlaHelper::getUserInfo($user_id); if (empty($user_info)) { $user_info = JINCJoomlaHelper::getUserInfoByUsername($user_id); if (empty($user_info)) { $user_info = JINCJoomlaHelper::getUserInfoByUsermail($user_id); if (!empty($user_info)) { $subscriber_info['user_id'] = $user_info['id']; } } else { $subscriber_info['user_id'] = $user_info['id']; } } break; default: break; } if ($newsletter->subscribe($subscriber_info, $attributes)) { $sub_result['result'] = 'OK'; } else { $sub_result['result'] = $newsletter->getError(); } array_push($result, $sub_result); } fclose($handle); return $result; }
/** * @param ReservationItemView $existingReservation * @return bool */ public function Handle(ReservationItemView $existingReservation) { $reservation = $this->repository->LoadById($existingReservation->GetId()); $reservation->ApplyChangesTo(SeriesUpdateScope::ThisInstance); $reservation->Delete(ServiceLocator::GetServer()->GetUserSession()); $this->repository->Delete($reservation); return true; }
public static function Create() { if (ServiceLocator::GetServer()->GetQuerystring(QueryStringKeys::RESPONSE_TYPE) == 'json') { return new ReservationDeleteJsonPage(); } else { return new ReservationDeletePage(); } }
public function __construct() { parent::__construct(); $this->_presenter->SetUserRepository(new GroupAdminUserRepository(new GroupRepository(), ServiceLocator::GetServer()->GetUserSession())); $groupRepository = new GroupAdminGroupRepository(new UserRepository(), ServiceLocator::GetServer()->GetUserSession()); $this->_presenter->SetGroupRepository($groupRepository); $this->_presenter->SetGroupViewRepository($groupRepository); }
public function PageLoad() { $this->presenter->PageLoad(ServiceLocator::GetServer()->GetUserSession()); header("Content-Type: text/Calendar"); header("Content-Disposition: inline; filename=calendar.ics"); $display = new CalendarExportDisplay(); echo $display->Render($this->reservations); }
public function setUp() { $this->_expectedName = FormKeys::FIRST_NAME; $this->_server = new FakeServer(); ServiceLocator::SetServer($this->_server); $this->_smarty = new FakeSmarty(); $this->_smarty->_Value = $this->_expectedValue; }
public function testGetAndSetInstanceDefaultConfig() { $defaultToRevertCfg = ServiceLocator::getInstanceDefaultConfig(); $cfgToTest = array('test1' => mt_rand()); ServiceLocator::setInstanceDefaultConfig($cfgToTest); $cfgToTestReturn = ServiceLocator::getInstanceDefaultConfig(); $this->assertEquals($cfgToTest['test1'], $cfgToTestReturn['test1']); }
/** * Redefine setError method inherited from Joomla! JObject class * * @access public * @since 0.6 */ function setError($error) { jincimport('utility.servicelocator'); $servicelocator = ServiceLocator::getInstance(); $logger = $servicelocator->getLogger(); $logger->finer(get_class($this) . ': ' . JText::_($error)); parent::setError($error); }
function testeReadByCriteria() { $criteria = array(); $criteria[CoordenadaCriteria::RASTREADOR_FK_EQ] = 3; $entityArray = ServiceLocator::getCoordenadaService()->readByCriteria($criteria); foreach ($entityArray as $entity) { echo $entity . "<br>"; } }
public function __construct($titleKey = '', $pageDepth = 1) { parent::__construct($titleKey, $pageDepth); $user = ServiceLocator::GetServer()->GetUserSession(); if (!$user->IsAdmin) { $this->RedirectResume(sprintf("%s%s?%s=%s", $this->path, Pages::LOGIN, QueryStringKeys::REDIRECT, urlencode($this->server->GetUrl()))); die; } }
function testeReadByCriteria() { $criteria = array(); $criteria[UsuarioRastreadorCriteria::USUARIO_FK_EQ] = 7; $entityArray = ServiceLocator::getUsuarioRastreadorService()->readByCriteria($criteria); foreach ($entityArray as $entity) { echo $entity . "<br>"; } }
function testeReadByCriteria() { $criteria = array(); $criteria[UsuarioCriteria::NOME_LK] = "B"; $entityArray = ServiceLocator::getUsuarioService()->readByCriteria($criteria); foreach ($entityArray as $entity) { echo $entity . "<br>"; } }