From 1527cce8124bc3b87c17c269aa92d711eb2df3fc Mon Sep 17 00:00:00 2001 From: euromark Date: Tue, 17 Sep 2013 01:10:22 +0200 Subject: [PATCH] doc block updates and timeline helper --- Lib/Cache/Engine/MemcachedEngine.php | 2 - .../Component/Auth/DirectAuthenticateTest.php | 1 - .../Component/Auth/TinyAuthorizeTest.php | 1 - .../Component/AutoLoginComponentTest.php | 4 - .../Model/Behavior/SluggedBehaviorTest.php | 2 - Test/Case/View/Helper/DatetimeHelperTest.php | 2 - Test/Case/View/Helper/FormExtHelperTest.php | 2 - Test/Case/View/Helper/QrCodeHelperTest.php | 2 - Test/Case/View/Helper/TimelineHelperTest.php | 71 +++++ Test/Fixture/MessageFixture.php | 2 - Test/Fixture/SoftDeletePostFixture.php | 2 - View/Helper/CaptchaHelper.php | 1 - View/Helper/FormExtHelper.php | 12 +- View/Helper/GoogleMapV3Helper.php | 3 +- View/Helper/GravatarHelper.php | 2 - View/Helper/TimelineHelper.php | 245 ++++++++++++++++++ View/Helper/TypographyHelper.php | 2 - 17 files changed, 328 insertions(+), 28 deletions(-) create mode 100644 Test/Case/View/Helper/TimelineHelperTest.php create mode 100644 View/Helper/TimelineHelper.php diff --git a/Lib/Cache/Engine/MemcachedEngine.php b/Lib/Cache/Engine/MemcachedEngine.php index 72e7a8651..4fdb398c1 100644 --- a/Lib/Cache/Engine/MemcachedEngine.php +++ b/Lib/Cache/Engine/MemcachedEngine.php @@ -13,7 +13,6 @@ * * @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org) * @link http://cakephp.org CakePHP(tm) Project - * @package Cake.Cache.Engine * @since CakePHP(tm) v 1.2.0.4933 * @license http://www.opensource.org/licenses/mit-license.php MIT License */ @@ -31,7 +30,6 @@ * (if memcached extension compiled with --enable-igbinary). * Compressed keys can also be incremented/decremented. * - * @package Cake.Cache.Engine */ class MemcachedEngine extends CacheEngine { diff --git a/Test/Case/Controller/Component/Auth/DirectAuthenticateTest.php b/Test/Case/Controller/Component/Auth/DirectAuthenticateTest.php index 7916104c3..d7948ab45 100644 --- a/Test/Case/Controller/Component/Auth/DirectAuthenticateTest.php +++ b/Test/Case/Controller/Component/Auth/DirectAuthenticateTest.php @@ -14,7 +14,6 @@ /** * Test case for DirectAuthentication * - * @package Cake.Test.Case.Controller.Component.Auth */ class DirectAuthenticateTest extends CakeTestCase { diff --git a/Test/Case/Controller/Component/Auth/TinyAuthorizeTest.php b/Test/Case/Controller/Component/Auth/TinyAuthorizeTest.php index 7dfa244fd..70a612a5c 100644 --- a/Test/Case/Controller/Component/Auth/TinyAuthorizeTest.php +++ b/Test/Case/Controller/Component/Auth/TinyAuthorizeTest.php @@ -13,7 +13,6 @@ /** * Test case for DirectAuthentication * - * @package Test.Case.Controller.Component.Auth */ class TinyAuthorizeTest extends MyCakeTestCase { diff --git a/Test/Case/Controller/Component/AutoLoginComponentTest.php b/Test/Case/Controller/Component/AutoLoginComponentTest.php index 1927314c1..0335def70 100644 --- a/Test/Case/Controller/Component/AutoLoginComponentTest.php +++ b/Test/Case/Controller/Component/AutoLoginComponentTest.php @@ -6,8 +6,6 @@ /** * Short description for class. * - * @package cake.tests - * @subpackage cake.tests.cases.libs.controller.components */ class AutoLoginComponentTest extends CakeTestCase { @@ -98,8 +96,6 @@ public function testLogin() { /** * Short description for class. * - * @package cake.tests - * @subpackage cake.tests.cases.libs.controller.components */ class AutoLoginTestController extends Controller { /** diff --git a/Test/Case/Model/Behavior/SluggedBehaviorTest.php b/Test/Case/Model/Behavior/SluggedBehaviorTest.php index 838289001..102901b1c 100644 --- a/Test/Case/Model/Behavior/SluggedBehaviorTest.php +++ b/Test/Case/Model/Behavior/SluggedBehaviorTest.php @@ -18226,8 +18226,6 @@ public function testDuplicateWithLengthRestriction() { * MessageSlugged class * * @uses CakeTestModel - * @package mi - * @subpackage mi.tests.cases.behaviors */ class MessageSlugged extends CakeTestModel { diff --git a/Test/Case/View/Helper/DatetimeHelperTest.php b/Test/Case/View/Helper/DatetimeHelperTest.php index 8eae82dfc..ec00fe3bb 100644 --- a/Test/Case/View/Helper/DatetimeHelperTest.php +++ b/Test/Case/View/Helper/DatetimeHelperTest.php @@ -7,8 +7,6 @@ /** * Datetime Test Case * - * @package cake.tests - * @subpackage cake.tests.cases.libs.view.helpers */ class DatetimeHelperTest extends MyCakeTestCase { diff --git a/Test/Case/View/Helper/FormExtHelperTest.php b/Test/Case/View/Helper/FormExtHelperTest.php index f9ca14f3c..d8ac7d33c 100644 --- a/Test/Case/View/Helper/FormExtHelperTest.php +++ b/Test/Case/View/Helper/FormExtHelperTest.php @@ -194,8 +194,6 @@ public function testNormalize() { /** * Contact class * - * @package cake - * @package Cake.Test.Case.View.Helper */ class ContactExt extends CakeTestModel { diff --git a/Test/Case/View/Helper/QrCodeHelperTest.php b/Test/Case/View/Helper/QrCodeHelperTest.php index 671a94f5a..006dd6cd2 100644 --- a/Test/Case/View/Helper/QrCodeHelperTest.php +++ b/Test/Case/View/Helper/QrCodeHelperTest.php @@ -16,8 +16,6 @@ /** * QrCode Test Case * - * @package cake.tests - * @subpackage cake.tests.cases.libs.view.helpers */ class QrCodeHelperTest extends MyCakeTestCase { /** diff --git a/Test/Case/View/Helper/TimelineHelperTest.php b/Test/Case/View/Helper/TimelineHelperTest.php new file mode 100644 index 000000000..ba0c0cae0 --- /dev/null +++ b/Test/Case/View/Helper/TimelineHelperTest.php @@ -0,0 +1,71 @@ +Timeline = new TimelineTestHelper(new View(null)); + $this->Timeline->Html = new HtmlHelper(new View(null)); + } + + /** + * @return void + */ + public function testAddItem() { + $data = array( + 'start' => '', + 'content' => '', + ); + $this->Timeline->addItem($data); + $items = $this->Timeline->items(); + $this->assertSame(1, count($items)); + + $data = array( + array( + 'start' => '', + 'content' => '', + ), + array( + 'start' => '', + 'content' => '', + ) + ); + $this->Timeline->addItems($data); + $items = $this->Timeline->items(); + $this->assertSame(3, count($items)); + } + + public function tearDown() { + parent::tearDown(); + + unset($this->Timeline); + } + +} + +class TimelineTestHelper extends TimelineHelper { + + /** + * @return array + */ + public function items() { + return $this->_items; + } + +} \ No newline at end of file diff --git a/Test/Fixture/MessageFixture.php b/Test/Fixture/MessageFixture.php index 9d5c3017d..39e8ec622 100644 --- a/Test/Fixture/MessageFixture.php +++ b/Test/Fixture/MessageFixture.php @@ -13,8 +13,6 @@ * * @copyright Copyright (c) 2008, Andy Dawson * @link www.ad7six.com - * @package mi - * @subpackage mi.tests.fixtures * @since v 1.0 * @modifiedBy $LastChangedBy$ * @lastModified $Date$ diff --git a/Test/Fixture/SoftDeletePostFixture.php b/Test/Fixture/SoftDeletePostFixture.php index 7f116edcd..275d5a1e0 100644 --- a/Test/Fixture/SoftDeletePostFixture.php +++ b/Test/Fixture/SoftDeletePostFixture.php @@ -2,8 +2,6 @@ /** * Short description for class. * - * @package cake - * @subpackage cake.tests.fixtures */ class SoftDeletePostFixture extends CakeTestFixture { diff --git a/View/Helper/CaptchaHelper.php b/View/Helper/CaptchaHelper.php index 950e985ec..d26e6afe4 100644 --- a/View/Helper/CaptchaHelper.php +++ b/View/Helper/CaptchaHelper.php @@ -11,7 +11,6 @@ * * @author Mark Scherer * @link http://www.dereuromark.de - * @package tools plugin * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ diff --git a/View/Helper/FormExtHelper.php b/View/Helper/FormExtHelper.php index f20abce21..549138d4a 100644 --- a/View/Helper/FormExtHelper.php +++ b/View/Helper/FormExtHelper.php @@ -92,7 +92,9 @@ public function postLink($title, $url = null, $options = array(), $confirmMessag } /** - * Overwrite FormHelper::create() to allow disabling browser html5 validation via configs + * Overwrite FormHelper::create() to allow disabling browser html5 validation via configs. + * It also grabs inputDefaults from your Configure if set. + * Also adds the class "form-control" to all inputs for better control over them. * * @param string $model * @param array $options @@ -102,6 +104,14 @@ public function create($model = null, $options = array()) { if (Configure::read('Validation.browserAutoRequire') === false && !isset($options['novalidate'])) { $options['novalidate'] = true; } + if (!isset($options['inputDefaults'])) { + $options['inputDefaults'] = array(); + } + $options['inputDefaults'] += (array)Configure::read('Form.inputDefaults'); + $options['inputDefaults'] += array( + 'class' => array('form-control'), + ); + return parent::create($model, $options); } diff --git a/View/Helper/GoogleMapV3Helper.php b/View/Helper/GoogleMapV3Helper.php index ac89327af..8f1841808 100644 --- a/View/Helper/GoogleMapV3Helper.php +++ b/View/Helper/GoogleMapV3Helper.php @@ -15,7 +15,6 @@ * * @author Mark Scherer * @link http://www.dereuromark.de/2010/12/21/googlemapsv3-cakephp-helper/ - * @package tools plugin * @license MIT License (http://www.opensource.org/licenses/mit-license.php) * * fixed brackets, spacesToTabs, indends, some improvements, supports multiple maps now. @@ -481,7 +480,7 @@ public function _initialLocation() { * * @param array $options * - lat and lng or address (to geocode on demand, not recommended, though) - * - title, content, icon, directions (optional) + * - title, content, icon, directions, maxWidth (optional) * @return int $markerCount or false on failure * @throws CakeException * 2010-12-18 ms diff --git a/View/Helper/GravatarHelper.php b/View/Helper/GravatarHelper.php index cfa6b4d49..a61679205 100644 --- a/View/Helper/GravatarHelper.php +++ b/View/Helper/GravatarHelper.php @@ -8,8 +8,6 @@ * * @copyright Copyright 2009-2010, Graham Weldon (http://grahamweldon.com) * @license http://www.opensource.org/licenses/mit-license.php The MIT License - * @package goodies - * @subpackage goodies.views.helpers * * hashtype now always md5 * 2010-12-21 ms diff --git a/View/Helper/TimelineHelper.php b/View/Helper/TimelineHelper.php new file mode 100644 index 000000000..d9417ad36 --- /dev/null +++ b/View/Helper/TimelineHelper.php @@ -0,0 +1,245 @@ +Html->script('timeline/timeline'); + * echo $this->Html->css('/js/timeline/timeline'); + * + * @link http://almende.github.io/chap-links-library/timeline.html + * @author Mark Scherer + * @license MIT + */ +class TimelineHelper extends AppHelper { + + public $helpers = array('Js'); + + protected $_defaults = array( + 'id' => 'mytimeline', + 'selectable' => false, + 'editable' => false, + 'min' => null, // Min date. + 'max' => null, // Max date. + 'width' => '100%', + 'height' => null, // Auto. + 'style' => 'box', + 'current' => null, // Current time. + ); + + protected $_items = array(); + + /** + * Constructor + * + * @param View $View The View this helper is being attached to. + * @param array $settings Configuration settings for the helper. + */ + public function __construct(View $View, $settings = array()) { + $this->settings = $this->_defaults; + parent::__construct($View, $settings); + } + + /** + * Apply settings and merge them with the defaults. + * + * Possible values are (with their default values): + * - 'min', + * - 'max', + * - 'width' + * - 'height' + * - 'minHeight' + * - 'selectable' => false, + * - 'editable' => false, + * - 'moveable' => true + * - 'animate' => true, + * - 'animateZoom' => true, + * - 'axisOnTop' => false, + * - 'cluster' => false + * - 'locale' (string) + * - 'style' (string) + * - ... + * + * @link http://almende.github.io/chap-links-library/js/timeline/doc/ + * @param array $settings Key value pairs to merge with current settings. + * @return void + */ + public function settings($settings) { + $this->settings = Hash::merge($this->settings, $settings); + } + + /** + * Add timeline item. + * + * Requires at least: + * - start (date or datetime) + * - content (string) + * Further data options: + * - end (date or datetime) + * - group (string) + * - className (string) + * - editable (boolean) + * + * @link http://almende.github.io/chap-links-library/js/timeline/doc/ + * @param array + * @return void + */ + public function addItem($item) { + $this->_items[] = $item; + } + + /** + * Add timeline items as an array of items. + * + * @see TimelineHelper::addItem() + * @return void + */ + public function addItems($items) { + foreach ($items as $item) { + $this->_items[] = $item; + } + } + + /** + * Finalize the timeline and write the javascript to the buffer. + * Make sure that your view does also output the buffer at some place! + * + * @param boolean $return If the output should be returned instead + * @return void or string Javascript if $return is true + */ + public function finalize($return = false) { + $settings = $this->settings; + $timelineId = $settings['id']; + $data = $this->_format($this->_items); + + $current = ''; + if ($settings['current']) { + $dateString = date('Y-m-d H:i:s', time()); + $current = 'timeline.setCurrentTime(' . $this->_date($dateString) . ');'; + } + unset($settings['id']); + unset($settings['current']); + $options = $this->_options($settings); + + $script = <<Js->buffer($script); + } + + /** + * Format options to JS code + * + * @param array $options + * @return string + */ + protected function _options($options) { + $e = array(); + foreach ($options as $option => $value) { + if (is_null($value)) { + continue; + } + if (is_string($value)) { + $value = '\'' . $value . '\''; + } elseif (is_object($value)) { // Datetime? + $value = $this->_date($value); + } elseif (is_bool($value)) { + $value = $value ? 'true' : 'false'; + } else { + $value = str_replace('\'', '\\\'', $value); + } + $e[] = '\'' . $option . '\': ' . $value; + } + $string = '{' . PHP_EOL . "\t" . implode(',' . PHP_EOL . "\t", $e) . PHP_EOL . '}'; + return $string; + } + + /** + * Format items to JS code + * + * @see TimelineHelper::addItem() + * @param array $items + * @return string + */ + protected function _format($items) { + $e = array(); + foreach ($items as $item) { + $tmp = array(); + foreach ($item as $key => $row) { + switch ($key) { + case 'editable': + $tmp[] = $row ? 'true' : 'false'; + break; + case 'start': + case 'end': + $tmp[] = '\'' . $key . '\': ' . $this->_date($row); + break; + default: + $tmp[] = '\'' . $key . '\': \'' . str_replace('\'', '\\\'', $row) . '\''; + } + } + $e[] = '{' . implode(',' . PHP_EOL, $tmp) . '}'; + } + $string = '[' . implode(',' . PHP_EOL, $e) . '];'; + return $string; + } + + /** + * Format date to JS code. + * + * @param string|DateTime $date + * @return string + */ + protected function _date($date) { + if (is_object($date)) { + // Datetime? + $datePieces = array(); + $datePieces[] = $date->format('Y'); + // JavaScript uses 0-indexed months, so we need to subtract 1 month from PHP's output + $datePieces[] = (int)($date->format('m') - 1); + $datePieces[] = (int)$date->format('d'); + $datePieces[] = (int)$date->format('H'); + $datePieces[] = (int)$date->format('i'); + $datePieces[] = (int)$date->format('s'); + } else { + // As string (fallback). + $dateTime = explode(' ', $date, 2); + $datePieces = array(); + $datePieces[] = substr($dateTime[0], 0, 4); + // JavaScript uses 0-indexed months, so we need to subtract 1 month from the output + $datePieces[] = (int)(substr($dateTime[0], 5, 2) - 1); + $datePieces[] = (int)substr($dateTime[0], 8, 2); + if (!empty($dateTime[1])) { + $datePieces[] = (int)substr($dateTime[1], 0, 2); + $datePieces[] = (int)substr($dateTime[1], 3, 2); + $datePieces[] = (int)substr($dateTime[1], 6, 2); + } + } + return 'new Date(' . implode(', ', $datePieces) . ')'; + } + +} diff --git a/View/Helper/TypographyHelper.php b/View/Helper/TypographyHelper.php index 5809952a6..791a50bc8 100644 --- a/View/Helper/TypographyHelper.php +++ b/View/Helper/TypographyHelper.php @@ -4,13 +4,11 @@ * * An open source application development framework for PHP 5.1.6 or newer * - * @package CodeIgniter * @author ExpressionEngine Dev Team * @copyright Copyright (c) 2008 - 2011, EllisLab, Inc. * @license http://codeigniter.com/user_guide/license.html * @link http://codeigniter.com * @since Version 1.0 - * @filesource */ App::uses('AppHelper', 'View/Helper');