/** * Adds this attribute to database queries. * * Database queries (select, insert and update) are passed to this method * so the attribute can 'hook' itself into the query. * * Framework method. It should not be necessary to call this method * directly. Derived attributes that consist of more than a single simple * database field (like relations for example), may have to reimplement * this method. * * @param Query $query The SQL query object * @param string $tablename The name of the table of this attribute * @param string $fieldaliasprefix Prefix to use in front of the alias * in the query. * @param array $record The record that contains the value of this attribute. * @param int $level Recursion level if relations point to eachother, an * endless loop could occur if they keep loading * eachothers data. The $level is used to detect this * loop. If overriden in a derived class, any subcall to * an addToQuery method should pass the $level+1. * @param string $mode Indicates what kind of query is being processing: * This can be any action performed on a node (edit, * add, etc) Mind you that "add" and "update" are the * actions that store something in the database, * whereas the rest are probably select queries. */ public function addToQuery($query, $tablename = '', $fieldaliasprefix = '', &$record, $level = 0, $mode = '') { if ($mode == 'add' || $mode == 'update') { if ($mode == 'add' && $this->hasFlag(self::AF_AUTO_INCREMENT)) { $query->addSequenceField($this->fieldName(), $record[$this->fieldName()], $this->getOwnerInstance()->m_seq); return; } if ($this->isEmpty($record) && !$this->hasFlag(self::AF_OBLIGATORY) && !$this->isNotNullInDb()) { $query->addField($this->fieldName(), 'NULL', '', '', false, true); } else { $query->addField($this->fieldName(), $this->value2db($record), '', '', !$this->hasFlag(self::AF_NO_QUOTES), true); } } else { $query->addField($this->fieldName(), '', $tablename, $fieldaliasprefix, !$this->hasFlag(self::AF_NO_QUOTES), true); } }