Exemplo n.º 1
0
	public function setValue($value){

		$timezone = isset($this->_attributes['savetimezone']) ? $this->_attributes['savetimezone'] : Time::TIMEZONE_GMT;

		if($value === '' || $value === NULL){
			// Allow empty values to be entered without manipulation.
			// This is to prevent an empty value from tripping up the !is_numeric check below and
			// getting set to an empty date string, which evaluates to the current date/time.
			return parent::setValue($value);
		}
		elseif(isset($this->_attributes['saveformat']) && !is_numeric($value)){
			// Set value succeeded, now I can convert the string to an int, (if requested).
			$dt = new CoreDateTime($value);
			$value = $dt->getFormatted($this->_attributes['saveformat'], $timezone);
			return parent::setValue($value);
		}
		else{
			return parent::setValue($value);
		}
	}
Exemplo n.º 2
0
	public function __construct($atts = null){

		if($atts === null) $atts = array();

		$atts['multiple'] = true;

		if(isset($atts['model'])){

			$page = $atts['model'];

			if(!$page instanceof PageModel){
				throw new Exception('PageMetaKeywords requires the model attribute to be a valid PageModel object!');
			}

			// Sift through the page and get out all the "keyword" metas.
			// This is a bit different than default because this one form retrieves data from multiple records.
			$atts['value'] = array();
			foreach($page->getLink('PageMeta') as $meta){
				/** @var $meta PageMetaModel */

				// I only am concerned with these.
				if($meta->get('meta_key') != 'keyword') continue;

				$atts['value'][ $meta->get('meta_value') ] = $meta->get('meta_value_title');
			}
		}


		parent::__construct($atts);

		// Find the value key and unset it from the valid attributes.  It's not a standard attribute on this input!
		unset($this->_validattributes[ array_search('value', $this->_validattributes) ]);

		$this->_attributes['class'] = 'formelement formpagemetakeywordsinput';
	}