/**
  * Set a registry value.
  *
  * @param   string $path  Registry Path (e.g. joomla.content.showauthor)
  * @param   mixed  $value Value of entry
  *
  * @return  mixed  The value of the that has been set.
  *
  * @since   11.1
  */
 public function set($path, $values)
 {
     // Get the old value if exists so we can return it
     if (is_array($values) && JArrayHelper::isAssociative($values) || is_object($values) && count((array) $values)) {
         foreach ($values as $key => $value) {
             $this->data->set("{$path}.{$key}", $value);
         }
     } else {
         $this->data->set($path, $values);
     }
     return $this;
 }
Пример #2
0
	/**
	 * Test the JArrayHelper::isAssociate method.
	 */
	public function testIsAssociative()
	{
		$this->assertThat(
			JArrayHelper::isAssociative(array(1,2,3)),
			$this->isFalse(),
			'Line: '.__LINE__.' This array should not be associative.'
		);

		$this->assertThat(
			JArrayHelper::isAssociative(array('a' => 1, 'b' => 2, 'c' => 3)),
			$this->isTrue(),
			'Line: '.__LINE__.' This array should be associative.'
		);

		$this->assertThat(
			JArrayHelper::isAssociative(array('a' => 1, 2, 'c' => 3)),
			$this->isTrue(),
			'Line: '.__LINE__.' This array should be associative.'
		);
	}
Пример #3
0
 /**
  * Method to bind data to the form for the group level.
  *
  * @param   string  $group  The dot-separated form group path on which to bind the data.
  * @param   mixed   $data   An array or object of data to bind to the form for the group level.
  *
  * @return  void
  *
  * @since   11.1
  */
 protected function bindLevel($group, $data)
 {
     // Ensure the input data is an array.
     settype($data, 'array');
     // Process the input data.
     foreach ($data as $k => $v) {
         if ($this->findField($k, $group)) {
             // If the field exists set the value.
             $this->data->set($group . '.' . $k, $v);
         } elseif (is_object($v) || JArrayHelper::isAssociative($v)) {
             // If the value is an object or an associative array, hand it off to the recursive bind level method
             $this->bindLevel($group . '.' . $k, $v);
         }
     }
 }
Пример #4
0
 /**
  * Method to recursively bind data to a parent object.
  *
  * @param	object	$parent	The parent object on which to attach the data values.
  * @param	mixed	$data	An array or object of data to bind to the parent object.
  *
  * @return	void
  * @since	1.6
  */
 protected function bindData(&$parent, $data)
 {
     // Ensure the input data is an array.
     if (is_object($data)) {
         $data = get_object_vars($data);
     } else {
         $data = (array) $data;
     }
     foreach ($data as $k => $v) {
         if (is_array($v) && JArrayHelper::isAssociative($v) || is_object($v)) {
             $parent->{$k} = new stdClass();
             $this->bindData($parent->{$k}, $v);
         } else {
             $parent->{$k} = $v;
         }
     }
 }
Пример #5
0
 /**
  * Method to bind data to the form for the group level.
  *
  * @param   string  $group  The dot-separated form group path on which to bind the data.
  * @param   mixed   $data   An array or object of data to bind to the form for the group level.
  *
  * @return  void
  *
  * @since   11.1
  */
 protected function bindLevel($group, $data)
 {
     // Ensure the input data is an array.
     if (is_object($data)) {
         if ($data instanceof Registry) {
             // Handle a Registry.
             $data = $data->toArray();
         } elseif ($data instanceof JObject) {
             // Handle a JObject.
             $data = $data->getProperties();
         } else {
             // Handle other types of objects.
             $data = (array) $data;
         }
     }
     // Process the input data.
     foreach ($data as $k => $v) {
         $level = $group ? $group . '.' . $k : $k;
         if ($this->findField($k, $group)) {
             // If the field exists set the value.
             $this->data->set($level, $v);
         } elseif (is_object($v) || JArrayHelper::isAssociative($v)) {
             // If the value is an object or an associative array, hand it off to the recursive bind level method.
             $this->bindLevel($level, $v);
         }
     }
 }
 /**
  * @since       1.1.0
  */
 protected static function _prepareQueyrBetweenFiltersANDValuesAND($query)
 {
     $db = JFactory::getDbo();
     if (JArrayHelper::isAssociative(self::$filters)) {
         if (count(self::$filters) > 1) {
             foreach (self::$filters as $filter => &$filter_values) {
                 $filter = (int) $filter;
                 self::_checkArg($filter_values);
                 if (!$filter || empty($filter_values)) {
                     continue;
                 }
                 while ($value = array_shift($filter_values)) {
                     $alias = 'c' . $value;
                     $and = array($db->quoteName($alias . '.element_id') . ' = ' . $db->quoteName('e.id'), $db->quoteName($alias . '.field_id') . ' = ' . $filter, $db->quoteName($alias . '.field_value_id') . ' = ' . $value);
                     $query->join('INNER', $db->quoteName('#__fieldsandfilters_connections', $alias) . ' ON ' . implode(' AND ', $and));
                     unset($and);
                 }
             }
         } else {
             self::_prepareQueyrValueAssociativeArray($query);
         }
     } else {
         self::_prepareQueyrFilterArray($query);
     }
 }
Пример #7
0
 /**
  * Method to recursively bind data to a parent object.
  *
  * @param   object   $parent     The parent object on which to attach the data values.
  * @param   mixed    $data       An array or object of data to bind to the parent object.
  * @param   boolean  $recursive  True to support recursive bindData.
  *
  * @return  void
  *
  * @since   1.0
  */
 protected function bindData($parent, $data, $recursive = true)
 {
     // Ensure the input data is an array.
     if (is_object($data)) {
         $data = get_object_vars($data);
     } else {
         $data = (array) $data;
     }
     foreach ($data as $k => $v) {
         // Modification from joomla/registry package - Using CMS JArrayHelper versus importing joomla/utilities package
         if ($recursive && (is_array($v) && \JArrayHelper::isAssociative($v) || is_object($v))) {
             if (!isset($parent->{$k})) {
                 $parent->{$k} = new \stdClass();
             }
             $this->bindData($parent->{$k}, $v);
         } else {
             $parent->{$k} = $v;
         }
     }
 }