/** * 通过主键,删除一条记录,禁止删除group_id=1,group_pid=0的根组 * @param integer $groupId * @return integer */ public function removeByPk($groupId) { if (($groupId = (int) $groupId) <= 1) { return false; } $tableName = $this->getTblprefix() . TableNames::getGroups(); $sql = $this->getCommandBuilder()->createDelete($tableName, '`group_id` = ?'); $rowCount = $this->delete($sql, $groupId); return $rowCount; }
/** * 删除一条记录 * @param integer $userId * @param integer $groupId * @return integer */ public function remove($userId, $groupId) { if (($userId = (int) $userId) <= 0) { return false; } if (($groupId = (int) $groupId) <= 0) { return false; } $pks = array('user_id' => $userId, 'group_id' => $groupId); $tableName = $this->getTblprefix() . TableNames::getUsergroups(); $sql = $this->getCommandBuilder()->createDelete($tableName, '`user_id` = ? AND `group_id` = ?'); $rowCount = $this->delete($sql, $pks); return $rowCount; }
/** * 新增或编辑后执行 * @param string $context * @param array $row * @param mixed $params * @return void */ public function onAfterSave($context, array &$row, $params = null) { $isCreate = $context === 'users\\services\\Users::create' ? true : false; $isModify = $context === 'users\\services\\Users::modifyByPk' ? true : false; if (!$isCreate && !$isModify) { return; } if (($userId = (int) $params) <= 0) { return; } $sexEnum = DataUsers::getSexEnum(); $sex = isset($row['sex']) ? trim($row['sex']) : ''; $birthday = isset($row['birthday']) ? trim($row['birthday']) : ''; $address = isset($row['address']) ? trim($row['address']) : ''; $qq = isset($row['qq']) ? (int) $row['qq'] : 0; $headPortrait = isset($row['head_portrait']) ? trim($row['head_portrait']) : ''; $remarks = isset($row['remarks']) ? trim($row['remarks']) : ''; $sex = isset($sexEnum[$sex]) ? $sex : DataUsers::SEX_UNKNOW; $birthday = date('Y-m-d', strtotime($birthday)) === $birthday ? $birthday : ''; $qq = $qq > 0 ? $qq : ''; $attributes = array(); if ($isCreate) { $attributes = array('sex' => $sex, 'birthday' => $birthday, 'address' => $address, 'qq' => $qq, 'head_portrait' => $headPortrait, 'remarks' => $remarks); } else { if (isset($row['sex'])) { $attributes['sex'] = $sex; } if (isset($row['birthday'])) { $attributes['birthday'] = $birthday; } if (isset($row['address'])) { $attributes['address'] = $address; } if (isset($row['qq'])) { $attributes['qq'] = $qq; } if (isset($row['head_portrait'])) { $attributes['head_portrait'] = $headPortrait; } if (isset($row['remarks'])) { $attributes['remarks'] = $remarks; } if ($attributes === array()) { return; } } $db = Service::getInstance('Users', 'users')->getDb(); $dbProxy = $db->getDbProxy(); $tableName = $db->getTblprefix() . TableNames::getUserProfile(); $profile = Profile::getInstance($tableName, $userId, $dbProxy); $profile->save($attributes); }
/** * 获取“事件名”验证规则 * @param mixed $value * @return array */ public function getAmcaNameRule($value) { if ($this->isUpdate()) { if ($this->_object->getAmcaNameByAmcaId($this->id) === $value) { return array(); } } return array('Alpha' => new validator\AlphaValidator($value, true, Lang::_('SRV_FILTER_USER_AMCAS_AMCA_NAME_ALPHA')), 'MinLength' => new validator\MinLengthValidator($value, 2, Lang::_('SRV_FILTER_USER_AMCAS_AMCA_NAME_MINLENGTH')), 'MaxLength' => new validator\MaxLengthValidator($value, 16, Lang::_('SRV_FILTER_USER_AMCAS_AMCA_NAME_MAXLENGTH')), 'DbExists2' => new validator\DbExists2Validator($value, false, Lang::_('SRV_FILTER_USER_AMCAS_AMCA_NAME_UNIQUE'), $this->getDbProxy(), TableNames::getAmcas(), 'amca_name', 'amca_pid', $this->amca_pid)); }
/** * 通过主键,删除一条记录 * @param integer $amcaId * @return integer */ public function removeByPk($amcaId) { if (($amcaId = (int) $amcaId) <= 0) { return false; } $tableName = $this->getTblprefix() . TableNames::getAmcas(); $sql = $this->getCommandBuilder()->createDelete($tableName, '`amca_id` = ? OR `amca_pid` = ?'); $rowCount = $this->delete($sql, array($amcaId, $amcaId)); return $rowCount; }
/** * 获取“登录名”验证规则 * @param mixed $value * @return array */ public function getLoginNameRule($value) { $rules = array('MinLength' => new validator\MinLengthValidator($value, 6, Lang::_('SRV_FILTER_USERS_LOGIN_NAME_MINLENGTH')), 'MaxLength' => new validator\MaxLengthValidator($value, 18, Lang::_('SRV_FILTER_USERS_LOGIN_NAME_MAXLENGTH'))); if ($this->_object->isMailLogin($this->login_type)) { $rules['Mail'] = new validator\MailValidator($value, true, Lang::_('SRV_FILTER_USERS_LOGIN_NAME_MAIL')); } elseif ($this->_object->isPhoneLogin($this->login_type)) { $rules['Phone'] = new validator\PhoneValidator($value, true, Lang::_('SRV_FILTER_USERS_LOGIN_NAME_PHONE')); } else { $rules['AlphaNum'] = new validator\AlphaNumValidator($value, true, Lang::_('SRV_FILTER_USERS_LOGIN_NAME_ALPHANUM')); } $rules['DbExists'] = new validator\DbExistsValidator($value, false, Lang::_('SRV_FILTER_USERS_LOGIN_NAME_UNIQUE'), $this->getDbProxy(), TableNames::getUsers(), 'login_name'); return $rules; }
/** * 获取“父ID”验证规则 * @param mixed $value * @return array */ public function getGroupPidRule($value) { return array('DbExists' => new validator\DbExistsValidator($value, true, Lang::_('SRV_FILTER_USER_GROUPS_GROUP_PID_EXISTS'), $this->getDbProxy(), TableNames::getGroups(), 'group_id')); }