Ejemplo n.º 1
0
 /**
  * Prepares attributes before performing validation.
  */
 protected function beforeValidate()
 {
     $scenario = $this->getScenario();
     // avoid sql error 'incorrect date value'
     isset($_POST[__CLASS__]['invoiceDate']) && ($this->invoiceDate = MDate::formatToDb($this->invoiceDate, 'date'));
     isset($_POST[__CLASS__]['dueDate']) && ($this->dueDate = MDate::formatToDb($this->dueDate, 'date'));
     isset($_POST[__CLASS__]['startDate']) && ($this->startDate = MDate::formatToDb($this->startDate, 'date'));
     isset($_POST[__CLASS__]['endDate']) && ($this->endDate = MDate::formatToDb($this->endDate, 'date'));
     // parent does all common work
     return parent::beforeValidate();
 }
Ejemplo n.º 2
0
 /**
  * Prepares attributes before performing validation.
  */
 protected function beforeValidate()
 {
     $scenario = $this->getScenario();
     if (isset($_POST[__CLASS__]['billToCompany']) && $this->billToCompany !== self::BILL_TO_COMPANY && $this->billToCompany !== self::DO_NOT_BILL_TO_COMPANY) {
         // enum('0','1') null
         $this->billToCompany = null;
     }
     // avoid sql error 'incorrect date value'
     isset($_POST[__CLASS__]['expenseDate']) && ($this->expenseDate = MDate::formatToDb($this->expenseDate, 'date'));
     // parent does all common work
     return parent::beforeValidate();
 }
Ejemplo n.º 3
0
 /**
  * Prepares attributes before performing validation.
  */
 protected function beforeValidate()
 {
     $scenario = $this->getScenario();
     $priority = (int) $this->priority;
     if (isset($_POST[__CLASS__]['priority']) && $priority !== self::PRIORITY_HIGHEST && $priority !== self::PRIORITY_HIGH && $priority !== self::PRIORITY_MEDIUM && $priority !== self::PRIORITY_LOW && $priority !== self::PRIORITY_LOWEST) {
         // allow defined priorities only
         $this->priority = self::PRIORITY_MEDIUM;
     }
     // avoid sql error 'incorrect date value'
     isset($_POST[__CLASS__]['closeDate']) && ($this->closeDate = MDate::formatToDb($this->closeDate, 'date'));
     isset($_POST[__CLASS__]['openDate']) && ($this->openDate = MDate::formatToDb($this->openDate, 'date'));
     // parent does all common work
     return parent::beforeValidate();
 }
Ejemplo n.º 4
0
 /**
  * Prepares attributes before performing validation.
  */
 protected function beforeValidate()
 {
     $scenario = $this->getScenario();
     if (isset($_POST[__CLASS__]['contentMarkup']) && $this->contentMarkup !== self::TEXT) {
         // allow defined markups only
         $this->contentMarkup = self::CHECK;
     }
     if (isset($_POST[__CLASS__]['content'], $_POST[__CLASS__]['contentMarkup']) && empty($this->content)) {
         // empty text needs no markup
         $this->contentMarkup = null;
     }
     if (isset($_POST[__CLASS__]['paymentMethod']) && $this->paymentMethod !== self::CASH && $this->paymentMethod !== self::CHECK && $this->paymentMethod !== self::CREDIT_CARD && $this->paymentMethod !== self::PAYPAL && $this->paymentMethod !== self::WIRE) {
         // allow defined methods only
         $this->paymentMethod = self::CHECK;
     }
     // avoid sql error 'incorrect date value'
     isset($_POST[__CLASS__]['paymentDate']) && ($this->paymentDate = MDate::formatToDb($this->paymentDate, 'date'));
     // parent does all common work
     return parent::beforeValidate();
 }
Ejemplo n.º 5
0
 /**
  * Prepares attributes before performing validation.
  */
 protected function beforeValidate()
 {
     $scenario = $this->getScenario();
     if (isset($_POST[__CLASS__]['isConfirmed'])) {
         if ($this->isConfirmed !== self::IS_CONFIRMED && $this->isConfirmed !== self::IS_NOT_CONFIRMED) {
             // enum('0','1') null
             $this->isConfirmed = null;
         }
         if ($this->isConfirmed === self::IS_CONFIRMED && empty($this->confirmationTime)) {
             // set time on confirm
             $this->confirmationTime = time();
         } else {
             if ($this->isConfirmed === self::IS_NOT_CONFIRMED && $this->confirmationTime !== null) {
                 // unset time on unconfirm
                 $this->confirmationTime = null;
             }
         }
     }
     // number of minutes = number of minutes + number of hours * 60
     if ($this->spentH !== null || $this->spentM !== null) {
         $this->spentMinute = (int) ((double) $this->spentH * 60 + (int) $this->spentM);
     }
     if ($this->billedH !== null || $this->billedM !== null) {
         $this->billedMinute = (int) ((double) $this->billedH * 60 + (int) $this->billedM);
     }
     // avoid sql error 'out of range value adjusted for column'
     if ($this->spentMinute > 999999) {
         $this->spentMinute = 999999;
     }
     if ($this->billedMinute > 999999) {
         $this->billedMinute = 999999;
     }
     // avoid sql error 'incorrect date value'
     isset($_POST[__CLASS__]['timeDate']) && ($this->timeDate = MDate::formatToDb($this->timeDate, 'date'));
     // parent does all common work
     return parent::beforeValidate();
 }
Ejemplo n.º 6
0
 /**
  * Prepares attributes before performing validation.
  */
 protected function beforeValidate()
 {
     $scenario = $this->getScenario();
     // parent does all common work
     return parent::beforeValidate();
 }
Ejemplo n.º 7
0
 /**
  * Prepares attributes before performing validation.
  */
 protected function beforeValidate()
 {
     $scenario = $this->getScenario();
     if (isset($_POST[__CLASS__]['isActive'])) {
         if ($this->isActive !== self::IS_ACTIVE && $this->isActive !== self::IS_NOT_ACTIVE) {
             // enum('0','1') null
             $this->isActive = null;
         }
         if ($this->isActive === self::IS_ACTIVE && $this->deactivationTime !== null) {
             // unset time on activate
             $this->deactivationTime = null;
         } else {
             if (($this->isActive === self::IS_NOT_ACTIVE || $this->isActive === null) && empty($this->deactivationTime)) {
                 // set time on deactivate
                 $this->deactivationTime = time();
             }
         }
     }
     // parent does all common work
     return parent::beforeValidate();
 }
Ejemplo n.º 8
0
 /**
  * Prepares attributes before performing validation.
  */
 protected function beforeValidate()
 {
     $scenario = $this->getScenario();
     if (isset($_POST[__CLASS__]['isConfirmed'])) {
         if ($this->isConfirmed !== self::IS_CONFIRMED && $this->isConfirmed !== self::IS_NOT_CONFIRMED) {
             // enum('0','1') null
             $this->isConfirmed = null;
         }
         if ($this->isConfirmed === self::IS_CONFIRMED && empty($this->confirmationTime)) {
             // set time on confirm
             $this->confirmationTime = time();
         } else {
             if ($this->isConfirmed === self::IS_NOT_CONFIRMED && $this->confirmationTime !== null) {
                 // unset time on unconfirm
                 $this->confirmationTime = null;
             }
         }
     }
     if (($this->status === self::CANCELLED || $this->status === self::COMPLETED) && empty($this->closeDate)) {
         // set close date on complete
         $this->closeDate = MDate::formatToDb(time(), 'date');
     } else {
         if ($this->status !== self::CANCELLED && $this->status !== self::COMPLETED && $this->closeDate !== null) {
             // unset close date when task is re-opened
             $this->closeDate = null;
         }
     }
     $priority = (int) $this->priority;
     if (isset($_POST[__CLASS__]['priority']) && $priority !== self::PRIORITY_HIGHEST && $priority !== self::PRIORITY_HIGH && $priority !== self::PRIORITY_MEDIUM && $priority !== self::PRIORITY_LOW && $priority !== self::PRIORITY_LOWEST) {
         // allow defined priorities only
         $this->priority = self::PRIORITY_MEDIUM;
     }
     if (isset($_POST[__CLASS__]['status']) && $this->status !== self::CANCELLED && $this->status !== self::COMPLETED && $this->status !== self::IN_PROGRESS && $this->status !== self::NOT_STARTED && $this->status !== self::READY_FOR_PRODUCTION && $this->status !== self::READY_TO_TEST) {
         // allow defined statuses only
         $this->status = self::NOT_STARTED;
     }
     // number of minutes = number of minutes + number of hours * 60
     if ($this->estimateH !== null || $this->estimateM !== null) {
         $this->estimateMinute = (int) ((double) $this->estimateH * 60 + (int) $this->estimateM);
     }
     // avoid sql error 'out of range value adjusted for column'
     if ($this->estimateMinute > 999999) {
         $this->estimateMinute = 999999;
     }
     // avoid sql error 'incorrect date value'
     isset($_POST[__CLASS__]['dueDate']) && ($this->dueDate = MDate::formatToDb($this->dueDate, 'date'));
     isset($_POST[__CLASS__]['openDate']) && ($this->openDate = MDate::formatToDb($this->openDate, 'date'));
     // parent does all common work
     return parent::beforeValidate();
 }
Ejemplo n.º 9
0
 /**
  * Prepares attributes before performing validation.
  */
 protected function beforeValidate()
 {
     $scenario = $this->getScenario();
     if (isset($_POST[__CLASS__]['isEmailConfirmed']) && $this->isEmailConfirmed !== self::EMAIL_IS_CONFIRMED && $this->isEmailConfirmed !== self::EMAIL_IS_NOT_CONFIRMED) {
         // enum('0','1') null
         $this->isEmailConfirmed = null;
     }
     if (isset($_POST[__CLASS__]['isEmailVisible']) && $this->isEmailVisible !== self::EMAIL_IS_VISIBLE && $this->isEmailVisible !== self::EMAIL_IS_NOT_VISIBLE) {
         // enum('0','1') null
         $this->isEmailVisible = null;
     }
     // parent does all common work
     return parent::beforeValidate();
 }
Ejemplo n.º 10
0
 /**
  * Prepares attributes before performing validation.
  */
 protected function beforeValidate()
 {
     $scenario = $this->getScenario();
     if (($scenario === 'create' || $scenario === 'register') && $this->screenNameSame && $this->username !== '' && $this->username !== null) {
         // make screenName same as username
         $this->screenName = $this->username;
     }
     if ($this->isNewRecord && !$this->hasVirtualAttribute('username') && ($this->username === '' || $this->username === null)) {
         // if username is not allowed, we make it equal to email
         // because in db username field is unique key
         $this->username = substr($this->email, 0, 128);
         if (User::model()->findByAttributes(array('username' => $this->username)) !== null) {
             // if username is already in use, generate an unique id
             $this->username = md5(uniqid(rand(), true));
         }
     }
     if ($scenario === 'update' && isset($_POST[__CLASS__]['email']) && $this->email !== $_POST[__CLASS__]['email']) {
         // email is being updated
         $this->email = $_POST[__CLASS__]['email'];
         $this->details->isEmailConfirmed = UserDetails::EMAIL_IS_NOT_CONFIRMED;
     }
     if (isset($_POST[__CLASS__]['isActive']) && $this->isActive !== self::IS_ACTIVE && $this->isActive !== self::IS_NOT_ACTIVE) {
         // enum('0','1') null
         $this->isActive = null;
     }
     if (isset($_POST[__CLASS__]['accessType']) && $this->accessType !== self::MEMBER && $this->accessType !== self::CLIENT && $this->accessType !== self::CONSULTANT && $this->accessType !== self::MANAGER && $this->accessType !== self::ADMINISTRATOR) {
         // we hope to switch to roles in nearest future
         $this->accessType = self::MEMBER;
     }
     if (isset($_POST[__CLASS__]['accessType'])) {
         // if access type changed, we need to adjust access level
         $accessLevel = array(self::MEMBER => 1, self::CLIENT => 2, self::CONSULTANT => 3, self::MANAGER => 4, self::ADMINISTRATOR => 5);
         $this->accessLevel = $accessLevel[$this->accessType];
     }
     // parent does all common work
     return parent::beforeValidate();
 }