# File core/lib/Thelia/Model/om/BaseAttributeCategory.php | thelia

       1: <?php
       2:
       3: namespace Thelia\Model\om;
       4:
       5: use \BaseObject;
       6: use \BasePeer;
       7: use \Criteria;
       8: use \DateTime;
       9: use \Exception;
      10: use \PDO;
      11: use \Persistent;
      12: use \Propel;
      13: use \PropelDateTime;
      14: use \PropelException;
      15: use \PropelPDO;
      16: use Thelia\Model\Attribute;
      17: use Thelia\Model\AttributeCategory;
      18: use Thelia\Model\AttributeCategoryPeer;
      19: use Thelia\Model\AttributeCategoryQuery;
      20: use Thelia\Model\AttributeQuery;
      21: use Thelia\Model\Category;
      22: use Thelia\Model\CategoryQuery;
      23:
      24: /**
      25:  * Base class that represents a row from the 'attribute_category' table.
      26:  *
      27:  *
      28:  *
      29:  * @package    propel.generator.Thelia.Model.om
      30:  */
      31: abstract class BaseAttributeCategory extends BaseObject implements Persistent
      32: {
      33:     /**
      34:      * Peer class name
      35:      */
      36:     const PEER = 'Thelia\\Model\\AttributeCategoryPeer';
      37:
      38:     /**
      39:      * The Peer class.
      40:      * Instance provides a convenient way of calling static methods on a class
      41:      * that calling code may not be able to identify.
      42:      * @var        AttributeCategoryPeer
      43:      */
      44:     protected static $peer;
      45:
      46:     /**
      47:      * The flag var to prevent infinit loop in deep copy
      48:      * @var       boolean
      49:      */
      50:     protected $startCopy = false;
      51:
      52:     /**
      53:      * The value for the id field.
      54:      * @var        int
      55:      */
      56:     protected $id;
      57:
      58:     /**
      59:      * The value for the category_id field.
      60:      * @var        int
      61:      */
      62:     protected $category_id;
      63:
      64:     /**
      65:      * The value for the attribute_id field.
      66:      * @var        int
      67:      */
      68:     protected $attribute_id;
      69:
      70:     /**
      71:      * The value for the created_at field.
      72:      * @var        string
      73:      */
      74:     protected $created_at;
      75:
      76:     /**
      77:      * The value for the updated_at field.
      78:      * @var        string
      79:      */
      80:     protected $updated_at;
      81:
      82:     /**
      83:      * @var        Category
      84:      */
      85:     protected $aCategory;
      86:
      87:     /**
      88:      * @var        Attribute
      89:      */
      90:     protected $aAttribute;
      91:
      92:     /**
      93:      * Flag to prevent endless save loop, if this object is referenced
      94:      * by another object which falls in this transaction.
      95:      * @var        boolean
      96:      */
      97:     protected $alreadyInSave = false;
      98:
      99:     /**
     100:      * Flag to prevent endless validation loop, if this object is referenced
     101:      * by another object which falls in this transaction.
     102:      * @var        boolean
     103:      */
     104:     protected $alreadyInValidation = false;
     105:
     106:     /**
     107:      * Get the [id] column value.
     108:      *
     109:      * @return int
     110:      */
     111:     public function getId()
     112:     {
     113:         return $this->id;
     114:     }
     115:
     116:     /**
     117:      * Get the [category_id] column value.
     118:      *
     119:      * @return int
     120:      */
     121:     public function getCategoryId()
     122:     {
     123:         return $this->category_id;
     124:     }
     125:
     126:     /**
     127:      * Get the [attribute_id] column value.
     128:      *
     129:      * @return int
     130:      */
     131:     public function getAttributeId()
     132:     {
     133:         return $this->attribute_id;
     134:     }
     135:
     136:     /**
     137:      * Get the [optionally formatted] temporal [created_at] column value.
     138:      *
     139:      *
     140:      * @param string $format The date/time format string (either date()-style or strftime()-style).
     141:      *               If format is null, then the raw DateTime object will be returned.
     142:      * @return mixed Formatted date/time value as string or DateTime object (if format is null), null if column is null, and 0 if column value is 0000-00-00 00:00:00
     143:      * @throws PropelException - if unable to parse/validate the date/time value.
     144:      */
     145:     public function getCreatedAt($format = 'Y-m-d H:i:s')
     146:     {
     147:         if ($this->created_at === null) {
     148:             return null;
     149:         }
     150:
     151:         if ($this->created_at === '0000-00-00 00:00:00') {
     152:             // while technically this is not a default value of null,
     153:             // this seems to be closest in meaning.
     154:             return null;
     155:         } else {
     156:             try {
     157:                 $dt = new DateTime($this->created_at);
     158:             } catch (Exception $x) {
     159:                 throw new PropelException("Internally stored date/time/timestamp value could not be converted to DateTime: " . var_export($this->created_at, true), $x);
     160:             }
     161:         }
     162:
     163:         if ($format === null) {
     164:             // Because propel.useDateTimeClass is true, we return a DateTime object.
     165:             return $dt;
     166:         } elseif (strpos($format, '%') !== false) {
     167:             return strftime($format, $dt->format('U'));
     168:         } else {
     169:             return $dt->format($format);
     170:         }
     171:     }
     172:
     173:     /**
     174:      * Get the [optionally formatted] temporal [updated_at] column value.
     175:      *
     176:      *
     177:      * @param string $format The date/time format string (either date()-style or strftime()-style).
     178:      *               If format is null, then the raw DateTime object will be returned.
     179:      * @return mixed Formatted date/time value as string or DateTime object (if format is null), null if column is null, and 0 if column value is 0000-00-00 00:00:00
     180:      * @throws PropelException - if unable to parse/validate the date/time value.
     181:      */
     182:     public function getUpdatedAt($format = 'Y-m-d H:i:s')
     183:     {
     184:         if ($this->updated_at === null) {
     185:             return null;
     186:         }
     187:
     188:         if ($this->updated_at === '0000-00-00 00:00:00') {
     189:             // while technically this is not a default value of null,
     190:             // this seems to be closest in meaning.
     191:             return null;
     192:         } else {
     193:             try {
     194:                 $dt = new DateTime($this->updated_at);
     195:             } catch (Exception $x) {
     196:                 throw new PropelException("Internally stored date/time/timestamp value could not be converted to DateTime: " . var_export($this->updated_at, true), $x);
     197:             }
     198:         }
     199:
     200:         if ($format === null) {
     201:             // Because propel.useDateTimeClass is true, we return a DateTime object.
     202:             return $dt;
     203:         } elseif (strpos($format, '%') !== false) {
     204:             return strftime($format, $dt->format('U'));
     205:         } else {
     206:             return $dt->format($format);
     207:         }
     208:     }
     209:
     210:     /**
     211:      * Set the value of [id] column.
     212:      *
     213:      * @param int $v new value
     214:      * @return AttributeCategory The current object (for fluent API support)
     215:      */
     216:     public function setId($v)
     217:     {
     218:         if ($v !== null) {
     219:             $v = (int) $v;
     220:         }
     221:
     222:         if ($this->id !== $v) {
     223:             $this->id = $v;
     224:             $this->modifiedColumns[] = AttributeCategoryPeer::ID;
     225:         }
     226:
     227:
     228:         return $this;
     229:     } // setId()
     230:
     231:     /**
     232:      * Set the value of [category_id] column.
     233:      *
     234:      * @param int $v new value
     235:      * @return AttributeCategory The current object (for fluent API support)
     236:      */
     237:     public function setCategoryId($v)
     238:     {
     239:         if ($v !== null) {
     240:             $v = (int) $v;
     241:         }
     242:
     243:         if ($this->category_id !== $v) {
     244:             $this->category_id = $v;
     245:             $this->modifiedColumns[] = AttributeCategoryPeer::CATEGORY_ID;
     246:         }
     247:
     248:         if ($this->aCategory !== null && $this->aCategory->getId() !== $v) {
     249:             $this->aCategory = null;
     250:         }
     251:
     252:
     253:         return $this;
     254:     } // setCategoryId()
     255:
     256:     /**
     257:      * Set the value of [attribute_id] column.
     258:      *
     259:      * @param int $v new value
     260:      * @return AttributeCategory The current object (for fluent API support)
     261:      */
     262:     public function setAttributeId($v)
     263:     {
     264:         if ($v !== null) {
     265:             $v = (int) $v;
     266:         }
     267:
     268:         if ($this->attribute_id !== $v) {
     269:             $this->attribute_id = $v;
     270:             $this->modifiedColumns[] = AttributeCategoryPeer::ATTRIBUTE_ID;
     271:         }
     272:
     273:         if ($this->aAttribute !== null && $this->aAttribute->getId() !== $v) {
     274:             $this->aAttribute = null;
     275:         }
     276:
     277:
     278:         return $this;
     279:     } // setAttributeId()
     280:
     281:     /**
     282:      * Sets the value of [created_at] column to a normalized version of the date/time value specified.
     283:      *
     284:      * @param mixed $v string, integer (timestamp), or DateTime value.
     285:      *               Empty strings are treated as null.
     286:      * @return AttributeCategory The current object (for fluent API support)
     287:      */
     288:     public function setCreatedAt($v)
     289:     {
     290:         $dt = PropelDateTime::newInstance($v, null, 'DateTime');
     291:         if ($this->created_at !== null || $dt !== null) {
     292:             $currentDateAsString = ($this->created_at !== null && $tmpDt = new DateTime($this->created_at)) ? $tmpDt->format('Y-m-d H:i:s') : null;
     293:             $newDateAsString = $dt ? $dt->format('Y-m-d H:i:s') : null;
     294:             if ($currentDateAsString !== $newDateAsString) {
     295:                 $this->created_at = $newDateAsString;
     296:                 $this->modifiedColumns[] = AttributeCategoryPeer::CREATED_AT;
     297:             }
     298:         } // if either are not null
     299:
     300:
     301:         return $this;
     302:     } // setCreatedAt()
     303:
     304:     /**
     305:      * Sets the value of [updated_at] column to a normalized version of the date/time value specified.
     306:      *
     307:      * @param mixed $v string, integer (timestamp), or DateTime value.
     308:      *               Empty strings are treated as null.
     309:      * @return AttributeCategory The current object (for fluent API support)
     310:      */
     311:     public function setUpdatedAt($v)
     312:     {
     313:         $dt = PropelDateTime::newInstance($v, null, 'DateTime');
     314:         if ($this->updated_at !== null || $dt !== null) {
     315:             $currentDateAsString = ($this->updated_at !== null && $tmpDt = new DateTime($this->updated_at)) ? $tmpDt->format('Y-m-d H:i:s') : null;
     316:             $newDateAsString = $dt ? $dt->format('Y-m-d H:i:s') : null;
     317:             if ($currentDateAsString !== $newDateAsString) {
     318:                 $this->updated_at = $newDateAsString;
     319:                 $this->modifiedColumns[] = AttributeCategoryPeer::UPDATED_AT;
     320:             }
     321:         } // if either are not null
     322:
     323:
     324:         return $this;
     325:     } // setUpdatedAt()
     326:
     327:     /**
     328:      * Indicates whether the columns in this object are only set to default values.
     329:      *
     330:      * This method can be used in conjunction with isModified() to indicate whether an object is both
     331:      * modified _and_ has some values set which are non-default.
     332:      *
     333:      * @return boolean Whether the columns in this object are only been set with default values.
     334:      */
     335:     public function hasOnlyDefaultValues()
     336:     {
     337:         // otherwise, everything was equal, so return true
     338:         return true;
     339:     } // hasOnlyDefaultValues()
     340:
     341:     /**
     342:      * Hydrates (populates) the object variables with values from the database resultset.
     343:      *
     344:      * An offset (0-based "start column") is specified so that objects can be hydrated
     345:      * with a subset of the columns in the resultset rows.  This is needed, for example,
     346:      * for results of JOIN queries where the resultset row includes columns from two or
     347:      * more tables.
     348:      *
     349:      * @param array $row The row returned by PDOStatement->fetch(PDO::FETCH_NUM)
     350:      * @param int $startcol 0-based offset column which indicates which restultset column to start with.
     351:      * @param boolean $rehydrate Whether this object is being re-hydrated from the database.
     352:      * @return int             next starting column
     353:      * @throws PropelException - Any caught Exception will be rewrapped as a PropelException.
     354:      */
     355:     public function hydrate($row, $startcol = 0, $rehydrate = false)
     356:     {
     357:         try {
     358:
     359:             $this->id = ($row[$startcol + 0] !== null) ? (int) $row[$startcol + 0] : null;
     360:             $this->category_id = ($row[$startcol + 1] !== null) ? (int) $row[$startcol + 1] : null;
     361:             $this->attribute_id = ($row[$startcol + 2] !== null) ? (int) $row[$startcol + 2] : null;
     362:             $this->created_at = ($row[$startcol + 3] !== null) ? (string) $row[$startcol + 3] : null;
     363:             $this->updated_at = ($row[$startcol + 4] !== null) ? (string) $row[$startcol + 4] : null;
     364:             $this->resetModified();
     365:
     366:             $this->setNew(false);
     367:
     368:             if ($rehydrate) {
     369:                 $this->ensureConsistency();
     370:             }
     371:
     372:             return $startcol + 5; // 5 = AttributeCategoryPeer::NUM_HYDRATE_COLUMNS.
     373:
     374:         } catch (Exception $e) {
     375:             throw new PropelException("Error populating AttributeCategory object", $e);
     376:         }
     377:     }
     378:
     379:     /**
     380:      * Checks and repairs the internal consistency of the object.
     381:      *
     382:      * This method is executed after an already-instantiated object is re-hydrated
     383:      * from the database.  It exists to check any foreign keys to make sure that
     384:      * the objects related to the current object are correct based on foreign key.
     385:      *
     386:      * You can override this method in the stub class, but you should always invoke
     387:      * the base method from the overridden method (i.e. parent::ensureConsistency()),
     388:      * in case your model changes.
     389:      *
     390:      * @throws PropelException
     391:      */
     392:     public function ensureConsistency()
     393:     {
     394:
     395:         if ($this->aCategory !== null && $this->category_id !== $this->aCategory->getId()) {
     396:             $this->aCategory = null;
     397:         }
     398:         if ($this->aAttribute !== null && $this->attribute_id !== $this->aAttribute->getId()) {
     399:             $this->aAttribute = null;
     400:         }
     401:     } // ensureConsistency
     402:
     403:     /**
     404:      * Reloads this object from datastore based on primary key and (optionally) resets all associated objects.
     405:      *
     406:      * This will only work if the object has been saved and has a valid primary key set.
     407:      *
     408:      * @param boolean $deep (optional) Whether to also de-associated any related objects.
     409:      * @param PropelPDO $con (optional) The PropelPDO connection to use.
     410:      * @return void
     411:      * @throws PropelException - if this object is deleted, unsaved or doesn't have pk match in db
     412:      */
     413:     public function reload($deep = false, PropelPDO $con = null)
     414:     {
     415:         if ($this->isDeleted()) {
     416:             throw new PropelException("Cannot reload a deleted object.");
     417:         }
     418:
     419:         if ($this->isNew()) {
     420:             throw new PropelException("Cannot reload an unsaved object.");
     421:         }
     422:
     423:         if ($con === null) {
     424:             $con = Propel::getConnection(AttributeCategoryPeer::DATABASE_NAME, Propel::CONNECTION_READ);
     425:         }
     426:
     427:         // We don't need to alter the object instance pool; we're just modifying this instance
     428:         // already in the pool.
     429:
     430:         $stmt = AttributeCategoryPeer::doSelectStmt($this->buildPkeyCriteria(), $con);
     431:         $row = $stmt->fetch(PDO::FETCH_NUM);
     432:         $stmt->closeCursor();
     433:         if (!$row) {
     434:             throw new PropelException('Cannot find matching row in the database to reload object values.');
     435:         }
     436:         $this->hydrate($row, 0, true); // rehydrate
     437:
     438:         if ($deep) {  // also de-associate any related objects?
     439:
     440:             $this->aCategory = null;
     441:             $this->aAttribute = null;
     442:         } // if (deep)
     443:     }
     444:
     445:     /**
     446:      * Removes this object from datastore and sets delete attribute.
     447:      *
     448:      * @param PropelPDO $con
     449:      * @return void
     450:      * @throws PropelException
     451:      * @throws Exception
     452:      * @see        BaseObject::setDeleted()
     453:      * @see        BaseObject::isDeleted()
     454:      */
     455:     public function delete(PropelPDO $con = null)
     456:     {
     457:         if ($this->isDeleted()) {
     458:             throw new PropelException("This object has already been deleted.");
     459:         }
     460:
     461:         if ($con === null) {
     462:             $con = Propel::getConnection(AttributeCategoryPeer::DATABASE_NAME, Propel::CONNECTION_WRITE);
     463:         }
     464:
     465:         $con->beginTransaction();
     466:         try {
     467:             $deleteQuery = AttributeCategoryQuery::create()
     468:                 ->filterByPrimaryKey($this->getPrimaryKey());
     469:             $ret = $this->preDelete($con);
     470:             if ($ret) {
     471:                 $deleteQuery->delete($con);
     472:                 $this->postDelete($con);
     473:                 $con->commit();
     474:                 $this->setDeleted(true);
     475:             } else {
     476:                 $con->commit();
     477:             }
     478:         } catch (Exception $e) {
     479:             $con->rollBack();
     480:             throw $e;
     481:         }
     482:     }
     483:
     484:     /**
     485:      * Persists this object to the database.
     486:      *
     487:      * If the object is new, it inserts it; otherwise an update is performed.
     488:      * All modified related objects will also be persisted in the doSave()
     489:      * method.  This method wraps all precipitate database operations in a
     490:      * single transaction.
     491:      *
     492:      * @param PropelPDO $con
     493:      * @return int             The number of rows affected by this insert/update and any referring fk objects' save() operations.
     494:      * @throws PropelException
     495:      * @throws Exception
     496:      * @see        doSave()
     497:      */
     498:     public function save(PropelPDO $con = null)
     499:     {
     500:         if ($this->isDeleted()) {
     501:             throw new PropelException("You cannot save an object that has been deleted.");
     502:         }
     503:
     504:         if ($con === null) {
     505:             $con = Propel::getConnection(AttributeCategoryPeer::DATABASE_NAME, Propel::CONNECTION_WRITE);
     506:         }
     507:
     508:         $con->beginTransaction();
     509:         $isInsert = $this->isNew();
     510:         try {
     511:             $ret = $this->preSave($con);
     512:             if ($isInsert) {
     513:                 $ret = $ret && $this->preInsert($con);
     514:                 // timestampable behavior
     515:                 if (!$this->isColumnModified(AttributeCategoryPeer::CREATED_AT)) {
     516:                     $this->setCreatedAt(time());
     517:                 }
     518:                 if (!$this->isColumnModified(AttributeCategoryPeer::UPDATED_AT)) {
     519:                     $this->setUpdatedAt(time());
     520:                 }
     521:             } else {
     522:                 $ret = $ret && $this->preUpdate($con);
     523:                 // timestampable behavior
     524:                 if ($this->isModified() && !$this->isColumnModified(AttributeCategoryPeer::UPDATED_AT)) {
     525:                     $this->setUpdatedAt(time());
     526:                 }
     527:             }
     528:             if ($ret) {
     529:                 $affectedRows = $this->doSave($con);
     530:                 if ($isInsert) {
     531:                     $this->postInsert($con);
     532:                 } else {
     533:                     $this->postUpdate($con);
     534:                 }
     535:                 $this->postSave($con);
     536:                 AttributeCategoryPeer::addInstanceToPool($this);
     537:             } else {
     538:                 $affectedRows = 0;
     539:             }
     540:             $con->commit();
     541:
     542:             return $affectedRows;
     543:         } catch (Exception $e) {
     544:             $con->rollBack();
     545:             throw $e;
     546:         }
     547:     }
     548:
     549:     /**
     550:      * Performs the work of inserting or updating the row in the database.
     551:      *
     552:      * If the object is new, it inserts it; otherwise an update is performed.
     553:      * All related objects are also updated in this method.
     554:      *
     555:      * @param PropelPDO $con
     556:      * @return int             The number of rows affected by this insert/update and any referring fk objects' save() operations.
     557:      * @throws PropelException
     558:      * @see        save()
     559:      */
     560:     protected function doSave(PropelPDO $con)
     561:     {
     562:         $affectedRows = 0; // initialize var to track total num of affected rows
     563:         if (!$this->alreadyInSave) {
     564:             $this->alreadyInSave = true;
     565:
     566:             // We call the save method on the following object(s) if they
     567:             // were passed to this object by their coresponding set
     568:             // method.  This object relates to these object(s) by a
     569:             // foreign key reference.
     570:
     571:             if ($this->aCategory !== null) {
     572:                 if ($this->aCategory->isModified() || $this->aCategory->isNew()) {
     573:                     $affectedRows += $this->aCategory->save($con);
     574:                 }
     575:                 $this->setCategory($this->aCategory);
     576:             }
     577:
     578:             if ($this->aAttribute !== null) {
     579:                 if ($this->aAttribute->isModified() || $this->aAttribute->isNew()) {
     580:                     $affectedRows += $this->aAttribute->save($con);
     581:                 }
     582:                 $this->setAttribute($this->aAttribute);
     583:             }
     584:
     585:             if ($this->isNew() || $this->isModified()) {
     586:                 // persist changes
     587:                 if ($this->isNew()) {
     588:                     $this->doInsert($con);
     589:                 } else {
     590:                     $this->doUpdate($con);
     591:                 }
     592:                 $affectedRows += 1;
     593:                 $this->resetModified();
     594:             }
     595:
     596:             $this->alreadyInSave = false;
     597:
     598:         }
     599:
     600:         return $affectedRows;
     601:     } // doSave()
     602:
     603:     /**
     604:      * Insert the row in the database.
     605:      *
     606:      * @param PropelPDO $con
     607:      *
     608:      * @throws PropelException
     609:      * @see        doSave()
     610:      */
     611:     protected function doInsert(PropelPDO $con)
     612:     {
     613:         $modifiedColumns = array();
     614:         $index = 0;
     615:
     616:         $this->modifiedColumns[] = AttributeCategoryPeer::ID;
     617:         if (null !== $this->id) {
     618:             throw new PropelException('Cannot insert a value for auto-increment primary key (' . AttributeCategoryPeer::ID . ')');
     619:         }
     620:
     621:          // check the columns in natural order for more readable SQL queries
     622:         if ($this->isColumnModified(AttributeCategoryPeer::ID)) {
     623:             $modifiedColumns[':p' . $index++]  = '`ID`';
     624:         }
     625:         if ($this->isColumnModified(AttributeCategoryPeer::CATEGORY_ID)) {
     626:             $modifiedColumns[':p' . $index++]  = '`CATEGORY_ID`';
     627:         }
     628:         if ($this->isColumnModified(AttributeCategoryPeer::ATTRIBUTE_ID)) {
     629:             $modifiedColumns[':p' . $index++]  = '`ATTRIBUTE_ID`';
     630:         }
     631:         if ($this->isColumnModified(AttributeCategoryPeer::CREATED_AT)) {
     632:             $modifiedColumns[':p' . $index++]  = '`CREATED_AT`';
     633:         }
     634:         if ($this->isColumnModified(AttributeCategoryPeer::UPDATED_AT)) {
     635:             $modifiedColumns[':p' . $index++]  = '`UPDATED_AT`';
     636:         }
     637:
     638:         $sql = sprintf(
     639:             'INSERT INTO `attribute_category` (%s) VALUES (%s)',
     640:             implode(', ', $modifiedColumns),
     641:             implode(', ', array_keys($modifiedColumns))
     642:         );
     643:
     644:         try {
     645:             $stmt = $con->prepare($sql);
     646:             foreach ($modifiedColumns as $identifier => $columnName) {
     647:                 switch ($columnName) {
     648:                     case '`ID`':
     649:                         $stmt->bindValue($identifier, $this->id, PDO::PARAM_INT);
     650:                         break;
     651:                     case '`CATEGORY_ID`':
     652:                         $stmt->bindValue($identifier, $this->category_id, PDO::PARAM_INT);
     653:                         break;
     654:                     case '`ATTRIBUTE_ID`':
     655:                         $stmt->bindValue($identifier, $this->attribute_id, PDO::PARAM_INT);
     656:                         break;
     657:                     case '`CREATED_AT`':
     658:                         $stmt->bindValue($identifier, $this->created_at, PDO::PARAM_STR);
     659:                         break;
     660:                     case '`UPDATED_AT`':
     661:                         $stmt->bindValue($identifier, $this->updated_at, PDO::PARAM_STR);
     662:                         break;
     663:                 }
     664:             }
     665:             $stmt->execute();
     666:         } catch (Exception $e) {
     667:             Propel::log($e->getMessage(), Propel::LOG_ERR);
     668:             throw new PropelException(sprintf('Unable to execute INSERT statement [%s]', $sql), $e);
     669:         }
     670:
     671:         try {
     672:             $pk = $con->lastInsertId();
     673:         } catch (Exception $e) {
     674:             throw new PropelException('Unable to get autoincrement id.', $e);
     675:         }
     676:         $this->setId($pk);
     677:
     678:         $this->setNew(false);
     679:     }
     680:
     681:     /**
     682:      * Update the row in the database.
     683:      *
     684:      * @param PropelPDO $con
     685:      *
     686:      * @see        doSave()
     687:      */
     688:     protected function doUpdate(PropelPDO $con)
     689:     {
     690:         $selectCriteria = $this->buildPkeyCriteria();
     691:         $valuesCriteria = $this->buildCriteria();
     692:         BasePeer::doUpdate($selectCriteria, $valuesCriteria, $con);
     693:     }
     694:
     695:     /**
     696:      * Array of ValidationFailed objects.
     697:      * @var        array ValidationFailed[]
     698:      */
     699:     protected $validationFailures = array();
     700:
     701:     /**
     702:      * Gets any ValidationFailed objects that resulted from last call to validate().
     703:      *
     704:      *
     705:      * @return array ValidationFailed[]
     706:      * @see        validate()
     707:      */
     708:     public function getValidationFailures()
     709:     {
     710:         return $this->validationFailures;
     711:     }
     712:
     713:     /**
     714:      * Validates the objects modified field values and all objects related to this table.
     715:      *
     716:      * If $columns is either a column name or an array of column names
     717:      * only those columns are validated.
     718:      *
     719:      * @param mixed $columns Column name or an array of column names.
     720:      * @return boolean Whether all columns pass validation.
     721:      * @see        doValidate()
     722:      * @see        getValidationFailures()
     723:      */
     724:     public function validate($columns = null)
     725:     {
     726:         $res = $this->doValidate($columns);
     727:         if ($res === true) {
     728:             $this->validationFailures = array();
     729:
     730:             return true;
     731:         } else {
     732:             $this->validationFailures = $res;
     733:
     734:             return false;
     735:         }
     736:     }
     737:
     738:     /**
     739:      * This function performs the validation work for complex object models.
     740:      *
     741:      * In addition to checking the current object, all related objects will
     742:      * also be validated.  If all pass then <code>true</code> is returned; otherwise
     743:      * an aggreagated array of ValidationFailed objects will be returned.
     744:      *
     745:      * @param array $columns Array of column names to validate.
     746:      * @return mixed <code>true</code> if all validations pass; array of <code>ValidationFailed</code> objets otherwise.
     747:      */
     748:     protected function doValidate($columns = null)
     749:     {
     750:         if (!$this->alreadyInValidation) {
     751:             $this->alreadyInValidation = true;
     752:             $retval = null;
     753:
     754:             $failureMap = array();
     755:
     756:
     757:             // We call the validate method on the following object(s) if they
     758:             // were passed to this object by their coresponding set
     759:             // method.  This object relates to these object(s) by a
     760:             // foreign key reference.
     761:
     762:             if ($this->aCategory !== null) {
     763:                 if (!$this->aCategory->validate($columns)) {
     764:                     $failureMap = array_merge($failureMap, $this->aCategory->getValidationFailures());
     765:                 }
     766:             }
     767:
     768:             if ($this->aAttribute !== null) {
     769:                 if (!$this->aAttribute->validate($columns)) {
     770:                     $failureMap = array_merge($failureMap, $this->aAttribute->getValidationFailures());
     771:                 }
     772:             }
     773:
     774:
     775:             if (($retval = AttributeCategoryPeer::doValidate($this, $columns)) !== true) {
     776:                 $failureMap = array_merge($failureMap, $retval);
     777:             }
     778:
     779:
     780:
     781:             $this->alreadyInValidation = false;
     782:         }
     783:
     784:         return (!empty($failureMap) ? $failureMap : true);
     785:     }
     786:
     787:     /**
     788:      * Retrieves a field from the object by name passed in as a string.
     789:      *
     790:      * @param string $name name
     791:      * @param string $type The type of fieldname the $name is of:
     792:      *               one of the class type constants BasePeer::TYPE_PHPNAME, BasePeer::TYPE_STUDLYPHPNAME
     793:      *               BasePeer::TYPE_COLNAME, BasePeer::TYPE_FIELDNAME, BasePeer::TYPE_NUM.
     794:      *               Defaults to BasePeer::TYPE_PHPNAME
     795:      * @return mixed Value of field.
     796:      */
     797:     public function getByName($name, $type = BasePeer::TYPE_PHPNAME)
     798:     {
     799:         $pos = AttributeCategoryPeer::translateFieldName($name, $type, BasePeer::TYPE_NUM);
     800:         $field = $this->getByPosition($pos);
     801:
     802:         return $field;
     803:     }
     804:
     805:     /**
     806:      * Retrieves a field from the object by Position as specified in the xml schema.
     807:      * Zero-based.
     808:      *
     809:      * @param int $pos position in xml schema
     810:      * @return mixed Value of field at $pos
     811:      */
     812:     public function getByPosition($pos)
     813:     {
     814:         switch ($pos) {
     815:             case 0:
     816:                 return $this->getId();
     817:                 break;
     818:             case 1:
     819:                 return $this->getCategoryId();
     820:                 break;
     821:             case 2:
     822:                 return $this->getAttributeId();
     823:                 break;
     824:             case 3:
     825:                 return $this->getCreatedAt();
     826:                 break;
     827:             case 4:
     828:                 return $this->getUpdatedAt();
     829:                 break;
     830:             default:
     831:                 return null;
     832:                 break;
     833:         } // switch()
     834:     }
     835:
     836:     /**
     837:      * Exports the object as an array.
     838:      *
     839:      * You can specify the key type of the array by passing one of the class
     840:      * type constants.
     841:      *
     842:      * @param     string  $keyType (optional) One of the class type constants BasePeer::TYPE_PHPNAME, BasePeer::TYPE_STUDLYPHPNAME,
     843:      *                    BasePeer::TYPE_COLNAME, BasePeer::TYPE_FIELDNAME, BasePeer::TYPE_NUM.
     844:      *                    Defaults to BasePeer::TYPE_PHPNAME.
     845:      * @param     boolean $includeLazyLoadColumns (optional) Whether to include lazy loaded columns. Defaults to true.
     846:      * @param     array $alreadyDumpedObjects List of objects to skip to avoid recursion
     847:      * @param     boolean $includeForeignObjects (optional) Whether to include hydrated related objects. Default to FALSE.
     848:      *
     849:      * @return array an associative array containing the field names (as keys) and field values
     850:      */
     851:     public function toArray($keyType = BasePeer::TYPE_PHPNAME, $includeLazyLoadColumns = true, $alreadyDumpedObjects = array(), $includeForeignObjects = false)
     852:     {
     853:         if (isset($alreadyDumpedObjects['AttributeCategory'][$this->getPrimaryKey()])) {
     854:             return '*RECURSION*';
     855:         }
     856:         $alreadyDumpedObjects['AttributeCategory'][$this->getPrimaryKey()] = true;
     857:         $keys = AttributeCategoryPeer::getFieldNames($keyType);
     858:         $result = array(
     859:             $keys[0] => $this->getId(),
     860:             $keys[1] => $this->getCategoryId(),
     861:             $keys[2] => $this->getAttributeId(),
     862:             $keys[3] => $this->getCreatedAt(),
     863:             $keys[4] => $this->getUpdatedAt(),
     864:         );
     865:         if ($includeForeignObjects) {
     866:             if (null !== $this->aCategory) {
     867:                 $result['Category'] = $this->aCategory->toArray($keyType, $includeLazyLoadColumns,  $alreadyDumpedObjects, true);
     868:             }
     869:             if (null !== $this->aAttribute) {
     870:                 $result['Attribute'] = $this->aAttribute->toArray($keyType, $includeLazyLoadColumns,  $alreadyDumpedObjects, true);
     871:             }
     872:         }
     873:
     874:         return $result;
     875:     }
     876:
     877:     /**
     878:      * Sets a field from the object by name passed in as a string.
     879:      *
     880:      * @param string $name peer name
     881:      * @param mixed $value field value
     882:      * @param string $type The type of fieldname the $name is of:
     883:      *                     one of the class type constants BasePeer::TYPE_PHPNAME, BasePeer::TYPE_STUDLYPHPNAME
     884:      *                     BasePeer::TYPE_COLNAME, BasePeer::TYPE_FIELDNAME, BasePeer::TYPE_NUM.
     885:      *                     Defaults to BasePeer::TYPE_PHPNAME
     886:      * @return void
     887:      */
     888:     public function setByName($name, $value, $type = BasePeer::TYPE_PHPNAME)
     889:     {
     890:         $pos = AttributeCategoryPeer::translateFieldName($name, $type, BasePeer::TYPE_NUM);
     891:
     892:         $this->setByPosition($pos, $value);
     893:     }
     894:
     895:     /**
     896:      * Sets a field from the object by Position as specified in the xml schema.
     897:      * Zero-based.
     898:      *
     899:      * @param int $pos position in xml schema
     900:      * @param mixed $value field value
     901:      * @return void
     902:      */
     903:     public function setByPosition($pos, $value)
     904:     {
     905:         switch ($pos) {
     906:             case 0:
     907:                 $this->setId($value);
     908:                 break;
     909:             case 1:
     910:                 $this->setCategoryId($value);
     911:                 break;
     912:             case 2:
     913:                 $this->setAttributeId($value);
     914:                 break;
     915:             case 3:
     916:                 $this->setCreatedAt($value);
     917:                 break;
     918:             case 4:
     919:                 $this->setUpdatedAt($value);
     920:                 break;
     921:         } // switch()
     922:     }
     923:
     924:     /**
     925:      * Populates the object using an array.
     926:      *
     927:      * This is particularly useful when populating an object from one of the
     928:      * request arrays (e.g. $_POST).  This method goes through the column
     929:      * names, checking to see whether a matching key exists in populated
     930:      * array. If so the setByName() method is called for that column.
     931:      *
     932:      * You can specify the key type of the array by additionally passing one
     933:      * of the class type constants BasePeer::TYPE_PHPNAME, BasePeer::TYPE_STUDLYPHPNAME,
     934:      * BasePeer::TYPE_COLNAME, BasePeer::TYPE_FIELDNAME, BasePeer::TYPE_NUM.
     935:      * The default key type is the column's BasePeer::TYPE_PHPNAME
     936:      *
     937:      * @param array  $arr     An array to populate the object from.
     938:      * @param string $keyType The type of keys the array uses.
     939:      * @return void
     940:      */
     941:     public function fromArray($arr, $keyType = BasePeer::TYPE_PHPNAME)
     942:     {
     943:         $keys = AttributeCategoryPeer::getFieldNames($keyType);
     944:
     945:         if (array_key_exists($keys[0], $arr)) $this->setId($arr[$keys[0]]);
     946:         if (array_key_exists($keys[1], $arr)) $this->setCategoryId($arr[$keys[1]]);
     947:         if (array_key_exists($keys[2], $arr)) $this->setAttributeId($arr[$keys[2]]);
     948:         if (array_key_exists($keys[3], $arr)) $this->setCreatedAt($arr[$keys[3]]);
     949:         if (array_key_exists($keys[4], $arr)) $this->setUpdatedAt($arr[$keys[4]]);
     950:     }
     951:
     952:     /**
     953:      * Build a Criteria object containing the values of all modified columns in this object.
     954:      *
     955:      * @return Criteria The Criteria object containing all modified values.
     956:      */
     957:     public function buildCriteria()
     958:     {
     959:         $criteria = new Criteria(AttributeCategoryPeer::DATABASE_NAME);
     960:
     961:         if ($this->isColumnModified(AttributeCategoryPeer::ID)) $criteria->add(AttributeCategoryPeer::ID, $this->id);
     962:         if ($this->isColumnModified(AttributeCategoryPeer::CATEGORY_ID)) $criteria->add(AttributeCategoryPeer::CATEGORY_ID, $this->category_id);
     963:         if ($this->isColumnModified(AttributeCategoryPeer::ATTRIBUTE_ID)) $criteria->add(AttributeCategoryPeer::ATTRIBUTE_ID, $this->attribute_id);
     964:         if ($this->isColumnModified(AttributeCategoryPeer::CREATED_AT)) $criteria->add(AttributeCategoryPeer::CREATED_AT, $this->created_at);
     965:         if ($this->isColumnModified(AttributeCategoryPeer::UPDATED_AT)) $criteria->add(AttributeCategoryPeer::UPDATED_AT, $this->updated_at);
     966:
     967:         return $criteria;
     968:     }
     969:
     970:     /**
     971:      * Builds a Criteria object containing the primary key for this object.
     972:      *
     973:      * Unlike buildCriteria() this method includes the primary key values regardless
     974:      * of whether or not they have been modified.
     975:      *
     976:      * @return Criteria The Criteria object containing value(s) for primary key(s).
     977:      */
     978:     public function buildPkeyCriteria()
     979:     {
     980:         $criteria = new Criteria(AttributeCategoryPeer::DATABASE_NAME);
     981:         $criteria->add(AttributeCategoryPeer::ID, $this->id);
     982:
     983:         return $criteria;
     984:     }
     985:
     986:     /**
     987:      * Returns the primary key for this object (row).
     988:      * @return int
     989:      */
     990:     public function getPrimaryKey()
     991:     {
     992:         return $this->getId();
     993:     }
     994:
     995:     /**
     996:      * Generic method to set the primary key (id column).
     997:      *
     998:      * @param  int $key Primary key.
     999:      * @return void
    1000:      */
    1001:     public function setPrimaryKey($key)
    1002:     {
    1003:         $this->setId($key);
    1004:     }
    1005:
    1006:     /**
    1007:      * Returns true if the primary key for this object is null.
    1008:      * @return boolean
    1009:      */
    1010:     public function isPrimaryKeyNull()
    1011:     {
    1012:
    1013:         return null === $this->getId();
    1014:     }
    1015:
    1016:     /**
    1017:      * Sets contents of passed object to values from current object.
    1018:      *
    1019:      * If desired, this method can also make copies of all associated (fkey referrers)
    1020:      * objects.
    1021:      *
    1022:      * @param object $copyObj An object of AttributeCategory (or compatible) type.
    1023:      * @param boolean $deepCopy Whether to also copy all rows that refer (by fkey) to the current row.
    1024:      * @param boolean $makeNew Whether to reset autoincrement PKs and make the object new.
    1025:      * @throws PropelException
    1026:      */
    1027:     public function copyInto($copyObj, $deepCopy = false, $makeNew = true)
    1028:     {
    1029:         $copyObj->setCategoryId($this->getCategoryId());
    1030:         $copyObj->setAttributeId($this->getAttributeId());
    1031:         $copyObj->setCreatedAt($this->getCreatedAt());
    1032:         $copyObj->setUpdatedAt($this->getUpdatedAt());
    1033:
    1034:         if ($deepCopy && !$this->startCopy) {
    1035:             // important: temporarily setNew(false) because this affects the behavior of
    1036:             // the getter/setter methods for fkey referrer objects.
    1037:             $copyObj->setNew(false);
    1038:             // store object hash to prevent cycle
    1039:             $this->startCopy = true;
    1040:
    1041:             //unflag object copy
    1042:             $this->startCopy = false;
    1043:         } // if ($deepCopy)
    1044:
    1045:         if ($makeNew) {
    1046:             $copyObj->setNew(true);
    1047:             $copyObj->setId(NULL); // this is a auto-increment column, so set to default value
    1048:         }
    1049:     }
    1050:
    1051:     /**
    1052:      * Makes a copy of this object that will be inserted as a new row in table when saved.
    1053:      * It creates a new object filling in the simple attributes, but skipping any primary
    1054:      * keys that are defined for the table.
    1055:      *
    1056:      * If desired, this method can also make copies of all associated (fkey referrers)
    1057:      * objects.
    1058:      *
    1059:      * @param boolean $deepCopy Whether to also copy all rows that refer (by fkey) to the current row.
    1060:      * @return AttributeCategory Clone of current object.
    1061:      * @throws PropelException
    1062:      */
    1063:     public function copy($deepCopy = false)
    1064:     {
    1065:         // we use get_class(), because this might be a subclass
    1066:         $clazz = get_class($this);
    1067:         $copyObj = new $clazz();
    1068:         $this->copyInto($copyObj, $deepCopy);
    1069:
    1070:         return $copyObj;
    1071:     }
    1072:
    1073:     /**
    1074:      * Returns a peer instance associated with this om.
    1075:      *
    1076:      * Since Peer classes are not to have any instance attributes, this method returns the
    1077:      * same instance for all member of this class. The method could therefore
    1078:      * be static, but this would prevent one from overriding the behavior.
    1079:      *
    1080:      * @return AttributeCategoryPeer
    1081:      */
    1082:     public function getPeer()
    1083:     {
    1084:         if (self::$peer === null) {
    1085:             self::$peer = new AttributeCategoryPeer();
    1086:         }
    1087:
    1088:         return self::$peer;
    1089:     }
    1090:
    1091:     /**
    1092:      * Declares an association between this object and a Category object.
    1093:      *
    1094:      * @param             Category $v
    1095:      * @return AttributeCategory The current object (for fluent API support)
    1096:      * @throws PropelException
    1097:      */
    1098:     public function setCategory(Category $v = null)
    1099:     {
    1100:         if ($v === null) {
    1101:             $this->setCategoryId(NULL);
    1102:         } else {
    1103:             $this->setCategoryId($v->getId());
    1104:         }
    1105:
    1106:         $this->aCategory = $v;
    1107:
    1108:         // Add binding for other direction of this n:n relationship.
    1109:         // If this object has already been added to the Category object, it will not be re-added.
    1110:         if ($v !== null) {
    1111:             $v->addAttributeCategory($this);
    1112:         }
    1113:
    1114:
    1115:         return $this;
    1116:     }
    1117:
    1118:
    1119:     /**
    1120:      * Get the associated Category object
    1121:      *
    1122:      * @param PropelPDO $con Optional Connection object.
    1123:      * @return Category The associated Category object.
    1124:      * @throws PropelException
    1125:      */
    1126:     public function getCategory(PropelPDO $con = null)
    1127:     {
    1128:         if ($this->aCategory === null && ($this->category_id !== null)) {
    1129:             $this->aCategory = CategoryQuery::create()->findPk($this->category_id, $con);
    1130:             /* The following can be used additionally to
    1131:                 guarantee the related object contains a reference
    1132:                 to this object.  This level of coupling may, however, be
    1133:                 undesirable since it could result in an only partially populated collection
    1134:                 in the referenced object.
    1135:                 $this->aCategory->addAttributeCategorys($this);
    1136:              */
    1137:         }
    1138:
    1139:         return $this->aCategory;
    1140:     }
    1141:
    1142:     /**
    1143:      * Declares an association between this object and a Attribute object.
    1144:      *
    1145:      * @param             Attribute $v
    1146:      * @return AttributeCategory The current object (for fluent API support)
    1147:      * @throws PropelException
    1148:      */
    1149:     public function setAttribute(Attribute $v = null)
    1150:     {
    1151:         if ($v === null) {
    1152:             $this->setAttributeId(NULL);
    1153:         } else {
    1154:             $this->setAttributeId($v->getId());
    1155:         }
    1156:
    1157:         $this->aAttribute = $v;
    1158:
    1159:         // Add binding for other direction of this n:n relationship.
    1160:         // If this object has already been added to the Attribute object, it will not be re-added.
    1161:         if ($v !== null) {
    1162:             $v->addAttributeCategory($this);
    1163:         }
    1164:
    1165:
    1166:         return $this;
    1167:     }
    1168:
    1169:
    1170:     /**
    1171:      * Get the associated Attribute object
    1172:      *
    1173:      * @param PropelPDO $con Optional Connection object.
    1174:      * @return Attribute The associated Attribute object.
    1175:      * @throws PropelException
    1176:      */
    1177:     public function getAttribute(PropelPDO $con = null)
    1178:     {
    1179:         if ($this->aAttribute === null && ($this->attribute_id !== null)) {
    1180:             $this->aAttribute = AttributeQuery::create()->findPk($this->attribute_id, $con);
    1181:             /* The following can be used additionally to
    1182:                 guarantee the related object contains a reference
    1183:                 to this object.  This level of coupling may, however, be
    1184:                 undesirable since it could result in an only partially populated collection
    1185:                 in the referenced object.
    1186:                 $this->aAttribute->addAttributeCategorys($this);
    1187:              */
    1188:         }
    1189:
    1190:         return $this->aAttribute;
    1191:     }
    1192:
    1193:     /**
    1194:      * Clears the current object and sets all attributes to their default values
    1195:      */
    1196:     public function clear()
    1197:     {
    1198:         $this->id = null;
    1199:         $this->category_id = null;
    1200:         $this->attribute_id = null;
    1201:         $this->created_at = null;
    1202:         $this->updated_at = null;
    1203:         $this->alreadyInSave = false;
    1204:         $this->alreadyInValidation = false;
    1205:         $this->clearAllReferences();
    1206:         $this->resetModified();
    1207:         $this->setNew(true);
    1208:         $this->setDeleted(false);
    1209:     }
    1210:
    1211:     /**
    1212:      * Resets all references to other model objects or collections of model objects.
    1213:      *
    1214:      * This method is a user-space workaround for PHP's inability to garbage collect
    1215:      * objects with circular references (even in PHP 5.3). This is currently necessary
    1216:      * when using Propel in certain daemon or large-volumne/high-memory operations.
    1217:      *
    1218:      * @param boolean $deep Whether to also clear the references on all referrer objects.
    1219:      */
    1220:     public function clearAllReferences($deep = false)
    1221:     {
    1222:         if ($deep) {
    1223:         } // if ($deep)
    1224:
    1225:         $this->aCategory = null;
    1226:         $this->aAttribute = null;
    1227:     }
    1228:
    1229:     /**
    1230:      * return the string representation of this object
    1231:      *
    1232:      * @return string
    1233:      */
    1234:     public function __toString()
    1235:     {
    1236:         return (string) $this->exportTo(AttributeCategoryPeer::DEFAULT_STRING_FORMAT);
    1237:     }
    1238:
    1239:     /**
    1240:      * return true is the object is in saving state
    1241:      *
    1242:      * @return boolean
    1243:      */
    1244:     public function isAlreadyInSave()
    1245:     {
    1246:         return $this->alreadyInSave;
    1247:     }
    1248:
    1249:     // timestampable behavior
    1250:
    1251:     /**
    1252:      * Mark the current object so that the update date doesn't get updated during next save
    1253:      *
    1254:      * @return     AttributeCategory The current object (for fluent API support)
    1255:      */
    1256:     public function keepUpdateDateUnchanged()
    1257:     {
    1258:         $this->modifiedColumns[] = AttributeCategoryPeer::UPDATED_AT;
    1259:
    1260:         return $this;
    1261:     }
    1262:
    1263: }
    1264: