Symfony保存每个更改状态的日期

时间:2016-09-24 17:30:27

标签: symfony doctrine

我怎么做到这一点:我有订单的OrderWork实体,并且与Status实体有很多关系。一切正常,但我希望每个保存和更新的订单都有日期。

   * Order
 *
 * @ORM\Table(name="order_work")
 * @ORM\Entity(repositoryClass="AppBundle\Repository\OrderWorkRepository")
 */
class OrderWork
{
    /**
     * @var int
     *
     * @ORM\Column(name="id", type="integer")
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="AUTO")
     */
    private $id;

    /**
     * @ORM\ManyToOne(targetEntity="Client", cascade={"persist"})
     * @ORM\JoinColumn(name="client_id", referencedColumnName="id")
     */
    private $client;

    /**
     * @var string
     *
     * @ORM\Column(name="orderNumber", type="string", length=255)
     */
    private $orderNumber;


    /**
     * @var string
     *
     * @ORM\Column(name="orderCity", type="string", length=255)
     */
    private $orderCity;

    /**
     * @var date
     *
     * @ORM\Column(name="date", type="string", length=255)
     */
    private $date;

    /**
     * @var \DateTime
     *
     * @ORM\Column(name="orderDate", type="string", length=255, options={"default": NULL})
     */
    private $orderDate;

    /**
     * @var \DateTime
     *
     * @ORM\Column(name="returnDate", type="string", length=255, nullable=true)
     */
    private $returnDate;

    /**
     * @var string
     *
     * @ORM\Column(name="device", type="string", length=255)
     */
    private $device;


    /**
     * @ORM\ManyToOne(targetEntity="SurrogatePhone", cascade={"persist"})
     * @ORM\JoinColumn(name="surrogate_id", referencedColumnName="id")
     */

    private $surrogatePhone;


    /**
     * @var int
     *
     * @ORM\Column(name="orderType", type="integer")
     */
    public $orderType;

    /**
     * @ORM\ManyToMany(targetEntity="Status")
     * @ORM\JoinTable(name="order_status",
     *      joinColumns={@ORM\JoinColumn(name="order_id", referencedColumnName="id", unique=false)},
     *      inverseJoinColumns={@ORM\JoinColumn(name="status_id", referencedColumnName="id", unique=false)}
     *      )
     */

    private $status;

如何更好地解决此问题?

1 个答案:

答案 0 :(得分:0)

在构造函数中定义日期(用于创建):

public boolean enable = false;

        imageView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if(enable)
{
 imageView.setImageResource(R.drawable.ic_home_enable);
}
else
{
 imageView.setImageResource(R.drawable.ic_home_disable);
}
            }
        });

更新时更新日期字段:

class OrderWork
{
    //...
    public function __construct()
    {
        $this->date = new DateTime();
    }

}