Concept - DataObjects

DataObjects are the most integral part of the ax System.

They are authorized components, that handle data manipulation, transformation, retrieving and storing to and from all data sources.

All DataObjects must at least hold: create(), load(), prepare() and save().

Basic buildup of a DataObject:

<?php

	class Customer extends AX_DataObject {
		
		public function create() {
			$this->data = $this->db->getObjectByTablename("democontractor_customers");
		}
		
		public function load() {
			$this->data = $this->db->fetchRowBySQL("SELECT * FROM democontractor_customers WHERE id = $this->id");
		}
		
		public function prepare() {
			$this->data->_text = $this->data->Name;
			$this->data->_html = $this->data->_text;
		}
		
		public function nestTasks() {
			$this->data->Tasks = $this->extendBySQL("SELECT id FROM democontractor_tasks WHERE Customer = " . $this->id . " AND Invoice IS NULL", "Task");
			foreach($this->data->Tasks as $myTask) {
				$myTask->load();
				$myTask->nestProduct();
				$myTask->nestEmployee();
				$myTask->prepare();
				$myTask->data->TaskButton = $this->renderStdOpenButton("Task",$myTask->id);
			}
		}
		
		public function nestInvoices() {
			$this->data->Invoices = $this->extendBySQL("SELECT id FROM democontractor_invoices WHERE Customer = " . $this->id, "Invoice");
			foreach($this->data->Invoices as $myInvoice) {
				$myInvoice->load();
				$myInvoice->prepare();
				$myInvoice->data->_InvoiceButton = $this->renderStdOpenButton("Invoice",$myInvoice->id);
			}
		}
		
		public function save() {
			if(isset($this->data->Tasks)) {
				$this->stdSaveChilds((object) array( 
						"table" => "democontractor_tasks",
						"data" => $this->data->Tasks,
						"childDO" => "Task",
						"childCond" => (object) array(
							"Customer" => $this->id,
							"Invoice" => null
						),
						"prepareRows" => function($myDataRow,$mainId) {
							$myDataRow->Customer = $mainId;
							return $myDataRow;
						}
				));
			}
			$this->stdSaveMain((object) array (
					"table" => "democontractor_customers"
			));
		}
		
		public function delete() {
			$Tasks = $this->db->fetchRowsBySQL("SELECT * FROM democontractor_tasks WHERE Customer = " . $this->id);
			if(count($Tasks)>0) {
				$this->addError("Customer " . $this->data->_text . " has linked Tasks and can therefore not be deleted");
				return false;
			}
			$this->db->performSQLString("DELETE FROM democontractor_customers WHERE id = " . $this->id);
		}
		
		public function findByText($searchVal) {
			$sql = "SELECT id FROM democontractor_customers WHERE (Name LIKE '$searchVal%' OR Info LIKE '$searchVal%')";
			return $this->db->fetchColBySQL($sql);
		}
		
		
	}

 

Common DataObject Handler:

  • create()

    A quick-start guide to all the basics you need to get up and running now. Vestibulum lacinia nibh vel porttitor lacinia.

  • load()

    A quick-start guide to all the basics you need to get up and running now. Vestibulum lacinia nibh vel porttitor lacinia.

  • nestDataXY()

    A quick-start guide to all the basics you need to get up and running now. Vestibulum lacinia nibh vel porttitor lacinia.

  • prepare()

    A quick-start guide to all the basics you need to get up and running now. Vestibulum lacinia nibh vel porttitor lacinia.

  • verify()

    A quick-start guide to all the basics you need to get up and running now. Vestibulum lacinia nibh vel porttitor lacinia.

  • save()

    A quick-start guide to all the basics you need to get up and running now. Vestibulum lacinia nibh vel porttitor lacinia.

  • delete()

    A quick-start guide to all the basics you need to get up and running now. Vestibulum lacinia nibh vel porttitor lacinia.

  • findByText()

    A quick-start guide to all the basics you need to get up and running now. Vestibulum lacinia nibh vel porttitor lacinia.

  • getVCardAsHTML()

    A quick-start guide to all the basics you need to get up and running now. Vestibulum lacinia nibh vel porttitor lacinia.