\BlockBehavior

Block Behavior

ブロックモデルにアソシエーションがあるモデルのビヘイビアです。
ブロックデータの内、ブロック編集にかかわる項目(名称、公開期限)を処理します。

設定項目

name

ブロック名称フィールドを指定すると、ブロックモデルの名称として登録されます。
お知らせなど名称がない場合でも名称となり得るフィールドを指定してください。 NAME_LENGTHの長さで登録されます。

loadModels

他にアソシエーションがあるモデルがある場合は、loadModelsに指定してください。
ブロックデータ登録後、指定されたモデルのblock_id、block_keyに値がセットされます。
ブロック削除時には指定されたモデルから削除されます。

サンプルコード

public $actsAs = array(
    'Blocks.Block' => array(
        'name' => 'Faq.name',
        'loadModels' => array(
            'Category' => 'Categories.Category',
            'CategoryOrder' => 'Categories.CategoryOrder',
            'WorkflowComment' => 'Workflow.WorkflowComment',
        )
    )
)

ブロックデータを取得する場合の条件
getBlockConditions
getBlockConditionById

登録時は自動的に登録しますが、削除は明示的に呼び出してください。
deleteBlock

Summary

Methods
Properties
Constants
setup()
beforeValidate()
beforeSave()
saveBlock()
getBlockConditions()
getBlockIndexSettings()
getBlockConditionById()
deleteBlock()
No public properties found
NAME_LENGTH
No protected methods found
No protected properties found
N/A
__setBlockFields()
__setRecursiveBlockField()
__saveBlock()
__getBlockName()
__getBlockDefaultConditions()
No private properties found
N/A

Constants

NAME_LENGTH

NAME_LENGTH = 255 : integer

Max length of content

名称が長い場合に切り取る文字数

Methods

setup()

setup(\Model  $model, array  $config = array()) : void

Setup this behavior with the specified configuration settings.

Parameters

\Model $model

ビヘイビアの呼び出しのモデル

array $config

Configuration settings for $model

beforeValidate()

beforeValidate(\Model  $model, array  $options = array()) : mixed

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.

Parameters

\Model $model

ビヘイビアの呼び出しのモデル

array $options

Options passed from Model::save().

Returns

mixed —

False or null will abort the operation. Any other result will continue.

beforeSave()

beforeSave(\Model  $model, array  $options = array()) : mixed

beforeSave is called before a model is saved. Returning false from a beforeSave callback will abort the save operation.

Parameters

\Model $model

ビヘイビアの呼び出しのモデル

array $options

Options passed from Model::save().

Returns

mixed —

False if the operation should abort. Any other result will continue.

saveBlock()

saveBlock(\Model  $model) : boolean

Blockの登録処理

Parameters

\Model $model

ビヘイビアの呼び出しのモデル

Throws

\InternalErrorException

Returns

boolean

getBlockConditions()

getBlockConditions(\Model  $model, array  $conditions = array()) : array

ブロック一覧データを取得する場合の条件を返します。

サンプルコード(Faqモデル)

$this->Paginator->settings = array(
    'Faq' => array(
        'order' => array('Block.id' => 'desc'),
        'conditions' => $this->Faq->getBlockConditions(),
        )
    );

Parameters

\Model $model

ビヘイビアの呼び出しのモデル

array $conditions

Model::find conditions default value

Returns

array —

Conditions data

getBlockIndexSettings()

getBlockIndexSettings(\Model  $model, array  $options = array()) : array

ブロック一覧データを取得するsettingsを返す。

サンプルコード(Faqモデル)

$this->Paginator->settings = array(
    'Faq' => $this->Faq->getBlockIndexSettings();

Parameters

\Model $model

ビヘイビアの呼び出しのモデル

array $options

Model::find conditions default value

Returns

array —

Conditions data

getBlockConditionById()

getBlockConditionById(\Model  $model, array  $conditions = array()) : array

ブロックデータを取得する場合の条件を返します。

サンプルコード(Faqモデル)

$faq = $this->find('all', array(
    'recursive' => -1,
    'conditions' => $this->getBlockConditionById(),
));

Parameters

\Model $model

ビヘイビアの呼び出しのモデル

array $conditions

Model::find conditions default value

Returns

array —

Conditions data

deleteBlock()

deleteBlock(\Model  $model, string  $blockKey) : boolean

ブロックデータを削除します。.

サンプルコード(Faqモデル)

public function deleteFaq($data) {
    $this->begin();
    try {
        if (!$this->delete($data[Faq][id])) {
            throw new InternalErrorException(__d('net_commons', 'Internal Server Error'));
        }

        $this->deleteBlock($data['Block']['key']);

        $this->commit();
    } catch (Exception $ex) {
    $this->rollback($ex);
    }
}

Parameters

\Model $model

ビヘイビアの呼び出しのモデル

string $blockKey

blocks.key

Throws

\InternalErrorException

Returns

boolean —

成否

__setBlockFields()

__setBlockFields(\Model  $model) : void

$model->dataのblock_idとblock_keyに値をセットする

Parameters

\Model $model

ビヘイビアの呼び出しのモデル

__setRecursiveBlockField()

__setRecursiveBlockField(\Model  $model,   $data, string  $field, string  $key, string  $value) : void

$model->dataのblock_idとblock_keyに値をセットする

Parameters

\Model $model

ビヘイビアの呼び出しのモデル

$data
string $field

フィールド名

string $key

再帰処理するKey

string $value

更新する値

__saveBlock()

__saveBlock(\Model  $model, array  $frame) : void

savePrepare

Parameters

\Model $model

ビヘイビアの呼び出しのモデル

array $frame

Frameデータ

Throws

\InternalErrorException

__getBlockName()

__getBlockName(\Model  $model) : string

ブロック名取得

Parameters

\Model $model

ビヘイビアの呼び出しのモデル

Returns

string

__getBlockDefaultConditions()

__getBlockDefaultConditions(\Model  $model) : array

ブロック一覧データを取得する場合のデフォルト条件を返します。

Parameters

\Model $model

ビヘイビアの呼び出しのモデル

Returns

array —

Conditions data