Skip to content

Commit

Permalink
Initial update for PyroCMS v2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
jerel committed Dec 1, 2011
1 parent a132e57 commit d19d86f
Show file tree
Hide file tree
Showing 11 changed files with 126 additions and 112 deletions.
10 changes: 8 additions & 2 deletions controllers/admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
*/
class Admin extends Admin_Controller
{
protected $section = 'items';

public function __construct()
{
Expand Down Expand Up @@ -62,7 +63,7 @@ public function create()
if($this->form_validation->run())
{
// See if the model can create the record
if($this->sample_m->create($_POST))
if($this->sample_m->create($this->input->post()))
{
// All good...
$this->session->set_flashdata('success', lang('sample.success'));
Expand All @@ -75,6 +76,11 @@ public function create()
redirect('admin/sample/create');
}
}

foreach ($this->item_validation_rules AS $rule)
{
$this->data->{$rule['field']} = $this->input->post($rule['field']);
}

// Build the view using sample/views/admin/form.php
$this->template->title($this->module_details['name'], lang('sample.new_item'))
Expand All @@ -96,7 +102,7 @@ public function edit($id = 0)
unset($_POST['btnAction']);

// See if the model can create the record
if($this->sample_m->update($id, $_POST))
if($this->sample_m->update($id, $this->input->post()))
{
// All good...
$this->session->set_flashdata('success', lang('sample.success'));
Expand Down
29 changes: 13 additions & 16 deletions controllers/sample.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,27 +30,24 @@ public function index($offset = 0)
// set the pagination limit
$limit = 5;

// instead of using MY_Models get_all() we use our own get_array()
// because Tags cannot handle an object
$this->data->items = $this->sample_m
->get_array($limit, $offset);
$data->items = $this->sample_m->limit($limit)
->offset($offset)
->get_all();

// we'll do a quick check here so we can tell tags whether there is data or not
if ( ! $this->data->items) $this->data->empty = TRUE;
if (count($data->items))
{
$data->items_exist = TRUE;
}
else
{
$data->items_exist = FALSE;
}

// we're using the pagination helper to do the pagination for us. Params are: (module/method, total count, limit, uri segment)
$this->data->pagination = create_pagination('sample', $this->sample_m->count_all(), $limit, 2);
$data->pagination = create_pagination('sample', $this->sample_m->count_all(), $limit, 2);

/**
* You'll notice that we are setting the "pagination" partial. An alternative is
* to do $this->load->view('admin/partials/pagination'); in the view but that
* requires php. By setting the partial here and displaying it with
* {pyro:template:partial name="pagination"} in index.php we can get rid of php.
* The only requirement is that the pagination data is available to the partial
* so we set $this->data->pagination in this controller and it gets passed when we build.
*/
$this->template->title($this->module_details['name'], 'the rest of the page title')
->set_partial('pagination', 'admin/partials/pagination')
->build('index', $this->data);
->build('index', $data);
}
}
27 changes: 20 additions & 7 deletions details.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

class Module_Sample extends Module {

public $version = '1.0';
public $version = '2.0';

public function info()
{
Expand All @@ -15,15 +15,28 @@ public function info()
),
'frontend' => TRUE,
'backend' => TRUE,
'menu' => 'content'
'menu' => 'content', // You can also place modules in their top level menu. For example try: 'menu' => 'Sample',
'sections' => array(
'items' => array(
'name' => 'sample.items', // These are translated from your language file
'uri' => 'admin/sample',
'shortcuts' => array(
'create' => array(
'name' => 'sample.create',
'uri' => 'admin/sample/create',
'class' => 'add'
)
)
)
)
);
}

public function install()
{
$this->dbforge->drop_table('sample');
$this->db->delete('settings', array('module' => 'sample'));

$sample = array(
'id' => array(
'type' => 'INT',
Expand All @@ -39,7 +52,7 @@ public function install()
'constraint' => '100'
)
);

$sample_setting = array(
'slug' => 'sample_setting',
'title' => 'Sample Setting',
Expand All @@ -52,13 +65,13 @@ public function install()
'is_gui' => 1,
'module' => 'sample'
);

$this->dbforge->add_field($sample);
$this->dbforge->add_key('id', TRUE);

if($this->dbforge->create_table('sample') AND
$this->db->insert('settings', $sample_setting) AND
is_dir('uploads/sample') OR @mkdir('uploads/sample',0777,TRUE))
is_dir($this->upload_path.'sample') OR @mkdir($this->upload_path.'sample',0777,TRUE))
{
return TRUE;
}
Expand Down Expand Up @@ -87,4 +100,4 @@ public function help()
return "No documentation has been added for this module.<br />Contact the module developer for assistance.";
}
}
/* End of file details.php */
/* End of file details.php */
5 changes: 5 additions & 0 deletions events.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ public function __construct()

//register the public_controller event
Events::register('public_controller', array($this, 'run'));

//register a second event that can be called any time.
// To execute the "run" method below you would use: Events::trigger('sample_event');
// in any php file within PyroCMS, even another module.
Events::register('sample_event', array($this, 'run'));
}

public function run()
Expand Down
6 changes: 6 additions & 0 deletions js/admin.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
jQuery(function($){

// generate a slug when the user types a title in
pyro.generate_slug('input[name="name"]', 'input[name="slug"]');

});
11 changes: 0 additions & 11 deletions models/sample_m.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,6 @@ public function __construct()
*/
$this->_table = 'sample';
}

//get all items in an array for Tags
public function get_array($limit, $offset)
{
return $this->db
->order_by('name')
->limit($limit)
->offset($offset)
->get('sample')
->result_array();
}

//create a new item
public function create($input)
Expand Down
6 changes: 3 additions & 3 deletions plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ class Plugin_Sample extends Plugin
* Item List
* Usage:
*
* {pyro:sample:items limit="5" order="asc"}
* {id} {name} {slug}
* {/pyro:sample:items}
* {{ sample:items limit="5" order="asc" }}
* {{ id }} {{ name }} {{ slug }}
* {{ /sample:items }}
*
* @return array
*/
Expand Down
14 changes: 8 additions & 6 deletions views/admin/form.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
<div id="sample_form_box">

<section class="title">
<!-- We'll use $this->method to switch between sample.create & sample.edit -->
<h3><?php echo lang('sample.'.$this->method); ?></h3>
<h4><?php echo lang('sample.'.$this->method); ?></h4>
</section>

<section class="item">

<?php echo form_open_multipart($this->uri->uri_string(), 'class="crud"'); ?>
<ol>
<ul class="form_inputs">
<li class="<?php echo alternator('', 'even'); ?>">
<label for="name"><?php echo lang('sample.name'); ?></label>
<?php echo form_input('name', set_value('name', $name), 'class="width-15"'); ?>
Expand All @@ -16,12 +18,12 @@
<?php echo form_input('slug', set_value('slug', $slug), 'class="width-15"'); ?>
<span class="required-icon tooltip">Required</span>
</li>
</ol>
</ul>

<div class="buttons">
<?php $this->load->view('admin/partials/buttons', array('buttons' => array('save', 'cancel') )); ?>
</div>

<?php echo form_close(); ?>

</div>
</section>
101 changes: 53 additions & 48 deletions views/admin/items.php
Original file line number Diff line number Diff line change
@@ -1,51 +1,56 @@
<?php echo form_open('admin/sample/delete');?>
<section class="title">
<h4><?php echo lang('sample.item_list'); ?></h4>
</section>

<?php if (!empty($items)): ?>
<h3><?php echo lang('sample.item_list'); ?></h3>

<table border="0" class="table-list">
<thead>
<tr>
<th><?php echo form_checkbox(array('name' => 'action_to_all', 'class' => 'check-all'));?></th>
<th><?php echo lang('sample.name'); ?></th>
<th><?php echo lang('sample.slug'); ?></th>
<th><?php echo lang('sample.manage'); ?></th>
</tr>
</thead>
<tfoot>
<tr>
<td colspan="5">
<div class="inner"><?php $this->load->view('admin/partials/pagination'); ?></div>
</td>
</tr>
</tfoot>
<tbody>
<?php foreach( $items as $item ): ?>
<tr>
<td><?php echo form_checkbox('action_to[]', $item->id); ?></td>
<td><?php echo $item->name; ?></td>
<td><a href="<?php echo rtrim(site_url(), '/').'/sample'; ?>">
<?php echo rtrim(site_url(), '/').'/sample'; ?></a></td>
<td>
<?php echo
anchor('sample', lang('sample.view'), 'target="_blank"') . ' | ' .
anchor('admin/sample/edit/' . $item->id, lang('sample.edit')) . ' | ' .
anchor('admin/sample/delete/' . $item->id, lang('sample.delete'), array('class'=>'confirm')); ?>
</td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
<div class="buttons">
<?php $this->load->view('admin/partials/buttons', array('buttons' => array('delete'))); ?>
</div>
<section class="item">
<?php echo form_open('admin/sample/delete');?>

<?php if (!empty($items)): ?>

<?php else: ?>
<div class="blank-slate">
<img src="<?php echo site_url('addons/modules/sample/img/album.png') ?>" />
<table border="0" class="table-list">
<thead>
<tr>
<th><?php echo form_checkbox(array('name' => 'action_to_all', 'class' => 'check-all'));?></th>
<th><?php echo lang('sample.name'); ?></th>
<th><?php echo lang('sample.slug'); ?></th>
<th><?php echo lang('sample.manage'); ?></th>
</tr>
</thead>
<tfoot>
<tr>
<td colspan="5">
<div class="inner"><?php $this->load->view('admin/partials/pagination'); ?></div>
</td>
</tr>
</tfoot>
<tbody>
<?php foreach( $items as $item ): ?>
<tr>
<td><?php echo form_checkbox('action_to[]', $item->id); ?></td>
<td><?php echo $item->name; ?></td>
<td><a href="<?php echo rtrim(site_url(), '/').'/sample'; ?>">
<?php echo rtrim(site_url(), '/').'/sample'; ?></a></td>
<td>
<?php echo
anchor('sample', lang('sample.view'), 'target="_blank"') . ' | ' .
anchor('admin/sample/edit/' . $item->id, lang('sample.edit')) . ' | ' .
anchor('admin/sample/delete/' . $item->id, lang('sample.delete'), array('class'=>'confirm')); ?>
</td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
<div class="buttons">
<?php $this->load->view('admin/partials/buttons', array('buttons' => array('delete'))); ?>
</div>

<h2><?php echo lang('sample.no_items'); ?></h2>
</div>
<?php endif;?>

<?php echo form_close(); ?>
<?php else: ?>
<div class="blank-slate">
<?php echo image('album.png', 'sample'); ?>

<h3><?php echo lang('sample.no_items'); ?></h3>
</div>
<?php endif;?>

<?php echo form_close(); ?>
</section>
9 changes: 0 additions & 9 deletions views/admin/partials/shortcuts.php

This file was deleted.

20 changes: 10 additions & 10 deletions views/index.php
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
<div class="sample-container">

{if '{pyro:empty}'}
{{ if items_exist == false }}
<p>There are no items.</p>
{else}
{{ else }}
<div class="sample-data">
<table cellpadding="0" cellspacing="0">
<tr>
<th>{pyro:helper:lang line="sample.name"}</th>
<th>{pyro:helper:lang line="sample.slug"}</th>
<th>{{ helper:lang line="sample.name" }}</th>
<th>{{ helper:lang line="sample.slug" }}</th>
</tr>
<!-- Here we loop through the $items array -->
{pyro:items}
{{ items }}
<tr>
<td>{name}</td>
<td>{slug}</td>
<td>{{ name }}</td>
<td>{{ slug }}</td>
</tr>
{/pyro:items}
{{ /items }}
</table>
</div>
{pyro:template:partial name="pagination"}
{{ pagination:links }}

{/if}
{{ endif }}

</div>

0 comments on commit d19d86f

Please sign in to comment.