コード例 #1
0
ファイル: Comment.php プロジェクト: OneTimeCZ/DofE
 /**
  * Exports the object as an array.
  *
  * You can specify the key type of the array by passing one of the class
  * type constants.
  *
  * @param     string  $keyType (optional) One of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_CAMELNAME,
  *                    TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM.
  *                    Defaults to TableMap::TYPE_PHPNAME.
  * @param     boolean $includeLazyLoadColumns (optional) Whether to include lazy loaded columns. Defaults to TRUE.
  * @param     array $alreadyDumpedObjects List of objects to skip to avoid recursion
  * @param     boolean $includeForeignObjects (optional) Whether to include hydrated related objects. Default to FALSE.
  *
  * @return array an associative array containing the field names (as keys) and field values
  */
 public function toArray($keyType = TableMap::TYPE_PHPNAME, $includeLazyLoadColumns = true, $alreadyDumpedObjects = array(), $includeForeignObjects = false)
 {
     if (isset($alreadyDumpedObjects['Comment'][$this->hashCode()])) {
         return '*RECURSION*';
     }
     $alreadyDumpedObjects['Comment'][$this->hashCode()] = true;
     $keys = CommentTableMap::getFieldNames($keyType);
     $result = array($keys[0] => $this->getId(), $keys[1] => $this->getIdUser(), $keys[2] => $this->getIdArticle(), $keys[3] => $this->getContent(), $keys[4] => $this->getLikeCount(), $keys[5] => $this->getCreatedAt(), $keys[6] => $this->getUpdatedAt());
     if ($result[$keys[5]] instanceof \DateTime) {
         $result[$keys[5]] = $result[$keys[5]]->format('c');
     }
     if ($result[$keys[6]] instanceof \DateTime) {
         $result[$keys[6]] = $result[$keys[6]]->format('c');
     }
     $virtualColumns = $this->virtualColumns;
     foreach ($virtualColumns as $key => $virtualColumn) {
         $result[$key] = $virtualColumn;
     }
     if ($includeForeignObjects) {
         if (null !== $this->aUser) {
             switch ($keyType) {
                 case TableMap::TYPE_CAMELNAME:
                     $key = 'user';
                     break;
                 case TableMap::TYPE_FIELDNAME:
                     $key = 'users';
                     break;
                 default:
                     $key = 'User';
             }
             $result[$key] = $this->aUser->toArray($keyType, $includeLazyLoadColumns, $alreadyDumpedObjects, true);
         }
         if (null !== $this->aArticle) {
             switch ($keyType) {
                 case TableMap::TYPE_CAMELNAME:
                     $key = 'article';
                     break;
                 case TableMap::TYPE_FIELDNAME:
                     $key = 'articles';
                     break;
                 default:
                     $key = 'Article';
             }
             $result[$key] = $this->aArticle->toArray($keyType, $includeLazyLoadColumns, $alreadyDumpedObjects, true);
         }
         if (null !== $this->collRatings) {
             switch ($keyType) {
                 case TableMap::TYPE_CAMELNAME:
                     $key = 'ratings';
                     break;
                 case TableMap::TYPE_FIELDNAME:
                     $key = 'ratingss';
                     break;
                 default:
                     $key = 'Ratings';
             }
             $result[$key] = $this->collRatings->toArray(null, false, $keyType, $includeLazyLoadColumns, $alreadyDumpedObjects);
         }
     }
     return $result;
 }