Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 24 additions & 3 deletions shrtr.install
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?php

/**
* Implements hook_schema().
*/
* Implements hook_schema().
*/
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Azok a szóközök kellenek oda...

function shrtr_schema() {
$schema['shrtr_urls'] = array(
'description' => 'Shortened URLs',
Expand Down Expand Up @@ -47,9 +47,15 @@ function shrtr_schema() {
'description' => 'Enabled',
'type' => 'int',
'not null' => TRUE,
'default' => 1,
'default' => 0,
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Erre a változtatásra biztosan szükség van?

'length' => 1,
),
'hits' => array(
'description' => 'Hits',
'type' => 'int',
'not null' => TRUE,
'default' => 0,
),
),
'primary key' => array('id'),
'unique keys' => array(
Expand All @@ -64,3 +70,18 @@ function shrtr_schema() {
);
return $schema;
}

/**
* Creates hit counter field.
*/
function shrtr_update_7901() {
$hits = array(
'description' => 'Hits',
'type' => 'int',
'not null' => TRUE,
'default' => 0,
);
db_add_field('shrtr_urls', 'expire', $hits);

return t('Hit counter field of added to database.');
}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nagyon jó, de fejlesztés közben most nem kell update hook-okat írni, ez azért maradhat :)

11 changes: 7 additions & 4 deletions shrtr.module
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ function shrtr_menu() {
}

/**
* Returns a form array for submit new ULR-s.
* Returns a form array for submit new URL-s.
*/
function shrtr_new_form($form = array(), &$form_state) {
$form['url'] = array(
Expand Down Expand Up @@ -120,6 +120,7 @@ function shrtr_new_form_submit($form, &$form_state) {
'uid' => $user->uid,
'created' => REQUEST_TIME,
'expire' => $expire,
'hits' => $hits,
'alias' => $alias,
);

Expand All @@ -133,12 +134,13 @@ function shrtr_new_form_submit($form, &$form_state) {
*/
function shrtr_goto($alias) {
$result = db_select('shrtr_urls', 's')
->fields('s', array('url', 'expire'))
->fields('s', array('url', 'expire', 'hits'))
->condition('alias', $alias)
->execute()
->fetchAssoc();

if ($result['expire'] == 0 || $result['expire'] > REQUEST_TIME) {
$result['hits']++;
drupal_goto($result['url']);
}
else {
Expand Down Expand Up @@ -178,7 +180,7 @@ function shrtr_list_page() {
->fields('s')
->execute();

$header = array(t('ID'), t('User'), t('Original URL'), t('New URL'), t('Subbmitted'), t('Expire time'));
$header = array(t('ID'), t('User'), t('Original URL'), t('New URL'), t('Submitted'), t('Expire time'), t('Hits'));
$rows = array();

while ($url = $urls->fetchAssoc()) {
Expand All @@ -190,6 +192,7 @@ function shrtr_list_page() {
$row[] = l($new_url, $new_url);
$row[] = format_date($url['created']);
$row[] = format_date($url['expire']);
$row[] = $url['hits'];
$rows[] = $row;
}

Expand All @@ -209,7 +212,7 @@ function shrtr_urls_admin() {
->fields('s')
->execute();

$header = array(t('ID'), t('Enabled'), t('User'), t('Original URL'), t('New URL'), t('Subbmitted'), t('Expire time'));
$header = array(t('ID'), t('Enabled'), t('User'), t('Original URL'), t('New URL'), t('Submitted'), t('Expire time'), t('Number of hits'));
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Az admin oldalra nem kell feltétlenül a statisztika, de ha már itt van, akkor a sorok közé is be kellene tenni.

$rows = array();
$default = array();

Expand Down