Example #1
0
 /**
  * 新增或编辑后执行
  * @param string $context
  * @param array $row
  * @param mixed $params
  * @return void
  */
 public function onAfterSave($context, array &$row, $params = null)
 {
     $isCreate = $context === 'posts\\services\\Posts::create' ? true : false;
     $isModify = $context === 'posts\\services\\Posts::modifyByPk' ? true : false;
     if (!$isCreate && !$isModify) {
         return;
     }
     if (($postId = (int) $params) <= 0) {
         return;
     }
     $service = Service::getInstance('Posts', 'posts');
     $fields = $service->getModuleFieldsByPostId($postId);
     if ($fields === array()) {
         return;
     }
     $attributes = array();
     foreach ($fields as $name => $field) {
         if (isset($row[$name])) {
             $attributes[$name] = $row[$name];
         } else {
             if ($isCreate) {
                 $attributes[$name] = '';
             }
         }
     }
     if ($attributes === array()) {
         return;
     }
     $db = $service->getDb();
     $dbProxy = $db->getDbProxy();
     $tableName = $db->getTblprefix() . TableNames::getPostProfile();
     $profile = Profile::getInstance($tableName, $postId, $dbProxy);
     $profile->save($attributes);
 }
Example #2
0
 /**
  * (non-PHPdoc)
  * @see \libsrv\FormProcessor::_cleanPostProcess()
  */
 protected function _cleanPostProcess()
 {
     if (isset($this->p_password)) {
         $portal = Service::getInstance('Portal', 'member');
         $row = $portal->findByPk($this->id);
         if (!$row || !is_array($row) || !isset($row['password']) || !isset($row['salt'])) {
             return false;
         }
         $pPassword = $portal->encrypt($this->p_password, $row['salt']);
         if ($pPassword === $row['password']) {
             $this->addError('p_password', Lang::_('SRV_FILTER_MEMBERS_P_PASSWORD_EQUAL'));
             return false;
         }
     }
     if (isset($this->p_password)) {
         if (isset($this->p_salt) && strlen($this->p_salt) > 0) {
             $this->p_password = $this->_object->encrypt($this->p_password, $this->p_salt);
         } else {
             return false;
         }
     } else {
         return false;
     }
     if (isset($this->p_repassword)) {
         unset($this->p_repassword);
     }
     return true;
 }
Example #3
0
 /**
  * 获取广告业务处理类
  * @return \advert\services\Adverts
  */
 public static function getService()
 {
     static $service = null;
     if ($service === null) {
         $service = Service::getInstance('Types', 'advert');
     }
     return $service;
 }
Example #4
0
 /**
  * 获取文档类别业务处理类
  * @return posts\services\Categories
  */
 public function getService()
 {
     static $service = null;
     if ($service === null) {
         $service = Service::getInstance('Categories', 'posts');
     }
     return $service;
 }
Example #5
0
 /**
  * 获取专题业务处理类
  * @return \topic\services\Topic
  */
 public function getService()
 {
     static $service = null;
     if ($service === null) {
         $service = Service::getInstance('Topic', 'topic');
     }
     return $service;
 }
Example #6
0
 /**
  * 获取投票选项业务处理类
  * @return \poll\services\Polloptions
  */
 public static function getService()
 {
     static $service = null;
     if ($service === null) {
         $service = Service::getInstance('Polloptions', 'poll');
     }
     return $service;
 }
Example #7
0
 /**
  * (non-PHPdoc)
  * @see \libsrv\FormProcessor::_cleanPreProcess()
  */
 protected function _cleanPreProcess(array $params)
 {
     if ($this->isInsert()) {
         if (isset($params['last_modifier_id'])) {
             unset($params['last_modifier_id']);
         }
         if (isset($params['last_modifier_name'])) {
             unset($params['last_modifier_name']);
         }
         $params['dt_created'] = $params['dt_last_modified'] = date('Y-m-d H:i:s');
         $params['ip_created'] = $params['ip_last_modified'] = Clean::ip2long(Ap::getRequest()->getClientIp());
         $params['good_count'] = $params['bad_count'] = 0;
         $postId = isset($params['post_id']) ? (int) $params['post_id'] : 0;
         if ($postId <= 0) {
             $this->addError('post_id', Lang::_('SRV_FILTER_POST_COMMENTS_POST_ID_EXISTS'));
             return false;
         }
         $row = Service::getInstance('Posts', 'posts')->findByPk($postId);
         if (!$row || !is_array($row) || !isset($row['comment_status'])) {
             $this->addError('post_id', Lang::_('SRV_FILTER_POST_COMMENTS_POST_ID_EXISTS'));
             return false;
         }
         switch (true) {
             case $row['comment_status'] === DataPosts::COMMENT_STATUS_DRAFT:
                 $params['is_published'] = DataComments::IS_PUBLISHED_N;
                 break;
             case $row['comment_status'] === DataPosts::COMMENT_STATUS_PUBLISH:
                 $params['is_published'] = DataComments::IS_PUBLISHED_Y;
                 break;
             default:
                 $this->addError('post_id', Lang::_('SRV_FILTER_POST_COMMENTS_POST_ID_POWER'));
                 return false;
         }
     } else {
         if (isset($params['creator_id'])) {
             unset($params['creator_id']);
         }
         if (isset($params['creator_name'])) {
             unset($params['creator_name']);
         }
         if (isset($params['dt_created'])) {
             unset($params['dt_created']);
         }
         if (isset($params['ip_created'])) {
             unset($params['ip_created']);
         }
         $params['dt_last_modified'] = date('Y-m-d H:i:s');
         $params['ip_last_modified'] = Clean::ip2long(Ap::getRequest()->getClientIp());
     }
     $rules = array('comment_pid' => 'intval', 'post_id' => 'intval', 'author_name' => 'trim', 'author_mail' => 'trim', 'author_url' => 'trim', 'is_published' => 'trim', 'good_count' => 'intval', 'bad_count' => 'intval', 'creator_id' => 'intval', 'creator_name' => 'trim', 'last_modifier_id' => 'intval', 'last_modifier_name' => 'trim', 'dt_created' => 'trim', 'dt_last_modified' => 'trim', 'ip_created' => 'intval', 'ip_last_modified' => 'intval');
     $ret = $this->clean($rules, $params);
     return $ret;
 }
Example #8
0
 /**
  * 新增或编辑前执行
  * @param string $context
  * @param array $row
  * @param mixed $params
  * @return void
  */
 public function onBeforeSave($context, array &$row, $params = null)
 {
     $isCreate = $context === 'advert\\services\\Adverts::create' ? true : false;
     $isModify = $context === 'advert\\services\\Adverts::modifyByPk' ? true : false;
     if (!$isCreate && !$isModify) {
         return;
     }
     $enum = DataAdverts::getShowTypeEnum();
     $showType = isset($row['show_type']) ? trim($row['show_type']) : '';
     if (!isset($enum[$showType])) {
         return;
     }
     if ($showType === DataAdverts::SHOW_TYPE_CODE) {
         return;
     }
     if (isset($row['show_code'])) {
         unset($row['show_code']);
     }
     $columns = array('advert_url', 'title', 'advert_src', 'advert_src2', 'attr_alt', 'attr_width', 'attr_height', 'attr_fontsize', 'attr_target');
     $hasColumn = false;
     foreach ($row as $columnName => $value) {
         if (in_array($columnName, $columns)) {
             $hasColumn = true;
             break;
         }
     }
     if (!$hasColumn) {
         return;
     }
     if ($isModify) {
         if (($advertId = (int) $params) <= 0) {
             return;
         }
         $advert = Service::getInstance('Adverts', 'advert')->findByPk($advertId);
         if (!$advert || !is_array($advert) || !isset($advert['advert_id']) || !isset($advert['advert_url'])) {
             Log::warning(sprintf('PlgShowcode is unable to find the result by id "%d"', $advertId), ErrorNo::ERROR_DB_SELECT, __METHOD__);
             return;
         }
         foreach ($columns as $columnName) {
             if (!isset($row[$columnName])) {
                 $row[$columnName] = $advert[$columnName];
             }
         }
     }
     $typeKey = isset($row['type_key']) ? strtolower(trim($row['type_key'])) : '';
     if (in_array($typeKey, $this->_specialTypes)) {
         $object = Singleton::getInstance('advert\\plugins\\showcode\\Special' . ucfirst($typeKey));
     } else {
         $object = $this;
     }
     $object->setShowCode($showType, $row, $this);
 }
Example #9
0
 /**
  * 通过主键,编辑一条记录
  * @param integer|array $value
  * @param array $params
  * @return integer
  */
 public function modifyByPk($value, array $params = array())
 {
     $srv = Service::getInstance('Regions', 'system');
     $columnNames = array('live_country_id' => 'live_country', 'live_province_id' => 'live_province', 'live_city_id' => 'live_city', 'live_district_id' => 'live_district', 'address_country_id' => 'address_country', 'address_province_id' => 'address_province', 'address_city_id' => 'address_city', 'address_district_id' => 'address_district');
     foreach ($columnNames as $columnId => $columnName) {
         if (isset($params[$columnId])) {
             $params[$columnName] = $srv->getRegionNameByRegionId($params[$columnId]);
         }
     }
     if (isset($params['interests'])) {
         if (is_string($params['interests'])) {
             $params['interests'] = explode(',', $params['interests']);
         }
     }
     return parent::modifyByPk($value, $params);
 }
Example #10
0
 /**
  * (non-PHPdoc)
  * @see \tfc\mvc\interfaces\Action::run()
  */
 public function run()
 {
     $req = Ap::getRequest();
     $pid = $req->getInteger('pid');
     $def = $req->getInteger('def');
     $srv = Service::getInstance('Regions', 'system');
     $data = $srv->findPairs($pid);
     if ($data && $def === 1) {
         $id = array_shift(array_keys(array_slice($data, 0, 1, true)));
         $type = $srv->getRegionTypeByRegionId($id);
         $hint = $srv->getRegionTypeLangByRegionType($type);
         if ($hint === '') {
             $hint = Text::_('CFG_SYSTEM_GLOBAL_SELECT_HINT');
         }
         $default = array(0 => '--' . $hint . '--');
         $data = $default + $data;
     }
     $this->display($data);
 }
Example #11
0
 /**
  * 初始化表单字段数据
  * @return instance of modules\builder\model\gc\Schema
  */
 protected function _initValidators()
 {
     $object = Service::getInstance('Validators', self::SRV_NAME);
     $tableName = $object->getTableName();
     Log::echoTrace('Query from ' . $tableName . ' Begin ...');
     foreach ($this->fields as $key => $fields) {
         $data = $object->findAllByAttributes(array('field_id' => $fields['field_id']), 'sort', 0, 1000);
         if ($data === false) {
             Log::errExit(__LINE__, 'Query from ' . $tableName . ' Failed!');
         }
         $temp = array();
         foreach ($data as $rows) {
             $validatorId = (int) $rows['validator_id'];
             $validatorName = trim($rows['validator_name']);
             $temp[$validatorId] = array('validator_id' => $validatorId, 'validator_name' => $validatorName, 'options' => $rows['options'], 'option_category' => strtolower(trim($rows['option_category'])), 'message' => trim($rows['message']), 'when' => strtolower(trim($rows['when'])), 'lang_key' => 'SRV_FILTER_' . $this->upTblName . '_' . $fields['up_field_name'] . '_' . strtoupper($validatorName));
         }
         $this->fields[$key]['validators'] = $temp;
     }
     Log::echoTrace('Query from ' . $tableName . ' Successfully');
     return $this;
 }
Example #12
0
 /**
  * 通过主键,编辑“权限设置”
  * <pre>
  * $params = array (
  *   'app_name' => array (
  *     'mod_name' => array (
  *       'ctrl_name' => array (
  *         'Power-SELECT', 'Power-INSERT', 'Power-UPDATE', 'Power-DELETE'
  *       )
  *     )
  *   )
  * );
  * 示例:
  * $params = array (
  *   'administrator' => array (
  *     'system' => array (
  *       'site' => array ( '1', '2', '4', '8' ),
  *     ),
  *     'posts' => array (
  *       'categories' => array ( '1', '2', '4', '8' ),
  *       'modules' => array ( '1', '2', '4', '8' ),
  *       'posts' => array ( '1', '2', '4', '8' ),
  *     ),
  *   ),
  *   'passport' => array (
  *     'system' => array (
  *       'options' => array ( '1', '2', '4', '8' ),
  *       'pictures' => array ( '1', '2', '4', '8' ),
  *       'site' => array ( '1', '2', '4', '8' ),
  *     ),
  *     'users' => array (
  *       'account' => array ( '1', '2', '4', '8' ),
  *       'amcas' => array ( '1', '2', '4', '8' ),
  *       'groups' => array ( '1', '2', '4', '8' ),
  *       'users' => array ( '1', '2', '4', '8' ),
  *     ),
  *   ),
  *   'programmer' => array (
  *     'builder' => array (
  *       'builders' => array ( '1', '2', '4', '8' ),
  *       'fields' => array ( '1', '2', '4', '8' ),
  *       'groups' => array ( '1', '2', '4', '8' ),
  *       'tblnames' => array ( '1', '2', '4', '8' ),
  *       'types' => array ( '1', '2', '4', '8' ),
  *       'validators' => array ( '1', '2', '4', '8' ),
  *     ),
  *     'system' => array (
  *       'site' => array ( '1', '2', '4', '8' ),
  *     ),
  *   ),
  * );
  * </pre>
  * @param integer $groupId
  * @param array $params
  * @return array
  */
 public function modifyPermissionByPk($groupId, array $params)
 {
     if (($groupId = (int) $groupId) <= 0) {
         Log::warning(sprintf('Groups group_id "%d" must be greater than 0', $groupId), 0, __METHOD__);
         return false;
     }
     $amcas = Service::getInstance('Amcas', $this->_srvName)->findAllByRecur();
     $powerEnum = DataGroups::getPowerEnum();
     $data = array();
     foreach ($params as $appName => $mods) {
         if (!isset($amcas[$appName])) {
             Log::warning(sprintf('Groups is unable to find the app name "%s".', $appName), 0, __METHOD__);
             return false;
         }
         if (!is_array($mods)) {
             continue;
         }
         foreach ($mods as $modName => $ctrls) {
             if (!isset($amcas[$appName]['rows'][$modName])) {
                 Log::warning(sprintf('Groups is unable to find the mod name "%s-%s".', $appName, $modName), 0, __METHOD__);
                 return false;
             }
             if (!is_array($ctrls)) {
                 continue;
             }
             foreach ($ctrls as $ctrlName => $powers) {
                 if (!isset($amcas[$appName]['rows'][$modName]['rows'][$ctrlName])) {
                     Log::warning(sprintf('Groups is unable to find the ctrl name "%s-%s-%s".', $appName, $modName, $ctrlName), 0, __METHOD__);
                     return false;
                 }
                 if (!is_array($powers)) {
                     continue;
                 }
                 foreach ($powers as $power) {
                     $power = (int) $power;
                     if (!isset($powerEnum[$power])) {
                         Log::warning(sprintf('Groups is unable to find the power "%s-%s-%s-%d".', $appName, $modName, $ctrlName, $power), 0, __METHOD__);
                         return false;
                     }
                     $data[$appName][$modName][$ctrlName][] = $power;
                 }
             }
         }
     }
     $data = base64_encode(serialize($data));
     $rowCount = $this->getDb()->modifyPermissionByPk($groupId, $data);
     if ($rowCount > 0) {
         $authoriz = new Authoriz();
         if (!$authoriz->flush()) {
             Log::warning('Groups Authoriz flush roles cache Failed.', 0, __METHOD__);
         }
     }
     return $rowCount;
 }
Example #13
0
 /**
  * 投票-支持会员或游客、支持单选或多选
  * @param string $pollKey
  * @param string $value
  * @param integer $memberId
  * @param integer $rankId
  * @return array
  */
 public function addVote($pollKey, $value, $memberId, $rankId)
 {
     $row = Service::getInstance('Polls', 'poll')->findByPollKey($pollKey, false);
     if (!$row || !is_array($row) || !isset($row['poll_id']) || !isset($row['is_published'])) {
         $errNo = DataVote::ERROR_FAILED;
         return array('err_no' => $errNo, 'err_msg' => DataVote::getErrMsgByErrNo($errNo));
     }
     if (!$row['is_published']) {
         $errNo = DataVote::ERROR_DT_PUBLISH_DOWN_WRONG;
         return array('err_no' => $errNo, 'err_msg' => DataVote::getErrMsgByErrNo($errNo));
     }
     $nowTime = date('Y-m-d H:i:s');
     if ($nowTime < $row['dt_publish_up']) {
         $errNo = DataVote::ERROR_DT_PUBLISH_UP_WRONG;
         return array('err_no' => $errNo, 'err_msg' => DataVote::getErrMsgByErrNo($errNo, $row['dt_publish_up']));
     }
     if ($row['dt_publish_down'] !== '0000-00-00 00:00:00' && $nowTime > $row['dt_publish_down']) {
         $errNo = DataVote::ERROR_DT_PUBLISH_DOWN_WRONG;
         return array('err_no' => $errNo, 'err_msg' => DataVote::getErrMsgByErrNo($errNo));
     }
     $checked = array();
     foreach (explode(',', $value) as $_v) {
         if (($_v = (int) $_v) > 0 && !in_array($_v, $checked)) {
             $checked[] = $_v;
         }
     }
     $memberId = (int) $memberId;
     $rankId = (int) $rankId;
     $pollId = (int) $row['poll_id'];
     $optIds = array();
     $visitorIp = Clean::ip2long(Ap::getRequest()->getClientIp());
     $allowUnregistered = $row['allow_unregistered'];
     $isMultiple = $row['is_multiple'];
     $maxChoices = (int) $row['max_choices'];
     $joinType = isset($row['join_type']) ? $row['join_type'] : '';
     $interval = isset($row['interval']) ? (int) $row['interval'] : 0;
     $mRankIds = isset($row['m_rank_ids']) ? (array) $row['m_rank_ids'] : array();
     if ($allowUnregistered) {
         $memberId = 0;
         $rankId = 0;
     } else {
         if ($memberId <= 0) {
             $errNo = DataVote::ERROR_ALLOW_UNREGISTERED_WRONG;
             return array('err_no' => $errNo, 'err_msg' => DataVote::getErrMsgByErrNo($errNo));
         }
         if ($mRankIds !== array() && !in_array($rankId, $mRankIds)) {
             $errNo = DataVote::ERROR_M_RANK_ID_WRONG;
             return array('err_no' => $errNo, 'err_msg' => DataVote::getErrMsgByErrNo($errNo));
         }
     }
     if ($checked === array()) {
         $errNo = DataVote::ERROR_POLLOPTIONS_EMPTY;
         return array('err_no' => $errNo, 'err_msg' => DataVote::getErrMsgByErrNo($errNo));
     }
     if ($isMultiple) {
         if ($maxChoices > 0 && count($checked) > $maxChoices) {
             $errNo = DataVote::ERROR_POLLOPTIONS_WRONG;
             return array('err_no' => $errNo, 'err_msg' => DataVote::getErrMsgByErrNo($errNo, $maxChoices));
         }
     }
     $options = Service::getInstance('Polloptions', 'poll')->findAllByPollId($pollId);
     foreach ($options as $row) {
         $optId = isset($row['option_id']) ? (int) $row['option_id'] : 0;
         if (in_array($optId, $checked)) {
             $optIds[] = $optId;
         }
     }
     if ($optIds === array()) {
         $errNo = DataVote::ERROR_POLLOPTIONS_NOT_EXISTS;
         return array('err_no' => $errNo, 'err_msg' => DataVote::getErrMsgByErrNo($errNo));
     }
     if (!$isMultiple) {
         $optIds = array_shift($optIds);
     }
     $row = array();
     if ($memberId > 0) {
         $row = $this->getMemberLogs($pollId, $memberId);
     } else {
         $row = $this->getVisitorLogs($pollId, $visitorIp);
     }
     if ($row && is_array($row) && isset($row['ts_last_modified'])) {
         if (($tsLastModified = (int) $row['ts_last_modified']) > 0) {
             $errNo = DataVote::SUCCESS_NUM;
             switch ($joinType) {
                 case DataPolls::JOIN_TYPE_FOREVER:
                     $errNo = DataVote::ERROR_JOIN_TYPE_FOREVER_WRONG;
                     break;
                 case DataPolls::JOIN_TYPE_YEAR:
                     if (date('Y', $tsLastModified) === date('Y')) {
                         $errNo = DataVote::ERROR_JOIN_TYPE_YEAR_WRONG;
                     }
                     break;
                 case DataPolls::JOIN_TYPE_MONTH:
                     if (date('Ym', $tsLastModified) === date('Ym')) {
                         $errNo = DataVote::ERROR_JOIN_TYPE_MONTH_WRONG;
                     }
                     break;
                 case DataPolls::JOIN_TYPE_DAY:
                     if (date('Ymd', $tsLastModified) === date('Ymd')) {
                         $errNo = DataVote::ERROR_JOIN_TYPE_DAY_WRONG;
                     }
                     break;
                 case DataPolls::JOIN_TYPE_HOUR:
                     if (date('YmdH', $tsLastModified) === date('YmdH')) {
                         $errNo = DataVote::ERROR_JOIN_TYPE_HOUR_WRONG;
                     }
                     break;
                 case DataPolls::JOIN_TYPE_INTERVAL:
                 default:
                     if (time() - $tsLastModified <= $interval) {
                         $errNo = DataVote::ERROR_JOIN_TYPE_INTERVAL_WRONG;
                     }
             }
             if ($errNo !== DataVote::SUCCESS_NUM) {
                 return array('err_no' => $errNo, 'err_msg' => DataVote::getErrMsgByErrNo($errNo, $interval));
             }
         }
     }
     if (!$this->getDb()->addVote($pollId, $optIds, $visitorIp, $memberId)) {
         $errNo = DataVote::ERROR_FAILED;
         return array('err_no' => $errNo, 'err_msg' => DataVote::getErrMsgByErrNo($errNo));
     }
     $errNo = DataVote::SUCCESS_NUM;
     return array('err_no' => $errNo, 'err_msg' => DataVote::getErrMsgByErrNo($errNo));
 }
Example #14
0
 /**
  * (non-PHPdoc)
  * @see \libsrv\FormProcessor::_cleanPostProcess()
  */
 public function _cleanPostProcess()
 {
     if (isset($this->when)) {
         $enum = DataAddresses::getWhenEnum();
         if (!isset($enum[$this->when])) {
             $this->when = DataAddresses::WHEN_ANYONE;
         }
     }
     if (isset($this->is_default)) {
         $enum = DataAddresses::getIsDefaultEnum();
         if (!isset($enum[$this->is_default])) {
             $this->is_default = DataAddresses::IS_DEFAULT_N;
         }
     }
     if ($this->isUpdate()) {
         $row = $this->_object->findByPk($this->id);
         if (!$row || !is_array($row) || !isset($row['address_id']) || !isset($row['mobiphone']) || !isset($row['telephone'])) {
             Log::warning(sprintf('FpAddresses is unable to find the result by id "%d"', $this->id), ErrorNo::ERROR_DB_SELECT, __METHOD__);
             return false;
         }
         if (isset($this->mobiphone) && $this->mobiphone === '') {
             if (!isset($this->telephone) && $row['telephone'] === '') {
                 $this->addError('mobiphone', Lang::_('SRV_FILTER_MEMBER_ADDRESSES_MOBIPHONE_TELEPHONE_NOTEMPTY'));
                 return false;
             }
         }
         if (isset($this->telephone) && $this->telephone === '') {
             if (!isset($this->mobiphone) && $row['mobiphone'] === '') {
                 $this->addError('telephone', Lang::_('SRV_FILTER_MEMBER_ADDRESSES_MOBIPHONE_TELEPHONE_NOTEMPTY'));
                 return false;
             }
         }
         $consignee = isset($this->consignee) ? $this->consignee : $row['consignee'];
     }
     if (isset($this->mobiphone) && $this->mobiphone === '' && (isset($this->telephone) && $this->telephone === '')) {
         $this->addError('mobiphone', Lang::_('SRV_FILTER_MEMBER_ADDRESSES_MOBIPHONE_TELEPHONE_NOTEMPTY'));
         $this->addError('telephone', Lang::_('SRV_FILTER_MEMBER_ADDRESSES_MOBIPHONE_TELEPHONE_NOTEMPTY'));
         return false;
     }
     if ($this->isInsert()) {
         $consignee = $this->consignee;
     }
     if ($this->isUpdate()) {
         if (!isset($this->addr_country_id) && !isset($this->addr_province_id) && !isset($this->addr_city_id) && !isset($this->addr_district_id)) {
             $this->address_name = $consignee . '-' . $row['addr_city'];
             return true;
         }
     }
     if (!isset($this->addr_country_id)) {
         $this->addr_country_id = 1;
     }
     if (!isset($this->addr_province_id)) {
         $this->addr_province_id = 0;
     }
     if (!isset($this->addr_city_id)) {
         $this->addr_city_id = 0;
     }
     if (!isset($this->addr_district_id)) {
         $this->addr_district_id = 0;
     }
     $addrCountryId = $this->addr_country_id;
     $addrProvinceId = $this->addr_province_id;
     $addrCityId = $this->addr_city_id;
     $addrDistrictId = $this->addr_district_id;
     $srv = Service::getInstance('Regions', 'system');
     $this->addr_country = $this->addr_province = $this->addr_city = $this->addr_district = '';
     $row = $srv->findByPk($addrCountryId);
     if ($row && is_array($row) && isset($row['region_pid'], $row['region_name'], $row['region_type'])) {
         if ((int) $row['region_pid'] === 0 && (int) $row['region_type'] === 0) {
             $this->addr_country = $row['region_name'];
         }
     }
     if ($this->addr_country === '') {
         $this->addError('addr_country_id', Lang::_('SRV_FILTER_MEMBER_ADDRESSES_ADDR_ID_INTEGER'));
         return false;
     }
     $row = $srv->findByPk($addrProvinceId);
     if ($row && is_array($row) && isset($row['region_pid'], $row['region_name'], $row['region_type'])) {
         if ((int) $row['region_pid'] === $addrCountryId && (int) $row['region_type'] === 1) {
             $this->addr_province = $row['region_name'];
         }
     }
     if ($this->addr_province === '') {
         $this->addError('addr_province_id', Lang::_('SRV_FILTER_MEMBER_ADDRESSES_ADDR_ID_INTEGER'));
         return false;
     }
     $row = $srv->findByPk($addrCityId);
     if ($row && is_array($row) && isset($row['region_pid'], $row['region_name'], $row['region_type'])) {
         if ((int) $row['region_pid'] === $addrProvinceId && (int) $row['region_type'] === 2) {
             $this->addr_city = $row['region_name'];
         }
     }
     if ($this->addr_city === '') {
         $this->addError('addr_city_id', Lang::_('SRV_FILTER_MEMBER_ADDRESSES_ADDR_ID_INTEGER'));
         return false;
     }
     $row = $srv->findByPk($addrDistrictId);
     if ($row && is_array($row) && isset($row['region_pid'], $row['region_name'], $row['region_type'])) {
         if ((int) $row['region_pid'] === $addrCityId && (int) $row['region_type'] === 3) {
             $this->addr_district = $row['region_name'];
         }
     }
     if ($this->addr_district === '') {
         $this->addError('addr_district_id', Lang::_('SRV_FILTER_MEMBER_ADDRESSES_ADDR_ID_INTEGER'));
         return false;
     }
     $this->address_name = $consignee . '-' . $this->addr_city;
     return true;
 }
Example #15
0
 /**
  * 通过“主键ID”,获取“文档扩展字段”
  * @param integer $postId
  * @return array
  */
 public function getModuleFieldsByPostId($postId)
 {
     $moduleId = $this->getModuleIdByPostId($postId);
     if ($moduleId <= 0) {
         return array();
     }
     $value = Service::getInstance('Modules', 'posts')->getFieldsByModuleId($moduleId);
     return is_array($value) ? $value : array();
 }
Example #16
0
 /**
  * 新增或编辑后执行
  * @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);
 }
Example #17
0
 /**
  * 通过位置Key,查询广告数
  * @param string $typeKey
  * @return integer
  */
 public function getAdvertCount($typeKey)
 {
     return Service::getInstance('Adverts', 'advert')->countByTypeKey($typeKey);
 }
Example #18
0
 /**
  * 获取“字段类型ID”验证规则
  * @param mixed $value
  * @return array
  */
 public function getTypeIdRule($value)
 {
     $enum = Service::getInstance('Types', 'builders')->getTypeNames();
     return array('InArray' => new validator\InArrayValidator($value, array_keys($enum), Lang::_('SRV_FILTER_BUILDER_FIELDS_TYPE_ID_INARRAY')));
 }
Example #19
0
 /**
  * 获取业务处理类
  * @return instance of srv\srvname\services\Types
  */
 public function getService()
 {
     if ($this->_service === null) {
         $this->_service = Service::getInstance($this->_className, $this->_srvName);
     }
     return $this->_service;
 }
Example #20
0
 /**
  * 通过主键,编辑会员成长度ID
  * @param integer $memberId
  * @param integer $rankId
  * @return integer
  */
 public function modifyRankId($memberId, $rankId)
 {
     $row = Service::getInstance('Ranks', 'member')->findByPk($rankId);
     if ($row && is_array($row) && isset($row['rank_id'])) {
         $rowCount = $this->getDb()->modifyRankId($memberId, $rankId);
         return $rowCount;
     }
     return false;
 }
Example #21
0
 /**
  * 通过类别ID,查询文档数
  * @param integer $categoryId
  * @return integer
  */
 public function getPostCount($categoryId)
 {
     return Service::getInstance('Posts', 'posts')->countByCategoryId($categoryId);
 }
Example #22
0
 /**
  * 获取菜单业务处理类
  * @return \menus\services\Menus
  */
 public static function getService()
 {
     static $service = null;
     if ($service === null) {
         $service = Service::getInstance('Menus', 'menus');
     }
     return $service;
 }
Example #23
0
 /**
  * 通过表Metadata生成Builders数据
  * @param string $tblName
  * @return void
  */
 public function gb($tblName)
 {
     Ap::getResponse()->contentType();
     $tableNames = $this->_metadata->getTableNames($tblName);
     if (!in_array($tblName, $tableNames)) {
         Log::errExit(__LINE__, 'Table Name Not Exists!');
     }
     Log::echoTrace('Generate Begin, Table Name "' . $tblName . '"');
     $tableSchema = $this->_metadata->getTableSchema($tblName);
     $comments = $this->_metadata->getComments($tableSchema->name);
     $tblPrefix = $this->getDbProxy()->getTblprefix();
     $tblPreLen = strlen($tblPrefix);
     Log::echoTrace('Import to builders Begin ...');
     $params = array('builder_name' => isset($comments['__table__']) ? $comments['__table__'] : $tableSchema->name, 'tbl_name' => substr($tableSchema->name, $tblPreLen), 'tbl_profile' => DataBuilders::TBL_PROFILE_N, 'tbl_engine' => DataBuilders::TBL_ENGINE_INNODB, 'tbl_charset' => DataBuilders::TBL_CHARSET_UTF8, 'tbl_comment' => isset($comments['__table__']) ? $comments['__table__'] : '', 'srv_type' => DataBuilders::SRV_TYPE_NORMAL, 'srv_name' => 'undefined', 'app_name' => 'administrator', 'mod_name' => 'undefined', 'ctrl_name' => substr($tableSchema->name, strrpos($tableSchema->name, '_') + 1), 'cls_name' => substr($tableSchema->name, strrpos($tableSchema->name, '_') + 1), 'fk_column' => '', 'act_index_name' => 'index', 'act_view_name' => 'view', 'act_create_name' => 'create', 'act_modify_name' => 'modify', 'act_remove_name' => 'remove', 'index_row_btns' => array(DataBuilders::INDEX_ROW_BTNS_PENCIL, DataBuilders::INDEX_ROW_BTNS_REMOVE), 'description' => '', 'author_name' => UserIdentity::getNick(), 'author_mail' => UserIdentity::getName());
     $mod = Service::getInstance('Builders', $this->_srvName);
     $builderId = $mod->create($params);
     if ($builderId > 0) {
         Log::echoTrace('Import to builders Successfully ...');
     } else {
         $errors = $mod->getErrors();
         Log::errExit(__LINE__, 'Import to builders Failed! ' . serialize($errors));
     }
     Log::echoTrace('Import to builder_fields Begin ...');
     $sort = 0;
     foreach ($tableSchema->columns as $columnSchema) {
         $sort++;
         if ($columnSchema->type === 'integer') {
             $columnLength = $columnSchema->size;
         } elseif (stripos($columnSchema->dbType, 'enum') !== false) {
             $columnLength = str_replace(array('\'', ','), array('', '|'), substr(substr($columnSchema->dbType, 5), 0, -1));
         } elseif (stripos($columnSchema->dbType, 'char') !== false) {
             $columnLength = $columnSchema->size;
         } else {
             $columnLength = '';
         }
         if ($columnSchema->isPrimaryKey) {
             $formRequired = DataFields::FORM_REQUIRED_N;
         } elseif (stripos($columnSchema->dbType, 'enum') !== false) {
             $formRequired = DataFields::FORM_REQUIRED_N;
         } else {
             $formRequired = DataFields::FORM_REQUIRED_Y;
         }
         if ($columnLength === 'y|n') {
             $typeId = 4;
         } elseif (stripos($columnSchema->dbType, 'enum') !== false) {
             $typeId = 5;
         } elseif ($columnSchema->isPrimaryKey) {
             $typeId = 9;
         } elseif ($columnSchema->type === 'integer') {
             $typeId = 2;
         } elseif (in_array($columnSchema->dbType, array('text', 'longtext'))) {
             $typeId = 10;
         } else {
             $typeId = 1;
         }
         $params = array('field_name' => $columnSchema->name, 'column_length' => $columnLength, 'column_auto_increment' => $columnSchema->isAutoIncrement ? DataFields::COLUMN_AUTO_INCREMENT_Y : DataFields::COLUMN_AUTO_INCREMENT_N, 'column_unsigned' => stripos($columnSchema->dbType, 'unsigned') !== false ? DataFields::COLUMN_UNSIGNED_Y : DataFields::COLUMN_UNSIGNED_N, 'column_comment' => isset($comments[$columnSchema->name]) ? $comments[$columnSchema->name] : '', 'builder_id' => $builderId, 'group_id' => 1, 'type_id' => $typeId, 'sort' => $sort, 'html_label' => isset($comments[$columnSchema->name]) ? $comments[$columnSchema->name] : $columnSchema->name, 'form_prompt' => '', 'form_required' => $formRequired, 'form_modifiable' => DataFields::FORM_MODIFIABLE_N, 'index_show' => DataFields::INDEX_SHOW_Y, 'index_sort' => $columnSchema->isPrimaryKey ? 1000 : $sort, 'form_create_show' => $columnSchema->isPrimaryKey ? DataFields::FORM_CREATE_SHOW_N : DataFields::FORM_CREATE_SHOW_Y, 'form_create_sort' => $sort, 'form_modify_show' => $columnSchema->isPrimaryKey ? DataFields::FORM_MODIFY_SHOW_N : DataFields::FORM_MODIFY_SHOW_Y, 'form_modify_sort' => $sort, 'form_search_show' => DataFields::FORM_SEARCH_SHOW_Y, 'form_search_sort' => $sort);
         $mod = Service::getInstance('Fields', $this->_srvName);
         $fieldId = $mod->create($params);
         if ($fieldId > 0) {
             Log::echoTrace('Import to builder_fields "' . $columnSchema->name . '" Successfully ...');
         } else {
             $errors = $mod->getErrors();
             Log::errExit(__LINE__, 'Import to builder_fields "' . $columnSchema->name . '" Failed! ' . serialize($errors));
         }
     }
     Log::echoTrace('Import to builder_fields Successfully ...');
     Log::echoTrace('Generate End, Table Name "' . $tblName . '"');
     exit;
 }
Example #24
0
 /**
  * 通过类型Key,查询菜单数
  * @param string $typeKey
  * @return integer
  */
 public function getMenuCount($typeKey)
 {
     return Service::getInstance('Menus', 'menus')->countByTypeKey($typeKey);
 }
Example #25
0
 /**
  * 获取“上次编辑人ID”验证规则
  * @param mixed $value
  * @return array
  */
 public function getLastModifierIdRule($value)
 {
     $columnName = 'last_modifier_id';
     if (($value = (int) $value) <= 0) {
         $this->addError($columnName, Lang::_('SRV_FILTER_POSTS_LAST_MODIFIER_ID_EXISTS'));
     }
     $userName = Service::getInstance('Users', 'users')->getUserNameByUserId($value);
     if ($userName === '') {
         $this->addError($columnName, Lang::_('SRV_FILTER_POSTS_LAST_MODIFIER_ID_EXISTS'));
     }
     $this->{$columnName} = $value;
     $this->last_modifier_name = $userName;
     return array();
 }