Zum Inhalt springen

Staff and Task

Erstellt am 9. April 2011 · 4 Antworten · letzte Antwort am 9. April 2011

Tags: Frage

Jan.​S ·

Hallo,
ich hab ein kleines Verständnis Problem.

Ich baue mir ein Formular in den man eine Aufgabe erstellen kann.
In diesen Formular gibt es eine Selectbox und in dieser stehen alle Mitarbeiter (staff) drinnen die angelegt wurden.
Die Mitarbeiter (staff) habe ein eigenes Repository. (Anlegen, Liste, Speicher, Bearbeiten, Löschen funktioniert auch)

Jetzt möchte ich jeder Aufgabe einen Mitarbeiter (staff) zuweisen.
Nur so funktioniert es nicht.😢

Im Tx_JsManager_Controller_TaskController mach ich mir eine Instanz von StaffRepository.

class Tx_JsManager_Controller_TaskController extends Tx_Extbase_MVC_Controller_ActionController {
	/**
	 * taskRepository
	 *
	 * @var Tx_JsManager_Domain_Repository_TaskRepository
	 */
	protected $taskRepository;

 	/**
	 * staffRepository
	 *
	 * @var Tx_JsManager_Domain_Repository_StaffRepository
	 */
	protected $staffRepository;  
     
	/**
	 * Initializes the current action
	 *
	 * @return void
	 */
	protected function initializeAction() {
		$this->taskRepository = t3lib_div::makeInstance('Tx_JsManager_Domain_Repository_TaskRepository');
		$this->staffRepository = t3lib_div::makeInstance('Tx_JsManager_Domain_Repository_StaffRepository');    
	
        }

Die new und creatAction sie wie folgt aus:

/**
 * Creates a new Task and forwards to the list action.
 *
 * @param Tx_JsManager_Domain_Model_Task $newTask a fresh Task object which has not yet been added to the repository
 * @return string An HTML form for creating a new Task
 * @dontvalidate $newTask
 */
 public function newAction(Tx_JsManager_Domain_Model_Task $newTask = null) {
    $this->view->assign('staffs', $this->staffRepository->findAll());
    $this->view->assign('newTask', $newTask);
 }

/**
 * Creates a new Task and forwards to the list action.
 *
 * @param Tx_JsManager_Domain_Model_Task $newTask a fresh Task object which has not yet been added to the repository
 * @return void
 */
 public function createAction(Tx_JsManager_Domain_Model_Task $newTask) {

	$this->taskRepository->add($newTask);
	$this->flashMessageContainer->add('Your new Task was created.');
	$this->redirect('list');
 }

Um die Mitarbeiter in die Selectbox zu bekommen funktioniert folgender Schnipsel:

<f:form.select property="staff" options="{staffs}" optionValueField="uid" optionLabelField="firstname" />

Im Tx_JsManager_Domain_Model_Task gibt es auch das passende Feld für staff:

/**
 * staff
 *
 * @var Tx_Extbase_Persistence_ObjectStorage<Tx_JsManager_Domain_Model_Staff> $staff
 */
  protected $staff;

Der Mitarbeiter wird nicht mit abgespeichert, der rest schon.
Ich glaube das mein Problem mit Fluid-Template liegt, steht aber grade etwas auf den schlauch.

Ich habe auch schon versucht das Formular Feld mit:

property="Tx_JsManager_Domain_Model_Staff.staff"

zu bezeichnen. Hat auch nicht funktioniert.

Jemand ne idee?

Gruß
Jan

Jan.​S ·

Ich hab mal mit blog_example geschaut wie es da gemach wird und auf meinen Fall übertragen.

<f:form.select property="staff" options="{staffs}" optionLabelField="lastname"><select><option>dummy</option></select></f:form.select>

Im Frontend sieht es eigentlich ganz gut aus.

<select name="tx_jsmanager_taskview[newTask][staff]">
<option value="1">Name0</option>
<option value="2">Name1</option>
<option value="3">Name2</option>
<option value="6">Name3</option>
</select>

Die value Felder entsprechen genau den uid Feldern aus der Datenbank (staff table).

Fehlt vielleicht noch irgendwas im Controller?

	/**
	 * Creates a new Task and forwards to the list action.
	 *
	 * @param Tx_JsManager_Domain_Model_Task $newTask a fresh Task object which has not yet been added to the repository
	 * @return void
	 */
	public function createAction(Tx_JsManager_Domain_Model_Task $newTask) {

		$this->taskRepository->add($newTask);
		$this->flashMessageContainer->add('Your new Task was created.');
		$this->redirect('list');
	}
Jan.​S ·

Bin immer noch nicht weiter gekommen.

Wenn man sich das Task Objekt in der Debug ansicht anschaut sieht es so aus:

|Object:
Tx_JsManager_Domain_Model_Task Object
(
    [title:protected] => sdf
    [jobnummber:protected] => sdf
    [status:protected] => sdf
    [timeCosts:protected] => 23
    [datefrom:protected] => 
    [dateto:protected] => 
    [staff:protected] => Tx_Extbase_Persistence_ObjectStorage Object
        (
            [warning:Tx_Extbase_Persistence_ObjectStorage:private] => You should never see this warning. If you do, you probably used PHP array functions like current() on the Tx_Extbase_Persistence_ObjectStorage. To retrieve the first result, you can use the getFirst() method.
            [storage:protected] => Array
                (
                )

            [isModified:protected] => 
        )

    [creator:protected] => 
    [uid:protected] => 
    [_localizedUid:protected] => 
    [_languageUid:protected] => 
    [pid:protected] => 
    [_isClone:Tx_Extbase_DomainObject_AbstractDomainObject:private] => 
    [_cleanProperties:Tx_Extbase_DomainObject_AbstractDomainObject:private] => 
)

Ist das so richtig?

    [staff:protected] => Tx_Extbase_Persistence_ObjectStorage Object

Muss da nicht eine int Wert rein?

Jan.​S ·

Bin immer noch nicht weiter gekommen.

Wenn man sich das Task Objekt in der Debug ansicht anschaut sieht es so aus:

|Object:
Tx_JsManager_Domain_Model_Task Object
(
    [title:protected] => sdf
    [jobnummber:protected] => sdf
    [status:protected] => sdf
    [timeCosts:protected] => 23
    [datefrom:protected] => 
    [dateto:protected] => 
    [staff:protected] => Tx_Extbase_Persistence_ObjectStorage Object
        (
            [warning:Tx_Extbase_Persistence_ObjectStorage:private] => You should never see this warning. If you do, you probably used PHP array functions like current() on the Tx_Extbase_Persistence_ObjectStorage. To retrieve the first result, you can use the getFirst() method.
            [storage:protected] => Array
                (
                )

            [isModified:protected] => 
        )

    [creator:protected] => 
    [uid:protected] => 
    [_localizedUid:protected] => 
    [_languageUid:protected] => 
    [pid:protected] => 
    [_isClone:Tx_Extbase_DomainObject_AbstractDomainObject:private] => 
    [_cleanProperties:Tx_Extbase_DomainObject_AbstractDomainObject:private] => 
)

Ist das so richtig?

    [staff:protected] => Tx_Extbase_Persistence_ObjectStorage Object

Muss da nicht eine int Wert rein?

Jan.​S ·

Es ist doch immer noch am schönsten wenn man sein Problem selbst löst. :o

Das Problem war in meinen Fall im Model zu suchen.

Vom Kickstarter angelegt:

/**
 * staff
 *
 * @var Tx_Extbase_Persistence_ObjectStorage<Tx_JsManager_Domain_Model_Staff> $staff
 */
protected $staff;

und so geht es:

/**
 * staff
 *
 * @var Tx_JsManager_Domain_Model_Staff
 * @lazy
 */
protected $staff;