Coding Tips - AX

 

Custom stdSaveChilds Handler

jiasjias

  • Create AX_DataObject_{ModuleName}.php in modulename/classes:

    			//-- save Tasks (childs)
    			$existingIds = $this->db->fetchColBySQL("SELECT id FROM democontractor_tasks WHERE Customer = " . $this->data->id);
    	        foreach($this->data->Tasks as $myTaskData) {
    	        	$myTaskData->Customer = $this->id;
    	        	$myTask = new Task($myTaskData->id);
    	        	$myTask->setData($myTaskData);
    	        	$myTask->save();
    	        }
    	        $currIds = getIdArrFromRows($this->data->Tasks);
    	        $idsToDelete = array_diff($existingIds, $currIds);
    	        if(count($idsToDelete)>0) {
    	        	$this->db->performSQLString("DELETE FROM democontractor_tasks WHERE id IN (" . join(",",$idsToDelete) . ")");
    	        }

Tweaking of AX_DataObject
  • Create AX_DataObject_{ModuleName}.php in modulename/classes:

    <?php
    
    	class AX_DataObject_{ModuleName} extends AX_DataObject {
    
    		// eg. override method log to exchange DataObject logging mechanism
    		
    		public function log($DataObject,$data) {
    			syslog(LOG_WARNING, "DataObject $DataObject now reads: " . json_encode($data));
    		}
    		
    	}

  • reference all your Module specific DataObject classes to AX_DataObject_{ModuleName}.
  • You're done. Safe for future updates :)