/**
  * Uninstall plugin
  *
  * @param Model $model Model using this behavior
  * @param array $data Plugin data
  * @return bool True on success
  * @throws InternalErrorException
  */
 public function uninstallPlugin(Model $model, $data)
 {
     $model->loadModels(['Plugin' => 'PluginManager.Plugin', 'PluginsRole' => 'PluginManager.PluginsRole', 'PluginsRoom' => 'PluginManager.PluginsRoom']);
     //トランザクションBegin
     $model->setDataSource('master');
     $dataSource = $model->getDataSource();
     $dataSource->begin();
     if (is_string($data)) {
         $key = $data;
     } else {
         $key = $data[$model->alias]['key'];
     }
     try {
         //Pluginの削除
         if (!$model->deleteAll(array($model->alias . '.key' => $key), false)) {
             throw new InternalErrorException(__d('net_commons', 'Internal Server Error'));
         }
         //PluginsRoomの削除
         if (!$model->PluginsRoom->deleteAll(array($model->PluginsRoom->alias . '.plugin_key' => $key), false)) {
             throw new InternalErrorException(__d('net_commons', 'Internal Server Error'));
         }
         //PluginsRoleの削除
         if (!$model->PluginsRole->deleteAll(array($model->PluginsRole->alias . '.plugin_key' => $key), false)) {
             throw new InternalErrorException(__d('net_commons', 'Internal Server Error'));
         }
         //トランザクションCommit
         $dataSource->commit();
     } catch (Exception $ex) {
         //トランザクションRollback
         $dataSource->rollback();
         CakeLog::error($ex);
         throw $ex;
     }
     return true;
 }
 /**
  * beforeValidate is called before a model is validated, you can use this callback to
  * add behavior validation rules into a models validate array. Returning false
  * will allow you to make the validation fail.
  *
  * @param Model $model Model using this behavior
  * @param array $options Options passed from Model::save().
  * @return mixed False or null will abort the operation. Any other result will continue.
  * @see Model::save()
  */
 public function beforeValidate(Model $model, $options = array())
 {
     $model->loadModels(array('CircularNoticeContent' => 'CircularNotices.CircularNoticeContent', 'CircularNoticeTargetUser' => 'CircularNotices.CircularNoticeTargetUser', 'User' => 'Users.User'));
     if (!$model->data['CircularNoticeContent']['is_room_target']) {
         // 回覧先ユーザのバリデーション処理
         if (!isset($model->data['CircularNoticeTargetUser'])) {
             $model->data['CircularNoticeTargetUser'] = array();
         }
         $model->CircularNoticeTargetUser->set($model->data['CircularNoticeTargetUser']);
         // ユーザ選択チェック
         $targetUsers = Hash::extract($model->data['CircularNoticeTargetUser'], '{n}.user_id');
         if (!$model->CircularNoticeTargetUser->isUserSelected($targetUsers)) {
             $model->CircularNoticeTargetUser->validationErrors['user_id'] = sprintf(__d('circular_notices', 'Select user'));
             $model->validationErrors = Hash::merge($model->validationErrors, $model->CircularNoticeTargetUser->validationErrors);
             return false;
         }
         if (!$model->CircularNoticeTargetUser->validates()) {
             $model->validationErrors = Hash::merge($model->validationErrors, $model->CircularNoticeTargetUser->validationErrors);
             return false;
         }
         if (!$model->User->existsUser($targetUsers)) {
             $model->CircularNoticeTargetUser->validationErrors['user_id'][] = sprintf(__d('net_commons', 'Failed on validation errors. Please check the input data.'));
             $model->validationErrors = Hash::merge($model->validationErrors, $model->CircularNoticeTargetUser->validationErrors);
             return false;
         }
     }
     return true;
 }
 /**
  * Save BbsArticlesUser
  *
  * @param object $model instance of model
  * @param array $bbsArticleKey received bbs_article_key
  * @return mixed On success Model::$data if its not empty or true, false on failure
  * @throws InternalErrorException
  */
 public function readToArticle(Model $model, $bbsArticleKey)
 {
     $model->loadModels(['BbsArticlesUser' => 'Bbses.BbsArticlesUser']);
     //既読チェック
     if (!Current::read('User.id')) {
         return true;
     }
     $count = $model->BbsArticlesUser->find('count', array('recursive' => -1, 'conditions' => array('bbs_article_key' => $bbsArticleKey, 'user_id' => Current::read('User.id'))));
     if ($count > 0) {
         return true;
     }
     //トランザクションBegin
     $model->BbsArticlesUser->begin();
     //バリデーション
     $data = $model->BbsArticlesUser->create(array('bbs_article_key' => $bbsArticleKey, 'user_id' => Current::read('User.id')));
     $model->BbsArticlesUser->set($data);
     if (!$model->BbsArticlesUser->validates()) {
         $model->BbsArticlesUser->rollback();
         return false;
     }
     try {
         if (!$model->BbsArticlesUser->save(null, false)) {
             throw new InternalErrorException(__d('net_commons', 'Internal Server Error'));
         }
         //トランザクションCommit
         $model->BbsArticlesUser->commit();
     } catch (Exception $ex) {
         //トランザクションRollback
         $model->BbsArticlesUser->rollback($ex);
     }
     return true;
 }
 /**
  * afterSave is called after a model is saved.
  *
  * @param Model $model Model using this behavior
  * @param bool $created True if this save created a new record
  * @param array $options Options passed from Model::save().
  * @return bool
  * @throws InternalErrorException
  * @see Model::save()
  */
 public function afterSave(Model $model, $created, $options = array())
 {
     if (!isset($model->data['Categories'])) {
         return true;
     }
     $model->loadModels(array('Category' => 'Categories.Category', 'CategoryOrder' => 'Categories.CategoryOrder'));
     $categoryKeys = Hash::combine($model->data['Categories'], '{n}.Category.key', '{n}.Category.key');
     //削除処理
     $conditions = array('block_id' => $model->data['Block']['id']);
     if ($categoryKeys) {
         $conditions[$model->Category->alias . '.key NOT'] = $categoryKeys;
     }
     if (!$model->Category->deleteAll($conditions, false)) {
         throw new InternalErrorException(__d('net_commons', 'Internal Server Error'));
     }
     $conditions = array('block_key' => $model->data['Block']['key']);
     if ($categoryKeys) {
         $conditions[$model->CategoryOrder->alias . '.category_key NOT'] = $categoryKeys;
     }
     if (!$model->CategoryOrder->deleteAll($conditions, false)) {
         throw new InternalErrorException(__d('net_commons', 'Internal Server Error'));
     }
     //登録処理
     foreach ($model->data['Categories'] as $category) {
         if (!($result = $model->Category->save($category['Category'], false))) {
             throw new InternalErrorException(__d('net_commons', 'Internal Server Error'));
         }
         $category['CategoryOrder']['category_key'] = $result['Category']['key'];
         if (!$model->CategoryOrder->save($category['CategoryOrder'], false)) {
             throw new InternalErrorException(__d('net_commons', 'Internal Server Error'));
         }
     }
     return parent::afterSave($model, $created, $options);
 }
 /**
  * UserAttributesRoleのデフォルト値
  *
  * * パスワード=自分/他人とも読み取り不可
  * * ラベル項目=自分/他人とも書き込み不可
  * * 会員管理が使用可=上記以外、自分・他人とも自分/他人の読み・書き可
  * * 会員管理が使用不可
  * ** 管理者以外、読み取り不可項目とする=自分/他人の読み・書き不可。※読めないのに書けるはあり得ないため。
  * ** 管理者以外、書き込み不可項目とする=自分/他人の書き込み不可。
  * ** 上記以外
  * *** ハンドル・アバター=自分は、読み・書き可。他人は、読み取り可/書き込み不可。
  * *** それ以外=自分は、読み・書き可。他人は、読み・書き不可。
  *
  * @param Model $model Model using this behavior
  * @param array|string $userAttrSetting 配列:ユーザ属性設定データ、文字列:ユーザ属性キー
  * @param bool $enableUserManager 有効かどうか
  * @return array ユーザ属性ロールデータ
  */
 public function defaultUserAttributeRole(Model $model, $userAttrSetting, $enableUserManager)
 {
     $model->loadModels(['UserAttributeSetting' => 'UserAttributes.UserAttributeSetting']);
     $userAttrSetting = $model->UserAttributeSetting->create($userAttrSetting);
     $userAttributeRole = array();
     $userAttributeRole['UserAttributesRole']['self_readable'] = true;
     $userAttributeRole['UserAttributesRole']['self_editable'] = true;
     $userAttributeKey = $userAttrSetting['UserAttributeSetting']['user_attribute_key'];
     if ($userAttributeKey === UserAttribute::PASSWORD_FIELD) {
         $userAttributeRole['UserAttributesRole']['self_readable'] = false;
         $userAttributeRole['UserAttributesRole']['other_readable'] = false;
     } elseif ($enableUserManager) {
         $userAttributeRole['UserAttributesRole']['other_readable'] = true;
     } elseif (Hash::get($userAttrSetting, 'UserAttributeSetting.only_administrator_readable')) {
         $userAttributeRole['UserAttributesRole']['self_readable'] = false;
         $userAttributeRole['UserAttributesRole']['other_readable'] = false;
         $userAttrSetting['UserAttributeSetting']['only_administrator_editable'] = true;
     } else {
         $userAttributeRole['UserAttributesRole']['self_readable'] = true;
         $userAttributeRole['UserAttributesRole']['other_readable'] = in_array($userAttributeKey, $this->readableDefault, true);
     }
     $userAttributeRole['UserAttributesRole']['other_editable'] = false;
     if ($userAttrSetting['UserAttributeSetting']['data_type_key'] === DataType::DATA_TYPE_LABEL) {
         $userAttributeRole['UserAttributesRole']['self_editable'] = false;
     } elseif ($enableUserManager) {
         $userAttributeRole['UserAttributesRole']['other_editable'] = true;
     } elseif (Hash::get($userAttrSetting, 'UserAttributeSetting.only_administrator_editable')) {
         $userAttributeRole['UserAttributesRole']['self_editable'] = false;
     }
     return $userAttributeRole;
 }
 /**
  * キュー削除
  *
  * @param Model $model モデル
  * @param string $value 削除条件の値
  * @param string $deleteColum 削除カラム
  * @return void
  * @throws InternalErrorException
  */
 public function deleteQueue(Model $model, $value, $deleteColum = 'content_key')
 {
     $model->loadModels(['MailQueue' => 'Mails.MailQueue', 'MailQueueUser' => 'Mails.MailQueueUser']);
     // キューの配信先 削除
     $conditions = array($model->MailQueueUser->alias . '.' . $deleteColum => $value);
     if (!$model->MailQueueUser->deleteAll($conditions, false)) {
         throw new InternalErrorException('Failed - MailQueueUser ' . __METHOD__);
     }
     // キュー 削除
     $conditions = array($model->MailQueue->alias . '.' . $deleteColum => $value);
     if (!$model->MailQueue->deleteAll($conditions, false)) {
         throw new InternalErrorException('Failed - MailQueue  ' . __METHOD__);
     }
 }
Example #7
0
 /**
  * beforeValidate is called before a model is validated, you can use this callback to
  * add behavior validation rules into a models validate array. Returning false
  * will allow you to make the validation fail.
  *
  * @param Model $model Model using this behavior
  * @param array $options Options passed from Model::save().
  * @return mixed False or null will abort the operation. Any other result will continue.
  * @see Model::save()
  */
 public function beforeValidate(Model $model, $options = array())
 {
     $model->loadModels(array('Group' => 'Groups.Group', 'GroupsUser' => 'Groups.GroupsUser', 'User' => 'Users.User'));
     $model->Group->set($model->Group->data['Group']);
     if (!isset($model->data['GroupsUser'])) {
         $model->data['GroupsUser'] = array();
     }
     $model->GroupsUser->set($model->data['GroupsUser']);
     if (!$model->GroupsUser->validates()) {
         $model->validationErrors = Hash::merge($model->validationErrors, $model->GroupsUser->validationErrors);
         return false;
     }
     return true;
 }
 /**
  * beforeValidate is called before a model is validated, you can use this callback to
  * add behavior validation rules into a models validate array. Returning false
  * will allow you to make the validation fail.
  *
  * @param Model $model Model using this behavior
  * @param array $options Options passed from Model::save().
  * @return mixed False or null will abort the operation. Any other result will continue.
  * @see Model::save()
  */
 public function beforeValidate(Model $model, $options = array())
 {
     if (!isset($model->data['BlockRolePermission'])) {
         return true;
     }
     $model->loadModels(array('BlockRolePermission' => 'Blocks.BlockRolePermission'));
     foreach ($model->data[$model->BlockRolePermission->alias] as $permission) {
         if (!$model->BlockRolePermission->validateMany($permission)) {
             $model->validationErrors = Hash::merge($model->validationErrors, $model->BlockRolePermission->validationErrors);
             return false;
         }
     }
     return true;
 }
 /**
  * Save default UserAttributeRoles
  *
  * @param Model $model Model using this behavior
  * @param array $data User role data
  * @return bool True on success
  * @throws InternalErrorException
  */
 public function saveDefaultUserAttributeRoles(Model $model, $data)
 {
     $model->loadModels(['UserRoleSetting' => 'UserRoles.UserRoleSetting', 'UserAttributesRole' => 'UserRoles.UserAttributesRole', 'PluginsRole' => 'PluginManager.PluginsRole']);
     $pluginsRoles = $model->PluginsRole->find('all', array('recursive' => -1, 'conditions' => array('plugin_key' => 'user_manager')));
     $userRoleSettings = $model->UserRoleSetting->find('all', array('recursive' => -1));
     foreach ($userRoleSettings as $userRoleSetting) {
         $params = array('role_key' => $userRoleSetting['UserRoleSetting']['role_key'], 'origin_role_key' => $userRoleSetting['UserRoleSetting']['origin_role_key'], 'user_attribute_key' => $data['UserAttributeSetting']['user_attribute_key'], 'only_administrator' => (bool) $data['UserAttributeSetting']['only_administrator'], 'is_systemized' => (bool) $data['UserAttributeSetting']['is_systemized']);
         $params['is_usable_user_manager'] = (bool) Hash::extract($pluginsRoles, '{n}.PluginsRole[role_key=' . $params['role_key'] . ']');
         $userAttributeRole = $model->UserAttributesRole->defaultUserAttributeRolePermissions($params);
         if (!$model->UserAttributesRole->save($userAttributeRole, array('validate' => false))) {
             throw new InternalErrorException(__d('net_commons', 'Internal Server Error'));
         }
     }
     return true;
 }
 /**
  *  ルームの容量の登録
  *
  * @param Model $model ビヘイビア呼び出し元モデル
  * @param array $data リクエストデータ配列
  * @return array リクエストデータ
  * @throws InternalErrorException
  */
 public function saveRoomDiskSize(Model $model, $data)
 {
     if (!isset($data[$model->alias]['App.disk_for_group_room']) || !isset($data[$model->alias]['App.disk_for_private_room'])) {
         return $data;
     }
     $model->loadModels(['Space' => 'Rooms.Space']);
     $spaces = array('App.disk_for_group_room' => Space::ROOM_SPACE_ID, 'App.disk_for_private_room' => Space::PRIVATE_SPACE_ID);
     foreach ($spaces as $key => $spaceId) {
         $value = (int) Hash::get($data[$model->alias][$key], '0.value');
         if ($value < 0) {
             $value = null;
         }
         $model->Space->id = $spaceId;
         if (!$model->Space->saveField('room_disk_size', $value)) {
             throw new InternalErrorException(__d('net_commons', 'Internal Server Error'));
         }
         unset($data[$model->alias][$key]);
     }
     return $data;
 }
 /**
  * 自動登録メール件名・本文の登録
  *
  * @param Model $model ビヘイビア呼び出し元モデル
  * @param array $data リクエストデータ配列
  * @return array リクエストデータ
  * @throws InternalErrorException
  */
 public function saveUserRegistMail(Model $model, $data)
 {
     if (!isset($data[$model->alias]['UserRegist.mail_subject']) || !isset($data[$model->alias]['UserRegist.mail_body'])) {
         return $data;
     }
     $model->loadModels(['MailSettingFixedPhrase' => 'Mails.MailSettingFixedPhrase']);
     $mails = $model->MailSettingFixedPhrase->find('all', array('recursive' => -1, 'conditions' => array('plugin_key' => 'user_manager', 'type_key' => 'save_notify')));
     foreach ($mails as $index => $mail) {
         $langId = $mail['MailSettingFixedPhrase']['language_id'];
         $subject = $data[$model->alias]['UserRegist.mail_subject'][$langId]['value'];
         $body = $data[$model->alias]['UserRegist.mail_body'][$langId]['value'];
         $mails[$index]['MailSettingFixedPhrase']['mail_fixed_phrase_subject'] = $subject;
         $mails[$index]['MailSettingFixedPhrase']['mail_fixed_phrase_body'] = $body;
     }
     if (!$model->MailSettingFixedPhrase->saveMany($mails)) {
         throw new InternalErrorException(__d('net_commons', 'Internal Server Error'));
     }
     unset($data[$model->alias]['UserRegist.mail_subject']);
     unset($data[$model->alias]['UserRegist.mail_body']);
     return $data;
 }
Example #12
0
 /**
  * usersテーブルに関連するテーブル削除
  *
  * @param Model $model ビヘイビア呼び出し元モデル
  * @param int $userId ユーザID
  * @return bool True on success
  * @throws InternalErrorException
  */
 public function deleteUserAssociations(Model $model, $userId)
 {
     $models = array('UsersLanguage' => 'Users.UsersLanguage', 'RolesRoomsUser' => 'Rooms.RolesRoomsUser');
     $model->loadModels($models);
     $modelNames = array_keys($models);
     foreach ($modelNames as $modelName) {
         $conditions = array($model->{$modelName}->alias . '.user_id' => $userId);
         if (!$model->{$modelName}->deleteAll($conditions, false)) {
             throw new InternalErrorException(__d('net_commons', 'Internal Server Error'));
         }
     }
     ////user_idがついているテーブルに対して削除する(必要ない?)
     //$tables = $model->query('SHOW TABLES');
     //foreach ($tables as $table) {
     //	$tableName = array_shift($table['TABLE_NAMES']);
     //	$columns = $model->query('SHOW COLUMNS FROM ' . $tableName);
     //	if (! Hash::check($columns, '{n}.COLUMNS[Field=user_id]')) {
     //		continue;
     //	}
     //
     //	$model->query('DELETE FROM ' . $tableName . ' WHERE user_id = ' . $userId);
     //}
     return true;
 }
 /**
  * Delete comments by content key
  *
  * @param Model $model Model using this behavior
  * @param string $contentKey content key
  * @return bool True on success
  * @throws InternalErrorException
  */
 public function deleteCommentsByContentKey(Model $model, $contentKey)
 {
     $model->loadModels(array('WorkflowComment' => 'Workflow.WorkflowComment'));
     $conditions = array($model->WorkflowComment->alias . '.content_key' => $contentKey);
     if (!$model->WorkflowComment->deleteAll($conditions, false, false)) {
         throw new InternalErrorException(__d('net_commons', 'Internal Server Error'));
     }
     return true;
 }
Example #14
0
 /**
  * setup
  *
  * #### サンプルコード
  * ##### Model
  * ```php
  * public $actsAs = array(
  *	'Mails.MailQueue' => array(
  *		'embedTags' => array(
  *			'X-SUBJECT' => 'Video.title',
  *			'X-BODY' => 'Video.description',
  *		),
  * 		// アンケート回答、登録フォーム回答時は指定
  * 		//'workflowType' => MailQueueBehavior::MAIL_QUEUE_WORKFLOW_TYPE_ANSWER,
  * 		// アンケートの未来公開日は指定
  * 		//'publishStartField' => 'answer_start_period',
  * 		// 動画のような{X-BODY}がウィジウィグでない時は指定
  * 		//'embedTagsWysiwyg' => array(),
  * 		// FAQのような{X-BODY}でない箇所がウィジウィグの時に指定
  * 		//'embedTagsWysiwyg' => array('X-ANSWER'),
  *	),
  * ```
  * 注意事項:ワークフロー利用時はWorkflow.Workflowより下に記述
  *
  * @param Model $model モデル
  * @param array $settings 設定値
  * @return void
  * @link http://book.cakephp.org/2.0/ja/models/behaviors.html#ModelBehavior::setup
  */
 public function setup(Model $model, $settings = array())
 {
     $this->settings[$model->alias] = $settings;
     $workflowTypeKey = self::MAIL_QUEUE_SETTING_WORKFLOW_TYPE;
     // --- 設定ないパラメータの処理
     if (!isset($this->settings[$model->alias][$workflowTypeKey])) {
         // --- ワークフローのstatusによって送信内容を変える
         if ($model->Behaviors->loaded('Workflow.Workflow')) {
             $this->settings[$model->alias][$workflowTypeKey] = self::MAIL_QUEUE_WORKFLOW_TYPE_WORKFLOW;
         } else {
             $this->settings[$model->alias][$workflowTypeKey] = self::MAIL_QUEUE_WORKFLOW_TYPE_NONE;
         }
     }
     // メール定型文の種類
     if (!isset($this->settings[$model->alias]['typeKey'])) {
         if ($this->settings[$model->alias][$workflowTypeKey] == self::MAIL_QUEUE_WORKFLOW_TYPE_ANSWER) {
             // 回答タイプ
             $this->settings[$model->alias]['typeKey'] = MailSettingFixedPhrase::ANSWER_TYPE;
         }
     }
     // 埋め込みタグのウィジウィグ対象(メール送信プレーンテキストの時、strap_tagsされる対象)
     if (!isset($this->settings[$model->alias]['embedTagsWysiwyg'])) {
         $this->settings[$model->alias]['embedTagsWysiwyg'] = array('X-BODY');
     }
     $this->_defaultSettings['pluginKey'] = Current::read('Plugin.key');
     $this->_defaultSettings[self::MAIL_QUEUE_SETTING_PLUGIN_NAME] = Current::read('Plugin.Name');
     $this->settings[$model->alias] = Hash::merge($this->_defaultSettings, $this->settings[$model->alias]);
     $model->loadModels(['MailSetting' => 'Mails.MailSetting', 'MailQueue' => 'Mails.MailQueue', 'MailQueueUser' => 'Mails.MailQueueUser', 'SiteSetting' => 'SiteManager.SiteSetting']);
 }
 /**
  * Delete plugin data by room id
  *
  * @param Model $model Model using this behavior
  * @param int $roomId rooms.id
  * @return bool True on success
  * @throws InternalErrorException
  */
 public function deletePluginByRoom(Model $model, $roomId)
 {
     $model->loadModels([]);
     return (bool) $roomId;
     //return true;
 }
Example #16
0
 /**
  * setup
  *
  * @param Model $model モデル
  * @param array $settings 設定値
  * @return void
  * @link http://book.cakephp.org/2.0/ja/models/behaviors.html#ModelBehavior::setup
  */
 public function setup(Model $model, $settings = array())
 {
     $this->settings[$model->alias] = $settings;
     $model->loadModels(['MailSetting' => 'Mails.MailSetting', 'MailQueue' => 'Mails.MailQueue', 'MailQueueUser' => 'Mails.MailQueueUser', 'SiteSetting' => 'SiteManager.SiteSetting', 'BlockSetting' => 'Blocks.BlockSetting']);
 }
 /**
  * afterSave is called after a model is saved.
  *
  * @param Model $model Model using this behavior
  * @param bool $created True if this save created a new record
  * @param array $options Options passed from Model::save().
  * @return bool
  * @throws InternalErrorException
  * @see Model::save()
  */
 public function afterSave(Model $model, $created, $options = array())
 {
     if (!isset($model->data['BlockRolePermission'])) {
         return true;
     }
     $model->loadModels(array('BlockRolePermission' => 'Blocks.BlockRolePermission'));
     foreach ($model->data['BlockRolePermission'] as $permission) {
         if (!$model->BlockRolePermission->saveMany($permission, ['validate' => false])) {
             throw new InternalErrorException(__d('net_commons', 'Internal Server Error'));
         }
     }
     return parent::afterSave($model, $created, $options);
 }
 /**
  * Save default RoomRolePermissions
  *
  * @param Model $model Model using this behavior
  * @param array $data Room data
  * @return bool True on success
  * @throws InternalErrorException
  */
 public function saveDefaultPage(Model $model, $data)
 {
     $model->loadModels(['Page' => 'Pages.Page']);
     $slug = $model->generateKey();
     $page = Hash::merge(array('Page' => array('slug' => $slug, 'permalink' => $slug, 'room_id' => $data['Room']['id'], 'parent_id' => $data['Page']['parent_id']), 'LanguagesPage' => array('language_id' => Configure::read('Config.languageId'), 'name' => __d('rooms', 'Top'))), $data);
     if (!($page = $model->Page->savePage($page, array('atomic' => false)))) {
         throw new InternalErrorException(__d('net_commons', 'Internal Server Error'));
     }
     if (!$model->Room->updateAll(array($model->Room->alias . '.page_id_top' => $page['Page']['id']), array($model->Room->alias . '.id' => $data['Room']['id']))) {
         throw new InternalErrorException(__d('net_commons', 'Internal Server Error'));
     }
     return true;
 }
Example #19
0
 /**
  * CSVヘッダー
  *
  * @param Model $model 呼び出しもとのModel
  * @param bool $description 戻り値にidのフィールド名を含めるか
  * @return void
  * @SuppressWarnings(PHPMD.BooleanArgumentFlag)
  */
 public function getCsvHeader(Model $model, $description = false)
 {
     $model->loadModels(['UserAttribute' => 'UserAttributes.UserAttribute', 'UsersLanguage' => 'Users.UsersLanguage']);
     $userAttributes = $model->UserAttribute->getUserAttriburesForAutoUserRegist();
     $userAttributes = Hash::combine($userAttributes, '{n}.UserAttribute.key', '{n}');
     foreach (self::$unexportFileds as $field) {
         $userAttributes = Hash::remove($userAttributes, $field);
     }
     $this->__header = array();
     $this->__descriptions = array();
     foreach ($userAttributes as $attrKey => $userAttribute) {
         $this->__prepareCsvHeader($model, $attrKey, $userAttribute);
     }
     if ($description) {
         return $this->__descriptions;
     } else {
         return $this->__header;
     }
 }
Example #20
0
 /**
  * Delete block.
  *
  * @param Model $model Model using this behavior
  * @param string $blockKey blocks.key
  * @return void
  * @throws InternalErrorException
  */
 public function deleteBlock(Model $model, $blockKey)
 {
     $model->loadModels(['Block' => 'Blocks.Block', 'Frame' => 'Frames.Frame']);
     //Blockデータ取得
     $conditions = array($model->Block->alias . '.key' => $blockKey);
     $blocks = $model->Block->find('list', array('recursive' => -1, 'conditions' => $conditions));
     //Blockデータ削除
     if (!$model->Block->deleteAll($conditions, false)) {
         throw new InternalErrorException(__d('net_commons', 'Internal Server Error'));
     }
     $blockIds = array_keys($blocks);
     foreach ($blockIds as $blockId) {
         if (!$model->Frame->updateAll(array('Frame.block_id' => null), array('Frame.block_id' => (int) $blockId))) {
             throw new InternalErrorException(__d('net_commons', 'Internal Server Error'));
         }
     }
     $settings = Hash::merge(array('BlockRolePermission' => 'Blocks.BlockRolePermission'), $this->settings['loadModels']);
     //関連Modelのデータ削除
     $model->loadModels($settings);
     $modelClasses = array_keys($settings);
     foreach ($modelClasses as $class) {
         $result = true;
         if ($model->{$class}->hasField('block_id')) {
             $result = $model->{$class}->deleteAll(array($model->{$class}->alias . '.block_id' => $blockIds), false);
         }
         if ($model->{$class}->hasField('block_key')) {
             $result = $model->{$class}->deleteAll(array($model->{$class}->alias . '.block_key' => $blockKey), false);
         }
         if (!$result) {
             throw new InternalErrorException(__d('net_commons', 'Internal Server Error'));
         }
     }
 }
Example #21
0
 /**
  * 新着に表示させる会員のリスト登録
  *
  * @param Model $model 呼び出し元のモデル
  * @param int $topicId トピックID
  * @return array
  * @throws InternalErrorException
  */
 protected function _saveTopicReadable(Model $model, $topicId)
 {
     $model->loadModels(['Topic' => 'Topics.Topic', 'TopicReadable' => 'Topics.TopicReadable']);
     //選択されていないユーザIDを削除
     $saved = $model->TopicReadable->find('list', array('recursive' => -1, 'fields' => array('id', 'user_id'), 'conditions' => ['topic_id' => $topicId]));
     $saved = array_unique(array_values($saved));
     $delete = array_diff($saved, $this->settings[$model->alias]['users']);
     if (count($delete) > 0) {
         $conditions = array($model->TopicReadable->alias . '.topic_id' => $topicId, $model->TopicReadable->alias . '.user_id' => $delete);
         if (!$model->TopicReadable->deleteAll($conditions, false)) {
             throw new InternalErrorException(__d('net_commons', 'Internal Server Error'));
         }
     }
     //登録処理
     foreach ($this->settings[$model->alias]['users'] as $userId) {
         $conditions = array('topic_id' => $topicId, 'user_id' => $userId);
         $count = $model->TopicReadable->find('count', array('recursive' => -1, 'conditions' => $conditions));
         if ($count === 0) {
             $model->TopicReadable->create(false);
             $result = $model->TopicReadable->save($conditions);
             if (!$result) {
                 throw new InternalErrorException(__d('net_commons', 'Internal Server Error'));
             }
         }
     }
     return true;
 }
 /**
  * 管理者のみの項目に対する更新
  *
  * @param Model $model Model using this behavior
  * @param string $roleKey ロールキー
  * @param bool $enableUserManager 有効かどうか
  * @return bool True on success
  * @throws InternalErrorException
  */
 private function __updateOnlyAdministorator(Model $model, $roleKey, $enableUserManager)
 {
     $model->loadModels(['UserAttributeSetting' => 'UserAttributes.UserAttributeSetting', 'UserAttributesRole' => 'UserRoles.UserAttributesRole']);
     $userAttrSettings = $model->UserAttributeSetting->find('all', array('recursive' => -1));
     $UserAttributesRoles = $model->UserAttributesRole->find('all', array('recursive' => -1, 'fields' => array('id', 'role_key', 'user_attribute_key'), 'conditions' => array('role_key' => $roleKey)));
     $data['UserAttributesRole'] = array();
     foreach ($userAttrSettings as $i => $userAttrSetting) {
         $userAttributeKey = $userAttrSetting['UserAttributeSetting']['user_attribute_key'];
         $userAttrRole = Hash::extract($UserAttributesRoles, '{n}.UserAttributesRole[user_attribute_key=' . $userAttributeKey . ']');
         $data['UserAttributesRole'][$i] = Hash::merge($model->UserAttributesRole->create(Hash::get($userAttrRole, '0')), $model->UserAttributesRole->defaultUserAttributeRole($userAttrSetting, $enableUserManager));
     }
     if (!$model->UserAttributesRole->saveUserAttributesRoles($data)) {
         throw new InternalErrorException(__d('net_commons', 'Internal Server Error'));
     }
     return true;
 }
Example #23
0
 /**
  * BlockSettingデータ保存
  *
  * ### 仕組み
  * 各プラグインの[横]の入力値を、BlockSettingをブロックキーで検索した縦データにセット or
  * データなしなら、新規作成データが取得できるので、ブロックキーをセット
  * して、縦データをsaveManyでまとめて保存します。
  * ```
  * //(例)各プラグインのBlockSettingControllerからの登録処理 [横]データ
  * array(
  * 	'VideoSetting' => array(
  * 		'use_comment' => '1',
  * 		'use_like' => '1',
  * 		'use_unlike' => '0',
  * 		'auto_play' => '0',
  * 		'use_comment' => '1',
  * 	)
  * )
  * ↓
  * ↓ ブロックキーで検索した[縦]データにセット
  * ↓
  * array(
  * 	'use_comment' => array(
  * 		'id' => '1',		// 新規登録時はidない
  * 		'plugin_key' => 'videos',
  * 		'room_id' => '2',
  * 		'block_key' => '2e86eb72e9cbd0ffa87ea23c81d4e3b7',
  * 		'field_name' => 'use_comment',
  * 		'value' => '1',
  * 		'type' => 'boolean',
  * 	),
  * 	'use_like' => array(
  * 		'id' => '1',
  * 		'plugin_key' => 'videos',
  * 		'room_id' => '2',
  * 		'block_key' => '2e86eb72e9cbd0ffa87ea23c81d4e3b7',
  * 		'field_name' => 'use_like',
  * 		'value' => '1',
  * 		'type' => 'boolean',
  * 	),
  * 	'use_unlike' => array(
  * 		'id' => '1',
  * 		'plugin_key' => 'videos',
  * 		'room_id' => '2',
  * 		'block_key' => '2e86eb72e9cbd0ffa87ea23c81d4e3b7',
  * 		'field_name' => 'use_unlike',
  * 		'value' => '0',
  * 		'type' => 'boolean',
  * 	),
  * 	'is_auto_play' => array(
  * 		'id' => '1',
  * 		'plugin_key' => 'videos',
  * 		'room_id' => '2',
  * 		'block_key' => '2e86eb72e9cbd0ffa87ea23c81d4e3b7',
  * 		'field_name' => 'auto_play',
  * 		'value' => '0',
  * 		'type' => 'boolean',
  * 	),
  * )
  * ```
  *
  * @param Model $model モデル
  * @param string $blockKey ブロックキー
  * @param int $roomId ルームID
  * @return mixed On success Model::$data if its not empty or true, false on failure
  * @throws InternalErrorException
  */
 public function saveBlockSetting(Model $model, $blockKey = null, $roomId = null)
 {
     $model->loadModels(array('BlockSetting' => 'Blocks.BlockSetting'));
     // 横の入力データを、検索した縦データにセット & 新規登録用にブロックキーをセット
     if (is_null($blockKey)) {
         $blockKey = Current::read('Block.key');
     }
     if (is_null($roomId)) {
         $roomId = Current::read('Room.id');
     }
     $blockSetting = $this->getBlockSetting($model, $blockKey, $roomId, true);
     $inputData = $model->data[$model->alias];
     $saveData = null;
     $fields = $this->_getFields($model);
     // セッティングしたフィールドを基に、入力したフィールドのみsaveDataにする
     foreach ($fields as $field) {
         if (array_key_exists($field, $inputData)) {
             $saveData[$field] = $blockSetting['BlockSetting'][$field];
             $saveData[$field]['value'] = $inputData[$field];
             // 新規登録用にブロックキーをセット
             $saveData[$field]['block_key'] = $blockKey;
         }
     }
     if ($saveData && !$model->BlockSetting->saveMany($saveData, ['validate' => false])) {
         throw new InternalErrorException('Failed - BlockSetting ' . __METHOD__);
     }
     return true;
 }
Example #24
0
 /**
  * Save default UserAttributesRole
  *
  * @param Model $model Model using this behavior
  * @param array $data User role data
  * @return bool True on success
  * @throws InternalErrorException
  */
 public function saveUserAttributesRole(Model $model, $data)
 {
     $model->loadModels(['UserAttribute' => 'UserAttributes.UserAttribute', 'UserAttributeSetting' => 'UserAttributes.UserAttributeSetting', 'UserAttributesRole' => 'UserRoles.UserAttributesRole']);
     $userAttributes = $model->UserAttribute->find('all', array('recursive' => 0, 'conditions' => array('language_id' => Configure::read('Config.languageId'))));
     foreach ($userAttributes as $userAttribute) {
         $params = array('role_key' => $data['UserRoleSetting']['role_key'], 'origin_role_key' => $data['UserRoleSetting']['origin_role_key'], 'user_attribute_key' => $userAttribute['UserAttribute']['key'], 'only_administrator' => (bool) $userAttribute['UserAttributeSetting']['only_administrator'], 'is_systemized' => (bool) $userAttribute['UserAttributeSetting']['is_systemized'], 'is_usable_user_manager' => (bool) $data['UserRoleSetting']['is_usable_user_manager']);
         $userAttributeRole = $model->UserAttributesRole->defaultUserAttributeRolePermissions($params);
         if (!$model->UserAttributesRole->save($userAttributeRole, array('validate' => false))) {
             throw new InternalErrorException(__d('net_commons', 'Internal Server Error'));
         }
     }
     return true;
 }
Example #25
0
 /**
  * 既読データの登録
  *
  * @param Model $model 呼び出し元のモデル
  * @param array $content コンテンツ
  * @param bool $answered 回答したかどうか
  * @return array
  * @throws InternalErrorException
  * @SuppressWarnings(PHPMD.BooleanArgumentFlag)
  */
 public function saveTopicUserStatus(Model $model, $content, $answered = false)
 {
     $model->loadModels(['Topic' => 'Topics.Topic', 'TopicUserStatus' => 'Topics.TopicUserStatus']);
     $topicAlias = $model->Topic->alias;
     $conditions = array($topicAlias . '.plugin_key' => Current::read('Plugin.key'), $topicAlias . '.language_id' => Current::read('Language.id'), $topicAlias . '.block_id' => Current::read('Block.id', '0'), $topicAlias . '.content_id' => Hash::get($content, $this->settings[$model->alias]['fields']['content_id'], '0'));
     //既読データ登録
     $update = array('read' => true, 'answered' => $answered);
     $model->TopicUserStatus->saveTopicUserStatus($content, $conditions, $update);
     return true;
 }
 /**
  * フィールドの削除
  * ※会員項目の削除で呼び出す
  *
  * @param Model $model Model ビヘイビア呼び出し元モデル
  * @param array $data 登録データ
  * @return bool True on success
  * @throws InternalErrorException
  */
 public function dropColumnByUserAttribute(Model $model, $data)
 {
     $model->loadModels(['UserAttributeSetting' => 'UserAttributes.UserAttributeSetting', 'User' => 'Users.User', 'UsersLanguage' => 'Users.UsersLanguage']);
     $userAttributeKey = $data[$model->UserAttributeSetting->alias]['user_attribute_key'];
     if (Hash::get($data, $model->UserAttributeSetting->alias . '.is_multilingualization')) {
         $this->cakeMigration->migration['up']['drop_field'][$model->User->table] = array();
         $tableName = $model->UsersLanguage->table;
     } else {
         $tableName = $model->User->table;
     }
     $this->cakeMigration->migration['up']['drop_field'][$tableName] = array($userAttributeKey);
     $this->cakeMigration->migration['up']['drop_field'][$model->User->table][] = sprintf(UserAttribute::PUBLIC_FIELD_FORMAT, $userAttributeKey);
     if ($data[$model->UserAttributeSetting->alias]['data_type_key'] === DataType::DATA_TYPE_EMAIL) {
         $this->cakeMigration->migration['up']['drop_field'][$model->User->table][] = sprintf(UserAttribute::MAIL_RECEPTION_FIELD_FORMAT, $userAttributeKey);
     }
     return $this->cakeMigration->run('up');
 }
Example #27
0
 /**
  * コミュニティのRolesRoomsUserデータ登録
  *
  * @param Model $model Model using this behavior
  * @return bool
  * @throws InternalErrorException
  */
 private function __saveCommunityRolesRoomsUser(Model $model)
 {
     $model->loadModels(['RolesRoomsUser' => 'Rooms.RolesRoomsUser', 'RolesRoom' => 'Rooms.RolesRoom', 'Room' => 'Rooms.Room', 'PluginsRole' => 'PluginManager.PluginsRole']);
     if (!Hash::get($model->data, 'User.role_key')) {
         return true;
     }
     //参加ルームの登録
     $count = $model->PluginsRole->find('count', array('recursive' => -1, 'conditions' => array('plugin_key' => 'rooms', 'role_key' => Hash::get($model->data, 'User.role_key'))));
     $roomId = Room::ROOM_PARENT_ID;
     if ($count) {
         $roomRoleKey = Role::ROOM_ROLE_KEY_ROOM_ADMINISTRATOR;
     } else {
         $room = $model->Room->find('first', array('recursive' => -1, 'fields' => array('id', 'default_role_key'), 'conditions' => array('id' => $roomId)));
         $roomRoleKey = Hash::get($room, 'Room.default_role_key');
     }
     $rolesRoomsUserId = $model->RolesRoomsUser->find('first', array('recursive' => -1, 'fields' => array('id', 'roles_room_id'), 'conditions' => array('room_id' => $roomId, 'user_id' => $model->data['User']['id'])));
     $rolesRooms = $model->RolesRoom->find('first', array('recursive' => -1, 'conditions' => array('room_id' => $roomId, 'role_key' => $roomRoleKey)));
     $rolesRoomsUser = array('id' => Hash::get($rolesRoomsUserId, 'RolesRoomsUser.id'), 'room_id' => $roomId, 'user_id' => $model->data['User']['id'], 'role_key' => $roomRoleKey, 'roles_room_id' => Hash::get($rolesRooms, 'RolesRoom.id'));
     if ($rolesRoomsUser['roles_room_id'] !== Hash::get($rolesRoomsUserId, 'RolesRoomsUser.roles_room_id')) {
         $result = $model->RolesRoomsUser->save($rolesRoomsUser);
         if (!$result) {
             throw new InternalErrorException(__d('net_commons', 'Internal Server Error'));
         }
     }
     return true;
 }