Skip to content

Commit f7915a9

Browse files
committedJan 23, 2015
Initial package
The first commit finished package.
1 parent 0597f97 commit f7915a9

File tree

16 files changed

+363
-2
lines changed

16 files changed

+363
-2
lines changed
 

‎.travis.yml

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
language: php
2+
3+
php:
4+
- 5.4
5+
- 5.5
6+
- 5.6
7+
- hhvm
8+
9+
before_script:
10+
- travis_retry composer self-update
11+
- travis_retry composer install --prefer-source --no-interaction --dev
12+
13+
script: phpunit

‎LICENSE

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) 2012 Florian Eckerstorfer
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
6+
7+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
8+
9+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

‎README.md

+66-2
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,66 @@
1-
# timezonelist
2-
A small package use to create a timezone list box in Laravel 4
1+
# Feature
2+
Render a timezone listbox (select box) in Laravel
3+
4+
## Installation
5+
6+
You can install this package through [Composer](https://getcomposer.org).
7+
8+
First, edit your project's `composer.json` file to require `jackiedo/timezonelist`:
9+
10+
```php
11+
...
12+
"require": {
13+
...
14+
"jackiedo/timezonelist": "dev-master"
15+
},
16+
```
17+
18+
Next, update Composer from the Terminal:
19+
20+
```shell
21+
$ composer update
22+
```
23+
24+
Once update operation completes, the final step is to add the service provider. Open `app/config/app.php`, and add a new item to the providers array:
25+
26+
```php
27+
...
28+
'providers' => array(
29+
...
30+
'Jackiedo\Timezonelist\TimezonelistServiceProvider',
31+
),
32+
```
33+
34+
### Usage
35+
36+
To render a timezone select box, use method Timezonelist::create($select_box_name).
37+
Example:
38+
```php
39+
Timezonelist::create('timezone');
40+
```
41+
42+
Method Timezonelist::create() have three parameters:
43+
```php
44+
Timezonelist::create($name, $selected_value, $html_atribute);
45+
```
46+
The first parameter is required, but the second and third is optional.
47+
48+
- The second parameter use to set selected value of list box.
49+
Example:
50+
```php
51+
Timezonelist::create('timezone', 'Asia/Ho_Chi_Minh');
52+
```
53+
54+
- The third parameter use to set HTML attribute of select tag
55+
Example:
56+
```php
57+
Timezonelist::create('timezone', null, 'class="styled"');
58+
```
59+
60+
You can also add multiple attribute
61+
Example:
62+
```php
63+
Timezonelist::create('timezone', null, 'class="styled" placeholder="Plese select a timezone"');
64+
```
65+
66+
Hopefully, this package is useful to you.

‎composer.json

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
{
2+
"name": "jackiedo/timezonelist",
3+
"description": "A small package use to create a timezone list box in Laravel 4",
4+
"keywords": ["timezone", "timezones", "timezonelist", "laravel"],
5+
"license": "MIT",
6+
"authors": [
7+
{
8+
"name": "Jackie Do",
9+
"email": "anhvudo@gmail.com"
10+
}
11+
],
12+
"require": {
13+
"php": ">=5.4.0",
14+
"illuminate/support": "4.2.*"
15+
},
16+
"autoload": {
17+
"classmap": [
18+
"src/migrations"
19+
],
20+
"psr-0": {
21+
"Jackiedo\\Timezonelist\\": "src/"
22+
}
23+
},
24+
"minimum-stability": "stable"
25+
}

‎composer.lock

+68
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎phpunit.xml

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<phpunit backupGlobals="false"
3+
backupStaticAttributes="false"
4+
bootstrap="vendor/autoload.php"
5+
colors="true"
6+
convertErrorsToExceptions="true"
7+
convertNoticesToExceptions="true"
8+
convertWarningsToExceptions="true"
9+
processIsolation="false"
10+
stopOnFailure="false"
11+
syntaxCheck="false"
12+
>
13+
<testsuites>
14+
<testsuite name="Package Test Suite">
15+
<directory suffix=".php">./tests/</directory>
16+
</testsuite>
17+
</testsuites>
18+
</phpunit>

‎public/.gitkeep

Whitespace-only changes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php namespace Jackiedo\Timezonelist\Facades;
2+
3+
use Illuminate\Support\Facades\Facade;
4+
5+
/**
6+
* Timezonelist
7+
*
8+
* @package jackiedo/timezonelist
9+
* @subpackage facades
10+
* @author Jackie Do <anhvudo@gmail.com>
11+
* @copyright 2015 Jackie Do
12+
*/
13+
14+
class Timezonelist extends Facade {
15+
16+
/**
17+
* Get the registered name of the component.
18+
*
19+
* @return string
20+
*/
21+
protected static function getFacadeAccessor() { return 'timezonelist'; }
22+
23+
}
24+
25+
?>
+80
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
<?php namespace Jackiedo\Timezonelist;
2+
3+
use DateTimeZone;
4+
use DateTime;
5+
6+
/**
7+
* Timezonelist
8+
*
9+
* @package jackiedo/timezonelist
10+
* @author Jackie Do <anhvudo@gmail.com>
11+
* @copyright 2015 Jackie Do
12+
*/
13+
14+
class Timezonelist {
15+
16+
/**
17+
* Create a GMT timezone list box
18+
*
19+
*
20+
**/
21+
public static function create($name, $selected='', $attr='') {
22+
23+
// List of all continents in the world
24+
$continents = array(
25+
'Africa' => DateTimeZone::AFRICA,
26+
'America' => DateTimeZone::AMERICA,
27+
'Antarctica' => DateTimeZone::ANTARCTICA,
28+
'Arctic' => DateTimeZone::ARCTIC,
29+
'Asia' => DateTimeZone::ASIA,
30+
'Atlantic' => DateTimeZone::ATLANTIC,
31+
'Australia' => DateTimeZone::AUSTRALIA,
32+
'Europe' => DateTimeZone::EUROPE,
33+
'Indian' => DateTimeZone::INDIAN,
34+
'Pacific' => DateTimeZone::PACIFIC
35+
);
36+
37+
// Create listbox
38+
$attrSet = (!empty($attr)) ? ' ' . $attr : '';
39+
$listbox = '<select name="' .$name. '"' .$attrSet. '>' . "\n";
40+
foreach ($continents as $name => $mask) {
41+
$zones = DateTimeZone::listIdentifiers($mask);
42+
$listbox .= "\t" . '<optgroup label="' .$name. '">' . "\n";
43+
foreach ($zones as $timezone) {
44+
// Lets sample the time there right now
45+
$time = new DateTime(NULL, new DateTimeZone($timezone));
46+
47+
// selected atribute
48+
$selected_attr = ($selected == $timezone) ? ' selected="selected"' : '';
49+
50+
// Create options tag
51+
$listbox .= "\t\t" . '<option value="' .$timezone. '"' .$selected_attr. '>';
52+
$listbox .= '(GMT' . $time->format('P') . ')&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;' . str_replace('_', ' ', substr($timezone, strlen($name) + 1));
53+
$listbox .= '</option>' . "\n";
54+
}
55+
$listbox .= "\t" . '</optgroup>' . "\n";
56+
57+
// Add two option general: UTC and GMT
58+
$listbox .= "\t" . '<optgroup label="General">' . "\n";
59+
$listbox .= "\t\t" . '<option value="UTC"';
60+
if ($selected == 'UTC') {
61+
$listbox .= ' selected="selected"';
62+
}
63+
$listbox .= '>(UTC)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;UTC timezone';
64+
$listbox .= '</option>' . "\n";
65+
$listbox .= "\t\t" . '<option value="GMT"';
66+
if ($selected == 'GMT') {
67+
$listbox .= ' selected="selected"';
68+
}
69+
$listbox .= '>(GMT)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;GMT timezone';
70+
$listbox .= '</option>' . "\n";
71+
$listbox .= "\t" . '</optgroup>' . "\n";
72+
}
73+
$listbox .= '</select>' . "\n";
74+
75+
// return lisbox
76+
return $listbox;
77+
}
78+
}
79+
80+
?>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
<?php namespace Jackiedo\Timezonelist;
2+
3+
use Illuminate\Support\ServiceProvider;
4+
5+
/**
6+
* TimezonelistServiceProvider
7+
*
8+
* @package jackiedo/timezonelist
9+
* @author Jackie Do <anhvudo@gmail.com>
10+
* @copyright 2015 Jackie Do
11+
*/
12+
13+
class TimezonelistServiceProvider extends ServiceProvider {
14+
15+
/**
16+
* Indicates if loading of the provider is deferred.
17+
*
18+
* @var bool
19+
*/
20+
protected $defer = false;
21+
22+
/**
23+
* Bootstrap the application events.
24+
*
25+
* @return void
26+
*/
27+
public function boot()
28+
{
29+
$this->package('jackiedo/timezonelist');
30+
}
31+
32+
/**
33+
* Register the service provider.
34+
*
35+
* @return void
36+
*/
37+
public function register()
38+
{
39+
$this->app['timezonelist'] = $this->app->share(function($app) {
40+
return new Timezonelist;
41+
});
42+
43+
$this->app->booting(function() {
44+
$loader = \Illuminate\Foundation\AliasLoader::getInstance();
45+
$loader->alias('Timezonelist', 'Jackiedo\Timezonelist\Facades\Timezonelist');
46+
});
47+
}
48+
49+
/**
50+
* Get the services provided by the provider.
51+
*
52+
* @return array
53+
*/
54+
public function provides()
55+
{
56+
return array();
57+
}
58+
59+
}

‎src/config/.gitkeep

Whitespace-only changes.

‎src/controllers/.gitkeep

Whitespace-only changes.

‎src/lang/.gitkeep

Whitespace-only changes.

‎src/migrations/.gitkeep

Whitespace-only changes.

‎src/views/.gitkeep

Whitespace-only changes.

‎tests/.gitkeep

Whitespace-only changes.

0 commit comments

Comments
 (0)
Please sign in to comment.