Beispiel #1
0
 /**
  * @deprecated Use \GalleryCreatorAlbumsModel::getChildAlbums() instead
  * @param $parentId
  * @param string $strSorting
  * @param null $iterationDepth
  * @return array
  */
 public static function getChildAlbums($parentId, $strSorting = '', $iterationDepth = null)
 {
     return \GalleryCreatorAlbumsModel::getChildAlbums($parentId, $strSorting = '', $iterationDepth);
 }
    /**
     * Input field callback for the album preview thumb select
     * list each image of the album (and child-albums)
     * @return string
     */
    public function inputFieldCbThumb()
    {
        $objAlbum = GalleryCreatorAlbumsModel::findByPk(Input::get('id'));
        // Save input
        if (Input::post('FORM_SUBMIT') == 'tl_gallery_creator_albums') {
            if (Input::post('thumb') == intval(Input::post('thumb'))) {
                $objAlbum->thumb = Input::post('thumb');
                $objAlbum->save();
            }
        }
        // Generate picture list
        $html = '<div class="preview_thumb">';
        $html .= '<h3><label for="ctrl_thumb">' . $GLOBALS['TL_LANG']['tl_gallery_creator_albums']['thumb']['0'] . '</label></h3>';
        $html .= '<p>' . $GLOBALS['TL_LANG']['MSC']['dragItemsHint'] . '</p>';
        $html .= '<ul id="previewThumbList">';
        $objPicture = $this->Database->prepare('SELECT * FROM tl_gallery_creator_pictures WHERE pid=? ORDER BY sorting')->execute(Input::get('id'));
        $arrData = array();
        while ($objPicture->next()) {
            $arrData[] = array('uuid' => $objPicture->uuid, 'id' => $objPicture->id);
        }
        // Get all child albums
        $arrSubalbums = GalleryCreatorAlbumsModel::getChildAlbums(Input::get('id'));
        if (count($arrSubalbums)) {
            $arrData[] = array('uuid' => 'beginn_childalbums', 'id' => '');
            $objPicture = $this->Database->execute("SELECT * FROM tl_gallery_creator_pictures WHERE pid IN (" . implode(',', $arrSubalbums) . ") ORDER BY id");
            while ($objPicture->next()) {
                $arrData[] = array('uuid' => $objPicture->uuid, 'id' => $objPicture->id);
            }
        }
        foreach ($arrData as $arrItem) {
            $uuid = $arrItem['uuid'];
            $id = $arrItem['id'];
            if ($uuid == 'beginn_childalbums') {
                $html .= '</ul><ul id="childAlbumsList">';
                continue;
            }
            $objFileModel = FilesModel::findByUuid($uuid);
            if ($objFileModel !== null) {
                if (file_exists(TL_ROOT . '/' . $objFileModel->path)) {
                    $objFile = new \File($objFileModel->path);
                    $src = 'placeholder.png';
                    if ($objFile->height <= $GLOBALS['TL_CONFIG']['gdMaxImgHeight'] && $objFile->width <= $GLOBALS['TL_CONFIG']['gdMaxImgWidth']) {
                        $src = Image::get($objFile->path, 80, 60, 'center_center');
                    }
                    $checked = $objAlbum->thumb == $id ? ' checked' : '';
                    $class = $checked != '' ? ' class="checked"' : '';
                    $html .= '<li' . $class . ' data-id="' . $id . '" title="' . specialchars($objFile->name) . '"><input type="radio" name="thumb" value="' . $id . '"' . $checked . '>' . \Image::getHtml($src, $objFile->name) . '</li>' . "\r\n";
                }
            }
        }
        $html .= '</ul>';
        $html .= '</div>';
        // Add javascript
        $script = '
<script>
	window.addEvent("domready", function() {
		$$(".preview_thumb input").addEvent("click", function(){
		    $$(".preview_thumb li").removeClass("checked");
		    this.getParent("li").addClass("checked");
		});

		/** sort album with drag and drop */
		new Sortables("#previewThumbList", {
            onComplete: function(){
                var ids = [];
                $$("#previewThumbList > li").each(function(el){
                    ids.push(el.getProperty("data-id"));
                });
                // ajax request
                if(ids.length > 0){
                    var myRequest = new Request({
                    url: document.URL + "&isAjaxRequest=true&pictureSorting=" + ids.join(),
                    method: "get"
                });
                // fire request (resort album)
                myRequest.send();
                }
            }
		});
	});
</script>
';
        // Return html
        return $html . $script;
    }