本文整理汇总了PHP中Model::loadModels方法的典型用法代码示例。如果您正苦于以下问题:PHP Model::loadModels方法的具体用法?PHP Model::loadModels怎么用?PHP Model::loadModels使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Model
的用法示例。
在下文中一共展示了Model::loadModels方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: uninstallPlugin
/**
* 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;
}
示例2: beforeValidate
/**
* 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;
}
示例3: readToArticle
/**
* 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;
}
示例4: afterSave
/**
* 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);
}
示例5: defaultUserAttributeRole
/**
* 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;
}
示例6: deleteQueue
/**
* キュー削除
*
* @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__);
}
}
示例7: beforeValidate
/**
* 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;
}
示例8: beforeValidate
/**
* 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;
}
示例9: saveDefaultUserAttributeRoles
/**
* 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;
}
示例10: saveRoomDiskSize
/**
* ルームの容量の登録
*
* @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;
}
示例11: saveUserRegistMail
/**
* 自動登録メール件名・本文の登録
*
* @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;
}
示例12: deleteUserAssociations
/**
* 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;
}
示例13: deleteCommentsByContentKey
/**
* 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;
}
示例14: setup
/**
* 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']);
}
示例15: deletePluginByRoom
/**
* 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;
}