/** * メッセージ保存用テーブルのフィールドを最適化する * 初回の場合、id/created/modifiedを追加する * 2回目以降の場合は、最後のカラムに追加する * * @param array $dbConfig * @param int $mailContentId * @return boolean * @access public */ function construction($mailContentId) { App::import('Model', 'Mail.MailField'); App::import('Model', 'Mail.MailContent'); $mailFieldClass = new MailField(); $mailContentClass = new MailContent(); // フィールドリストを取得 $mailFields = $mailFieldClass->findAll(array('MailField.mail_content_id' => $mailContentId)); // コンテンツ名を取得 $contentName = $mailContentClass->field('name', array('MailContent.id' => $mailContentId)); if (!$this->tableExists($this->getTablePrefixByContentName($contentName) . 'messages')) { /* 初回の場合 */ $this->createTable($contentName); } else { /* 2回目以降の場合 */ $this->tablePrefix = $this->getTablePrefixByContentName($contentName); $this->_schema = null; $this->cacheSources = false; $schema = $this->schema(); $messageFields = array_keys($schema); foreach ($mailFields as $mailField) { if (!in_array($mailField['MailField']['field_name'], $messageFields)) { $this->addField($contentName, $mailField['MailField']['field_name']); } } } return true; }
/** * 受信メッセージの内容を表示状態に変換する * * @param int $id * @param array $messages * @return array * @access public */ public function convertMessageToCsv($id, $messages) { App::uses('MailField', 'Mail.Model'); $mailFieldClass = new MailField(); // フィールドの一覧を取得する $mailFields = $mailFieldClass->find('all', array('conditions' => array('MailField.mail_content_id' => $id), 'order' => 'sort')); // フィールド名とデータの変換に必要なヘルパーを読み込む App::uses('MaildataHelper', 'Mail.View/Helper'); App::uses('MailfieldHelper', 'Mail.View/Helper'); $Maildata = new MaildataHelper(new View()); $Mailfield = new MailfieldHelper(new View()); foreach ($messages as $key => $message) { $inData = array(); $inData['NO'] = $message[$this->alias]['id']; foreach ($mailFields as $mailField) { if ($mailField['MailField']['type'] == 'file') { $inData[$mailField['MailField']['field_name'] . ' (' . $mailField['MailField']['name'] . ')'] = $message[$this->alias][$mailField['MailField']['field_name']]; } else { $inData[$mailField['MailField']['field_name'] . ' (' . $mailField['MailField']['name'] . ')'] = $Maildata->toDisplayString($mailField['MailField']['type'], $message[$this->alias][$mailField['MailField']['field_name']], $Mailfield->getOptions($mailField['MailField'])); } } $inData['作成日'] = $message[$this->alias]['created']; $inData['更新日'] = $message[$this->alias]['modified']; $messages[$key][$this->alias] = $inData; } return $messages; }