5 * Base class that represents a row from the 'werkzeug' table.
9 * @package propel.generator.propel.om
11 abstract class BaseWerkzeug extends BaseObject implements Persistent
16 const PEER = 'WerkzeugPeer';
20 * Instance provides a convenient way of calling static methods on a class
21 * that calling code may not be able to identify.
24 protected static $peer;
27 * The flag var to prevent infinite loop in deep copy
30 protected $startCopy = false;
33 * The value for the id field.
39 * The value for the mod field.
45 * The value for the typ field.
51 * The value for the beschreibung field.
54 protected $beschreibung;
57 * The value for the eigentumer field.
60 protected $eigentumer;
63 * The value for the zz_bei field.
69 * Flag to prevent endless save loop, if this object is referenced
70 * by another object which falls in this transaction.
73 protected $alreadyInSave = false;
76 * Flag to prevent endless validation loop, if this object is referenced
77 * by another object which falls in this transaction.
80 protected $alreadyInValidation = false;
83 * Flag to prevent endless clearAllReferences($deep=true) loop, if this object is referenced
86 protected $alreadyInClearAllReferencesDeep = false;
89 * Get the [id] column value.
93 public function getId()
100 * Get the [mod] column value.
104 public function getMod()
111 * Get the [typ] column value.
115 public function getTyp()
122 * Get the [beschreibung] column value.
126 public function getBeschreibung()
129 return $this->beschreibung;
133 * Get the [eigentumer] column value.
137 public function getEigentumer()
140 return $this->eigentumer;
144 * Get the [zz_bei] column value.
148 public function getZzBei()
151 return $this->zz_bei;
155 * Set the value of [id] column.
157 * @param int $v new value
158 * @return Werkzeug The current object (for fluent API support)
160 public function setId($v)
162 if ($v !== null && is_numeric($v)) {
166 if ($this->id !== $v) {
168 $this->modifiedColumns[] = WerkzeugPeer::ID;
176 * Set the value of [mod] column.
178 * @param int $v new value
179 * @return Werkzeug The current object (for fluent API support)
181 public function setMod($v)
183 if ($v !== null && is_numeric($v)) {
187 if ($this->mod !== $v) {
189 $this->modifiedColumns[] = WerkzeugPeer::MOD;
197 * Set the value of [typ] column.
199 * @param string $v new value
200 * @return Werkzeug The current object (for fluent API support)
202 public function setTyp($v)
208 if ($this->typ !== $v) {
210 $this->modifiedColumns[] = WerkzeugPeer::TYP;
218 * Set the value of [beschreibung] column.
220 * @param string $v new value
221 * @return Werkzeug The current object (for fluent API support)
223 public function setBeschreibung($v)
229 if ($this->beschreibung !== $v) {
230 $this->beschreibung = $v;
231 $this->modifiedColumns[] = WerkzeugPeer::BESCHREIBUNG;
236 } // setBeschreibung()
239 * Set the value of [eigentumer] column.
241 * @param string $v new value
242 * @return Werkzeug The current object (for fluent API support)
244 public function setEigentumer($v)
250 if ($this->eigentumer !== $v) {
251 $this->eigentumer = $v;
252 $this->modifiedColumns[] = WerkzeugPeer::EIGENTUMER;
260 * Set the value of [zz_bei] column.
262 * @param string $v new value
263 * @return Werkzeug The current object (for fluent API support)
265 public function setZzBei($v)
271 if ($this->zz_bei !== $v) {
273 $this->modifiedColumns[] = WerkzeugPeer::ZZ_BEI;
281 * Indicates whether the columns in this object are only set to default values.
283 * This method can be used in conjunction with isModified() to indicate whether an object is both
284 * modified _and_ has some values set which are non-default.
286 * @return boolean Whether the columns in this object are only been set with default values.
288 public function hasOnlyDefaultValues()
290 // otherwise, everything was equal, so return true
292 } // hasOnlyDefaultValues()
295 * Hydrates (populates) the object variables with values from the database resultset.
297 * An offset (0-based "start column") is specified so that objects can be hydrated
298 * with a subset of the columns in the resultset rows. This is needed, for example,
299 * for results of JOIN queries where the resultset row includes columns from two or
302 * @param array $row The row returned by PDOStatement->fetch(PDO::FETCH_NUM)
303 * @param int $startcol 0-based offset column which indicates which resultset column to start with.
304 * @param boolean $rehydrate Whether this object is being re-hydrated from the database.
305 * @return int next starting column
306 * @throws PropelException - Any caught Exception will be rewrapped as a PropelException.
308 public function hydrate($row, $startcol = 0, $rehydrate = false)
312 $this->id = ($row[$startcol + 0] !== null) ? (int) $row[$startcol + 0] : null;
313 $this->mod = ($row[$startcol + 1] !== null) ? (int) $row[$startcol + 1] : null;
314 $this->typ = ($row[$startcol + 2] !== null) ? (string) $row[$startcol + 2] : null;
315 $this->beschreibung = ($row[$startcol + 3] !== null) ? (string) $row[$startcol + 3] : null;
316 $this->eigentumer = ($row[$startcol + 4] !== null) ? (string) $row[$startcol + 4] : null;
317 $this->zz_bei = ($row[$startcol + 5] !== null) ? (string) $row[$startcol + 5] : null;
318 $this->resetModified();
320 $this->setNew(false);
323 $this->ensureConsistency();
325 $this->postHydrate($row, $startcol, $rehydrate);
327 return $startcol + 6; // 6 = WerkzeugPeer::NUM_HYDRATE_COLUMNS.
329 } catch (Exception $e) {
330 throw new PropelException("Error populating Werkzeug object", $e);
335 * Checks and repairs the internal consistency of the object.
337 * This method is executed after an already-instantiated object is re-hydrated
338 * from the database. It exists to check any foreign keys to make sure that
339 * the objects related to the current object are correct based on foreign key.
341 * You can override this method in the stub class, but you should always invoke
342 * the base method from the overridden method (i.e. parent::ensureConsistency()),
343 * in case your model changes.
345 * @throws PropelException
347 public function ensureConsistency()
350 } // ensureConsistency
353 * Reloads this object from datastore based on primary key and (optionally) resets all associated objects.
355 * This will only work if the object has been saved and has a valid primary key set.
357 * @param boolean $deep (optional) Whether to also de-associated any related objects.
358 * @param PropelPDO $con (optional) The PropelPDO connection to use.
360 * @throws PropelException - if this object is deleted, unsaved or doesn't have pk match in db
362 public function reload($deep = false, PropelPDO $con = null)
364 if ($this->isDeleted()) {
365 throw new PropelException("Cannot reload a deleted object.");
368 if ($this->isNew()) {
369 throw new PropelException("Cannot reload an unsaved object.");
373 $con = Propel::getConnection(WerkzeugPeer::DATABASE_NAME, Propel::CONNECTION_READ);
376 // We don't need to alter the object instance pool; we're just modifying this instance
377 // already in the pool.
379 $stmt = WerkzeugPeer::doSelectStmt($this->buildPkeyCriteria(), $con);
380 $row = $stmt->fetch(PDO::FETCH_NUM);
381 $stmt->closeCursor();
383 throw new PropelException('Cannot find matching row in the database to reload object values.');
385 $this->hydrate($row, 0, true); // rehydrate
387 if ($deep) { // also de-associate any related objects?
393 * Removes this object from datastore and sets delete attribute.
395 * @param PropelPDO $con
397 * @throws PropelException
399 * @see BaseObject::setDeleted()
400 * @see BaseObject::isDeleted()
402 public function delete(PropelPDO $con = null)
404 if ($this->isDeleted()) {
405 throw new PropelException("This object has already been deleted.");
409 $con = Propel::getConnection(WerkzeugPeer::DATABASE_NAME, Propel::CONNECTION_WRITE);
412 $con->beginTransaction();
414 $deleteQuery = WerkzeugQuery::create()
415 ->filterByPrimaryKey($this->getPrimaryKey());
416 $ret = $this->preDelete($con);
418 $deleteQuery->delete($con);
419 $this->postDelete($con);
421 $this->setDeleted(true);
425 } catch (Exception $e) {
432 * Persists this object to the database.
434 * If the object is new, it inserts it; otherwise an update is performed.
435 * All modified related objects will also be persisted in the doSave()
436 * method. This method wraps all precipitate database operations in a
437 * single transaction.
439 * @param PropelPDO $con
440 * @return int The number of rows affected by this insert/update and any referring fk objects' save() operations.
441 * @throws PropelException
445 public function save(PropelPDO $con = null)
447 if ($this->isDeleted()) {
448 throw new PropelException("You cannot save an object that has been deleted.");
452 $con = Propel::getConnection(WerkzeugPeer::DATABASE_NAME, Propel::CONNECTION_WRITE);
455 $con->beginTransaction();
456 $isInsert = $this->isNew();
458 $ret = $this->preSave($con);
460 $ret = $ret && $this->preInsert($con);
462 $ret = $ret && $this->preUpdate($con);
465 $affectedRows = $this->doSave($con);
467 $this->postInsert($con);
469 $this->postUpdate($con);
471 $this->postSave($con);
472 WerkzeugPeer::addInstanceToPool($this);
478 return $affectedRows;
479 } catch (Exception $e) {
486 * Performs the work of inserting or updating the row in the database.
488 * If the object is new, it inserts it; otherwise an update is performed.
489 * All related objects are also updated in this method.
491 * @param PropelPDO $con
492 * @return int The number of rows affected by this insert/update and any referring fk objects' save() operations.
493 * @throws PropelException
496 protected function doSave(PropelPDO $con)
498 $affectedRows = 0; // initialize var to track total num of affected rows
499 if (!$this->alreadyInSave) {
500 $this->alreadyInSave = true;
502 if ($this->isNew() || $this->isModified()) {
504 if ($this->isNew()) {
505 $this->doInsert($con);
507 $this->doUpdate($con);
510 $this->resetModified();
513 $this->alreadyInSave = false;
517 return $affectedRows;
521 * Insert the row in the database.
523 * @param PropelPDO $con
525 * @throws PropelException
528 protected function doInsert(PropelPDO $con)
530 $modifiedColumns = array();
533 $this->modifiedColumns[] = WerkzeugPeer::ID;
534 if (null !== $this->id) {
535 throw new PropelException('Cannot insert a value for auto-increment primary key (' . WerkzeugPeer::ID . ')');
538 // check the columns in natural order for more readable SQL queries
539 if ($this->isColumnModified(WerkzeugPeer::ID)) {
540 $modifiedColumns[':p' . $index++] = '`id`';
542 if ($this->isColumnModified(WerkzeugPeer::MOD)) {
543 $modifiedColumns[':p' . $index++] = '`mod`';
545 if ($this->isColumnModified(WerkzeugPeer::TYP)) {
546 $modifiedColumns[':p' . $index++] = '`typ`';
548 if ($this->isColumnModified(WerkzeugPeer::BESCHREIBUNG)) {
549 $modifiedColumns[':p' . $index++] = '`beschreibung`';
551 if ($this->isColumnModified(WerkzeugPeer::EIGENTUMER)) {
552 $modifiedColumns[':p' . $index++] = '`eigentumer`';
554 if ($this->isColumnModified(WerkzeugPeer::ZZ_BEI)) {
555 $modifiedColumns[':p' . $index++] = '`zz_bei`';
559 'INSERT INTO `werkzeug` (%s) VALUES (%s)',
560 implode(', ', $modifiedColumns),
561 implode(', ', array_keys($modifiedColumns))
565 $stmt = $con->prepare($sql);
566 foreach ($modifiedColumns as $identifier => $columnName) {
567 switch ($columnName) {
569 $stmt->bindValue($identifier, $this->id, PDO::PARAM_INT);
572 $stmt->bindValue($identifier, $this->mod, PDO::PARAM_INT);
575 $stmt->bindValue($identifier, $this->typ, PDO::PARAM_STR);
577 case '`beschreibung`':
578 $stmt->bindValue($identifier, $this->beschreibung, PDO::PARAM_STR);
581 $stmt->bindValue($identifier, $this->eigentumer, PDO::PARAM_STR);
584 $stmt->bindValue($identifier, $this->zz_bei, PDO::PARAM_STR);
589 } catch (Exception $e) {
590 Propel::log($e->getMessage(), Propel::LOG_ERR);
591 throw new PropelException(sprintf('Unable to execute INSERT statement [%s]', $sql), $e);
595 $pk = $con->lastInsertId();
596 } catch (Exception $e) {
597 throw new PropelException('Unable to get autoincrement id.', $e);
601 $this->setNew(false);
605 * Update the row in the database.
607 * @param PropelPDO $con
611 protected function doUpdate(PropelPDO $con)
613 $selectCriteria = $this->buildPkeyCriteria();
614 $valuesCriteria = $this->buildCriteria();
615 BasePeer::doUpdate($selectCriteria, $valuesCriteria, $con);
619 * Array of ValidationFailed objects.
620 * @var array ValidationFailed[]
622 protected $validationFailures = array();
625 * Gets any ValidationFailed objects that resulted from last call to validate().
628 * @return array ValidationFailed[]
631 public function getValidationFailures()
633 return $this->validationFailures;
637 * Validates the objects modified field values and all objects related to this table.
639 * If $columns is either a column name or an array of column names
640 * only those columns are validated.
642 * @param mixed $columns Column name or an array of column names.
643 * @return boolean Whether all columns pass validation.
645 * @see getValidationFailures()
647 public function validate($columns = null)
649 $res = $this->doValidate($columns);
651 $this->validationFailures = array();
656 $this->validationFailures = $res;
662 * This function performs the validation work for complex object models.
664 * In addition to checking the current object, all related objects will
665 * also be validated. If all pass then <code>true</code> is returned; otherwise
666 * an aggregated array of ValidationFailed objects will be returned.
668 * @param array $columns Array of column names to validate.
669 * @return mixed <code>true</code> if all validations pass; array of <code>ValidationFailed</code> objects otherwise.
671 protected function doValidate($columns = null)
673 if (!$this->alreadyInValidation) {
674 $this->alreadyInValidation = true;
677 $failureMap = array();
680 if (($retval = WerkzeugPeer::doValidate($this, $columns)) !== true) {
681 $failureMap = array_merge($failureMap, $retval);
686 $this->alreadyInValidation = false;
689 return (!empty($failureMap) ? $failureMap : true);
693 * Retrieves a field from the object by name passed in as a string.
695 * @param string $name name
696 * @param string $type The type of fieldname the $name is of:
697 * one of the class type constants BasePeer::TYPE_PHPNAME, BasePeer::TYPE_STUDLYPHPNAME
698 * BasePeer::TYPE_COLNAME, BasePeer::TYPE_FIELDNAME, BasePeer::TYPE_NUM.
699 * Defaults to BasePeer::TYPE_PHPNAME
700 * @return mixed Value of field.
702 public function getByName($name, $type = BasePeer::TYPE_PHPNAME)
704 $pos = WerkzeugPeer::translateFieldName($name, $type, BasePeer::TYPE_NUM);
705 $field = $this->getByPosition($pos);
711 * Retrieves a field from the object by Position as specified in the xml schema.
714 * @param int $pos position in xml schema
715 * @return mixed Value of field at $pos
717 public function getByPosition($pos)
721 return $this->getId();
724 return $this->getMod();
727 return $this->getTyp();
730 return $this->getBeschreibung();
733 return $this->getEigentumer();
736 return $this->getZzBei();
745 * Exports the object as an array.
747 * You can specify the key type of the array by passing one of the class
750 * @param string $keyType (optional) One of the class type constants BasePeer::TYPE_PHPNAME, BasePeer::TYPE_STUDLYPHPNAME,
751 * BasePeer::TYPE_COLNAME, BasePeer::TYPE_FIELDNAME, BasePeer::TYPE_NUM.
752 * Defaults to BasePeer::TYPE_PHPNAME.
753 * @param boolean $includeLazyLoadColumns (optional) Whether to include lazy loaded columns. Defaults to true.
754 * @param array $alreadyDumpedObjects List of objects to skip to avoid recursion
756 * @return array an associative array containing the field names (as keys) and field values
758 public function toArray($keyType = BasePeer::TYPE_PHPNAME, $includeLazyLoadColumns = true, $alreadyDumpedObjects = array())
760 if (isset($alreadyDumpedObjects['Werkzeug'][$this->getPrimaryKey()])) {
761 return '*RECURSION*';
763 $alreadyDumpedObjects['Werkzeug'][$this->getPrimaryKey()] = true;
764 $keys = WerkzeugPeer::getFieldNames($keyType);
766 $keys[0] => $this->getId(),
767 $keys[1] => $this->getMod(),
768 $keys[2] => $this->getTyp(),
769 $keys[3] => $this->getBeschreibung(),
770 $keys[4] => $this->getEigentumer(),
771 $keys[5] => $this->getZzBei(),
773 $virtualColumns = $this->virtualColumns;
774 foreach ($virtualColumns as $key => $virtualColumn) {
775 $result[$key] = $virtualColumn;
783 * Sets a field from the object by name passed in as a string.
785 * @param string $name peer name
786 * @param mixed $value field value
787 * @param string $type The type of fieldname the $name is of:
788 * one of the class type constants BasePeer::TYPE_PHPNAME, BasePeer::TYPE_STUDLYPHPNAME
789 * BasePeer::TYPE_COLNAME, BasePeer::TYPE_FIELDNAME, BasePeer::TYPE_NUM.
790 * Defaults to BasePeer::TYPE_PHPNAME
793 public function setByName($name, $value, $type = BasePeer::TYPE_PHPNAME)
795 $pos = WerkzeugPeer::translateFieldName($name, $type, BasePeer::TYPE_NUM);
797 $this->setByPosition($pos, $value);
801 * Sets a field from the object by Position as specified in the xml schema.
804 * @param int $pos position in xml schema
805 * @param mixed $value field value
808 public function setByPosition($pos, $value)
812 $this->setId($value);
815 $this->setMod($value);
818 $this->setTyp($value);
821 $this->setBeschreibung($value);
824 $this->setEigentumer($value);
827 $this->setZzBei($value);
833 * Populates the object using an array.
835 * This is particularly useful when populating an object from one of the
836 * request arrays (e.g. $_POST). This method goes through the column
837 * names, checking to see whether a matching key exists in populated
838 * array. If so the setByName() method is called for that column.
840 * You can specify the key type of the array by additionally passing one
841 * of the class type constants BasePeer::TYPE_PHPNAME, BasePeer::TYPE_STUDLYPHPNAME,
842 * BasePeer::TYPE_COLNAME, BasePeer::TYPE_FIELDNAME, BasePeer::TYPE_NUM.
843 * The default key type is the column's BasePeer::TYPE_PHPNAME
845 * @param array $arr An array to populate the object from.
846 * @param string $keyType The type of keys the array uses.
849 public function fromArray($arr, $keyType = BasePeer::TYPE_PHPNAME)
851 $keys = WerkzeugPeer::getFieldNames($keyType);
853 if (array_key_exists($keys[0], $arr)) $this->setId($arr[$keys[0]]);
854 if (array_key_exists($keys[1], $arr)) $this->setMod($arr[$keys[1]]);
855 if (array_key_exists($keys[2], $arr)) $this->setTyp($arr[$keys[2]]);
856 if (array_key_exists($keys[3], $arr)) $this->setBeschreibung($arr[$keys[3]]);
857 if (array_key_exists($keys[4], $arr)) $this->setEigentumer($arr[$keys[4]]);
858 if (array_key_exists($keys[5], $arr)) $this->setZzBei($arr[$keys[5]]);
862 * Build a Criteria object containing the values of all modified columns in this object.
864 * @return Criteria The Criteria object containing all modified values.
866 public function buildCriteria()
868 $criteria = new Criteria(WerkzeugPeer::DATABASE_NAME);
870 if ($this->isColumnModified(WerkzeugPeer::ID)) $criteria->add(WerkzeugPeer::ID, $this->id);
871 if ($this->isColumnModified(WerkzeugPeer::MOD)) $criteria->add(WerkzeugPeer::MOD, $this->mod);
872 if ($this->isColumnModified(WerkzeugPeer::TYP)) $criteria->add(WerkzeugPeer::TYP, $this->typ);
873 if ($this->isColumnModified(WerkzeugPeer::BESCHREIBUNG)) $criteria->add(WerkzeugPeer::BESCHREIBUNG, $this->beschreibung);
874 if ($this->isColumnModified(WerkzeugPeer::EIGENTUMER)) $criteria->add(WerkzeugPeer::EIGENTUMER, $this->eigentumer);
875 if ($this->isColumnModified(WerkzeugPeer::ZZ_BEI)) $criteria->add(WerkzeugPeer::ZZ_BEI, $this->zz_bei);
881 * Builds a Criteria object containing the primary key for this object.
883 * Unlike buildCriteria() this method includes the primary key values regardless
884 * of whether or not they have been modified.
886 * @return Criteria The Criteria object containing value(s) for primary key(s).
888 public function buildPkeyCriteria()
890 $criteria = new Criteria(WerkzeugPeer::DATABASE_NAME);
891 $criteria->add(WerkzeugPeer::ID, $this->id);
897 * Returns the primary key for this object (row).
900 public function getPrimaryKey()
902 return $this->getId();
906 * Generic method to set the primary key (id column).
908 * @param int $key Primary key.
911 public function setPrimaryKey($key)
917 * Returns true if the primary key for this object is null.
920 public function isPrimaryKeyNull()
923 return null === $this->getId();
927 * Sets contents of passed object to values from current object.
929 * If desired, this method can also make copies of all associated (fkey referrers)
932 * @param object $copyObj An object of Werkzeug (or compatible) type.
933 * @param boolean $deepCopy Whether to also copy all rows that refer (by fkey) to the current row.
934 * @param boolean $makeNew Whether to reset autoincrement PKs and make the object new.
935 * @throws PropelException
937 public function copyInto($copyObj, $deepCopy = false, $makeNew = true)
939 $copyObj->setMod($this->getMod());
940 $copyObj->setTyp($this->getTyp());
941 $copyObj->setBeschreibung($this->getBeschreibung());
942 $copyObj->setEigentumer($this->getEigentumer());
943 $copyObj->setZzBei($this->getZzBei());
945 $copyObj->setNew(true);
946 $copyObj->setId(NULL); // this is a auto-increment column, so set to default value
951 * Makes a copy of this object that will be inserted as a new row in table when saved.
952 * It creates a new object filling in the simple attributes, but skipping any primary
953 * keys that are defined for the table.
955 * If desired, this method can also make copies of all associated (fkey referrers)
958 * @param boolean $deepCopy Whether to also copy all rows that refer (by fkey) to the current row.
959 * @return Werkzeug Clone of current object.
960 * @throws PropelException
962 public function copy($deepCopy = false)
964 // we use get_class(), because this might be a subclass
965 $clazz = get_class($this);
966 $copyObj = new $clazz();
967 $this->copyInto($copyObj, $deepCopy);
973 * Returns a peer instance associated with this om.
975 * Since Peer classes are not to have any instance attributes, this method returns the
976 * same instance for all member of this class. The method could therefore
977 * be static, but this would prevent one from overriding the behavior.
979 * @return WerkzeugPeer
981 public function getPeer()
983 if (self::$peer === null) {
984 self::$peer = new WerkzeugPeer();
991 * Clears the current object and sets all attributes to their default values
993 public function clear()
998 $this->beschreibung = null;
999 $this->eigentumer = null;
1000 $this->zz_bei = null;
1001 $this->alreadyInSave = false;
1002 $this->alreadyInValidation = false;
1003 $this->alreadyInClearAllReferencesDeep = false;
1004 $this->clearAllReferences();
1005 $this->resetModified();
1006 $this->setNew(true);
1007 $this->setDeleted(false);
1011 * Resets all references to other model objects or collections of model objects.
1013 * This method is a user-space workaround for PHP's inability to garbage collect
1014 * objects with circular references (even in PHP 5.3). This is currently necessary
1015 * when using Propel in certain daemon or large-volume/high-memory operations.
1017 * @param boolean $deep Whether to also clear the references on all referrer objects.
1019 public function clearAllReferences($deep = false)
1021 if ($deep && !$this->alreadyInClearAllReferencesDeep) {
1022 $this->alreadyInClearAllReferencesDeep = true;
1024 $this->alreadyInClearAllReferencesDeep = false;
1030 * return the string representation of this object
1034 public function __toString()
1036 return (string) $this->exportTo(WerkzeugPeer::DEFAULT_STRING_FORMAT);
1040 * return true is the object is in saving state
1044 public function isAlreadyInSave()
1046 return $this->alreadyInSave;