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