Skip to content
Snippets Groups Projects
CRMEntity.php 125 KiB
Newer Older
Prasad's avatar
Prasad committed
						WHERE vtiger_crmentity.deleted = 0 AND vtiger_activity.activitytype <> 'Emails'
							AND vtiger_seactivityrel.crmid = ".$id;

		$return_value = GetRelatedList($this_module, $related_module, '', $query, '', '');
		if($return_value == null) $return_value = Array();
		return $return_value;
	}

	function get_comments($relatedRecordId = false) {
		$current_user = vglobal('current_user');
		$moduleName = $this->moduleName;
		if($moduleName != 'ModComments') {
			return false;
		}
		$queryGenerator = new EnhancedQueryGenerator($moduleName, $current_user);
		if(is_object($this->column_fields)) {
			$fields = $this->column_fields->getColumnFieldNames();
		} else if(is_array($this->column_fields)) {
			$fields = array_keys($this->column_fields);
		}
		array_push($fields, 'id');
		$queryGenerator->setFields($fields);
		$query = $queryGenerator->getQuery();
		if($relatedRecordId){
			$query .= " AND related_to = ".$relatedRecordId." ORDER BY vtiger_crmentity.createdtime DESC";
		}
		return $query;
	}
Prasad's avatar
Prasad committed
}
Prasad's avatar
Prasad committed

class TrackableObject implements ArrayAccess, IteratorAggregate {
	private $storage;
	private $trackingEnabled = true;
its4you's avatar
its4you committed
	private $tracking;
	
Prasad's avatar
Prasad committed
	function __construct($value = array()) {
		$this->storage = $value;
	}

	function offsetExists($key) {
		return isset($this->storage[$key]);
	}

	function offsetSet($key, $value) {
		if($this->tracking && $this->trackingEnabled) {
			$olderValue = $this->offsetGet($key);
			// decode_html only expects string
			$olderValue = is_string($olderValue) ? decode_html($olderValue) : $olderValue ;
			//same logic is used in vtEntityDelta to check for delta
			if((empty($olderValue) && !empty($value)) || ($olderValue !== $value)) {
Prasad's avatar
Prasad committed
				$this->changed[] = $key;
			}
		}
		$this->storage[$key] = $value;
	}

	public function offsetUnset($key) {
		unset($this->storage[$key]);
	}

	public function offsetGet($key) {
		return isset($this->storage[$key]) ? $this->storage[$key] : null;
	}

	public function getIterator() {
		$iterator = new ArrayObject($this->storage);
		return $iterator->getIterator();
	}

	function getChanged() {
		return $this->changed;
	}

	function startTracking() {
		if($this->tracking && $this->trackingEnabled) return;
		$this->tracking = true;
		$this->changed = array();
	}

	function restartTracking() {
		$this->tracking = true;
		$this->startTracking();
	}

	function pauseTracking() {
		$this->tracking = false;
	}

	function resumeTracking() {
		if($this->trackingEnabled)
			$this->tracking = true;
	}

	function getColumnFields() {
		return $this->storage;
	}

	function getColumnFieldNames(){
		return array_keys($this->storage);
	}