Last active
December 12, 2015 03:48
-
-
Save crisu83/4709315 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* TbThumbnails class file. | |
* @author Christoffer Niska <christoffer.niska@gmail.com> | |
* @copyright Copyright © Christoffer Niska 2013- | |
* @license http://www.opensource.org/licenses/bsd-license.php New BSD License | |
* @package bootstrap.widgets | |
*/ | |
Yii::import('bootstrap.widgets.TbListView'); | |
/** | |
* Bootstrap thumbnails widget. | |
* http://twitter.github.com/bootstrap/components.html#thumbnails | |
*/ | |
class TbThumbnails extends TbListView | |
{ | |
/** | |
* @var mixed a PHP expression that is evaluated for every item and whose result is used | |
* as the URL for the thumbnail. | |
*/ | |
public $url; | |
/** | |
* @var integer the number of grid columns that the thumbnails spans over. | |
*/ | |
public $span; | |
/** | |
* Renders the data items for the view. | |
* Each item is corresponding to a single data model instance. | |
*/ | |
public function renderItems() | |
{ | |
$thumbnails = array(); | |
$data = $this->dataProvider->getData(); | |
if (!empty($data)) | |
{ | |
$owner = $this->getOwner(); | |
$render = $owner instanceof CController ? 'renderPartial' : 'render'; | |
foreach ($data as $i => $item) | |
{ | |
$thumbnail = array(); | |
$data = $this->viewData; | |
$data['index'] = $i; | |
$data['data'] = $item; | |
$data['widget'] = $this; | |
$thumbnail['content'] = $owner->$render($this->itemView, $data, true); | |
if (isset($this->url)) | |
$thumbnail['url'] = $this->evaluateExpression($this->url, array('data' => $item)); | |
if (isset($this->span)) | |
$thumbnail['span'] = $this->span; | |
$thumbnails[] = $thumbnail; | |
} | |
echo TbHtml::thumbnails($thumbnails, $this->htmlOptions); | |
} | |
else | |
$this->renderEmptyText(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment