Esempio n. 1
0
 /**
  * @param AbstractView $view
  */
 public function __construct(AbstractView $view = null)
 {
     $config = ClosureFactory::getInstance()->get('config');
     $this->session = ClosureFactory::getInstance()->get('session', ['type' => 'cache', 'param' => ['session_cache' => $config->get('session_cache')]], true);
     $this->authentification = ClosureFactory::getInstance()->get('authentication-service', [], true);
     parent::__construct($view);
 }
Esempio n. 2
0
 public function endAction()
 {
     if (!$this->loadUserFromSession()) {
         $this->errorMessage('login-needed', _('please login!'), null, ['logout' => true]);
         return;
     }
     $request = ClosureFactory::getInstance()->get('request-handler', []);
     if (!$request->getRaw()) {
         $this->errorMessage('error', _('no request data'));
         return;
     }
     /**
      * @var EntityManager $em
      */
     $em = ClosureFactory::getInstance()->get('entity-manager');
     /**
      * @var Session $session
      */
     $session = $em->findOneBy(new Session(), ['id' => (int) $request->getRaw()->get('sessionId')]);
     if (!$session->getId()) {
         $this->errorMessage('error', _('no session found'));
         return;
     }
     $endTime = new \DateTime('now');
     $startTime = new \DateTime($session->getStartTime());
     $diff = $startTime->diff($endTime);
     $session->setEndTime($endTime->format('Y-m-d H:i:s'));
     $transformer = new DateDiffToDecimalTime();
     $session->setTimeDiff($transformer->transform($diff));
     if ($em->persist($session)) {
         $this->successMessage('session-ended', _('Session successfully ended!'), null, $session);
     } else {
         $this->errorMessage('session-end-failed', _('Session could not be ended!'));
     }
 }
 /**
  * @param string $username
  *
  * @return null
  */
 public function getUserByUsername($username)
 {
     if (!$username) {
         return null;
     }
     $em = ClosureFactory::getInstance()->get('entity-manager');
     return $em->findOneBy(new \timetracker\app\module\user\model\User(), ['name' => $username]);
 }
Esempio n. 4
0
 public function createTaskAction()
 {
     if (!$this->loadUserFromSession()) {
         $this->errorMessage('login-needed', _('please login!'), null, ['logout' => true]);
         return;
     }
     $request = ClosureFactory::getInstance()->get('request-handler', []);
     if (!$request->getRaw()) {
         $this->errorMessage('error', _('no request data'));
         return;
     }
     $taskName = $request->getRaw()->get('task_name');
     if (!$taskName) {
         $this->errorMessage('error', _('no project id has been given'));
         return;
     }
     /**
      * @var EntityManager $em
      */
     $em = ClosureFactory::getInstance()->get('entity-manager');
     $task = new TaskModel();
     $task->setName($taskName);
     $task->setPublic((bool) $request->getRaw()->get('public'));
     $task->setCreated(date('Y-m-d H:i:s'));
     $task->setModified(date('Y-m-d H:i:s'));
     if (!$em->persist($task)) {
         $this->errorMessage('error', _('task could not be created'));
         return;
     }
     // if it's mapped to a user it will be created accordingly
     if ($request->getRaw()->get('project_id')) {
         $map = new UserProjectTaskMap();
         $map->setUserId($this->getUser()->getUser()->getId());
         $map->setProjectId((int) $request->getRaw()->get('project_id'));
         $map->setTaskId($task->getId());
         $em->persist($map);
     }
     $this->successMessage('success', '', null, $task);
 }
 /**
  * @test
  */
 public function checkIfPseudoSingeltonIsWorking()
 {
     $di = ClosureFactory::getInstance();
     $di->set('my-test', function () {
         return new \stdClass();
     });
     $asSingelton = $di->get('my-test', [], true);
     $asSingelton2 = $di->get('my-test', [], true);
     self::assertEquals(true, $asSingelton === $asSingelton2);
 }
Esempio n. 6
0
 public function createAction()
 {
     $request = ClosureFactory::getInstance()->get('request-handler', []);
     if (!$request->getRaw()) {
         $this->errorMessage('user-create-failed', _('Please enter username and Password!'));
         return;
     }
     $username = $request->getRaw()->get('username');
     $clearTextPassword = $request->getRaw()->get('password');
     if (!$username || !$clearTextPassword) {
         $this->errorMessage('user-create-failed', _('Please enter username and Password!'));
         return;
     }
     /**
      * @var EntityManager $em
      */
     $em = ClosureFactory::getInstance()->get('entity-manager', []);
     $user = $em->findOneBy(new UserModel(), ['username' => $username]);
     /**
      * @var UserModel $user
      */
     if ($user !== null) {
         $this->errorMessage('user-already-exists', _('The user already exists!'));
         return;
     }
     $userNew = new UserModel();
     $userNew->setName($username);
     $userNew->setActive(1);
     $userNew->setPassword(password_hash($clearTextPassword, PASSWORD_DEFAULT));
     $userNew->setCreated(date('Y-m-d H:i:s'));
     if ($em->persist($userNew)) {
         $this->successMessage('user-creation-success', _('The user was successfully created!'));
     } else {
         $this->errorMessage('user-creation-failed', _('The user could not be created!'));
     }
 }
Esempio n. 7
0
 public function deleteAction()
 {
     if (!$this->loadUserFromSession()) {
         $this->errorMessage('login-needed', _('please login!'), null, ['logout' => true]);
         return;
     }
     $request = ClosureFactory::getInstance()->get('request-handler', []);
     if (!$request->getRaw()) {
         $this->errorMessage('creation-failed', _('Please enter project-name!'));
         return;
     }
     $projectId = (int) $request->getRaw()->get('projectId');
     /**
      * @var EntityManager $em
      */
     $em = ClosureFactory::getInstance()->get('entity-manager');
     $project = $em->findOneBy(new Project(), ['id' => $projectId]);
     if (!$project->getId()) {
         $this->errorMessage('project-deletion-failed', _('Project-name already exists!'));
         return;
     }
     if (!$em->delete($project)) {
         $this->successMessage('project-deleted', _('Project successfully deleted'));
     } else {
         $this->errorMessage('project-deletion-failed', _('Project could not be deleted'));
     }
 }
 /**
  * @param AbstractModel $model
  * @param MySQLTableData $tableData
  *
  * @return array
  */
 public function prepareModelData(AbstractModel $model, MySQLTableData $tableData)
 {
     $data = $columData = [];
     $keyList = $tableData->getPrimaryKey();
     $reflection = new \ReflectionClass($model);
     foreach ($tableData->getColumnNames() as $column) {
         try {
             $reflectedProperty = $reflection->getProperty($column);
             $reflectedProperty->setAccessible(true);
             $columData = ['value' => $reflectedProperty->getValue($model), 'name' => $column];
             if (in_array($column, $keyList, false)) {
                 array_merge($columData, ['KEY' => true]);
             }
             $data[] = $columData;
         } catch (\Exception $e) {
             $logger = \chilimatic\lib\di\ClosureFactory::getInstance()->get('error-log');
             $logger->error($e->getMessage(), $e->getTraceAsString());
         }
     }
     return $data;
 }
}, 'template-resolver' => function ($setting = []) {
    return new chilimatic\lib\view\resolver\templatePathStack($setting);
}, 'cache' => function ($setting = []) {
    return chilimatic\lib\cache\engine\CacheFactory::make($setting['type'], isset($setting['setting']) ? $setting['setting'] : null);
}, 'entity-manager' => function ($setting = []) {
    $connection = new \chilimatic\lib\database\sql\mysql\connection\MySQLConnection(new \chilimatic\lib\database\sql\mysql\connection\MySQLConnectionSettings($setting['host'], $setting['username'], $setting['password'], isset($setting['database']) ? $setting['database'] : null, isset($setting['port']) ? $setting['port'] : null, isset($setting['charset']) ? $setting['charset'] : null));
    $queryBuilder = \chilimatic\lib\di\ClosureFactory::getInstance()->get('query-builder', ['db' => new \chilimatic\lib\database\sql\mysql\Mysql($connection)]);
    $em = new \chilimatic\lib\database\sql\orm\EntityManager(new \chilimatic\lib\database\sql\mysql\Mysql($connection), $queryBuilder);
    return $em;
}, 'query-builder' => function ($setting = []) {
    $config = \chilimatic\lib\di\ClosureFactory::getInstance()->get('config');
    $cacheType = empty($setting['cache']['type']) ? $config->get('query_builder_cache') : $setting['cache']['type'];
    $cacheSettings = empty($setting['cache']['setting']) ? $config->get('query_builder_cache_setting') : $setting['cache']['setting'];
    $db = empty($setting['db']) ? $this->get('db') : $setting['db'];
    $queryBuilder = new \chilimatic\lib\database\sql\mysql\querybuilder\MySQLQueryBuilder(\chilimatic\lib\di\ClosureFactory::getInstance()->get('cache', ['type' => $cacheType, 'setting' => $cacheSettings]), $db);
    return $queryBuilder;
}, 'error-handler' => function ($setting = []) {
    return new \chilimatic\lib\error\Handler(new \chilimatic\lib\log\client\PrintOutWebTemplate());
}, 'authentication-service' => function ($setting = []) {
    return new \timetracker\app\module\user\service\Authentification();
}, 'log' => function ($setting = []) {
    return new \chilimatic\lib\log\client\ToFile(new \chilimatic\lib\formatter\Log());
}, 'error-log' => function ($setting = []) {
    /**
     * @var \chilimatic\lib\log\client\ToFile $logger
     */
    $logger = \chilimatic\lib\di\ClosureFactory::getInstance()->get('log');
    $config = \chilimatic\lib\di\ClosureFactory::getInstance()->get('config');
    $logger->setTargetFile($config->get('error_log_path') . DIRECTORY_SEPARATOR . "error-" . date('Y-m-d') . ".log");
    return $logger;
}];
Esempio n. 10
0
<?php

date_default_timezone_set('Europe/Vienna');
set_exception_handler(function ($e) {
    echo $e->getMessage();
    echo $e->getTraceAsString();
});
try {
    $dispatcher = \chilimatic\lib\di\ClosureFactory::getInstance(realpath(APPLICATION_PATH . '/app/config/serviceCollection.php'));
    /**
     * Create the config
     */
    $config = $dispatcher->get('config', ['type' => 'File', \chilimatic\lib\config\File::CONFIG_PATH_INDEX => APPLICATION_PATH . '/app/config/']);
    /**
     * Set default timezone based on the config
     */
    date_default_timezone_set((string) $config->get('default_timezone'));
    if (!$config->get((string) 'document_root')) {
        $config->set((string) 'document_root', (string) APPLICATION_PATH);
    }
    $config->set('app_root', (string) $config->get('document_root') . (string) "/app");
    $config->set('lib_root', (string) $config->get('document_root') . (string) $config->get('lib_dir'));
    if (!isset($_SERVER['SHELL'])) {
        /**
         * set the current protocol SSL or normal
         */
        $config->set('protocol', (string) ($_SERVER['SERVER_PORT'] == '443') ? 'https://' : 'http://');
        /**
         * set the current default url
         */
        $config->set('base_url', (string) $config->get('protocol') . (string) $_SERVER['HTTP_HOST']);
Esempio n. 11
0
 /**
  * @throws \ErrorException
  */
 public function indexAction()
 {
     $em = \chilimatic\lib\di\ClosureFactory::getInstance()->get('entity-manager');
     $phtml = new \chilimatic\lib\view\PHtml();
     $this->getView()->response = ['data' => ['title' => 'Settings', 'jsController' => 'SettingManager', 'content' => $phtml->render(\chilimatic\lib\config\Config::get('document_root') . '/app/view/admin/user/settings.phtml')], 'call' => 'initWindow'];
 }