⚠ In case you've missed it we have migrated to our new website, with a brand new forum. For more details about the migration you can read our blog post for website migration. This forum is read-only and soon will be archived. ⚠


Dan

Member Since 30 Dec 2013
Offline Last Active Mar 07 2014 01:04 AM
-----

Topics I've Started

$row value being replaced with function result

04 March 2014 - 11:32 PM

Hello, hope you guys can help. I dont even know how to explain this problem in a simple way and english is not my native language  ;)

 

I have two callbacks with conflicts and I need to use the '$row->mas_doce' variable in 'mostrar_tarifa_masdoce' function, but is being replaced with the result from the 'boton_masdoce' function which generates a button for the other column. Here are the functions and a screenshot from the result.

	public function mostrar_carrera($id) {
		
		$crud = new grocery_CRUD ();
		$crud->set_table ( 'usuariosxcarrera' );
		$crud->where ( 'id_carrera', $id );
		$crud->set_relation ( 'id_usuario', 'usuarios', 'nombre' );
		
		$crud->callback_column ( 'mas_doce', array ($this,	'boton_masdoce' ) );
		$crud->callback_column ( 'tarifa_doce_conductor', array (	$this,	'mostrar_tarifa_masdoce' 	) );
		

		$output = $crud->render ();
		$data ['titulo'] = "Carreras";
		
		$this->vista_administrar ( $output, $data );
	}
	

	
	function boton_masdoce($value, $row) {
		
		if ($row->mas_doce == 'no') {
			
			return '<form method="post" class="btn btn-primary" action="' . site_url ( 'admin/actualizar_mas_doce/' ) . '">
					<input type="hidden" name="id" value=' . $row->id . ' />
					<input type="hidden" name="id_carrera" value=' . $row->id_carrera . ' />
					<input type="hidden" name="porcentaje_doce_conductor" value=' . $row->porcentaje_doce_conductor . ' />
					<input type="hidden" name="porcentaje_doce_tienda_gerente" value=' . $row->porcentaje_doce_tienda_gerente . ' />
					<input type="hidden" name="tarifa_doce_conductor" value=' . $row->tarifa_doce_conductor . ' />
					<input type="hidden" name="tarifa_doce_tienda_gerente" value=' . $row->tarifa_doce_tienda_gerente . ' />
					<input type="hidden" name="mas_doce" value="si" />
				    <input type="submit" value="<12">
					</form>';
		}
		
		if ($row->mas_doce == 'si') {
			return '<form method="post" class="btn btn-danger" action="' . site_url ( 'admin/actualizar_mas_doce_no/' ) . '">
					<input type="hidden" name="id" value=' . $row->id . ' />
					<input type="hidden" name="id_carrera" value=' . $row->id_carrera . ' />
					<input type="hidden" name="mas_doce" value="no" />
				    <input type="submit" value=">12">
					</form>';
		} 

		else
			return;
	}
	
	public function mostrar_tarifa_masdoce($value, $row) {
	
		return $row->mas_doce;
	
	}

Copy a value from another table

30 December 2013 - 07:38 PM

Hello, I'm trying to make a callback function for this code.

	public function trips() {
		
		$crud = new grocery_CRUD ();
		
		$crud->set_table ( 'trips' );
		
		$crud->set_relation ( 'driver_id', 'users', 'name', array (
				'user_type' => 'Driver' 
		) );
		
		$crud->set_relation_n_n ( 'passengers', 'users_per_trip', 'users', 'trip_id', 'user_id', 'name', null, "user_type = 'Sub-manager' OR user_type = 'Passenger'" );
		
		
		$crud->add_fields ( 'driver_id', 'date', 'passengers' );
		
		$crud->display_as ( 'driver_id', 'Driver' );
		$crud->display_as ( 'tax', 'Tax' );

        $output = $crud->render ();
        
        $data ['title'] = "Trips";
        
        $this->_example_output ( $output, $data );
    }
   

I have a 'users' table which has a 'price' field and I need to copy that value to my 'users_per_trip' table which has a 'price' field too. What I need here is that when every user is inserted in the 'users_per_trip' table the price is copied where user_id=id from table users, assuming that is a many to many relation. Hope you understand my example.

 

Thank you very much in advance.