/** * 执行表单数据验证操作 * @param string $opType * @param array $params * @param integer|array $id * @return boolean * @throws ErrorException 如果指定的操作类型不是INSERT或UPDATE,抛出异常 * @throws ErrorException 如果是UPDATE操作类型但是ID小于等于0,抛出异常 */ public function run($opType, array $params, $id = 0) { $this->clearValues(); $this->clearErrors(); $this->_opType = strtoupper($opType); if (!defined('static::OP_' . $this->_opType)) { throw new ErrorException(sprintf('FormProcessor op type "%s" must be INSERT or UPDATE', $this->_opType)); } $this->id = Clean::positiveInteger($id); if ($this->isUpdate() && $this->id === false) { $isArr = is_array($id); Log::warning(sprintf('FormProcessor op type is Update, "%s" "%s" must be greater than 0', $isArr ? 'IDs' : 'ID', $isArr ? serialize($id) : $id)); return false; } $params = $this->_cleanPreProcess($params); if ($params === false) { return false; } if ($this->_process($params)) { return $this->_cleanPostProcess(); } return false; }
/** * 通过主键,编辑多条记录 * @param array|integer $memberIds * @param array $params * @return integer */ public function batchModifyByPk($memberIds, array $params = array()) { $memberIds = Clean::positiveInteger($memberIds); if ($memberIds === false) { return false; } if (is_array($memberIds)) { $memberIds = implode(', ', $memberIds); } $attributes = array(); if (isset($params['valid_mail'])) { $validMail = trim($params['valid_mail']); if ($validMail !== '') { $attributes['valid_mail'] = $validMail; } else { return false; } } if (isset($params['valid_phone'])) { $validPhone = trim($params['valid_phone']); if ($validPhone !== '') { $attributes['valid_phone'] = $validPhone; } else { return false; } } if (isset($params['forbidden'])) { $forbidden = trim($params['forbidden']); if ($forbidden !== '') { $attributes['forbidden'] = $forbidden; } else { return false; } } if (isset($params['trash'])) { $trash = trim($params['trash']); if ($trash !== '') { $attributes['trash'] = $trash; } else { return false; } } $rowCount = 0; if ($attributes === array()) { return $rowCount; } $tableName = $this->getTblprefix() . TableNames::getPortal(); $condition = '`member_id` IN (' . $memberIds . ')'; $sql = $this->getCommandBuilder()->createUpdate($tableName, array_keys($attributes), $condition); $rowCount = $this->update($sql, $attributes); return $rowCount; }
/** * 清理正整数数据,如果为负数则返回false * @param integer|array $value * @return mixed */ public function cleanPositiveInteger($value) { $result = Clean::positiveInteger($value); if ($result === false) { $isArr = is_array($value); Log::warning(sprintf('AbstractService cleanPositiveInteger ARGS Error, "%s" "%s" must be greater than 0', $isArr ? 'PKs' : 'PK', $isArr ? serialize($value) : $value)); } return $result; }
/** * 通过主键,编辑多条记录 * @param array|integer $postId * @param array $params * @return integer */ public function batchModifyByPk($postIds, array $params = array()) { $postIds = Clean::positiveInteger($postIds); if ($postIds === false) { return false; } if (is_array($postIds)) { $postIds = implode(', ', $postIds); } $attributes = array(); if (isset($params['sort'])) { $sort = (int) $params['sort']; if ($sort > 0) { $attributes['sort'] = $sort; } else { return false; } } if (isset($params['is_head'])) { $isHead = trim($params['is_head']); if ($isHead !== '') { $attributes['is_head'] = $isHead; } else { return false; } } if (isset($params['is_recommend'])) { $isRecommend = trim($params['is_recommend']); if ($isRecommend !== '') { $attributes['is_recommend'] = $isRecommend; } else { return false; } } if (isset($params['is_published'])) { $isPublished = trim($params['is_published']); if ($isPublished !== '') { $attributes['is_published'] = $isPublished; } else { return false; } } if (isset($params['dt_publish_up'])) { $dtPublishUp = trim($params['dt_publish_up']); if ($dtPublishUp !== '') { $attributes['dt_publish_up'] = $dtPublishUp; } else { return false; } } if (isset($params['dt_publish_down'])) { $dtPublishDown = trim($params['dt_publish_down']); if ($dtPublishDown !== '') { $attributes['dt_publish_down'] = $dtPublishDown; } else { return false; } } if (isset($params['comment_status'])) { $commentStatus = trim($params['comment_status']); if ($commentStatus !== '') { $attributes['comment_status'] = $commentStatus; } else { return false; } } if (isset($params['allow_other_modify'])) { $allowOtherModify = trim($params['allow_other_modify']); if ($allowOtherModify !== '') { $attributes['allow_other_modify'] = $allowOtherModify; } else { return false; } } if (isset($params['trash'])) { $trash = trim($params['trash']); if ($trash !== '') { $attributes['trash'] = $trash; } else { return false; } } $rowCount = 0; if ($attributes === array()) { return $rowCount; } $tableName = $this->getTblprefix() . TableNames::getPosts(); $condition = '`post_id` IN (' . $postIds . ')'; $sql = $this->getCommandBuilder()->createUpdate($tableName, array_keys($attributes), $condition); $rowCount = $this->update($sql, $attributes); return $rowCount; }
/** * 通过主键,删除多条记录 * @param array|integer $commentIds * @return integer */ public function batchRemoveByPk($commentIds, array $params = array()) { $commentIds = Clean::positiveInteger($commentIds); if ($commentIds === false) { return false; } if (is_array($commentIds)) { $commentIds = implode(', ', $commentIds); } $tableName = $this->getTblprefix() . TableNames::getComments(); $condition = '`comment_id` IN (' . $commentIds . ')'; $sql = $this->getCommandBuilder()->createDelete($tableName, $condition); $rowCount = $this->delete($sql); return $rowCount; }