Skip to content
This repository has been archived by the owner on Oct 14, 2020. It is now read-only.

Commit

Permalink
Flash News Module init
Browse files Browse the repository at this point in the history
  • Loading branch information
imknight committed Aug 27, 2011
1 parent 24ca502 commit 6c95c87
Show file tree
Hide file tree
Showing 12 changed files with 205 additions and 0 deletions.
7 changes: 7 additions & 0 deletions flash_news/config/flash_news.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?php
/*
|--------------------------------------------------------------------------
| FUEL NAVIGATION: An array of navigation items for the left menu
|--------------------------------------------------------------------------
*/
$config['nav']['manage']['flash_news/news'] = lang('module_flash_news');
4 changes: 4 additions & 0 deletions flash_news/config/flash_news_constants.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?php
define('FLASH_NEWS_VERSION', '1.0');
define('FLASH_NEWS_FOLDER', 'flash_news');
define('FLASH_NEWS_PATH', MODULES_PATH.FLASH_NEWS_FOLDER.'/');
22 changes: 22 additions & 0 deletions flash_news/config/flash_news_fuel_modules.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php
// included in the main config/MY_fuel_modules.php

$config['modules']['flash_news_news'] = array(
'module_name' => 'Flash News',
'module_uri' => 'flash_news/news',
'model_name' => 'flash_news_model',
'model_location' => 'flash_news',
'permission' => 'flash_news/news',
'nav_selected' => 'flash_news/news',
'instructions' => lang('module_instructions_flash_news', 'flash_news'),
);

$config['modules']['flash_news_category'] = array(
'module_name' => 'Flash News Category',
'module_uri' => 'flash_news/category',
'model_name' => 'flash_news_categories_model',
'model_location' => 'flash_news',
'permission' => 'flash_news/category',
'instructions' => lang('module_instructions_flash_news_category', 'flash_news'),
);

13 changes: 13 additions & 0 deletions flash_news/config/flash_news_routes.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php
//link the controller to the nav link

$flash_news_controllers = array('category','news');

foreach($flash_news_controllers as $c)
{
$route[FUEL_ROUTE.'flash_news/'.$c] = FUEL_FOLDER.'/module';
$route[FUEL_ROUTE.'flash_news/'.$c.'/(.*)'] = FUEL_FOLDER.'/module/$1';
}

$route[FUEL_ROUTE.'flash_news/dashboard'] = FLASH_NEWS_FOLDER.'/dashboard';

10 changes: 10 additions & 0 deletions flash_news/config/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<html>
<head>
<title>403 Forbidden</title>
</head>
<body>

<p>Directory access is forbidden.</p>

</body>
</html>
33 changes: 33 additions & 0 deletions flash_news/controllers/dashboard.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php
require_once(FUEL_PATH.'/libraries/Fuel_base_controller.php');

class Dashboard extends Fuel_base_controller {

function __construct()
{
parent::__construct();
}

function index()
{
$session_key = $this->fuel_auth->get_session_namespace();
$user_data = $this->session->userdata($session_key);

$this->load->module_model(FLASH_NEWS_FOLDER, 'flash_news_model');
$vars = '';
$vars['latest_news'] = $this->flash_news_model->find_all_array(array('active'=>'yes'),'date_added desc');
$flash_news = $this->flash_news_model->find_one_array(array('active'=>'yes','sticky'=>'yes'),'date_added desc');
//need to clear off from the session if changes has done
if ($flash_news) {
$user_data['flash_news'] ='<strong>'.$flash_news['category'].'</strong> : '.$flash_news['news'];
}else{
$user_data['flash_news'] = '';
}
$this->session->set_userdata($session_key, $user_data);
$this->load->view('dashboard_view', $vars);
}

}

/* End of file dashboard.php */
/* Location: ./fuel/modules/backup/controllers/dashboard.php */
21 changes: 21 additions & 0 deletions flash_news/install/flash_news.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
CREATE TABLE `module_flash_news` (
`id` int(10) unsigned NOT NULL auto_increment,
`news` varchar(255) collate utf8_unicode_ci NOT NULL,
`cat_id` int(10) unsigned NOT NULL,
`sticky` enum('yes','no') collate utf8_unicode_ci NOT NULL default 'no',
`active` enum('yes','no') collate utf8_unicode_ci NOT NULL default 'yes',
`date_added` datetime default NULL,
`last_modified` timestamp NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;

CREATE TABLE `module_flash_news_categories` (
`id` int(10) unsigned NOT NULL auto_increment,
`name` varchar(30) collate utf8_unicode_ci NOT NULL,
`active` enum('yes','no') collate utf8_unicode_ci NOT NULL default 'yes',
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;

INSERT INTO `fuel_permissions` (`id`,`name`,`description`,`active`) VALUES
('','flash_news/news','Manage flash news','yes'),
('','flash_news/view_news','Read flash news','yes');
20 changes: 20 additions & 0 deletions flash_news/install/notifications.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php if (!empty($error)) :
add_errors($error);
echo display_errors('error ico_error');
?>
<?php elseif ($this->session->flashdata('error') AND $this->session->flashdata('error') !== TRUE AND $this->session->flashdata('success') !== '1') :
add_errors($this->session->flashdata('error'));
echo display_errors('error ico_error');
?>
<?php elseif ($this->session->flashdata('success') AND $this->session->flashdata('success') !== TRUE AND $this->session->flashdata('success') !== '1') : ?>
<div class="success ico_success"><?=$this->session->flashdata('success');?></div>
<?php else: ?>
<?php echo display_errors('error ico_error')?>
<?php endif; ?>
<?php
$session_key = $this->fuel_auth->get_session_namespace();
$user_data = $this->session->userdata($session_key);
if (!empty($user_data['flash_news'])) { ?>

<div class="ico_info"><?=$user_data['flash_news']?></div>
<? } ?>
4 changes: 4 additions & 0 deletions flash_news/language/english/flash_news_lang.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?php
$lang['module_flash_news'] = 'Flash News';
$lang['module_instructions_flash_news'] = 'Manage Your Flash News Here.';
$lang['module_instructions_flash_news_category'] = 'Manage Your Flash News Category Here.';
15 changes: 15 additions & 0 deletions flash_news/models/flash_news_categories_model.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php if (!defined('BASEPATH')) exit('No direct script access allowed');

require_once(FUEL_PATH.'models/base_module_model.php');
require_once(MODULES_PATH.'/flash_news/config/flash_news_constants.php');

class Flash_news_categories_model extends Base_module_model {

function __construct()
{
parent::__construct('module_flash_news_categories'); // table name
}

}

?>
46 changes: 46 additions & 0 deletions flash_news/models/flash_news_model.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?php if (!defined('BASEPATH')) exit('No direct script access allowed');

require_once(FUEL_PATH.'models/base_module_model.php');
require_once(MODULES_PATH.'/flash_news/config/flash_news_constants.php');

class Flash_news_model extends Base_module_model {

public $required = array('news');
public $foreign_keys = array('cat_id' => array(FLASH_NEWS_FOLDER=>'flash_news_categories_model'));

function __construct()
{
parent::__construct('module_flash_news'); // table name
}

function list_items($limit = NULL, $offset = NULL, $col = 'id', $order = 'asc')
{
$this->db->select('module_flash_news.id,news,module_flash_news_categories.name as category,sticky,module_flash_news.active,module_flash_news.date_added', FALSE);
$this->db->join('module_flash_news_categories','module_flash_news_categories.id=module_flash_news.cat_id','left');
$data = parent::list_items($limit, $offset, $col, $order);
return $data;
}

function form_fields($values = array())
{
$fields = parent::form_fields();
$fields['cat_id']['label'] = 'Category';
$fields['cat_id']['class'] = 'add_edit flash_news/category';
return $fields;
}

function _common_query()
{
$this->db->select('module_flash_news.*,module_flash_news_categories.name as category');
$this->db->join('module_flash_news_categories','module_flash_news_categories.id=module_flash_news.cat_id','left');
}

// save one to many permission in group_to_permissions table
function on_after_save($values)
{

}

}

?>
10 changes: 10 additions & 0 deletions flash_news/views/dashboard_view.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php if ($this->fuel_auth->has_permission('flash_news/view_news')) : ?>
<div class="dashboard_pod" style="width: 400px;">
<h3><?=lang('dashboard_latest_news')?></h3>
<ul class="nobullets">
<?php foreach($latest_news as $k => $val) : ?>
<li><strong><?=english_date($val['date_added'], false)?>:</strong> [<?=$val['category']?>] - <?=$val['news']?></li>
<?php endforeach; ?>
</ul>
</div>
<?php endif; ?>

0 comments on commit 6c95c87

Please sign in to comment.