1
0

Worked on Programs/Index page

This commit is contained in:
2014-05-28 17:19:57 +02:00
parent e8f7c5d093
commit b5fd33e012
17 changed files with 456 additions and 401 deletions

View File

@@ -22,7 +22,7 @@ class ProgramHelper {
$criteria = new CDbCriteria;
$criteria->order = "add_date DESC";
$criteria->limit = 8;
$criteria->condition = "Sterne=4 AND visible=1 AND enabled=1";
$criteria->condition = "Sterne >= 4 AND visible=1 AND enabled=1";
foreach (Program::model()->findAll($criteria) as $row) {
$dropDownModels[] = $row;
}

View File

@@ -0,0 +1,20 @@
<?php
class ThumbnailPreview extends CWidget {
public $caption = '';
public $description = '';
public $category = '';
public $language = [];
public $starcount = 0;
public $downloads = 0;
public $date = null;
public $image = '';
public function run() {
if ($this->date == null)
$this->date = new DateTime('2000-01-01');
$this->render('thumbnailPreview');
}
}
?>

View File

@@ -0,0 +1,66 @@
<?php
/* @var $this ThumbnailPreview */
?>
<li class="span3" style="width: 270px">
<div style="min-height: 600px">
<div class="thumbnail" style="padding: 0;">
<div style="padding:4px; height: 225px; overflow-y: hidden">
<img style="width: 100%" src="<?php echo $this->image; ?>">
</div>
<div class="caption">
<?php //TODO Line out css to styles.css !!!!
if ( strlen($this->caption) > 13)
echo '<h3 class="progThumbnailCaption">' . $this->caption . '</h3>';
else
echo '<h2 class="progThumbnailCaption">' . $this->caption . '</h2>';
?>
<p style="min-height: 70px;"><?php echo $this->description; ?></p>
<p>
<?php
if (!empty($this->category)) {
echo TbHtml::icon(TbHtml::ICON_TAG);
echo $this->category . '';
}
?>
</p>
<p>
<?php
foreach ($this->language as $lang) {
echo TbHtml::icon(TbHtml::ICON_GLOBE);
echo $lang;
echo '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
}
?>
</div>
<div class="modal-footer" style="text-align: left">
<div class="text-center">
<?php
for ($i = 0; $i < 4; $i++) {
if ($i < $this->starcount)
echo TbHtml::icon(TbHtml::ICON_STAR);
else
echo TbHtml::icon(TbHtml::ICON_STAR_EMPTY);
}
?>
</div>
<br>
<div class="row-fluid">
<div class="span4"><b><?php echo $this->downloads; ?></b><br/>
<small>Downloads</small>
</div>
<div class="span4"><b><?php echo $this->date->format('d.m.y'); ?></b><br/>
<small>Added On</small>
</div>
<div class="span4"><b><?php echo $this->starcount . '/4'; ?></b><br/>
<small>Rating</small>
</div>
</div>
</div>
</div>
</div>
</li>

View File

@@ -17,7 +17,7 @@ return [
'errorHandler' =>
[
'errorAction' => 'site/error',
'errorAction' => 'site/debugerror',
],
],

View File

@@ -55,8 +55,6 @@ return ArrayX::merge(
'allowAutoLogin' => true,
],
// uncomment the following to enable URLs in path-format
'urlManager' =>
[
'urlFormat' => 'path',

View File

@@ -47,16 +47,18 @@ class ProgramsController extends Controller
/**
* Displays a particular model.
* @param integer $id the ID of the model to be displayed
* @throws CHttpException when $id is integer
*/
public function actionView($id)
{
if (is_string($id))
if (is_numeric($id))
{
$model = $this->loadModelByName($id);
throw new CHttpException(400, "You can't access a program by ID");
//$model = $this->loadModelByID($id);
}
else
{
$model = $this->loadModelByID($id);
$model = $this->loadModelByName($id);
}
$this->render('view',array(
@@ -94,7 +96,7 @@ class ProgramsController extends Controller
*/
public function actionUpdate($id)
{
$model=$this->loadModel($id);
$model=$this->loadModelByID($id);
// Uncomment the following line if AJAX validation is needed
// $this->performAjaxValidation($model);
@@ -121,7 +123,7 @@ class ProgramsController extends Controller
{
if (Yii::app()->request->isPostRequest) {
// we only allow deletion via POST request
$this->loadModel($id)->delete();
$this->loadModelByID($id)->delete();
// if AJAX request (triggered by deletion via admin grid view), we should not redirect the browser
if (!isset($_GET['ajax'])) {
@@ -169,7 +171,7 @@ class ProgramsController extends Controller
{
$model=Program::model()->findByPk($id);
if ($model===null) {
throw new CHttpException(404,'The requested page does not exist.');
throw new CHttpException(404,'The requested Programm (by ID) does not exist.');
}
return $model;
}
@@ -185,7 +187,7 @@ class ProgramsController extends Controller
{
$model=Program::model()->findByAttributes(['Name' => $name]);
if ($model===null) {
throw new CHttpException(404,'The requested page does not exist.');
throw new CHttpException(404,'The requested programm (by Name) does not exist.');
}
return $model;
}

View File

@@ -24,6 +24,17 @@ class SiteController extends Controller
}
}
public function actionDebugError()
{
if($error=Yii::app()->errorHandler->error)
{
if(Yii::app()->request->isAjaxRequest)
echo $error['message'];
else
$this->render('debugerror', $error);
}
}
public function actionAbout()
{
$data = array();

View File

@@ -6,6 +6,7 @@
* The followings are the available columns in table 'program':
* @property integer $ID
* @property string $Name
* @property string Thumbnailname
* @property double $Downloads
* @property string $Kategorie
* @property double $Sterne
@@ -41,13 +42,13 @@ class Program extends CActiveRecord
// NOTE: you should only define rules for those attributes that
// will receive user inputs.
return array(
array('Name, Downloads, Kategorie, Sterne, enabled, visible, Language, Description, add_date, download_url, viewable_code, sourceforge_url, homepage_url, github_url, uses_absCanv, update_identifier', 'required'),
array('Name, Thumbnailname, Downloads, Kategorie, Sterne, enabled, visible, Language, Description, add_date, download_url, viewable_code, sourceforge_url, homepage_url, github_url, uses_absCanv, update_identifier', 'required'),
array('enabled, visible, viewable_code, uses_absCanv, highscore_gid', 'numerical', 'integerOnly'=>true),
array('Downloads, Sterne', 'numerical'),
array('update_identifier', 'length', 'max'=>28),
// The following rule is used by search().
// @todo Please remove those attributes that should not be searched.
array('ID, Name, Downloads, Kategorie, Sterne, enabled, visible, Language, Description, add_date, download_url, viewable_code, sourceforge_url, homepage_url, github_url, uses_absCanv, update_identifier, highscore_gid', 'safe', 'on'=>'search'),
array('ID, Name, Thumbnailname, Downloads, Kategorie, Sterne, enabled, visible, Language, Description, add_date, download_url, viewable_code, sourceforge_url, homepage_url, github_url, uses_absCanv, update_identifier, highscore_gid', 'safe', 'on'=>'search'),
);
}
@@ -70,6 +71,7 @@ class Program extends CActiveRecord
return array(
'ID' => 'ID',
'Name' => 'Name',
'Thumbnailname' => 'Thumbnail name',
'Downloads' => 'Downloads',
'Kategorie' => 'Kategorie',
'Sterne' => 'Sterne',
@@ -107,6 +109,7 @@ class Program extends CActiveRecord
$criteria->compare('ID',$this->ID);
$criteria->compare('Name',$this->Name,true);
$criteria->compare('Thumbnailname',$this->Thumbnailname,true);
$criteria->compare('Downloads',$this->Downloads);
$criteria->compare('Kategorie',$this->Kategorie,true);
$criteria->compare('Sterne',$this->Sterne);

View File

@@ -19,11 +19,13 @@
<?php echo $form->errorSummary($model); ?>
<?php echo $form->textAreaControlGroup($model,'Name',array('rows'=>6,'span'=>8)); ?>
<?php echo $form->textFieldControlGroup($model,'Name',array('rows'=>6,'span'=>8)); ?>
<?php echo $form->textFieldControlGroup($model,'Thumbnailname',array('rows'=>6,'span'=>8)); ?>
<?php echo $form->textFieldControlGroup($model,'Downloads',array('span'=>5)); ?>
<?php echo $form->textAreaControlGroup($model,'Kategorie',array('rows'=>6,'span'=>8)); ?>
<?php echo $form->textFieldControlGroup($model,'Kategorie',array('rows'=>6,'span'=>8)); ?>
<?php echo $form->textFieldControlGroup($model,'Sterne',array('span'=>5)); ?>
@@ -31,21 +33,21 @@
<?php echo $form->textFieldControlGroup($model,'visible',array('span'=>5)); ?>
<?php echo $form->textAreaControlGroup($model,'Language',array('rows'=>6,'span'=>8)); ?>
<?php echo $form->textFieldControlGroup($model,'Language',array('rows'=>6,'span'=>8)); ?>
<?php echo $form->textAreaControlGroup($model,'Description',array('rows'=>6,'span'=>8)); ?>
<?php echo $form->textFieldControlGroup($model,'add_date',array('span'=>5)); ?>
<?php echo $form->textAreaControlGroup($model,'download_url',array('rows'=>6,'span'=>8)); ?>
<?php echo $form->textFieldControlGroup($model,'download_url',array('rows'=>6,'span'=>8)); ?>
<?php echo $form->textFieldControlGroup($model,'viewable_code',array('span'=>5)); ?>
<?php echo $form->textAreaControlGroup($model,'sourceforge_url',array('rows'=>6,'span'=>8)); ?>
<?php echo $form->textFieldControlGroup($model,'sourceforge_url',array('rows'=>6,'span'=>8)); ?>
<?php echo $form->textAreaControlGroup($model,'homepage_url',array('rows'=>6,'span'=>8)); ?>
<?php echo $form->textFieldControlGroup($model,'homepage_url',array('rows'=>6,'span'=>8)); ?>
<?php echo $form->textAreaControlGroup($model,'github_url',array('rows'=>6,'span'=>8)); ?>
<?php echo $form->textFieldControlGroup($model,'github_url',array('rows'=>6,'span'=>8)); ?>
<?php echo $form->textFieldControlGroup($model,'uses_absCanv',array('span'=>5)); ?>

View File

@@ -15,6 +15,8 @@
<?php echo $form->textAreaControlGroup($model,'Name',array('rows'=>6,'span'=>8)); ?>
<?php echo $form->textAreaControlGroup($model,'Thumbnailname',array('rows'=>6,'span'=>8)); ?>
<?php echo $form->textFieldControlGroup($model,'Downloads',array('span'=>5)); ?>
<?php echo $form->textAreaControlGroup($model,'Kategorie',array('rows'=>6,'span'=>8)); ?>

View File

@@ -13,6 +13,10 @@
<?php echo CHtml::encode($data->Name); ?>
<br />
<b><?php echo CHtml::encode($data->getAttributeLabel('Thumbnailname')); ?>:</b>
<?php echo CHtml::encode($data->Thumbnailname); ?>
<br />
<b><?php echo CHtml::encode($data->getAttributeLabel('Downloads')); ?>:</b>
<?php echo CHtml::encode($data->Downloads); ?>
<br />

View File

@@ -15,20 +15,33 @@ $this->menu = array(
?>
<div class="container">
<div class="span12">
<h1>My Prog's</h1>
<br>
<br>
<div class="row-fluid">
<?php
$all = Program::model()->findAll();
$rows = ceil((count($all) / 4));
foreach (Program::model()->findAll() as $record) {
echo "<div class='well'>";
echo nl2br(print_r($record->attributes, true));
echo "</div>";
for ($i = 0; $i < $rows; $i++) {
echo '<ul class="thumbnails">';
foreach (array_slice(Program::model()->findAll(), $i * 4, 4) as $record) {
$this->widget('ThumbnailPreview',
[
'caption' => $record->attributes['Thumbnailname'],
'description' => $record->attributes['Description'],
'category' => $record->attributes['Kategorie'],
'language' => explode("|", $record->attributes['Language']),
'image' => '/images/programs/thumbnails/' . $record->attributes['Name'] . '.jpg',
'starcount' => $record->attributes['Sterne'],
'downloads' => $record->attributes['Downloads'],
'date' => new DateTime($record->attributes['add_date']),
]);
}
echo '</ul>';
}
?>
</div>
</div>

View File

@@ -0,0 +1,21 @@
<?php
/* @var $this SiteController */
/* @var $error array */
$this->pageTitle=Yii::app()->name . ' - Error';
$this->breadcrumbs=array(
'Error (debug)',
);
$content = $message. "\n\n" .
'File: <code>' . $file. '</code> : <code>' . $line . "</code>\n\n" .
"Stacktrace:\n" .
'<div class="well">' . $trace . '</div>' . "\n";
$this->widget('bootstrap.widgets.TbHeroUnit', array(
'heading' => 'ERROR ' . $type . ': ' . $code,
'content' => nl2br($content),
));
?>