/** * Validate the current record. * * @return boolean True for valid. */ public function recordValidate() { $data = $this->_data; $fields = $this->_informationManager->getFieldDefinition(Phprojekt_ModelInformation_Default::ORDERING_FORM); if ($this->_data['id'] == 1 && $this->_data['saveType'] != 0) { $this->_validate->error->addError(array('field' => 'Module', 'label' => Phprojekt::getInstance()->translate('Module'), 'message' => Phprojekt::getInstance()->translate('Project module must be a normal module'))); return false; } return $this->_validate->recordValidate($this, $data, $fields); }
/** * Validate the current record. * * @return boolean True on valid. */ public function recordValidate() { $data = $this->_data; $fields = $this->_informationManager->getFieldDefinition(Phprojekt_ModelInformation_Default::ORDERING_FORM); $result = $this->_validate->recordValidate($this, $data, $fields); if ($result) { // Username repeated? $db = Phprojekt::getInstance()->getDb(); $where = sprintf("username = %s AND id != %d", $db->quote($this->username), (int) $this->id); $records = $this->fetchAll($where); if (count($records) > 0) { $this->_validate->error->addError(array('field' => 'username', 'label' => Phprojekt::getInstance()->translate('Username'), 'message' => Phprojekt::getInstance()->translate('Already exists, choose another one please'))); $result = false; } } return $result; }
/** * Return if the values are valid or not. * * @return boolean True for valid. */ public function recordValidate() { $data = $this->_data; $fields = $this->getInformation()->getFieldDefinition(Phprojekt_ModelInformation_Default::ORDERING_FORM); return $this->_validate->recordValidate($this, $data, $fields); }
/** * Validate the current record * * @return boolean */ public function recordValidate() { $data = $this->_data; $fields = $this->_informationManager->getFieldDefinition(Phprojekt_ModelInformation_Default::ORDERING_FORM); if (isset($data['startDatetime'])) { $startTime = str_replace(":", "", substr($data['startDatetime'], 11)); if (strlen($startTime) == 6) { $startTime = substr($startTime, 0, 4); } $startTime = (int) $startTime; if ($startTime >= 2400 || $startTime < 0) { $this->_validate->error->addError(array('field' => 'Hours', 'label' => Phprojekt::getInstance()->translate('Hours'), 'message' => Phprojekt::getInstance()->translate('Start time has to be between 0:00 and 24:00'))); return false; } else { $startMinutes = substr($startTime, strlen($startTime) - 2, 2); if ($startMinutes > 59 || $startMinutes < 0) { $this->_validate->error->addError(array('field' => 'Hours', 'label' => Phprojekt::getInstance()->translate('Hours'), 'message' => Phprojekt::getInstance()->translate('The start time is invalid'))); return false; } } if (!isset($data['endTime'])) { // Start Hours button pressed - Check if new start time overlaps any existing period $records = $this->fetchAll($this->_getWhereForTimes()); if (count($records) > 0) { $this->_validate->error->addError(array('field' => 'Time period', 'label' => Phprojekt::getInstance()->translate('Time period'), 'message' => Phprojekt::getInstance()->translate('Can not Start Working Time because this ' . 'moment is occupied by an existing period or an open one'))); return false; } } } if (isset($data['endTime']) && !empty($data['endTime'])) { if ($this->getDiffTime($data['endTime'], substr($data['startDatetime'], 11)) < 0) { if ($data['endTime'] != "00:00:00" && $data['endTime'] != "00:00") { $this->_validate->error->addError(array('field' => 'Hours', 'label' => Phprojekt::getInstance()->translate('Hours'), 'message' => Phprojekt::getInstance()->translate('The end time must be after the start time'))); return false; } } $endTime = str_replace(":", "", $data['endTime']); if (strlen($endTime) == 6) { $endTime = substr($endTime, 0, 4); } $endTime = (int) $endTime; if ($endTime > 2400 || $endTime < 0) { $this->_validate->error->addError(array('field' => 'Hours', 'label' => Phprojekt::getInstance()->translate('Hours'), 'message' => Phprojekt::getInstance()->translate('End time has to be between 0:00 and 24:00'))); return false; } else { $endMinutes = substr($endTime, strlen($endTime) - 2, 2); if ($endMinutes > 59 || $endMinutes < 0) { $this->_validate->error->addError(array('field' => 'Hours', 'label' => Phprojekt::getInstance()->translate('Hours'), 'message' => Phprojekt::getInstance()->translate('The end time is invalid'))); return false; } } if (empty($data['startDatetime']) || $data['startDatetime'] == ':') { $this->_validate->error->addError(array('field' => 'Hours', 'label' => Phprojekt::getInstance()->translate('Hours'), 'message' => Phprojekt::getInstance()->translate('The start time is invalid'))); return false; } if (!empty($data['startDatetime'])) { $startTime = str_replace(":", "", substr($data['startDatetime'], 11)); if (strlen($startTime) == 6) { $startTime = substr($startTime, 0, 4); } $startTime = (int) $startTime; $showError = false; $records = $this->fetchAll($this->_getWhereForTimes()); if ($this->id != 0) { // Stop Working Times button pressed, or it is being saved an existing period // Check if end time overlaps any existing period but the current one if (count($records) > 0) { foreach ($records as $record) { if ($record->id != $this->id) { $showError = true; break; } } if ($showError) { $this->_validate->error->addError(array('field' => 'Time period', 'label' => Phprojekt::getInstance()->translate('Time period'), 'message' => Phprojekt::getInstance()->translate('Can not End Working Time because this' . ' moment is occupied by an existing period'))); return false; } } } else { if (count($records) > 0 && $this->id == 0) { $showError = true; } if ($showError) { $this->_validate->error->addError(array('field' => 'Time period', 'label' => Phprojekt::getInstance()->translate('Time period'), 'message' => Phprojekt::getInstance()->translate('Can not save it because it overlaps ' . 'existing one'))); return false; } } } } return $this->_validate->recordValidate($this, $data, $fields); }