Commits

magmax  committed f728f7f

working belongs_to.

  • Participants
  • Parent commits 9076ade

Comments (0)

Files changed (3)

File classes/controller/default.php

 	 */
 	public function action_add ()
 	{
+		
 		$view = View::factory($this->view_name_add);
 
 		$obj = ORM::factory ($this->model_name);
 		$orm = ORM::factory($this->model_name);
 		
 		$view->set('type', $this->model_name);
-		$view->set('columns', $orm->list_columns());
+		$view->set('columns', $this->get_header_list());
 		
 		if ( isset($_POST['submit']) )
 		{		
 			$itemorm = ORM::factory($relation['model']);
 			$item['label'] = $this->get_beautiful_name ($relation['model']);
 			$item['data_type'] = 'foreign';
-			$item['column_name'] = $relation['foreign_key'];
-			$item['is_nullable'] = false; // FIXME
+			$item['column_name'] = $relation['model'];
+			// FIXME: lo siguiente debería cogerlo del modelo!!!!
+			if (isset ($relation['is_nullable']))
+				$item['is_nullable'] = $relation['is_nullable']; 
+			else
+				$item['is_nullable'] = false;
 			
-			$result[$relation['model']] = $item;
+			$result[$relation['foreign_key']] = $item;
 		}
 		
 		return $result ;

File views/default_file_functions.php

 	print form::file($name);
 }
 
+function print_combobox ( $name, $attrs, $default, $basename )
+{
+	$options = array ();
+	
+	$obj = ORM::factory ($attrs['column_name']);
+
+	if ($attrs['is_nullable'])
+		$options[null] = '-----';
+	
+	foreach ($obj->find_all() as $each)
+	{
+		$options[$each->pk()] = $each;
+	}
+	
+	print form::select($name, $options, $default);
+}
+
 function is_date_field ($type)
 {
 	return $type == 'datetime' 
 		OR $type == 'date';	
 }
 
+function is_combobox_field ($type)
+{
+	return $type == 'foreign';	
+}
+
 function is_text_field ($type)
 {
 	return $type == 'longtext'
 	
 	$type = $attrs['data_type'];
 	
-	if (is_date_field($type))
+	if (is_combobox_field ($type))
+		print_combobox ( $name, $attrs, $default, $basename );
+	elseif (is_date_field($type))
 		print_column_date ( $name, $attrs, $default );
 	elseif (is_text_field($type))
 		print_column_longtext ( $name, $attrs, $default );

File views/default_index.php

 		echo '<td>';
 		if ($hvalues['data_type'] == 'foreign')
 		{
-			echo $row->__get($hname)->__toString();
+			echo $row->__get($hvalues['column_name'])->__toString();
 			//print_r ($hvalues);
 		}
 		elseif ($first)