public static function save_current_entry() { $oDataSheet = new DataSheet(); $oDataEntryPage = DataObject::get_one('DataEntryPage'); $iDataEntryPageID = $oDataEntryPage->ID; $oDataSheet->DataEntryPageID = $iDataEntryPageID; $oDataSheet->write(); return $oDataSheet; }
/** * DataEntry Form * */ function SubmitDataSheet($data, $form, $request) { // Create a new DataSheet object $oDataSheet = DataSheet::save_current_entry(); $form->saveInto($oDataSheet); //save to current Member //check that this is member is the owner of the CleanUpEvent $oCurrentMember = Member::currentUser(); $iMemberID = $oCurrentMember->ID; $oDataSheet->MemberID = $iMemberID; //Save Image //Save DataCategories -> DataItems $oDataEntryPage = DataObject::get_one('DataEntryPage'); $iDataEntryPageID = $oDataEntryPage->ID; $oFormCategorys = DataObject::get('FormCategory', 'DataEntryPageID =' . $iDataEntryPageID, '', ''); foreach ($oFormCategorys as $category) { $sCatFieldName = $category->ID . '_' . $category->FieldName; if ($data[$sCatFieldName]) { $oDataCategory = new DataCategory(); $oDataCategory->Title = $category->Title; $oDataCategory->Percentage = $data[$sCatFieldName]; //Save to page $oDataCategory->DataEntryPageID = $iDataEntryPageID; //Save to datasheet $oDataCategory->DataSheetID = $oDataSheet->ID; $oDataCategory->MemberID = $iMemberID; $oDataCategory->write(); //Get the items $oCatItems = DataObject::get('FormItem', 'DataEntryPageID =' . $iDataEntryPageID . ' AND FormCategoryID = ' . $category->ID, '', ''); //Loop through category->items saving as DataItems foreach ($oCatItems as $item) { $oDataItem = new DataItem(); $sItemFieldName = $item->ID . '_' . $item->FieldName; $oDataItem->Title = $item->Title; $oDataItem->Amount = $data[$sItemFieldName]; //Save to page $oDataItem->DataEntryPageID = $iDataEntryPageID; //Save to datasheet $oDataItem->DataSheetID = $oDataSheet->ID; //Very Important that you save all items with the newly created Data Category ID $oDataItem->DataCategoryID = $oDataCategory->ID; $oDataItem->MemberID = $iMemberID; $oDataItem->write(); } } } //Write data to the data sheet $oDataSheet->write(); // Email the administrator $oDataSheet->mailSiteOwner(); // Email the user $oDataSheet->mailSiteUser(); Director::redirect('my-data-sheets/success/'); }