Ejemplo n.º 1
0
 /**
  * Conversion to type.
  *
  * @param mixed $value value
  * @return mixed
  */
 public static function toType($value)
 {
     if (!is_string($value)) {
         return $value;
     }
     if ($value === 'null') {
         $value = null;
     } elseif (is_numeric($value)) {
         $value = NumericHelper::toNumeric($value);
     } elseif ($value === 'false') {
         $value = false;
     } elseif ($value === 'true') {
         $value = true;
     }
     return $value;
 }
 /**
  * send an email with all accounts and current money to admin email
  * for security reasons (if DB crashes etc) and transparency
  * @return boolean success
  */
 public function sendOverviewEmail()
 {
     $accounts = $this->find('all', array('contain' => array('User.email'), 'conditions' => array($this->alias . '.amount >' => 0)));
     App::uses('NumericHelper', 'Tools.View/Helper');
     $Numeric = new NumericHelper(new View(null));
     $message = '';
     $total = 0;
     foreach ($accounts as $key => $account) {
         $message .= '#' . str_pad($key + 1, 3, '0', STR_PAD_LEFT) . ':' . TB . str_pad($Numeric->money($account[$this->alias]['amount']), 10, ' ', STR_PAD_LEFT) . ' - ' . $account['User']['email'] . PHP_EOL;
         $total += $account[$this->alias]['amount'];
     }
     $message = __('Total') . ': ' . $Numeric->money($total) . PHP_EOL . PHP_EOL . __('Details') . ':' . PHP_EOL . $message;
     App::uses('EmailLib', 'Tools.Lib');
     $this->Email = new EmailLib();
     $this->Email->to(Configure::read('Config.admin_email'), Configure::read('Config.admin_emailname'));
     $this->Email->subject(__('Prepaid Accounts') . ' - ' . __('Overview'));
     $this->Email->template('default', 'internal');
     $this->Email->viewVars(compact('message', 'subject', 'emailFrom', 'nameFrom'));
     if ($this->Email->send($message)) {
         return true;
     }
     return false;
 }