/** * @param array $value * @return boolean indicating is any valid data of interest was passed */ protected function _isValid($value) { $partialHappened = false; $isPost = 'post' == $this->getMethodContext(); // comment is set optional for put, required for post if (isset($value['comment'])) { $partialHappened = true; $validate = new Zend_Validate_StringLength(array(1, 1000)); if (!$validate->isValid($value['comment'])) { $this->_addValidateMessagesAndErrors($validate); } } elseif ($isPost) { $this->_error(self::COMMENT_REQUIRED); } // creator_user_id required for post // creator can't be changed for put, so if not post, then don't bother // checking this, it will be ignored later if (isset($value['creator_user_id']) && $isPost) { $userTable = new Default_Model_DbTable_User(); if (false === current($userTable->find($value['creator_user_id']))) { $this->_error(self::CREATOR_USER_ID_INVALID, $value['creator_user_id']); } } elseif ($isPost) { $this->_error(self::CREATOR_USER_ID_REQUIRED); } return $partialHappened; }
/** * @param array $item */ protected function _post_pre_persist(array &$item) { // force the user to be that from the acl context $item['creator_user_id'] = $this->getAclContextUser()->id; $item['modified'] = date('Y-m-d H:i:s'); // make sure that the user is valid require_once 'models/DbTable/User.php'; $userTable = new Default_Model_DbTable_User(); $resultSet = $userTable->find($item['creator_user_id']); if (false === current($resultSet)) { throw new Rest_Model_BadRequestException('creator_user_id does not match with an existing user'); } }