Tyhjien korttipohjien haku tietokannasta

This commit is contained in:
2013-12-10 14:15:21 +02:00
parent 3ddcb31fb6
commit 74436ec57a
4 changed files with 64 additions and 5 deletions

View File

@@ -65,7 +65,7 @@ class Welcome extends CI_Controller
'page_title' => array( 'Uusi eKortti', 'Ystäväkylä eKortti' ), 'page_title' => array( 'Uusi eKortti', 'Ystäväkylä eKortti' ),
'page_classes' => array( 'new_card' ), 'page_classes' => array( 'new_card' ),
'count' => $this->card_count, 'count' => $this->card_count,
'images' => fetchBaseCards(), 'images' => $this->ecard->getCardsTemplates(1),
'user' => $this->user 'user' => $this->user
); );

View File

@@ -183,6 +183,49 @@ class Ecard_model extends MY_Model
return true; 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 * countStatuses
* Get numbers for card statuses * Get numbers for card statuses

View File

@@ -78,12 +78,14 @@
<?php <?php
if (! empty($images)) { if (! empty($images)) {
foreach ($images as $i => $image) { 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 ?>' value='<?php
echo $image; echo $url;
?>'>Kuva: <?=$name;?></option><?php ?>'>Kuva: <?php echo $name; ?></option><?php
echo "\n"; echo "\n";
} }
} }

View File

@@ -48,3 +48,17 @@ CREATE TABLE IF NOT EXISTS `ystavakyla_ecards__users` (
PRIMARY KEY (`id`), PRIMARY KEY (`id`),
UNIQUE KEY `username` (`username`) UNIQUE KEY `username` (`username`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8; ) 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 ;