Exemplo n.º 1
0
	/**
	 * Format recordsets
	 * 
	 * @param SLS_XMLToolBox $xml
	 * @param array PDO $recordsets
	 * @param string $fkRecursiveExists
	 * @return SLS_XMLToolBox $xml modified
	 */
	public function formatRecordsets($xml,$recordsets,$fkRecursiveExists="")
	{	
		$xml->startTag("entities");
		for($i=0 ; $i<$count=count($recordsets) ; $i++)
		{
			$xml->startTag("entity",array("gap" => $this->_gap));
			foreach($recordsets[$i] as $key => $value)
			{	
				if (array_key_exists($key,$this->_columns) && ($this->_columns[$key]["list"] == "true" || $key == $this->_object->getPrimaryKey()))
				{
					$hashExists = $this->_xmlFilter->getTag("//sls_configs/entry[@table='".strtolower($this->_db_alias."_".$this->_columns[$key]["table"])."' and @column='".$key."' and @filter='hash']/@hash");
					
					if (!empty($this->_columns[$key]["specific_type"]))
					{
						switch($this->_columns[$key]["specific_type"])
						{
							case "email":
								if (SLS_String::validateEmail($value))
									$value = "<a href='mailto:".$value."' target='_blank' class='sls-bo-color-text'>".$value."</a>";
								break;
							case "url":
								if (SLS_String::isValidUrl($value))
									$value = "<a href='".$value."' target='_blank' class='sls-bo-color-text'>".SLS_String::substrAfterLastDelimiter($value,"://")."</a>";
								break;
							case "file";
								switch($this->_columns[$key]["specific_type_extended"])
								{
									case "all":
										if (!empty($value) && file_exists($this->_generic->getPathConfig("files").$value))
											$value = "<a href='".SLS_String::getUrlFile($value)."' target='_blank' class='sls-bo-color-text'>".SLS_String::substrAfterLastDelimiter($value,"/")."</a>";
										break;
									case "img":
										if (!empty($value) && file_exists($this->_generic->getPathConfig("files").$value))
											$value = "<a href='".SLS_String::getUrlFile($value)."' target='_blank'><img class='sls-image' sls-image-src='".((!empty($this->_columns[$key]["image_thumb"])) ? SLS_String::getUrlFileImg($value,$this->_columns[$key]["image_thumb"]) : SLS_String::getUrlFile($value))."' alt='".SLS_String::substrAfterLastDelimiter($value,"/")."' title='".SLS_String::substrAfterLastDelimiter($value,"/")."' /></a>";
										break;
								}
								break;
							case "color":
								$rgb = SLS_String::hex2RGB($value);
								$value = "<div class='sls-bo-box-color' style='color:".((((0.213 * $rgb["red"]) + (0.715 * $rgb["green"]) + (0.072 * $rgb["blue"])) < 0.5) ? "#FFF" : "#000").";background-color:#".$value."'>#".$value."</div>";
								break;
						}
					}
					if ($this->_columns[$key]["html_type"] == "input_textarea")
						$value = "<p>".SLS_String::trimStringToLength(strip_tags($value),150)."</p>";
					if (!empty($hashExists))
						$value = "********";
						
					$xml->addFullTag($key,$value,true);
				}
			}			
			if (!empty($fkRecursiveExists))
			{
				$this->_gap++;
				$xml = $this->getFkChildrens($xml,$fkRecursiveExists,$recordsets[$i]->{$this->_object->getPrimaryKey()});
				$this->_gap--;
			}
			$xml->endTag("entity");
		}
		$xml->endTag("entities");
		
		return $xml;
	}