Exemplo n.º 1
0
	/**
	 * (PHP 5 &gt;= 5.0.0)<br/>
	 * Offset to set
	 * @link http://php.net/manual/en/arrayaccess.offsetset.php
	 * @param mixed $offset <p>
	 * The offset to assign the value to.
	 * </p>
	 * @param mixed $value <p>
	 * The value to set.
	 * </p>
	 * @return void
	 *
	 * @throws Exception
	 */
	public function offsetSet($offset, $value) {
		if($offset === null){
			// The user just wants the next available one.

			if($this->valid()){
				$this->next();

			}
			$offset = $this->key();
		}

		if($value instanceof ViewControl){
			$this->_links[$offset] = $value;
		}
		elseif(is_array($value)){
			$control = new ViewControl();

			// Completely associative-array based version!
			foreach($value as $k => $v){
				$control->set($k, $v);
			}

			// Some legacy updates for the icon.
			if(!$control->icon){
				switch($control->class){
					case 'add':
					case 'edit':
					case 'directory':
						$control->icon = $control->class;
						break;
					case 'delete':
						$control->icon = 'remove';
						break;
					case 'view':
						$control->icon = 'eye-open';
						break;
				}
			}

			$this->_links[] = $control;
		}
		else{
			throw new Exception('Invalid offset type for ViewControls::offsetSet, please only set a ViewControl or an associative array');
		}
	}
Exemplo n.º 2
0
	/**
	 * Add a control into the page template.
	 *
	 * Useful for embedding functions and administrative utilities inline without having to adjust the
	 * application template.
	 *
	 * @param string|array $title       The title to set for this control
	 * @param string $link        The link to set for this control
	 * @param string|array $class The class name or array of attributes to set on this control
	 *                            If this is an array, it should be an associative array for the advanced parameters
	 */
	public function addControl($title, $link = null, $class = 'edit') {
		$control = new \ViewControl();

		// Completely associative-array based version!
		if(func_num_args() == 1 && is_array($title)){
			foreach($title as $k => $v){
				$control->set($k, $v);
			}
		}
		else{
			// Advanced method, allow for associative arrays.
			if(is_array($class)){
				foreach($class as $k => $v){
					$control->set($k, $v);
				}
			}
			// Default method; just a string for the class name.
			else{
				$control->class = $class;
			}

			$control->title = $title;
			$control->link = \Core\resolve_link($link);
		}

		$this->getControls()->addLink($control);
	}
Exemplo n.º 3
0
	/**
	 * Add a control into the page template.
	 *
	 * Useful for embedding functions and administrative utilities inline without having to adjust the
	 * application template.
	 *
	 * @param string|array|Model $title  The title to set for this control
	 * @param string             $link   The link to set for this control
	 * @param string|array       $class  The class name or array of attributes to set on this control
	 *                            If this is an array, it should be an associative array for the advanced parameters
	 */
	public function addControl($title, $link = null, $class = 'edit') {

		if($title instanceof Model){
			// Allow a raw Model to be sent in as the control subject.
			// This is a shortcut for Controllers much like the {controls} smarty function has.
			$this->controls = ViewControls::DispatchModel($title);
			return;
		}

		$control = new ViewControl();

		// Completely associative-array based version!
		if(func_num_args() == 1 && is_array($title)){
			foreach($title as $k => $v){
				$control->set($k, $v);
			}
		}
		else{
			// Advanced method, allow for associative arrays.
			if(is_array($class)){
				foreach($class as $k => $v){
					$control->set($k, $v);
				}
			}
			// Default method; just a string for the class name.
			else{
				$control->class = $class;
			}

			$control->title = $title;
			$control->link = \Core\resolve_link($link);
		}

		// Is this control the current page?  If so don't display it.
		if($control->link != \Core\resolve_link($this->baseurl)){
			$this->controls[] = $control;
		}
	}