Exemplo n.º 1
0
 /**
  * revise tables
  * @param $albumId
  * @param bool $blnCleanDb
  */
 public static function reviseTables($albumId, $blnCleanDb = false)
 {
     $_SESSION['GC_ERROR'] = array();
     //Upload-Verzeichnis erstellen, falls nicht mehr vorhanden
     new \Folder(GALLERY_CREATOR_UPLOAD_PATH);
     // Get album model
     $objAlbum = \MCupic\GalleryCreatorAlbumsModel::findByPk($albumId);
     if ($objAlbum === null) {
         return;
     }
     // Check for valid album owner
     $objUser = \UserModel::findByPk($objAlbum->owner);
     if ($objUser !== null) {
         $owner = $objUser->name;
     } else {
         $owner = "no-name";
     }
     $objAlbum->owners_name = $owner;
     $objAlbum->save();
     // Check for valid pid
     if ($objAlbum->pid > 0) {
         $objParentAlb = $objAlbum->getRelated('pid');
         if ($objParentAlb === null) {
             $objAlbum->pid = null;
             $objAlbum->save();
         }
     }
     if (\Database::getInstance()->fieldExists('path', 'tl_gallery_creator_pictures')) {
         // Datensaetzen ohne gültige uuid über den Feldinhalt path versuchen zu "retten"
         $objPictures = \GalleryCreatorPicturesModel::findByPid($albumId);
         if ($objPictures !== null) {
             while ($objPictures->next()) {
                 // Get parent album
                 $objFile = \FilesModel::findByUuid($objPictures->uuid);
                 if ($objFile === null) {
                     if ($objPictures->path != '') {
                         if (is_file(TL_ROOT . '/' . $objPictures->path)) {
                             $objModel = \Dbafs::addResource($objPictures->path);
                             if (\Validator::isUuid($objModel->uuid)) {
                                 $objPictures->uuid = $objModel->uuid;
                                 $objPictures->save();
                                 continue;
                             }
                         }
                     }
                     if ($blnCleanDb !== false) {
                         $msg = ' Deleted Datarecord with ID ' . $objPictures->id . '.';
                         $_SESSION['GC_ERROR'][] = $msg;
                         $objPictures->delete();
                     } else {
                         //show the error-message
                         $path = $objPictures->path != '' ? $objPictures->path : 'unknown path';
                         $_SESSION['GC_ERROR'][] = sprintf($GLOBALS['TL_LANG']['ERR']['link_to_not_existing_file_1'], $objPictures->id, $path, $objAlbum->alias);
                     }
                 } elseif (!is_file(TL_ROOT . '/' . $objFile->path)) {
                     // If file has an entry in Dbafs, but doesn't exist on the server anymore
                     if ($blnCleanDb !== false) {
                         $msg = 'Deleted Datarecord with ID ' . $objPictures->id . '.';
                         $_SESSION['GC_ERROR'][] = $msg;
                         $objPictures->delete();
                     } else {
                         $_SESSION['GC_ERROR'][] = sprintf($GLOBALS['TL_LANG']['ERR']['link_to_not_existing_file_1'], $objPictures->id, $objFile->path, $objAlbum->alias);
                     }
                 } else {
                     // Pfadangaben mit tl_files.path abgleichen (Redundanz)
                     if ($objPictures->path != $objFile->path) {
                         $objPictures->path = $objFile->path;
                         $objPictures->save();
                     }
                 }
             }
         }
     }
     /**
      * Sorgt dafuer, dass in tl_content im Feld gc_publish_albums keine verwaisten AlbumId's vorhanden sind
      * Prueft, ob die im Inhaltselement definiertern Alben auch noch existieren.
      * Wenn nein, werden diese aus dem Array entfernt.
      */
     $objCont = \Database::getInstance()->prepare('SELECT id, gc_publish_albums FROM tl_content WHERE type=?')->execute('gallery_creator');
     while ($objCont->next()) {
         $newArr = array();
         $arrAlbums = unserialize($objCont->gc_publish_albums);
         if (is_array($arrAlbums)) {
             foreach ($arrAlbums as $AlbumID) {
                 $objAlb = \Database::getInstance()->prepare('SELECT id FROM tl_gallery_creator_albums WHERE id=?')->limit('1')->execute($AlbumID);
                 if ($objAlb->next()) {
                     $newArr[] = $AlbumID;
                 }
             }
         }
         \Database::getInstance()->prepare('UPDATE tl_content SET gc_publish_albums=? WHERE id=?')->execute(serialize($newArr), $objCont->id);
     }
 }
 /**
  * sortBy  - save_callback
  * @param $varValue
  * @param \Contao\DataContainer $dc
  * @return string
  */
 public function saveCbSortAlbum($varValue, \Contao\DataContainer $dc)
 {
     if ($varValue == 'custom') {
         return $varValue;
     }
     $objPictures = GalleryCreatorPicturesModel::findByPid($dc->id);
     if ($objPictures === null) {
         return 'custom';
     }
     $files = array();
     $auxDate = array();
     while ($objPictures->next()) {
         $oFile = FilesModel::findByUuid($objPictures->uuid);
         $objFile = new \File($oFile->path, true);
         $files[$oFile->path] = array('id' => $objPictures->id);
         $auxDate[] = $objFile->mtime;
     }
     switch ($varValue) {
         case 'custom':
             break;
         case 'name_asc':
             uksort($files, 'basename_natcasecmp');
             break;
         case 'name_desc':
             uksort($files, 'basename_natcasercmp');
             break;
         case 'date_asc':
             array_multisort($files, SORT_NUMERIC, $auxDate, SORT_ASC);
             break;
         case 'date_desc':
             array_multisort($files, SORT_NUMERIC, $auxDate, SORT_DESC);
             break;
     }
     $sorting = 0;
     foreach ($files as $arrFile) {
         $sorting += 10;
         $objPicture = GalleryCreatorPicturesModel::findByPk($arrFile['id']);
         $objPicture->sorting = $sorting;
         $objPicture->save();
     }
     // return default value
     return 'custom';
 }