mirror of
https://github.com/Ekokumppanit/ystavakylaecard.git
synced 2026-01-26 03:04:00 +00:00
Tyhjien korttipohjien haku tietokannasta
This commit is contained in:
@@ -65,7 +65,7 @@ class Welcome extends CI_Controller
|
||||
'page_title' => array( 'Uusi eKortti', 'Ystäväkylä eKortti' ),
|
||||
'page_classes' => array( 'new_card' ),
|
||||
'count' => $this->card_count,
|
||||
'images' => fetchBaseCards(),
|
||||
'images' => $this->ecard->getCardsTemplates(1),
|
||||
'user' => $this->user
|
||||
);
|
||||
|
||||
|
||||
@@ -183,6 +183,49 @@ class Ecard_model extends MY_Model
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* getCardTemplates fetches templates from database
|
||||
*
|
||||
* @param bool $status Card templates based on status
|
||||
* @param integer $limit How many should we fetch
|
||||
* @param integer $offset Offset for limit
|
||||
*
|
||||
* @return object Cards sorted by database ID
|
||||
*/
|
||||
public function getCardsTemplates($status = 1, $limit = 25, $offset = 0)
|
||||
{
|
||||
$return = new stdClass();
|
||||
|
||||
// Get templates from database
|
||||
$result = $this->db->get_where(
|
||||
'templates',
|
||||
array(
|
||||
'card_status' => $status
|
||||
),
|
||||
$limit,
|
||||
$offset
|
||||
)
|
||||
->result_object();
|
||||
|
||||
// Make easier to use, remove non existing
|
||||
if (!empty($result)) {
|
||||
foreach ($result as $image) {
|
||||
|
||||
$image->card_path = APPPATH . '../assets/basecards/' . $image->card_filename;
|
||||
|
||||
if (! is_readable($image->card_path)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$image->card_url = site_url('assets/basecards/' . $image->card_filename);
|
||||
$return->{$image->id} = $image;
|
||||
}
|
||||
}
|
||||
|
||||
// Return our defaults, or our counts
|
||||
return $return;
|
||||
}
|
||||
|
||||
/**
|
||||
* countStatuses
|
||||
* Get numbers for card statuses
|
||||
|
||||
@@ -78,12 +78,14 @@
|
||||
<?php
|
||||
if (! empty($images)) {
|
||||
foreach ($images as $i => $image) {
|
||||
$name = pathinfo($image, PATHINFO_FILENAME);
|
||||
|
||||
?> <option data-img-src='<?php echo $image;
|
||||
$url = $image->card_url;
|
||||
$name = $image->card_alt . ' (#' . $i . ')';
|
||||
|
||||
?> <option data-img-src='<?php echo $url;
|
||||
?>' value='<?php
|
||||
echo $image;
|
||||
?>'>Kuva: <?=$name;?></option><?php
|
||||
echo $url;
|
||||
?>'>Kuva: <?php echo $name; ?></option><?php
|
||||
echo "\n";
|
||||
}
|
||||
}
|
||||
|
||||
14
tables.sql
14
tables.sql
@@ -48,3 +48,17 @@ CREATE TABLE IF NOT EXISTS `ystavakyla_ecards__users` (
|
||||
PRIMARY KEY (`id`),
|
||||
UNIQUE KEY `username` (`username`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
|
||||
|
||||
CREATE TABLE IF NOT EXISTS `ystavakyla_ecards__templates` (
|
||||
`id` int(22) NOT NULL AUTO_INCREMENT,
|
||||
`card_filename` varchar(255) DEFAULT NULL COMMENT 'cardname.jpg',
|
||||
`card_author` varchar(255) DEFAULT NULL COMMENT 'Copyright notice',
|
||||
`card_alt` varchar(255) DEFAULT NULL COMMENT 'Alternative for img tag',
|
||||
`card_status` tinyint(1) NOT NULL DEFAULT '1' COMMENT 'Is the card active',
|
||||
`created_by` int(55) DEFAULT NULL COMMENT 'User id who uploaded',
|
||||
`created_at` timestamp NULL DEFAULT NULL,
|
||||
`updated_at` timestamp NULL DEFAULT NULL,
|
||||
PRIMARY KEY (`id`),
|
||||
UNIQUE KEY `card_filename` (`card_filename`),
|
||||
KEY `card_status` (`card_status`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;
|
||||
Reference in New Issue
Block a user