beforeSave() public method

public beforeSave ( )
 protected function beforeSave()
 {
     if (parent::beforeSave()) {
         if ($this->id < 0) {
             $this->code = preg_replace('/\\s+/', '', $this->name);
         }
     }
     return true;
 }
Example #2
0
 protected function beforeSave()
 {
     if (parent::beforeSave()) {
         if ($this->fileContent !== null) {
             return $this->fileContent->save();
         }
         return true;
     } else {
         return false;
     }
 }
Example #3
0
 protected function beforeSave()
 {
     if (parent::beforeSave()) {
         if (isset($this->originalAttributeValues['role']) && $this->originalAttributeValues['role'][1] > 0) {
             //copy to new object, so we can populate the old parent role as the related role.
             //otherwise it gets passed by reference. We need the old $this->role information to properly
             //utilize the roleParentBeingRemoved method.
             $role = unserialize(serialize($this));
             $role->role = Role::getById($this->originalAttributeValues['role'][1]);
             ReadPermissionsOptimizationUtil::roleParentBeingRemoved($role);
             assert('$this->originalAttributeValues["role"][1] != $this->role->id');
         }
         return true;
     } else {
         return false;
     }
 }
 public function beforeSave()
 {
     if (parent::beforeSave()) {
         $this->latestDateTime = DateTimeUtil::convertTimestampToDbFormatDateTime(time());
         return true;
     }
     return false;
 }
Example #5
0
 protected function beforeSave()
 {
     if (parent::beforeSave()) {
         $this->productkey = 'GICRM|' . $this->productcode;
         $currencyHelper = Yii::app()->currencyHelper;
         if ($this->costofgoodssold->value == 'Labor') {
             if ($this->departmentreference->id < 0) {
                 $this->addError('departmentreference', Zurmo::t('Core', 'Department Reference cannot be blank'));
                 $currencyHelper->resetErrors();
                 return false;
             } else {
                 $deptRefId = $this->departmentreference->id;
                 $deptRefs = DepartmentReference::getDeptRefById(intval($deptRefId));
                 $this->laborCost = $deptRefs[0]->laborCost;
                 $this->burdenCost = $deptRefs[0]->burdonCost;
                 $this->costperunit = $this->laborCost + $this->burdenCost;
                 $this->unitdirectcost = $this->laborCost + $this->burdenCost;
             }
             if ($this->id < 0) {
                 $this->productcode = 'L-' . $this->productcode;
             }
             return true;
         }
         if ($this->costofgoodssold->value == 'Equipment' || $this->costofgoodssold->value == 'Material' || $this->costofgoodssold->value == 'Subcontractor' || $this->costofgoodssold->value == 'Other') {
             if ($this->unitofmeasure == '(None)') {
                 $this->addError('unitofmeasure', Zurmo::t('Core', 'Please select Unit Of Measure'));
                 $currencyHelper->resetErrors();
                 return false;
             }
             if ($this->costperunit == '') {
                 $this->addError('costperunit', Zurmo::t('Core', 'Cost Rate cannot be blank'));
                 $currencyHelper->resetErrors();
                 return false;
             } else {
                 $cost = floatval($this->costperunit);
                 $this->unitdirectcost = $cost;
             }
             if ($this->id < 0) {
                 if ($this->costofgoodssold->value == 'Equipment') {
                     $this->productcode = 'E-' . $this->productcode;
                 }
                 if ($this->costofgoodssold->value == 'Material') {
                     $this->productcode = 'M-' . $this->productcode;
                 }
                 if ($this->costofgoodssold->value == 'Subcontractor') {
                     $this->productcode = 'S-' . $this->productcode;
                 }
                 if ($this->costofgoodssold->value == 'Other') {
                     $this->productcode = 'O-' . $this->productcode;
                 }
             }
             return true;
         }
         if ($this->costofgoodssold->value == 'Assembly') {
             if (empty($_POST['Costbook']['assemblydetailsearch']['values']) && preg_match('/edit/', $_SERVER['REQUEST_URI'])) {
                 $this->assemblydetailsearch = NULL;
                 $this->assemblydetail = NULL;
             }
             if ($this->unitofmeasure == '(None)') {
                 $this->addError('unitofmeasure', Zurmo::t('Core', 'Please select Unit Of Measure'));
                 $currencyHelper->resetErrors();
                 return false;
             }
             if ($this->id < 0) {
                 $this->productcode = 'A-' . $this->productcode;
             }
             return true;
         }
     } else {
         return false;
     }
 }