scaffolding++

This commit is contained in:
wclouser%mozilla.com 2006-06-12 18:18:40 +00:00
parent 530cb37df0
commit b429830b34
7 changed files with 148 additions and 0 deletions

View File

@ -0,0 +1,6 @@
<?php
class ApplicationsController extends AppController {
var $name = 'Applications';
var $scaffold;
}
?>

View File

@ -0,0 +1,78 @@
<?php
uses('sanitize');
class DownloadablesController extends AppController {
var $name = 'Downloadables';
var $scaffold;
var $helpers = array('Html', 'Pagination');
var $show;
var $sortBy;
var $direction;
var $page;
var $order;
var $sanitize;
var $scaffold;
function __construct()
{
$this->sanitize = &new Sanitize;
$this->show = empty($_GET['show'])? '10': $this->sanitize->sql($_GET['show']);
$this->sortBy = empty($_GET['sort'])? 'Downloadable.id': $this->sanitize->sql($_GET['sort']);
$this->direction = empty($_GET['direction'])? 'desc': $this->sanitize->sql($_GET['direction']);
$this->page = empty($_GET['page'])? '1': $this->sanitize->sql($_GET['page']);
$this->order = $this->sortBy.' '.strtoupper($this->direction);
parent::__construct();
}
function index()
{
$data = $this->Downloadable->findAll($criteria=null, $fields=null, $this->order, $this->show, $this->page);
$paging['style'] = 'html'; //set the style of the links: html or ajax
foreach ($this->Downloadable->_tableInfo->value as $column) {
// If the sortBy is the same as the current link, we want to switch it.
// By default, we don't -- so that when a user changes columns, the order doesn't also reverse.
if ($this->sortBy == $column['name']) {
switch ($this->direction) {
case 'desc':
$link_direction = 'asc';
break;
case 'asc':
default:
$link_direction = 'desc';
break;
}
} else {
$link_direction =& $this->direction;
}
$paging['headers'][$column['name']] = $this->sanitize->html('/downloadables/?show='.$this->show.'&sort='.$column['name'].'&direction='.$link_direction.'&page='.$this->page);
}
$paging['link'] = $this->sanitize->html('./?show='.$this->show.'&sort='.$this->sortBy.'&direction='.$this->direction.'&page=');
$paging['count'] = $this->Downloadable->findCount($criteria=null,'1000');
$paging['page'] = $this->page;
$paging['limit'] = $this->show;
$paging['show'] = array('10','25','50','100');
$this->set('paging',$paging);
$this->set('data',$data);
}
function view($id) {
$this->Downloadable->setId($id);
$this->set('data', $this->Downloadable->read());
}
function destroy($id) {
if (empty($this->params['data'])) {
$this->set('data', $this->Downloadable->read());
$this->render();
} elseif ($this->Downloadable->del($id)) {
$this->flash('Downloadable '.$id.' has been deleted.', '/downloadables');
}
}
}
?>

View File

@ -0,0 +1,5 @@
<?php
class Application extends AppModel {
var $name = 'Application';
}
?>

View File

@ -0,0 +1,7 @@
<?php
class Downloadable extends AppModel {
var $name = 'Downloadable';
var $belongsTo = array('File','Mirror');
}
?>

View File

@ -1,5 +1,7 @@
<?php
class File extends AppModel {
var $name = 'File';
var $belongsTo = array('Application', 'Platform', 'Locale', 'Template');
}
?>

View File

@ -0,0 +1,47 @@
<h1>Downloadables</h1>
<?php if($pagination->setPaging($paging)):?>
<div class="pagination">
<?php echo $pagination->result('Results: '); ?>
<?php echo $pagination->prevPage('Prev'); ?>
<?php echo $pagination->pageNumbers(); ?>
<?php echo $pagination->nextPage('Next'); ?>
</div>
<?php endif;?>
<table class="inav">
<tr>
<th><?php echo $html->link('ID',$paging['headers']['id']); ?></th>
<th><?php echo $html->link('Mirror ID',$paging['headers']['mirror_id']); ?></th>
<th><?php echo $html->link('File ID',$paging['headers']['file_id']); ?></th>
<th><?php echo $html->link('URL',$paging['headers']['url']); ?></th>
<th><?php echo $html->link('Active',$paging['headers']['active']); ?></th>
<th><?php echo $html->link('Count',$paging['headers']['downloadable_count']); ?></th>
<th>Action</th>
</tr>
<?php foreach ($data as $downloadable): ?>
<tr>
<td><?php echo $downloadable['Downloadable']['id']; ?></td>
<td><?php echo $downloadable['Downloadable']['mirror_id']; ?></td>
<td><?php echo $downloadable['Downloadable']['file_id']; ?></td>
<td>
<?php echo $html->link( $downloadable['Downloadable']['url'], "/downloadables/view/{$downloadable['Downloadable']['id']}" ); ?>
</td>
<td><?php echo ($downloadable['Downloadable']['active'])?'On':'Off'; ?></td>
<td><?php echo ($downloadable['Downloadable']['downloadable_count']); ?></td>
<td>
<?=$html->link('Edit',"/downloadables/edit/{$downloadable['Downloadable']['id']}",'class="action"')?>
</td>
</tr>
<?php endforeach; ?>
</table>
<?php if($pagination->setPaging($paging)):?>
<ul id="page-numbers">
<li><?php echo $pagination->show('Show '); ?></li>
<li><?php echo $pagination->result('Results: '); ?></li>
<li><?php echo $pagination->prevPage('Prev'); ?></li>
<li><?php echo $pagination->pageNumbers(); ?></li>
<li><?php echo $pagination->nextPage('Next'); ?></li>
</ul>
<?php endif;?>

View File

@ -0,0 +1,3 @@
<h1><?php echo $data['Downloadable']['id']; ?></h1>
<p><?php echo $data['Downloadable']['url']; ?></p>
<p><?php echo $data['Downloadable']['active']?'Active':'Not Active'; ?></p>