Example #1
0
 /**
  * @param Account $creditor
  * @param $amount
  * @param Entity $owner
  * @param $due
  * @param $increasePerHour
  * @param bool $name
  * @param bool $creation
  * @param bool $originalAmount
  * @param bool $lastInterestUpdate
  */
 public function __construct(Account $creditor, $amount, $owner, $due, $increasePerHour, $name = false, $creation = false, $originalAmount = false, $lastInterestUpdate = false)
 {
     // setting defaults
     if (!$creditor->getName() instanceof Service and !$creditor->getEntity() instanceof PlayerEnt) {
         throw new \InvalidArgumentException("Loan must be provided by a player or a service");
     }
     if ($creation === false) {
         $creation = time();
     }
     if (!is_string($name)) {
         $name = sprintf("Loan from {$creditor->getUniqueName()}");
     }
     $oname = $name;
     for ($i = 2; $owner->getAccount($name) instanceof Account; $i++) {
         $name = "{$oname} ({$i})";
     }
     if (!is_numeric($originalAmount)) {
         $originalAmount = $amount;
     }
     if (!is_int($lastInterestUpdate)) {
         $lastInterestUpdate = time();
     }
     // saving fields
     $this->name = strtolower($name);
     $this->creditor = $creditor;
     $this->amount = $amount;
     $this->owner = $owner;
     $this->due = $due;
     $this->increasePerHour = $increasePerHour;
     $this->creation = $creation;
     $this->originalAmount = $originalAmount;
     $this->lastInterestUpdate = $lastInterestUpdate;
 }