Example #1
0
 public function testDisplayName()
 {
     $crud = new LouisCRUD();
     $field = new Field($crud, "product_name", "varchar(255)");
     $field->setDisplayName("!@#\$%^&*()_");
     $this->assertEquals("!@#\$%^&*()_", $field->getDisplayName());
 }
	protected function initReportRows()
	{
		$tag = "ReportDrafter: initReportRows()";
		Log::debug("$tag");
		
		/*
		// Build the results table
		*/
		$reportColumnNames = array();
		$reportRows = array();
		
		// convenience pointers
		$query = $this->query;
		$reportBP = $this->reportBlueprint;
		$rowIdKey = $reportBP->getRowIdKey();
		
		try
		{
			$sql = new DatabaseQuery($query->toString());
			$sql->doQuery();
			
			// determine which fields to render
			$fields = $reportBP->fields();
			if(count($fields) == 0)
			{
				// use sql result meta data for fields
				Log::debug("$tag: Using meta data to determine fields");
				$fields = array();
				$num_cols = $sql->get_num_columns();
				for($i=0; $i<$num_cols; $i++)
				{
					$col_name = $sql->get_column_name($i);
					
					// create a new ListField for this column
					$f = new Field($col_name);
					$f->setDisplayName($col_name);
					$fields[] = $f;
				}
			}
			
			$num_rows = $sql->get_num_rows();
			if($num_rows > 0)
			{
				for($i=0; $i<$num_rows; $i++)
				{
					$row = $sql->get_next_row();
					$id = $row->$rowIdKey;
					
					$reportRow = new ListRow($id);
					
					foreach($fields as $f)
					{
						// NOTE: treat "f" as a generic Field
						$key = $f->getKey();
						
						// add to list of column names
						$reportColumnNames["$key"] = $f->getDisplayName();
						
						// retrieve value for field
						$value = $row->$key;
						
						/*
						// FORMAT VALUES
						*/
						
						if( (!empty($value)) || ($value=="0") )
						{
							// format by report blueprint format string
							if(count($reportBP->fields()) > 0)
							{
								try
								{
									$reportField = $reportBP->get($key);
									$format = $reportField->getFormat();
									
									if(!empty($format))
									{
										if("password" == strtolower($format))
										{
											$value = "********";
										}
									} // END: if(!empty($format))
								}
								catch(Exception $e)
								{
									// Report Blueprint does not contain a field for current key
									// Continue...
								}
							}
						
						} // END: if( (!empty($value) || ($value=="0") )
						
						// Look for additional column attributes from report blueprint
						$href = null;
						if(count($reportBP->fields()) > 0)
						{
							try
							{
								$reportField = $reportBP->get($key);
								$href = $reportField->getHref();
								
								// replace references to report fields with their values
								if(!empty($href)) { $href = $this->replaceKeys($href, $row); }
								
							}
							catch(Exception $e)
							{
								// Report Blueprint does not contain a field for current key
								// Continue...
							}						
						}
						
						// add a new report column to the report row
						$reportRow->addColumn($key, $value, $href);
						
					} // END: foreach($fields as $f)
					
					$reportRows[$i] = $reportRow;
					
				} // END: for($i=0; $i<$num_rows; $i++)
				
				$this->reportColumnNames = $reportColumnNames;
				$this->reportRows = $reportRows;
			
			} // END: if($num_rows > 0)
			
		}
		catch(Exception $e)
		{
			throw($e);
		}
	} // END: protected function initReportRows()