Ejemplo n.º 1
0
 /**
  * get user instance which last updated database entry of metafile
  * the updater can be changed
  *
  * @return NULL|\vxPHP\User\User
  */
 public function getUpdatedBy()
 {
     if (is_null($this->updatedBy)) {
         // no user was stored with instance
         if (empty($this->data['updatedBy'])) {
             return NULL;
         } else {
             $this->createdBy = User::getInstance($this->data['updatedBy']);
         }
     }
     return $this->updatedBy;
 }
Ejemplo n.º 2
0
 /**
  * creates a meta file based on filesystem file
  * @return MetaFile
  * @throws FilesystemFileException
  */
 public function createMetaFile()
 {
     $db = Application::getInstance()->getDb();
     if (count($db->doPreparedQuery("\n\t\t\tSELECT\n\t\t\t\tf.filesID\n\t\t\tFROM\n\t\t\t\tfiles f\n\t\t\t\tINNER JOIN folders fo ON fo.foldersID = f.foldersID\n\t\t\tWHERE\n\t\t\t\tf.File  COLLATE utf8_bin = ? AND\n\t\t\t\tfo.Path COLLATE utf8_bin = ?\n\t\t\tLIMIT 1", array($this->filename, $this->folder->getRelativePath())))) {
         throw new FilesystemFileException("Metafile '{$this->filename}' in '{$this->folder->getRelativePath()}' already exists.", FilesystemFileException::METAFILE_ALREADY_EXISTS);
     }
     $mf = $this->folder->createMetaFolder();
     $user = User::getSessionUser();
     if (!($filesID = $db->insertRecord('files', array('foldersID' => $mf->getId(), 'File' => $this->filename, 'Mimetype' => $this->getMimetype(), 'createdBy' => is_null($user) ? NULL : $user->getAdminId())))) {
         throw new FilesystemFileException("Could not create metafile for '{$this->filename}'.", FilesystemFileException::METAFILE_CREATION_FAILED);
     } else {
         $mf = MetaFile::getInstance(NULL, $filesID);
         FileEvent::create(FileEvent::AFTER_METAFILE_CREATE, $this)->trigger();
         return $mf;
     }
 }
Ejemplo n.º 3
0
 /**
  * fallback method for authenticating single menu entry access on observe_table/observe_row level
  * positive authentication if auth_parameter contains a table name found in the admins table access setting
  *
  * @param MenuEntry $e
  * @return boolean
  */
 protected function authenticateMenuEntry(MenuEntry $e)
 {
     $p = $e->getAuthParameters();
     if (empty($p)) {
         return FALSE;
     }
     $admin = User::getSessionUser();
     if (!$admin) {
         return FALSE;
     }
     $tables = preg_split('/\\s*,\\s*/', trim($p));
     return !array_intersect($tables, $admin->getTableAccess());
 }
Ejemplo n.º 4
0
 /**
  * create Article instance from data supplied in $articleData
  *
  * @param array $articleData
  * @return Article
  */
 private static function createInstance(array $articleData)
 {
     $article = new self();
     // set identification
     $article->alias = $articleData['Alias'];
     $article->id = $articleData['articlesID'];
     // set category
     $article->category = ArticleCategory::getInstance($articleData['articlecategoriesID']);
     /*
      * set admin information (cast type explicitly to ensure lookup by adminID)
      * exceptions with invalid user ids are caught and ignored
      */
     if ($articleData['createdBy']) {
         try {
             $article->createdBy = User::getInstance((int) $articleData['createdBy']);
         } catch (\InvalidArgumentException $e) {
         } catch (UserException $e) {
         }
     }
     if ($articleData['updatedBy']) {
         try {
             $article->updatedBy = User::getInstance((int) $articleData['updatedBy']);
         } catch (\InvalidArgumentException $e) {
         } catch (UserException $e) {
         }
     }
     if ($articleData['publishedBy']) {
         try {
             $article->publishedBy = User::getInstance((int) $articleData['publishedBy']);
         } catch (\InvalidArgumentException $e) {
         } catch (UserException $e) {
         }
     }
     // set date information
     if (!empty($articleData['Display_from'])) {
         $article->displayFrom = new \DateTime($articleData['Display_from']);
     }
     if (!empty($articleData['Display_until'])) {
         $article->displayUntil = new \DateTime($articleData['Display_until']);
     }
     if (!empty($articleData['Article_Date'])) {
         $article->articleDate = new \DateTime($articleData['Article_Date']);
     }
     if (!empty($articleData['firstCreated'])) {
         $article->firstCreated = new \DateTime($articleData['firstCreated']);
     }
     if (!empty($articleData['lastUpdated'])) {
         $article->lastUpdated = new \DateTime($articleData['lastUpdated']);
     }
     // flags and sort
     $article->published = $articleData['published'];
     $article->customFlags = $articleData['customFlags'];
     $article->customSort = $articleData['customSort'];
     // set various text fields
     $article->setHeadline($articleData['Headline']);
     $article->setData($articleData);
     // backup values to check whether record was changed
     $article->previouslySavedValues = new \stdClass();
     $article->previouslySavedValues->headline = $article->headline;
     $article->previouslySavedValues->category = $article->category;
     $article->previouslySavedValues->data = $article->data;
     $article->previouslySavedValues->displayFrom = $article->displayFrom;
     $article->previouslySavedValues->displayUntil = $article->displayUntil;
     $article->previouslySavedValues->articleDate = $article->articleDate;
     $article->previouslySavedValues->published = $article->published;
     $article->previouslySavedValues->customFlags = $article->customFlags;
     $article->previouslySavedValues->customSort = $article->customSort;
     return $article;
 }
Ejemplo n.º 5
0
 /**
  * check whether authentication level required by route is met by user
  *
  * @param Route $route
  * @param User $user
  * @return boolean
  */
 private static function authenticateRoute(Route $route, User $user = NULL)
 {
     $auth = $route->getAuth();
     if (!is_null($auth)) {
         if (is_null($user) && !($user = User::getSessionUser())) {
             return FALSE;
         }
         if (!$user->isAuthenticated()) {
             return FALSE;
         }
         // UserAbstract::AUTH_OBSERVE_TABLE and UserAbstract::AUTH_OBSERVE_ROW are handled by controller
         return $auth >= $user->getPrivilegeLevel();
     }
     return TRUE;
 }
Ejemplo n.º 6
0
    /**
     * get list of users belonging to given admingroup
     *
     * @param string $admingroup_alias
     * @param callback $callBackSort
     * @throws UserException
     *
     * @return array [User]
     */
    public static function getUsersBelongingToGroup($admingroup_alias, $callBackSort = NULL)
    {
        $users = array();
        $rows = Application::getInstance()->getDb()->doPreparedQuery('
			SELECT
				adminID
			FROM
				admin a
				INNER JOIN admingroups ag ON a.admingroupsID = ag.admingroupsID
			WHERE
				UPPER(ag.alias) = ?
			', array(strtoupper($admingroup_alias)));
        foreach ($rows as $r) {
            $users[] = User::getInstance($r['adminID']);
        }
        if (is_null($callBackSort)) {
            return $users;
        } else {
            if (is_callable($callBackSort)) {
                usort($users, $callBackSort);
                return $users;
            } else {
                if (is_callable("UserAbstract::{$callBackSort}")) {
                    usort($users, "UserAbstract::{$callBackSort}");
                    return $users;
                } else {
                    throw new UserException("'{$callBackSort}' is not callable.", UserException::SORT_CALLBACK_NOT_CALLABLE);
                }
            }
        }
    }