Hardcode Block
Permalink Browser Info Environment
How can I hardcode this block into a pagetype? I want the pass the fileset as the same as the page name. I tried this:
But get an SQL error.
Loader::model('file_set'); $fs = FileSet::getByName($c->getCollectionName()); $imgal = BlockType::getByHandle('sortable_fancybox_gallery'); $imgal->controller->enableLightbox ='1'; $imgal->controller->thumbWidth = '100'; $imgal->controller->thumbHeight = '100'; $imgal->controller->fullWidth = '800'; $imgal->controller->fullHeight = '600'; $imgal->controller->displayColumns = '5'; $imgal->controller->lightboxTransitionEffect = 'fade'; $imgal->controller->lightboxTitlePosition = 'outside'; $imgal->controller->fsID = $fs; $imgal->render('view');
But get an SQL error.
Type: | Discussion |
---|---|
Status: | New |
Also, you're setting the fsID to the entire $fs variable -- that needs to be just the ID not the whole fileset, so change your second-last line to this:
$imgal->controller->fsID = $fs->fsID;
I changed that line, but I still get the error.
mysql error: [1064: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'AND EXISTS (SELECT * FROM FileVersions fv WHERE fv.fID = fsf.fID AND fv.fvIsAppr' at line 1] in EXECUTE("SELECT fsf.fID, p.position, fsf.fsDisplayOrder FROM FileSetFiles fsf INNER JOIN ( btSortableFancyboxGallery b INNER JOIN btSortableFancyboxGalleryPositions p ON b.bID=p.bID ) ON fsf.fsID=b.fsID AND fsf.fID=p.fID WHERE b.bID = AND EXISTS (SELECT * FROM FileVersions fv WHERE fv.fID = fsf.fID AND fv.fvIsApproved = 1 AND fv.fvType = 1) UNION SELECT fsf.fID, NULL as position, fsf.fsDisplayOrder FROM FileSetFiles fsf LEFT JOIN btSortableFancyboxGallery b ON fsf.fsID=b.fsID WHERE b.bID = AND NOT EXISTS(SELECT * FROM btSortableFancyboxGalleryPositions p WHERE p.bID = AND p.fID = fsf.fID) AND EXISTS (SELECT * FROM FileVersions fv WHERE fv.fID = fsf.fID AND fv.fvIsApproved = 1 AND fv.fvType = 1) ORDER BY (position IS NULL), position, fsDisplayOrder, fID")
mysql error: [1064: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'AND EXISTS (SELECT * FROM FileVersions fv WHERE fv.fID = fsf.fID AND fv.fvIsAppr' at line 1] in EXECUTE("SELECT fsf.fID, p.position, fsf.fsDisplayOrder FROM FileSetFiles fsf INNER JOIN ( btSortableFancyboxGallery b INNER JOIN btSortableFancyboxGalleryPositions p ON b.bID=p.bID ) ON fsf.fsID=b.fsID AND fsf.fID=p.fID WHERE b.bID = AND EXISTS (SELECT * FROM FileVersions fv WHERE fv.fID = fsf.fID AND fv.fvIsApproved = 1 AND fv.fvType = 1) UNION SELECT fsf.fID, NULL as position, fsf.fsDisplayOrder FROM FileSetFiles fsf LEFT JOIN btSortableFancyboxGallery b ON fsf.fsID=b.fsID WHERE b.bID = AND NOT EXISTS(SELECT * FROM btSortableFancyboxGalleryPositions p WHERE p.bID = AND p.fID = fsf.fID) AND EXISTS (SELECT * FROM FileVersions fv WHERE fv.fID = fsf.fID AND fv.fvIsApproved = 1 AND fv.fvType = 1) ORDER BY (position IS NULL), position, fsDisplayOrder, fID")
Oh, I see. Actually, it's not possible to hardcode this block in this way, because it uses more than one table for its data (which can't be accessed via this kind of code as far as I know).
The only alternative I can think of is instead of hardcoding the whole block, hardcode it as a global scrapbook block:
1) Go to Dashboard -> Scrapbook, create a new global scrapbook (if one doesn't already exist), and put a Sortable Fancybox Gallery block in there. After you've saved it, give it a name (name can be anything, but for example let's say it's "Global Fancybox").
2) In your template where you have that code, replace it with this:
It will show that fancybox block on every page that uses that template -- the only difference is you can edit it now via the scrapbook in the dashboard.
The only alternative I can think of is instead of hardcoding the whole block, hardcode it as a global scrapbook block:
1) Go to Dashboard -> Scrapbook, create a new global scrapbook (if one doesn't already exist), and put a Sortable Fancybox Gallery block in there. After you've saved it, give it a name (name can be anything, but for example let's say it's "Global Fancybox").
2) In your template where you have that code, replace it with this:
Block::getByName('Global Fancybox')->display();
It will show that fancybox block on every page that uses that template -- the only difference is you can edit it now via the scrapbook in the dashboard.
I don't know if that approach will work for me. I have a pagetype which is used for about 40 different pages which each have their own file set. I need to display the gallery on each of those pages showing only the images within the page's own fileset. So, the fileset that the gallery uses needs to be dynamic based on the page name.
Hmm... unfortunately I don't think it's possible with the Sortable Fancybox Gallery. You could use the Simple Image Gallery instead, which is basically the same as Sortable Fancybox Gallery but doesn't allow you to drag-and-drop the images. But it only has one database table which means it should work with your hardcoding method:
http://www.concrete5.org/marketplace/addons/simple-image-gallery...
http://www.concrete5.org/marketplace/addons/simple-image-gallery...
I switched over to the Simple image Gallery.
New Error message:
mysql error: [1054: Unknown column 'fsDisplayOrder' in 'order clause'] in EXECUTE("SELECT DISTINCT f.fID, u.uName as fvAuthorName FROM Files f INNER JOIN FileVersions fv ON f.fID = fv.fID LEFT JOIN Users u on u.uID = fv.fvAuthorUID left join FileSearchIndexAttributes on (fv.fID = FileSearchIndexAttributes.fID) where 1=1 and fv.fvType = '1' and fvIsApproved = '1' order by fsDisplayOrder asc, fID asc ")
New Error message:
mysql error: [1054: Unknown column 'fsDisplayOrder' in 'order clause'] in EXECUTE("SELECT DISTINCT f.fID, u.uName as fvAuthorName FROM Files f INNER JOIN FileVersions fv ON f.fID = fv.fID LEFT JOIN Users u on u.uID = fv.fvAuthorUID left join FileSearchIndexAttributes on (fv.fID = FileSearchIndexAttributes.fID) where 1=1 and fv.fvType = '1' and fvIsApproved = '1' order by fsDisplayOrder asc, fID asc ")
What version of Concrete5 are you running?
-----Original Message-----
From: "Concrete5 Community" <discussions@concretecms.com>
Sent: Thursday, October 13, 2011 11:48am
To: concrete@jordanlev.com
Subject: Hardcode Block: Hardcode Block
C5 - 5.4.2.1
Simple Image Gallery - 1.1.2
Simple Image Gallery - 1.1.2
So I uninstalled the package and reinstalled it and now the error has changed to:
Fatal error: Call to a member function getPackageID() on a non-object in /home/tcalw/public_html/concrete/libraries/block_view.php on line 123
This is the code I am using:
Fatal error: Call to a member function getPackageID() on a non-object in /home/tcalw/public_html/concrete/libraries/block_view.php on line 123
This is the code I am using:
Loader::model('file_set'); $fs = FileSet::getByName($c->getCollectionName()); $imgal = BlockType::getByHandle('simple_image_gallery'); $imgal->controller->enableLightbox ='1'; $imgal->controller->thumbWidth = '100'; $imgal->controller->thumbHeight = '100'; $imgal->controller->fullWidth = '800'; $imgal->controller->fullHeight = '600'; $imgal->controller->displayColumns = '5'; $imgal->controller->lightboxTransitionEffect = 'fade'; $imgal->controller->lightboxTitlePosition = 'outside'; $imgal->controller->fsID = $fs->fsID; $imgal->render('view');
Uhh... sorry, but I unfortunately have no idea why it's giving that error. Try uninstalling Simple Image Gallery, clearing your site cache (via Dashboard -> Sitewide Settings), then reinstalling it.
Otherwise, sorry I don't know how to make it work :(
Otherwise, sorry I don't know how to make it work :(
I finally got this to work, so thanks for getting me started...
1. You need to include the required simple image gallery headers manually in your page <head> (I copied the details from another page that had a Simple Image Gallery set up):
<link rel="stylesheet" type="text/css" href="/packages/simple_image_gallery/blocks/simple_image_gallery/view.css?v=9546acbe14fd90a5ae7de0f5fe91fbc9" />
<link rel="stylesheet" type="text/css" href="/packages/simple_image_gallery/blocks/simple_image_gallery/fancybox/jquery.fancybox-1.3.1.css?v=9546acbe14fd90a5ae7de0f5fe91fbc9" />
<script type="text/javascript" src="/packages/simple_image_gallery/blocks/simple_image_gallery/fancybox/jquery.fancybox-1.3.1.pack.js?v=9546acbe14fd90a5ae7de0f5fe91fbc9"></script>
2. Modify line 65 of Simple Image Controller - /packages/simple_image_gallery/blocks/simple_image_gallery/controller.php
/* MDE20111129 added test condition for when getBlockObject is not an object ie. the case when we render a BlockType of simple_image_gallery */
if (is_object($this->getBlockObject())) {
$bv->setBlockObject($this->getBlockObject());
$css_output_object = $html->css($bv->getBlockURL() . '/view.css'); //Pick up theme overrides
$this->set('inline_view_css_url', $css_output_object->file);
}
3. Insert 2 lines (at line 4)to /packages/simple_image_gallery/blocks/simple_image_gallery/view.php (displayColumns was not passing through, getting divide by zero?)
//MDE20111129 - BlockType->controller->parameters not passing through?
if ($displayColumns == 0) { $displayColumns =3; }
$enableLightbox=1;
There's no doubt better ways to do all of this, but this is my hack to get it going for now....Good Luck
1. You need to include the required simple image gallery headers manually in your page <head> (I copied the details from another page that had a Simple Image Gallery set up):
<link rel="stylesheet" type="text/css" href="/packages/simple_image_gallery/blocks/simple_image_gallery/view.css?v=9546acbe14fd90a5ae7de0f5fe91fbc9" />
<link rel="stylesheet" type="text/css" href="/packages/simple_image_gallery/blocks/simple_image_gallery/fancybox/jquery.fancybox-1.3.1.css?v=9546acbe14fd90a5ae7de0f5fe91fbc9" />
<script type="text/javascript" src="/packages/simple_image_gallery/blocks/simple_image_gallery/fancybox/jquery.fancybox-1.3.1.pack.js?v=9546acbe14fd90a5ae7de0f5fe91fbc9"></script>
2. Modify line 65 of Simple Image Controller - /packages/simple_image_gallery/blocks/simple_image_gallery/controller.php
/* MDE20111129 added test condition for when getBlockObject is not an object ie. the case when we render a BlockType of simple_image_gallery */
if (is_object($this->getBlockObject())) {
$bv->setBlockObject($this->getBlockObject());
$css_output_object = $html->css($bv->getBlockURL() . '/view.css'); //Pick up theme overrides
$this->set('inline_view_css_url', $css_output_object->file);
}
3. Insert 2 lines (at line 4)to /packages/simple_image_gallery/blocks/simple_image_gallery/view.php (displayColumns was not passing through, getting divide by zero?)
//MDE20111129 - BlockType->controller->parameters not passing through?
if ($displayColumns == 0) { $displayColumns =3; }
$enableLightbox=1;
There's no doubt better ways to do all of this, but this is my hack to get it going for now....Good Luck
And can you show me the SQL error you're getting?