/**
  * Set the field value
  *
  * Method will set the field value, overriding the existing one
  *
  * @access public
  * @param mixed $value The default value to set
  * @param bool $setFromDB TRUE to specify that this value is from the DB, FALSE from the request.
  *                        Default is FALSE
  * @param bool $assignRealValue TRUE to filter out any values that is not in the options array,
  *                              FALSE to set as is. Default is TRUE
  */
 public function setValue($value, $setFromDB = false, $assignRealValue = true)
 {
     if ($assignRealValue && !empty($this->extraInfo['options'])) {
         $index = array_isearch($value, $this->extraInfo['options']);
         if ($index !== false) {
             $value = $this->extraInfo['options'][$index];
         } else {
             $value = '';
         }
     }
     parent::setValue($value, $setFromDB);
 }
 /**
  * Set the field value
  *
  * Method will set the field value, overriding the existing one
  *
  * @access public
  * @param mixed $value The default value to set
  * @param bool $setFromDB TRUE to specify that this value is from the DB, FALSE from the request.
  *                        Default is FALSE
  * @param bool $assignRealValue TRUE to filter out any values that is not in the options array,
  *                              FALSE to set as is. Default is TRUE
  */
 public function setValue($value, $setFromDB = false, $assignRealValue = true)
 {
     if (!is_array($value)) {
         $value = array($value);
         $value = array_filter($value);
     }
     if ($assignRealValue && !empty($this->extraInfo['options'])) {
         $filtered = array();
         foreach ($value as $key => $val) {
             $index = array_isearch($val, $this->extraInfo['options']);
             if ($index !== false) {
                 $filtered[$key] = $this->extraInfo['options'][$index];
             }
         }
         $value = $filtered;
     }
     parent::setValue($value, $setFromDB);
 }
示例#3
0
	/**
	 * Set the field value
	 *
	 * Method will set the field value, overriding the existing one
	 *
	 * @access public
	 * @param mixed $value The default value to set
	 * @param bool $setFromDB TRUE to specify that this value is from the DB, FALSE from the request.
	 *                        Default is FALSE
	 * @param bool $fromUserImport TRUE if this value is from a user import, FALSE if not. If TRUE then
	 *                             the value will pass through a few filters to get the proper value.
	 *                             Default is FALSE
	 */
	public function setValue($value, $setFromDB=false, $fromUserImport=false)
	{
		$realValue = $value;

		/**
		 * Are we setting the value from a user import?
		 */
		if ($fromUserImport) {
			$exploded = preg_split('/[\s-\/\.]+/', $value);
			$exploded = array_filter($exploded);

			if (count($exploded) !== 3) {
				$realValue = '';

			/**
			 * If the first digit is 4 characters long then it is Y-m-d
			 */
			} else if (strlen($exploded[0]) == 4) {
				$realValue = implode('-', $exploded);

			/**
			 * Else it is m-d-Y
			 */
			} else {
				$realValue = date('Y-m-d', mktime(1, 1, 1, (int)$exploded[0], (int)$exploded[1], (int)$exploded[2]));
			}
		}

		return parent::setValue($realValue, $setFromDB);
	}