浏览代码

doc block updates and timeline helper

euromark 12 年之前
父节点
当前提交
1527cce812

+ 0 - 2
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 {
 

+ 0 - 1
Test/Case/Controller/Component/Auth/DirectAuthenticateTest.php

@@ -14,7 +14,6 @@ App::uses('CakeResponse', 'Network');
 /**
  * Test case for DirectAuthentication
  *
- * @package       Cake.Test.Case.Controller.Component.Auth
  */
 class DirectAuthenticateTest extends CakeTestCase {
 

+ 0 - 1
Test/Case/Controller/Component/Auth/TinyAuthorizeTest.php

@@ -13,7 +13,6 @@ App::uses('CakeRequest', 'Network');
 /**
  * Test case for DirectAuthentication
  *
- * @package Test.Case.Controller.Component.Auth
  */
 class TinyAuthorizeTest extends MyCakeTestCase {
 

+ 0 - 4
Test/Case/Controller/Component/AutoLoginComponentTest.php

@@ -6,8 +6,6 @@ App::uses('Controller', 'Controller');
 /**
  * Short description for class.
  *
- * @package cake.tests
- * @subpackage cake.tests.cases.libs.controller.components
  */
 class AutoLoginComponentTest extends CakeTestCase {
 
@@ -98,8 +96,6 @@ class AutoLoginComponentTest extends CakeTestCase {
 /**
  * Short description for class.
  *
- * @package cake.tests
- * @subpackage cake.tests.cases.libs.controller.components
  */
 class AutoLoginTestController extends Controller {
 	/**

+ 0 - 2
Test/Case/Model/Behavior/SluggedBehaviorTest.php

@@ -18226,8 +18226,6 @@ class SluggedBehaviorTest extends CakeTestCase {
  * MessageSlugged class
  *
  * @uses CakeTestModel
- * @package mi
- * @subpackage mi.tests.cases.behaviors
  */
 class MessageSlugged extends CakeTestModel {
 

+ 0 - 2
Test/Case/View/Helper/DatetimeHelperTest.php

@@ -7,8 +7,6 @@ App::uses('View', 'View');
 /**
  * Datetime Test Case
  *
- * @package cake.tests
- * @subpackage cake.tests.cases.libs.view.helpers
  */
 class DatetimeHelperTest extends MyCakeTestCase {
 

+ 0 - 2
Test/Case/View/Helper/FormExtHelperTest.php

@@ -194,8 +194,6 @@ class FormExtHelperTest extends MyCakeTestCase {
 /**
  * Contact class
  *
- * @package	   cake
- * @package       Cake.Test.Case.View.Helper
  */
 class ContactExt extends CakeTestModel {
 

+ 0 - 2
Test/Case/View/Helper/QrCodeHelperTest.php

@@ -16,8 +16,6 @@ App::uses('MyCakeTestCase', 'Tools.TestSuite');
 /**
  * QrCode Test Case
  *
- * @package cake.tests
- * @subpackage cake.tests.cases.libs.view.helpers
  */
 class QrCodeHelperTest extends MyCakeTestCase {
 /**

+ 71 - 0
Test/Case/View/Helper/TimelineHelperTest.php

@@ -0,0 +1,71 @@
+<?php
+
+App::uses('TimelineHelper', 'Tools.View/Helper');
+App::uses('MyCakeTestCase', 'Tools.TestSuite');
+App::uses('HtmlHelper', 'View/Helper');
+App::uses('View', 'View');
+
+/**
+ * Timeline Helper Test Case
+ */
+class TimelineHelperTest extends MyCakeTestCase {
+
+	public $Timeline;
+
+	/**
+	 * TimelineHelperTest::setUp()
+	 *
+	 * @return void
+	 */
+	public function setUp() {
+		parent::setUp();
+
+		$this->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;
+	}
+
+}

+ 0 - 2
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$

+ 0 - 2
Test/Fixture/SoftDeletePostFixture.php

@@ -2,8 +2,6 @@
 /**
  * Short description for class.
  *
- * @package cake
- * @subpackage cake.tests.fixtures
  */
 class SoftDeletePostFixture extends CakeTestFixture {
 

+ 0 - 1
View/Helper/CaptchaHelper.php

@@ -11,7 +11,6 @@ if (!defined('BR')) {
  *
  * @author Mark Scherer
  * @link http://www.dereuromark.de
- * @package tools plugin
  * @license MIT License (http://www.opensource.org/licenses/mit-license.php)
  */
 

+ 11 - 1
View/Helper/FormExtHelper.php

@@ -92,7 +92,9 @@ class FormExtHelper extends FormHelper {
 	}
 
 	/**
-	 * 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 @@ class FormExtHelper extends FormHelper {
 		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);
 	}
 

+ 1 - 2
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 @@ class GoogleMapV3Helper extends AppHelper {
 	 *
 	 * @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

+ 0 - 2
View/Helper/GravatarHelper.php

@@ -8,8 +8,6 @@ App::uses('AppHelper', 'View/Helper');
  *
  * @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

+ 245 - 0
View/Helper/TimelineHelper.php

@@ -0,0 +1,245 @@
+<?php
+
+App::uses('AppHelper', 'View/Helper');
+
+/**
+ * TimelineHelper for easy output of a timeline with multiple items.
+ *
+ * You need to include your css and js file, manually:
+ *
+ *   echo $this->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
+var timeline;
+var data;
+var options;
+
+// Called when the Visualization API is loaded.
+function drawVisualization() {
+	// Create a JSON data table
+	data = $data
+	options = $options
+
+	// Instantiate our timeline object.
+	timeline = new links.Timeline(document.getElementById('$timelineId'));
+
+	// Draw our timeline with the created data and options
+	timeline.draw(data, options);
+	$current
+}
+
+drawVisualization();
+JS;
+		if ($return) {
+			return $script;
+		}
+		$this->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) . ')';
+	}
+
+}

+ 0 - 2
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');