The subscription is not created when the user is created - stripe-payments

When registering, a user is created, but a subscription is not created in Stripe and the Trial period does not appear. What is the correct way to write the "createAndStartSubscription" function?
public function __construct(User $user)
{
$this->user = $user;
$this->invoiceService = new InvoiceService();
}
/**
* #param User $user
* #return SubscriptionService
*/
public static function user(User $user)
{
return new self($user);
}
/**
* #param array $options
* #return void
*/
public function createAndStartSubscription(array $options = [])
{
$this->createCustomer($options);
$this->newSubscription();
}
/**
* #param array $options
* #return \Stripe\Customer
* #throws \Laravel\Cashier\Exceptions\CustomerAlreadyCreated
*/
public function createCustomer(array $options = [])
{
return $this->user->createAsStripeCustomer($options);
}
/**
* #param $paymentMethod
* #return void
*/
public function addPaymentMethod($paymentMethod)
{
$this->user->addPaymentMethod($paymentMethod);
$this->user->updateDefaultPaymentMethod($paymentMethod);
}
/**
* #param $plan
* #param $paymentMethod
* #return void
* #throws \Laravel\Cashier\Exceptions\IncompletePayment
*/
public function newSubscription($plan, $paymentMethod)
{
$this->user->newSubscription('default', self::E_PLANS[$plan])
->trialDays(1)
->create($paymentMethod);
$this->user->subscription_type = $plan;
$this->user->save();
}
I really need help. Thanks to everyone who responded!

Related

Using Carbon diffForHumans in my model in laravel 8

I am using laravel 8 framework as my backend for my android application and I want to output time the same way instagram shows time but each time I use carbon diffForHumans it shows 2hours from now and I want it to show 1 minute ago, just now, 2 weeks ago,2 hours ago.
here is my model
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Carbon\Carbon;
class News extends Model
{
use HasFactory;
protected $table = "news";
protected $fillable = [
'title',
'image',
'body'
];
protected $casts = [
'created_at' => 'datetime:d-m-Y',
'updated_at' => 'datetime:d-m-Y'
];
protected $appends=['published'];
public function getPublishedAttribute(){
return Carbon::createFromTimeStamp(strtotime($this->attributes['created_at']) )->diffForHumans();
}
}
here is my controller
<?php
namespace App\Http\Controllers;
use App\News;
use Illuminate\Http\Request;
class NewsController extends Controller
{
/**
* Display a listing of the resource.
*
* #return \Illuminate\Http\Response
*/
public function index()
{
$allposts = News:://get()->sortByDesc(function($query){
// return $query->toArray(['id']);
//})->
all();
return response()->json(['newsitemlist' => $allposts], 200);
}
/**
* Show the form for creating a new resource.
*
* #return \Illuminate\Http\Response
*/
public function create()
{
//
}
/**
* Store a newly created resource in storage.
*
* #param \Illuminate\Http\Request $request
* #return \Illuminate\Http\Response
*/
public function store(Request $request)
{
//
}
/**
* Display the specified resource.
*
* #param int $id
* #return \Illuminate\Http\Response
*/
public function show($id)
{
$allposts = News::find($id);
if (is_null($allposts)) {
return response()->json(['message' => "News not available"], 404);
}
return response()->json(['newsitemlist' => $allposts], 200);
}
/**
* Show the form for editing the specified resource.
*
* #param int $id
* #return \Illuminate\Http\Response
*/
public function edit($id)
{
//
}
/**
* Update the specified resource in storage.
*
* #param \Illuminate\Http\Request $request
* #param int $id
* #return \Illuminate\Http\Response
*/
public function update(Request $request, $id)
{
//
}
/**
* Remove the specified resource from storage.
*
* #param int $id
* #return \Illuminate\Http\Response
*/
public function destroy($id)
{
$allposts = News::find($id);
if (is_null($allposts)) {
return response()->json(['message' => "News not available"], 404);
}
$allposts->delete();
return response()->json(['message' => "News Deleted Succesfully"], 200);
}
}
You can also use
public function getCreatedAtAttribute($value){
return Carbon::parse($value)->diffForHumans();
}
Based on Docs, this is what you need to do to modify created_at value. Its called Accessor
public function getCreatedAtAttribute($value){
return Carbon::createFromFormat('Y-m-d H:i:s', $value)->diffForHumans();
}
Also you can check more about Carbon API here

Laravel task scheduling- making multiple commands and tasks

I am trying to make 2 artisan commands that would each do a different task that should also be scheduled to do their tasks each day.
So far, I have set it up like this:
I have created a FolderImport class in the Console/Commands directory:
class FolderImport extends Command
{
protected $signature = 'import:folders';
/**
* The console command description.
*
* #var string
*/
protected $description = 'Imports folders';
/**
* Create a new command instance.
*
* #return void
*/
public function __construct(ImportController $folders)
{
parent::__construct();
$this->folders = $folders;
}
/**
* Execute the console command.
*
* #return mixed
*/
public function handle()
{
$this->folders->scheduledImport();
}
}
And the ContentImport class:
class ContentImport extends Command
{
protected $signature = 'import:content';
/**
* The console command description.
*
* #var string
*/
protected $description = 'Imports content';
/**
* Create a new command instance.
*
* #return void
*/
public function __construct(ImportController $content)
{
parent::__construct();
$this->content = $content;
}
/**
* Execute the console command.
*
* #return mixed
*/
public function handle()
{
$this->content->scheduledImport();
}
}
And then in the Kernel file I have added them like this:
class Kernel extends ConsoleKernel
{
/**
* The Artisan commands provided by your application.
*
* #var array
*/
protected $commands = [
Commands\Inspire::class,
Commands\ContentImport::class,
Commands\FolderImport::class,
];
/**
* Define the application's command schedule.
*
* #param \Illuminate\Console\Scheduling\Schedule $schedule
* #return void
*/
protected function schedule(Schedule $schedule)
{
$schedule->command('import:content')
->withoutOverlapping();
$schedule->command('import:folders')
->withoutOverlapping();
$schedule->call('App\Http\Controllers\ImportController#all')
->dailyAt('00:00');
$schedule->call('App\Http\Controllers\ImportController#folder')
->dailyAt('00:00');
}
}
How can I connect the import:folders command with the call to ImportController#folder and the command import:content to the call to ImportController#all?

Twig Relationship with extra columns

I have a problem and don't know the best practice to solve it.
I want to have a form for my core data. The core data is all versionable.
I solved it with a GUID, to know the togetherness of the versions.
So now I have two versionable entities AgeClass and HighscoreList that can have a many-to-many relationship. The relationship has to be versionable, too, so I created a ReferenceEntity RefAgeClassHighscoreList. Now I have relationships with extra columns
valid-from [and]
valid-to
But now I don't know how I should build my form.
When I edit an AgeClass, all current (valid) HighscoreList items should be show as a checkbox.
But when I build the edit form, the values must be bound with a RefAgeClassHighscoreList entity.
I hope you understand my problem.
AgeClass:
/**
* #ORM\Entity(repositoryClass="AppBundle\Repository\DSV\Core\BaseDSVCoreDataRepository")
* */
class AgeClass extends BaseDSVCoreData
{
/**
* #ORM\Column(type="integer")
* #NotBlank()
* #var int
*/
protected $minAge;
/**
* #ORM\Column(type="integer")
* #NotBlank()
* #var int
*/
protected $maxAge;
/**
* #ORM\OneToMany(targetEntity="RefAgeClassHighscoreList", mappedBy="ageClass", cascade={"persist"})
* #var PersistentCollection
*/
private $ageClassHighscoreLists;
/**
* AgeClass constructor.
*/
function __construct()
{
$this->setGuid(GuidHelper::generateGuid());
$this->setValidFrom(new \DateTime());
}
/**
* #return int
*/
public function getMinAge()
{
return $this->minAge;
}
/**
* #param int $minAge
* #return AgeClass
*/
public function setMinAge($minAge)
{
$this->minAge = $minAge;
return $this;
}
/**
* #return int
*/
public function getMaxAge()
{
return $this->maxAge;
}
/**
* #param int $maxAge
* #return AgeClass
*/
public function setMaxAge($maxAge)
{
$this->maxAge = $maxAge;
return $this;
}
/**
* #return array
*/
public function getAgeClassHighscoreLists()
{
if($this->ageClassHighscoreLists == null)
return array();
return $this->ageClassHighscoreLists->toArray();
}
/**
* #param PersistentCollection $valuationClasses
* #return AgeClass
*/
public function seAgeClassHighscoreLists($valuationClasses)
{
$this->ageClassHighscoreLists = $valuationClasses;
return $this;
}
/**
* #return HighscoreList[]
*/
public function getHighscoreLists()
{
return array_map(
function ($ageClassHighscoreList) {
/** #var RefAgeClassHighscoreList $ageClassHighscoreList */
return $ageClassHighscoreList->getHighscoreList();
},
$this->getAgeClassHighscoreLists()
);
}
/**
* #param RefAgeClassHighscoreList $ageClassHighscoreList
* #return $this
*/
public function addAgeClassHighscoreList($ageClassHighscoreList)
{
if (!$this->ageClassHighscoreLists->contains($ageClassHighscoreList)) {
$this->ageClassHighscoreLists->add($ageClassHighscoreList);
$ageClassHighscoreList->setAgeClass($this);
}
return $this;
}
}
HighscoreList
/**
* #ORM\Entity(repositoryClass="AppBundle\Repository\DSV\Core\BaseDSVCoreDataRepository")
* */
class HighscoreList extends BaseDSVCoreData
{
/**
* #ORM\OneToMany(targetEntity="RefAgeClassHighscoreList", mappedBy="highscoreList", cascade={"persist"})
* #var PersistentCollection
*/
private $ageClassHighscoreLists;
function __construct()
{
$this->setGuid(GuidHelper::generateGuid());
}
/**
* #return PersistentCollection
*/
public function getAgeClassReferences()
{
return $this->ageClassHighscoreLists;
}
/**
* #param PersistentCollection $valuationClasses
* #return AgeClass
*/
public function setAgeClassReferences($valuationClasses)
{
$this->ageClassReferences = $valuationClasses;
return $this;
}
/**
* #return AgeClass[]
*/
public function getAgeClasses()
{
return array_map(
function ($ageClassHighscoreList) {
/** #var RefAgeClassHighscoreList $ageClassHighscoreList */
return $ageClassHighscoreList->getAgeClass();
},
$this->ageClassHighscoreLists->toArray()
);
}
/**
* #param RefAgeClassHighscoreList $ageClassHighscoreList
* #return HighscoreList
*/
public function addAgeClassReference($ageClassHighscoreList)
{
if (!$this->ageClassHighscoreLists->contains($ageClassHighscoreList)) {
$this->ageClassHighscoreLists->add($ageClassHighscoreList);
$ageClassHighscoreList->setHighscoreList($this);
}
return $this;
}
}
}
RefAgeClassHighscoreList
/**
* #ORM\Entity()
* */
class RefAgeClassHighscoreList implements IVersionable
{
/**
* #ORM\Column(type="integer")
* #ORM\Id
* #ORM\GeneratedValue
*/
protected $id;
/**
* #ORM\Column(type="datetime")
*/
protected $validFrom;
/**
* #ORM\Column(type="datetime", nullable=true)
*/
protected $validTo;
/**
* #ORM\ManyToOne(targetEntity="AgeClass", inversedBy="highscoreListReferences")
* #ORM\JoinColumn(name="ageclass_id", referencedColumnName="id", nullable=FALSE)
*/
protected $ageClass;
/**
* #ORM\ManyToOne(targetEntity="highscoreList", inversedBy="ageClassReferences")
* #ORM\JoinColumn(name="highscorelist_id", referencedColumnName="id", nullable=FALSE)
*/
protected $highscoreList;
protected $hasChanges = false;
/**
* #see IVersionable
*/
public function getId()
{
return $this->id;
}
/**
* #see IVersionable
*/
public function setId($id)
{
$this->id = $id;
return $this;
}
/**
* #see IVersionable
*/
public function getGuid()
{
return null;
}
/**
* #see IVersionable
*/
public function setGuid($guid)
{
return $this;
}
/**
* #see IVersionable
*/
public function getValidFrom()
{
return $this->validFrom;
}
/**
* #see IVersionable
*/
public function setValidFrom($validFrom)
{
$this->validFrom = $validFrom;
return $this;
}
/**
* #see IVersionable
*/
public function getValidTo()
{
return $this->validTo;
}
/**
* #see IVersionable
*/
public function setValidTo($validTo)
{
$this->validTo = $validTo;
return $this;
}
/**
* #see IVersionable
*/
public function isValid()
{
return ($this->validTo == null);
}
/**
* #see IVersionable
*/
public function createNewVersion()
{
$newVersion = clone $this;
$newVersion->setValidFrom(new \DateTime());
return $newVersion;
}
/**
* #see IVersionable
*/
public function hasChanges()
{
return $this->hasChanges;
}
/**
* #return AgeClass
*/
public function getAgeClass()
{
return $this->ageClass;
}
/**
* #param AgeClass $ageClass
* #return RefAgeClassHighscoreList
*/
public function setAgeClass($ageClass)
{
$this->ageClass = $ageClass;
return $this;
}
/**
* #return HighscoreList
*/
public function getHighscoreList()
{
return $this->highscoreList;
}
/**
* #param HighscoreList $highscoreList
* #return RefAgeClassHighscoreList
*/
public function setHighscoreList($highscoreList)
{
$this->gighscoreList = $highscoreList;
return $this;
}
}
Well, you have a very recurrent and tedious problem. You can do an embed form with AgeClass and embedding a form for RefAgeClassHighscoreList type. In that embedded form you can have an attribute of type HighscoreList , the problem is that the default rendered component for what you need is a multi-select list of HighscoreList, you can see it putting the attribute multiple = true to the property of HighscoreList.
For transform that list to a check-box list you need to create a custom theme extending or adding new blocks to the default one provided by symfony. My advice is to create new widgets and rows for your specific form using the form name. You can find a lot of documentation about what I mention and need to get a small part of each one to do what you ask.
Hope all this clues help you.

CustomHTMLTagProcessor for iTextSharp

I have the following code;
Dim sr As StreamReader = New StreamReader("C:\\temp\\test.htm")
Dim line As String
line = sr.ReadToEnd
sr.Close()
Dim fsNew As New StringReader(line)
Dim Document As New Document()
Using fs As New FileStream("C:\\temp\\test.pdf", FileMode.Create)
PdfWriter.GetInstance(Document, fs)
Using stringReader As New StringReader(line)
Dim parsedList As List(Of IElement) = HTMLWorker.ParseToList(stringReader, Nothing)
Document.Open()
For Each item As Object In parsedList
Document.Add(DirectCast(item, IElement))
Next
Document.Close()
End Using
End Using
Document.Close()
I am trying to fix the problem with embedded base64 images that is referenced here. I created the CustomImageHTMLTagProcessor which is using the IHTMLTagProcessor interface, but when it came time to modify the HTMLWorker class, I wasn't sure what to change. This is the HTMLWorker class.
using System;
using System.IO;
using System.Text;
using System.Collections.Generic;
using System.Globalization;
using System.util;
using iTextSharp.text;
using iTextSharp.text.log;
using iTextSharp.text.html;
using iTextSharp.text.pdf;
using iTextSharp.text.pdf.draw;
using iTextSharp.text.xml.simpleparser;
namespace iTextSharp.text.html.simpleparser {
[Obsolete]
public class HTMLWorker : ISimpleXMLDocHandler, IDocListener {
private static readonly ILogger LOGGER = LoggerFactory.GetLogger(typeof(HTMLWorker));
protected IDocListener document;
protected internal IDictionary<String, IHTMLTagProcessor> tags;
public HTMLWorker(IDocListener document) : this(document, null, null) {
}
public HTMLWorker(IDocListener document, IDictionary<String, IHTMLTagProcessor> tags, StyleSheet style) {
this.document = document;
SetSupportedTags(tags);
SetStyleSheet(style);
}
virtual public void SetSupportedTags(IDictionary<String, IHTMLTagProcessor> tags) {
if (tags == null)
tags = new HTMLTagProcessors();
this.tags = tags;
}
virtual public void SetStyleSheet(StyleSheet style) {
if (style == null)
style = new StyleSheet();
this.style = style;
}
virtual public void Parse(TextReader reader) {
LOGGER.Info("Please note, there is a more extended version of the HTMLWorker available in the iText XMLWorker");
SimpleXMLParser.Parse(this, null, reader, true);
}
// state machine
protected Stack<IElement> stack = new Stack<IElement>();
protected Paragraph currentParagraph;
private ChainedProperties chain = new ChainedProperties();
public virtual void StartDocument() {
Dictionary<String, String> attrs = new Dictionary<String, String>();
style.ApplyStyle(HtmlTags.BODY, attrs);
chain.AddToChain(HtmlTags.BODY, attrs);
}
public virtual void StartElement(String tag, IDictionary<String, String> attrs) {
IHTMLTagProcessor htmlTag;
tags.TryGetValue(tag, out htmlTag);
if (htmlTag == null) {
return;
}
style.ApplyStyle(tag, attrs);
StyleSheet.ResolveStyleAttribute(attrs, chain);
htmlTag.StartElement(this, tag, attrs);
}
public virtual void Text(String content) {
if (skipText)
return;
if (currentParagraph == null) {
currentParagraph = CreateParagraph();
}
if (!insidePRE) {
// newlines and carriage returns are ignored
if (content.Trim().Length == 0 && content.IndexOf(' ') < 0) {
return;
}
content = HtmlUtilities.EliminateWhiteSpace(content);
}
Chunk chunk = CreateChunk(content);
currentParagraph.Add(chunk);
}
public virtual void EndElement(String tag) {
IHTMLTagProcessor htmlTag;
tags.TryGetValue(tag, out htmlTag);
if (htmlTag == null) {
return;
}
// process the tag
htmlTag.EndElement(this, tag);
}
public virtual void EndDocument() {
// flush the stack
foreach (IElement e in stack)
document.Add(e);
// add current paragraph
if (currentParagraph != null)
document.Add(currentParagraph);
currentParagraph = null;
}
virtual public void NewLine() {
if (currentParagraph == null) {
currentParagraph = new Paragraph();
}
currentParagraph.Add(CreateChunk("\n"));
}
virtual public void CarriageReturn() {
if (currentParagraph == null)
return;
if (stack.Count == 0)
document.Add(currentParagraph);
else {
IElement obj = stack.Pop();
if (obj is ITextElementArray) {
ITextElementArray current = (ITextElementArray) obj;
current.Add(currentParagraph);
}
stack.Push(obj);
}
currentParagraph = null;
}
/**
* Stacks the current paragraph, indicating that we're starting
* a new span.
* #since 5.0.6
*/
virtual public void FlushContent() {
PushToStack(currentParagraph);
currentParagraph = new Paragraph();
}
/**
* Pushes an element to the Stack.
* #param element
* #since 5.0.6
*/
virtual public void PushToStack(IElement element) {
if (element != null)
stack.Push(element);
}
/**
* Updates the chain with a new tag and new attributes.
* #param tag the new tag
* #param attrs the corresponding attributes
* #since 5.0.6
*/
virtual public void UpdateChain(String tag, IDictionary<String, String> attrs) {
chain.AddToChain(tag, attrs);
}
/**
* Updates the chain by removing a tag.
* #param tag the new tag
* #since 5.0.6
*/
virtual public void UpdateChain(String tag) {
chain.RemoveChain(tag);
}
// providers that help find resources such as images and fonts
/**
* Key used to store the image provider in the providers map.
* #since 5.0.6
*/
public const String IMG_PROVIDER = "img_provider";
/**
* Key used to store the image processor in the providers map.
* #since 5.0.6
*/
public const String IMG_PROCESSOR = "img_interface";
/**
* Key used to store the image store in the providers map.
* #since 5.0.6
*/
public const String IMG_STORE = "img_static";
/**
* Key used to store the image baseurl provider in the providers map.
* #since 5.0.6
*/
public const String IMG_BASEURL = "img_baseurl";
/**
* Key used to store the font provider in the providers map.
* #since 5.0.6
*/
public const String FONT_PROVIDER = "font_factory";
/**
* Key used to store the link provider in the providers map.
* #since 5.0.6
*/
public const String LINK_PROVIDER = "alink_interface";
/**
* IDictionary containing providers such as a FontProvider or ImageProvider.
* #since 5.0.6 (renamed from interfaceProps)
*/
private IDictionary<String, Object> providers = new Dictionary<String, Object>();
/**
* Setter for the providers.
* If a FontProvider is added, the ElementFactory is updated.
* #param providers a IDictionary with different providers
* #since 5.0.6
*/
virtual public void SetProviders(IDictionary<String, Object> providers) {
if (providers == null)
return;
this.providers = providers;
IFontProvider ff = null;
if (providers.ContainsKey(FONT_PROVIDER))
ff = (IFontProvider)providers[FONT_PROVIDER];
if (ff != null)
factory.FontProvider = ff;
}
// factory that helps create objects
/**
* Factory that is able to create iText Element objects.
* #since 5.0.6
*/
private ElementFactory factory = new ElementFactory();
/**
* Creates a Chunk using the factory.
* #param content the content of the chunk
* #return a Chunk with content
* #since 5.0.6
*/
virtual public Chunk CreateChunk(String content) {
return factory.CreateChunk(content, chain);
}
/**
* Creates a Paragraph using the factory.
* #return a Paragraph without any content
* #since 5.0.6
*/
virtual public Paragraph CreateParagraph() {
return factory.CreateParagraph(chain);
}
/**
* Creates a List object.
* #param tag should be "ol" or "ul"
* #return a List object
* #since 5.0.6
*/
virtual public List CreateList(String tag) {
return factory.CreateList(tag, chain);
}
/**
* Creates a ListItem object.
* #return a ListItem object
* #since 5.0.6
*/
virtual public ListItem CreateListItem() {
return factory.CreateListItem(chain);
}
/**
* Creates a LineSeparator object.
* #param attrs properties of the LineSeparator
* #return a LineSeparator object
* #since 5.0.6
*/
virtual public LineSeparator CreateLineSeparator(IDictionary<String, String> attrs) {
return factory.CreateLineSeparator(attrs, currentParagraph.Leading / 2);
}
/**
* Creates an Image object.
* #param attrs properties of the Image
* #return an Image object (or null if the Image couldn't be found)
* #throws DocumentException
* #throws IOException
* #since 5.0.6
*/
virtual public Image CreateImage(IDictionary<String, String> attrs) {
String src;
attrs.TryGetValue(HtmlTags.SRC, out src);
if (src == null)
return null;
Image img = factory.CreateImage(
src, attrs, chain, document,
providers.ContainsKey(IMG_PROVIDER) ? (IImageProvider)providers[IMG_PROVIDER] : null,
providers.ContainsKey(IMG_STORE) ? (ImageStore)providers[IMG_STORE] : null,
providers.ContainsKey(IMG_BASEURL) ? (string)providers[IMG_BASEURL] : null);
return img;
}
/**
* Creates a Cell.
* #param tag the tag
* #return a CellWrapper object
* #since 5.0.6
*/
virtual public CellWrapper CreateCell(String tag) {
return new CellWrapper(tag, chain);
}
// processing objects
/**
* Adds a link to the current paragraph.
* #since 5.0.6
*/
virtual public void ProcessLink() {
if (currentParagraph == null) {
currentParagraph = new Paragraph();
}
// The link provider allows you to do additional processing
ILinkProcessor i = null;
if (providers.ContainsKey(LINK_PROVIDER))
i = (ILinkProcessor) providers[LINK_PROVIDER];
if (i == null || !i.Process(currentParagraph, chain)) {
// sets an Anchor for all the Chunks in the current paragraph
String href = chain[HtmlTags.HREF];
if (href != null) {
foreach (Chunk ck in currentParagraph.Chunks) {
ck.SetAnchor(href);
}
}
}
// a link should be added to the current paragraph as a phrase
if (stack.Count == 0) {
// no paragraph to add too, 'a' tag is first element
Paragraph tmp = new Paragraph(new Phrase(currentParagraph));
currentParagraph = tmp;
} else {
Paragraph tmp = (Paragraph) stack.Pop();
tmp.Add(new Phrase(currentParagraph));
currentParagraph = tmp;
}
}
/**
* Fetches the List from the Stack and adds it to
* the TextElementArray on top of the Stack,
* or to the Document if the Stack is empty.
* #throws DocumentException
* #since 5.0.6
*/
virtual public void ProcessList() {
if (stack.Count == 0)
return;
IElement obj = stack.Pop();
if (!(obj is List)) {
stack.Push(obj);
return;
}
if (stack.Count == 0)
document.Add(obj);
else
((ITextElementArray) stack.Peek()).Add(obj);
}
/**
* Looks for the List object on the Stack,
* and adds the ListItem to the List.
* #throws DocumentException
* #since 5.0.6
*/
virtual public void ProcessListItem() {
if (stack.Count == 0)
return;
IElement obj = stack.Pop();
if (!(obj is ListItem)) {
stack.Push(obj);
return;
}
if (stack.Count == 0) {
document.Add(obj);
return;
}
ListItem item = (ListItem) obj;
IElement list = stack.Pop();
if (!(list is List)) {
stack.Push(list);
return;
}
((List) list).Add(item);
item.AdjustListSymbolFont();
stack.Push(list);
}
/**
* Processes an Image.
* #param img
* #param attrs
* #throws DocumentException
* #since 5.0.6
*/
virtual public void ProcessImage(Image img, IDictionary<String, String> attrs) {
IImageProcessor processor = null;
if (providers.ContainsKey(IMG_PROCESSOR))
processor = (IImageProcessor)providers[IMG_PROCESSOR];
if (processor == null || !processor.Process(img, attrs, chain, document)) {
String align;
attrs.TryGetValue(HtmlTags.ALIGN, out align);
if (align != null) {
CarriageReturn();
}
if (currentParagraph == null) {
currentParagraph = CreateParagraph();
}
currentParagraph.Add(new Chunk(img, 0, 0, true));
currentParagraph.Alignment = HtmlUtilities.AlignmentValue(align);
if (align != null) {
CarriageReturn();
}
}
}
/**
* Processes the Table.
* #throws DocumentException
* #since 5.0.6
*/
virtual public void ProcessTable() {
TableWrapper table = (TableWrapper) stack.Pop();
PdfPTable tb = table.CreateTable();
tb.SplitRows = true;
if (stack.Count == 0)
document.Add(tb);
else
((ITextElementArray) stack.Peek()).Add(tb);
}
/**
* Gets the TableWrapper from the Stack and adds a new row.
* #since 5.0.6
*/
virtual public void ProcessRow() {
List<PdfPCell> row = new List<PdfPCell>();
List<float> cellWidths = new List<float>();
bool percentage = false;
float width;
float totalWidth = 0;
int zeroWidth = 0;
TableWrapper table = null;
while (true) {
IElement obj = stack.Pop();
if (obj is CellWrapper) {
CellWrapper cell = (CellWrapper)obj;
width = cell.Width;
cellWidths.Add(width);
percentage |= cell.IsPercentage;
if (width == 0) {
zeroWidth++;
}
else {
totalWidth += width;
}
row.Add(cell.Cell);
}
if (obj is TableWrapper) {
table = (TableWrapper) obj;
break;
}
}
table.AddRow(row);
if (cellWidths.Count > 0) {
// cells come off the stack in reverse, naturally
totalWidth = 100 - totalWidth;
cellWidths.Reverse();
float[] widths = new float[cellWidths.Count];
bool hasZero = false;
for (int i = 0; i < widths.Length; i++) {
widths[i] = cellWidths[i];
if (widths[i] == 0 && percentage && zeroWidth > 0) {
widths[i] = totalWidth / zeroWidth;
}
if (widths[i] == 0) {
hasZero = true;
break;
}
}
if (!hasZero)
table.ColWidths = widths;
}
stack.Push(table);
}
// state variables and methods
/** Stack to keep track of table tags. */
private Stack<bool[]> tableState = new Stack<bool[]>();
/** Boolean to keep track of TR tags. */
private bool pendingTR = false;
/** Boolean to keep track of TD and TH tags */
private bool pendingTD = false;
/** Boolean to keep track of LI tags */
private bool pendingLI = false;
/**
* Boolean to keep track of PRE tags
* #since 5.0.6 renamed from isPRE
*/
private bool insidePRE = false;
/**
* Indicates if text needs to be skipped.
* #since iText 5.0.6 (private => protected)
*/
protected internal bool skipText = false;
/**
* Pushes the values of pendingTR and pendingTD
* to a state stack.
* #since 5.0.6
*/
virtual public void PushTableState() {
tableState.Push(new bool[] { pendingTR, pendingTD });
}
/**
* Pops the values of pendingTR and pendingTD
* from a state stack.
* #since 5.0.6
*/
virtual public void PopTableState() {
bool[] state = tableState.Pop();
pendingTR = state[0];
pendingTD = state[1];
}
/**
* #return the pendingTR
* #since 5.0.6
*/
virtual public bool IsPendingTR() {
return pendingTR;
}
/**
* #param pendingTR the pendingTR to set
* #since 5.0.6
*/
virtual public void SetPendingTR(bool pendingTR) {
this.pendingTR = pendingTR;
}
/**
* #return the pendingTD
* #since 5.0.6
*/
virtual public bool IsPendingTD() {
return pendingTD;
}
/**
* #param pendingTD the pendingTD to set
* #since 5.0.6
*/
virtual public void SetPendingTD(bool pendingTD) {
this.pendingTD = pendingTD;
}
/**
* #return the pendingLI
* #since 5.0.6
*/
virtual public bool IsPendingLI() {
return pendingLI;
}
/**
* #param pendingLI the pendingLI to set
* #since 5.0.6
*/
virtual public void SetPendingLI(bool pendingLI) {
this.pendingLI = pendingLI;
}
/**
* #return the insidePRE
* #since 5.0.6
*/
virtual public bool IsInsidePRE() {
return insidePRE;
}
/**
* #param insidePRE the insidePRE to set
* #since 5.0.6
*/
virtual public void SetInsidePRE(bool insidePRE) {
this.insidePRE = insidePRE;
}
/**
* #return the skipText
* #since 5.0.6
*/
virtual public bool IsSkipText() {
return skipText;
}
/**
* #param skipText the skipText to set
* #since 5.0.6
*/
virtual public void SetSkipText(bool skipText) {
this.skipText = skipText;
}
// static methods to parse HTML to a List of Element objects.
/** The resulting list of elements. */
protected List<IElement> objectList;
/**
* Parses an HTML source to a List of Element objects
* #param reader the HTML source
* #param style a StyleSheet object
* #return a List of Element objects
* #throws IOException
*/
public static List<IElement> ParseToList(TextReader reader, StyleSheet style) {
return ParseToList(reader, style, null);
}
/**
* Parses an HTML source to a List of Element objects
* #param reader the HTML source
* #param style a StyleSheet object
* #param providers map containing classes with extra info
* #return a List of Element objects
* #throws IOException
*/
public static List<IElement> ParseToList(TextReader reader, StyleSheet style,
Dictionary<String, Object> providers) {
return ParseToList(reader, style, null, providers);
}
/**
* Parses an HTML source to a List of Element objects
* #param reader the HTML source
* #param style a StyleSheet object
* #param tags a map containing supported tags and their processors
* #param providers map containing classes with extra info
* #return a List of Element objects
* #throws IOException
* #since 5.0.6
*/
public static List<IElement> ParseToList(TextReader reader, StyleSheet style,
IDictionary<String, IHTMLTagProcessor> tags, Dictionary<String, Object> providers) {
HTMLWorker worker = new HTMLWorker(null, tags, style);
worker.document = worker;
worker.SetProviders(providers);
worker.objectList = new List<IElement>();
worker.Parse(reader);
return worker.objectList;
}
// DocListener interface
/**
* #see com.itextpdf.text.ElementListener#add(com.itextpdf.text.Element)
*/
virtual public bool Add(IElement element) {
objectList.Add(element);
return true;
}
/**
* #see com.itextpdf.text.DocListener#close()
*/
virtual public void Close() {
}
/**
* #see com.itextpdf.text.DocListener#newPage()
*/
virtual public bool NewPage() {
return true;
}
/**
* #see com.itextpdf.text.DocListener#open()
*/
virtual public void Open() {
}
/**
* #see com.itextpdf.text.DocListener#resetPageCount()
*/
virtual public void ResetPageCount() {
}
/**
* #see com.itextpdf.text.DocListener#setMarginMirroring(bool)
*/
virtual public bool SetMarginMirroring(bool marginMirroring) {
return false;
}
/**
* #see com.itextpdf.text.DocListener#setMarginMirroring(bool)
* #since 2.1.6
*/
virtual public bool SetMarginMirroringTopBottom(bool marginMirroring) {
return false;
}
/**
* #see com.itextpdf.text.DocListener#setMargins(float, float, float, float)
*/
virtual public bool SetMargins(float marginLeft, float marginRight,
float marginTop, float marginBottom) {
return true;
}
/**
* #see com.itextpdf.text.DocListener#setPageCount(int)
*/
virtual public int PageCount {
set {
}
}
/**
* #see com.itextpdf.text.DocListener#setPageSize(com.itextpdf.text.Rectangle)
*/
virtual public bool SetPageSize(Rectangle pageSize) {
return true;
}
// deprecated methods
/**
* Sets the providers.
* #deprecated use SetProviders() instead
*/
virtual public void SetInterfaceProps(Dictionary<String, Object> providers) {
SetProviders(providers);
}
/**
* Gets the providers
* #deprecated use GetProviders() instead
*/
virtual public IDictionary<String, Object> GetInterfaceProps() {
return providers;
}
public virtual void Dispose() {
Close();
}
}
}
As Chris Haas Mentioned HtmlWorker is Deprecated. XmlWorker is the new way to convert HTML to PDF.

Combine Tables User Session Login

I log in perfectly with the entity User. When I log in, I can get to user via Security.Context. Can I include another table, e.g. UserSettings to security.context? What I have to do in entity User.php.
My entity User.php:
<?php
namespace Frontend\AccountBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Security\Core\User\UserInterface;
use Symfony\Component\Security\Core\User\AdvancedUserInterface;
use Symfony\Component\Validator\Constraints as Assert;
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
use Symfony\Component\Security\Core\Exception\DisabledException;
/**
* User
*
* #ORM\Table(name="user")
* #ORM\Entity
* #UniqueEntity("email")
*/
class User implements AdvancedUserInterface, \Serializable {
/**
* #var integer
*
* #ORM\Column(name="id", type="integer", nullable=false)
* #ORM\Id
* #ORM\GeneratedValue(strategy="IDENTITY")
*/
private $id;
...
public function getId()
{
return $this->id;
}
...
My UserSettings.php:
<?php
namespace Frontend\AccountBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* UserSettings
*
* #ORM\Table(name="user_settings")
* #ORM\Entity
*/
class UserSettings
{
/**
* #var \Language
*
* #ORM\ManyToOne(targetEntity="Language")
* #ORM\JoinColumns({
* #ORM\JoinColumn(name="locale", referencedColumnName="id")
* })
*/
private $locale;
/**
* #var \User
*
* #ORM\Id
* #ORM\GeneratedValue(strategy="NONE")
* #ORM\OneToOne(targetEntity="User")
* #ORM\JoinColumns({
* #ORM\JoinColumn(name="id", referencedColumnName="id")
* })
*/
private $id;
/**
* Set locale
*
* #param \Frontend\AccountBundle\Entity\Language $locale
* #return UserSettings
*/
public function setLocale(\Frontend\AccountBundle\Entity\Language $locale = null)
{
$this->locale = $locale;
return $this;
}
/**
* Get locale
*
* #return \Frontend\AccountBundle\Entity\Language
*/
public function getLocale()
{
return $this->locale;
}
/**
* Set id
*
* #param \Frontend\AccountBundle\Entity\User $id
* #return UserSettings
*/
public function setId(\Frontend\AccountBundle\Entity\User $id)
{
$this->id = $id;
return $this;
}
/**
* Get id
*
* #return \Frontend\AccountBundle\Entity\User
*/
public function getId()
{
return $this->id;
}
}

Resources