Skip to content

Instantly share code, notes, and snippets.

@co3k
Created June 15, 2010 07:09
Show Gist options
  • Save co3k/438792 to your computer and use it in GitHub Desktop.
Save co3k/438792 to your computer and use it in GitHub Desktop.
diff --git a/config/doctrine/schema.yml b/config/doctrine/schema.yml
index 388662d..ad12d25 100644
--- a/config/doctrine/schema.yml
+++ b/config/doctrine/schema.yml
@@ -3,6 +3,9 @@ options:
actAs: [Timestampable]
CommunityTopic:
+ actAs:
+ opCommunityTopicPluginImagesBehavior:
+ Timestampable:
columns:
id: { type: integer(4), primary: true, autoincrement: true }
community_id: { type: integer(4), notnull: true }
@@ -17,6 +20,9 @@ CommunityTopic:
onDelete: cascade
CommunityTopicComment:
+ actAs:
+ opCommunityTopicPluginImagesBehavior:
+ Timestampable:
columns:
id: { type: integer(4), primary: true, autoincrement: true }
community_topic_id: { type: integer(4), notnull: true }
@@ -30,6 +36,9 @@ CommunityTopicComment:
onDelete: cascade
CommunityEvent:
+ actAs:
+ opCommunityTopicPluginImagesBehavior:
+ Timestampable:
columns:
id: { type: integer(4), primary: true, autoincrement: true }
community_id: { type: integer(4), notnull: true }
@@ -49,6 +58,9 @@ CommunityEvent:
onDelete: cascade
CommunityEventComment:
+ actAs:
+ opCommunityTopicPluginImagesBehavior:
+ Timestampable:
columns:
id: { type: integer(4), primary: true, autoincrement: true }
community_event_id: { type: integer(4), notnull: true }
diff --git a/lib/behavior/opCommunityTopicPluginImagesBehavior.class.php b/lib/behavior/opCommunityTopicPluginImagesBehavior.class.php
new file mode 100644
index 0000000..0aa6898
--- /dev/null
+++ b/lib/behavior/opCommunityTopicPluginImagesBehavior.class.php
@@ -0,0 +1,42 @@
+<?php
+
+class opCommunityTopicPluginImagesBehavior extends Doctrine_Template
+{
+ public function __construct(array $options = array())
+ {
+ parent::__construct($options);
+
+ $this->_plugin = new opCommunityTopicPluginImagesRecordGenerator($this->_options);
+ }
+
+ public function setUp()
+ {
+ $this->_plugin->initialize($this->_table);
+
+ // リスナに以下
+ /*
+
+ public function save(Doctrine_Connection $conn = null)
+ {
+ $this->setFileNamePrefix();
+
+ return parent::save($conn);
+ }
+
+ protected function setFileNamePrefix()
+ {
+ $prefix = 'd_'.$this->Diary->id.'_'.$this->number.'_';
+
+ $file = $this->File;
+ $file->setName($prefix.$file->name);
+ }
+
+ public function postDelete($event)
+ {
+ $this->File->FileBin->delete();
+ $this->File->delete();
+ }
+
+ */
+ }
+}
diff --git a/lib/behavior/opCommunityTopicPluginImagesRecordGenerator.class.php b/lib/behavior/opCommunityTopicPluginImagesRecordGenerator.class.php
new file mode 100644
index 0000000..778c901
--- /dev/null
+++ b/lib/behavior/opCommunityTopicPluginImagesRecordGenerator.class.php
@@ -0,0 +1,63 @@
+<?php
+
+class opCommunityTopicPluginImagesRecordGenerator extends Doctrine_Record_Generator
+{
+ protected $_options = array(
+ 'className' => '%CLASS%Image',
+ 'tableName' => '%TABLE%_image',
+ 'generateFiles' => false,
+ 'table' => false,
+ 'pluginTable' => false,
+ 'children' => array(),
+ 'options' => array(),
+ 'cascadeDelete' => true,
+ 'appLevelDelete'=> false,
+ );
+
+ public function __construct($options)
+ {
+ $this->_options = Doctrine_Lib::arrayDeepMerge($this->_options, $options);
+ }
+
+ public function buildRelation()
+ {
+ $this->buildForeignRelation('Images');
+ $this->buildLocalRelation();
+ }
+
+ public function setTableDefinition()
+ {
+ $this->hasColumn('file_id', 'integer', 4, array(
+ 'type' => 'integer',
+ 'notnull' => true,
+ 'length' => 4,
+ ));
+
+ $this->hasColumn('number', 'integer', 4, array(
+ 'type' => 'integer',
+ 'notnull' => true,
+ 'length' => 4,
+ ));
+
+ $this->index('id_number', array(
+ 'fields' =>
+ array(
+ 0 => 'id',
+ 1 => 'number',
+ ),
+ 'type' => 'unique',
+ ));
+ $this->option('charset', 'utf8');
+ }
+
+ public function setUp()
+ {
+ parent::setUp();
+
+ $this->hasOne('File', array(
+ 'local' => 'file_id',
+ 'foreign' => 'id',
+ 'onDelete' => 'cascade',
+ ));
+ }
+}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment