Ejemplo n.º 1
0
void Element::setUsers( UserList ul )
{
	if (!isRecord())
		return;

	UserList toAdd;
	UserList toRemove;

	UserList currentUsers = users();

	foreach( User emp, ul )
		if( !currentUsers.contains( emp ) )
			toAdd += emp;

	foreach( User eu, currentUsers )
		if( !ul.contains( eu ) )
			toRemove += eu;

	ElementUserList tul = ElementUser::recordsByElement( *this );
	foreach( ElementUser eu, tul )
		if( toRemove.contains( eu.user() ) )
			eu.remove();

	foreach( User emp, toAdd )
	{
		ElementUser tu;
		tu.setElement( *this );
		tu.setUser( emp );
		tu.setActive( 1 );
		tu.commit();
	}
Ejemplo n.º 2
0
void ScheduleDialog::accept()
{
	RecordList assetSelection = mAssetTree->selection();
	Element e = assetSelection.isEmpty() ? Element(mProject) : Element(assetSelection[0]);

	if( mSchedule.isRecord() ) {
		Database::current()->beginTransaction( "Modify Schedule" );
		mSchedule.setDuration( Interval().addHours(mHoursSpin->value()) );
		mSchedule.setElement( e );
		mSchedule.setAssetType( mAssetType );
		mSchedule.setUser( mEmployee );
		mSchedule.setDate( mDateStartEdit->date() );
		mSchedule.setCreatedByUser( User::currentUser() );
		mSchedule.commit();
		Database::current()->commitTransaction();
	} else {
		Database::current()->beginTransaction( "Create Schedule" );

		ScheduleList toCommit;
		QDate start = mDateStartEdit->date();
		QDate end = mDateEndEdit->date();
		while( start <= end ) {
			Schedule s;
			s.setUser( mEmployee );
			s.setElement( e );
			s.setAssetType( mAssetType );
			s.setDate( start );
			s.setDuration( Interval().addHours(mHoursSpin->value()) );
			s.setCreatedByUser( User::currentUser() );
			toCommit += s;
			start = start.addDays( 1 );
		}
		toCommit.commit();
	
		if( !e.users().contains( mEmployee ) ) {
			ElementUser eu;
			eu.setElement( e );
			eu.setUser( mEmployee );
			eu.commit();
		}
	
		Database::current()->commitTransaction();
	}
	QDialog::accept();
}
Ejemplo n.º 3
0
ElementUser Element::addUser( const User & user )
{
	if( !isRecord() || !user.isRecord() )
		return ElementUser();

	ElementUserList tul( ElementUser::recordsByElement( *this ) );
	foreach( ElementUser eu, tul )
		if( eu.user() == user )
			return eu;
	
	ElementUser tu;
	tu.setUser( user );
	tu.setElement( *this );
	tu.setActive( 1 );
	tu.commit();
	
	if( !elementStatus().isRecord() || elementStatus().name() == "New" ) {
		setElementStatus( ElementStatus::recordByName( "Assigned" ) );
		commit();
	}
	
	return tu;
}