Last active
December 29, 2015 07:59
-
-
Save motin/7640171 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class ActiveRecord extends CActiveRecord | |
{ | |
// Hard code source language to en for now. TODO: Be able to choose and store source language | |
public $source_language = 'en'; | |
public function behaviors() | |
{ | |
$behaviors = array(); | |
if (!in_array(get_class($this), array("Workflow", "Profiles", "Users", "Account", "Message", "SourceMessage")) && strpos(get_class($this), "QaState") === false) { | |
$behaviors['CTimestampBehavior'] = array( | |
'class' => 'zii.behaviors.CTimestampBehavior', | |
'createAttribute' => 'created', | |
'updateAttribute' => 'modified', | |
); | |
} | |
$qaModels = DataModel::qaModels(); | |
if (isset($qaModels[get_class($this)])) { | |
$behaviors['qa-state'] = array( | |
'class' => 'QaStateBehavior', | |
); | |
$behaviors['owner-behavior'] = array( | |
'class' => 'OwnerBehavior', | |
); | |
} | |
$graphModels = DataModel::graphModels(); | |
if (isset($graphModels[get_class($this)])) { | |
$behaviors['relational-graph-db'] = array( | |
'class' => 'RelationalGraphDbBehavior', | |
); | |
} | |
// List of model attributes to translate using yii-i18n-attribute-messages | |
$i18nAttributeMessages = DataModel::i18nAttributeMessages(); | |
$i18nAttributeMessagesMap = $i18nAttributeMessages['attributes']; | |
if (isset($i18nAttributeMessagesMap[get_class($this)])) { | |
$behaviors['i18n-attribute-messages'] = array( | |
'class' => 'I18nAttributeMessagesBehavior', | |
'translationAttributes' => $i18nAttributeMessagesMap[get_class($this)], | |
'languageSuffixes' => array_keys(Yii::app()->params["languages"]), | |
'messageSourceComponent' => 'writableMessages', | |
); | |
} | |
// List of model attributes and relations to make multilingual using yii-i18n-columns | |
$i18nColumns = DataModel::i18nColumns(); | |
$i18nColumnsMap = $i18nColumns['attributes']; | |
$i18nColumnsMultilingualRelationsMap = $i18nColumns['relations']; | |
if (isset($i18nColumnsMap[get_class($this)])) { | |
$behaviors['i18n-columns'] = array( | |
'class' => 'I18nColumnsBehavior', | |
'translationAttributes' => $i18nColumnsMap[get_class($this)], | |
); | |
} | |
if (isset($i18nColumnsMultilingualRelationsMap[get_class($this)])) { | |
$behaviors['i18n-columns']['multilingualRelations'] = $i18nColumnsMultilingualRelationsMap[get_class($this)]; | |
} | |
return array_merge(parent::behaviors(), $behaviors); | |
} | |
/** | |
* Ensures node relation | |
*/ | |
public function node() | |
{ | |
if (is_null($this->node_id)) { | |
$node = new Node(); | |
$node->save(); | |
$this->node_id = $node->id; | |
$this->save(); | |
$this->refresh(); | |
} | |
return $this->node; | |
} | |
public function relations() | |
{ | |
$relations = array(); | |
$graphModels = DataModel::graphModels(); | |
if (isset($graphModels[get_class($this)])) { | |
$relations = array( | |
'outEdges' => array(self::HAS_MANY, 'Edge', array('id' => 'from_node_id'), 'through' => 'node'), | |
'outNodes' => array(self::HAS_MANY, 'Node', array('to_node_id' => 'id'), 'through' => 'outEdges'), | |
'inEdges' => array(self::HAS_MANY, 'Edge', array('id' => 'to_node_id'), 'through' => 'node'), | |
'inNodes' => array(self::HAS_MANY, 'Node', array('from_node_id' => 'id'), 'through' => 'inEdges'), | |
); | |
} | |
return array_merge( | |
parent::relations(), | |
$relations | |
); | |
} | |
public function attributeLabels() | |
{ | |
return array(); | |
} | |
public function attributeHints() | |
{ | |
return array(); | |
} | |
public function getAttributeHint($key) | |
{ | |
$a = $this->attributeHints(); | |
if (isset($a[$key])) { | |
return $a[$key]; | |
} | |
} | |
public function getModelLabel() | |
{ | |
$labels = DataModel::modelLabels(); | |
return $labels[get_class($this)]; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class DataModel | |
{ | |
static public function crudModels() | |
{ | |
return array( | |
// Contents | |
'Changeset' => 'changeset', | |
'Chapter' => 'chapter', | |
'DataChunk' => 'data_chunk', | |
'DataSource' => 'data_source', | |
'DownloadLink' => 'download_link', | |
'ExamQuestion' => 'exam_question', | |
'ExamQuestionAlternative' => 'exam_question_alternative', | |
'Exercise' => 'exercise', | |
'HtmlChunk' => 'html_chunk', | |
'Node' => 'node', | |
'Edge' => 'edge', | |
'Page' => 'page', | |
'PoFile' => 'po_file', | |
'Section' => 'section', | |
'SectionContent' => 'section_content', | |
'SlideshowFile' => 'slideshow_file', | |
'Snapshot' => 'snapshot', | |
'SpreadsheetFile' => 'spreadsheet_file', | |
'TextDoc' => 'text_doc', | |
'Tool' => 'tool', | |
'VectorGraphic' => 'vector_graphic', | |
'VideoFile' => 'video_file', | |
// User management | |
'Account' => 'users', | |
'Profiles' => 'profiles', | |
// Translations | |
'Message' => 'Message', | |
'SourceMessage' => 'SourceMessage' | |
); | |
} | |
static public function qaModels() | |
{ | |
return array( | |
'Chapter' => 'chapter', | |
'DataChunk' => 'data_chunk', | |
'DataSource' => 'data_source', | |
'ExamQuestion' => 'exam_question', | |
'Exercise' => 'exercise', | |
'PoFile' => 'po_file', | |
'SlideshowFile' => 'slideshow_file', | |
'Snapshot' => 'snapshot', | |
'TextDoc' => 'text_doc', | |
'Tool' => 'tool', | |
'VectorGraphic' => 'vector_graphic', | |
'VideoFile' => 'video_file', | |
// Special pages | |
'HtmlChunk' => 'html_chunk', | |
'DownloadLink' => 'download_link', | |
); | |
} | |
static public function qaStateModels() | |
{ | |
$qaStateModels = array(); | |
foreach (self::qaModels() as $model => $table) { | |
$qaStateModels[$model . "QaState"] = $table . "_qa_state"; | |
} | |
return $qaStateModels; | |
} | |
static public function graphModels() | |
{ | |
return array_merge(self::qaModels(), array( | |
'ExamQuestionAlternative' => 'exam_question_alternative', | |
)); | |
} | |
static public function internalModels() | |
{ | |
return array_merge(array( | |
"Node" => "node", | |
"EzcExecution" => "ezc_execution", | |
"Users" => "users", | |
), self::qaStateModels()); | |
} | |
static public function modelLabels() | |
{ | |
return array( | |
'Chapter' => 'n==0#Chapter(s)|n==1#Chapter|n>1#Chapters', | |
'DataChunk' => 'n==0#DataChunk(s)|n==1#DataChunk|n>1#DataChunks', | |
'DataSource' => 'n==0#DataSource(s)|n==1#DataSource|n>1#DataSources', | |
'ExamQuestion' => 'n==0#ExamQuestion(s)|n==1#ExamQuestion|n>1#ExamQuestions', | |
'Exercise' => 'n==0#Exercise(s)|n==1#Exercise|n>1#Exercises', | |
'PoFile' => 'n==0#PoFile(s)|n==1#PoFile|n>1#PoFiles', | |
'SlideshowFile' => 'n==0#SlideshowFile(s)|n==1#SlideshowFile|n>1#SlideshowFiles', | |
'Snapshot' => 'n==0#Snapshot(s)|n==1#Snapshot|n>1#Snapshots', | |
'TextDoc' => 'n==0#TextDoc(s)|n==1#TextDoc|n>1#TextDocs', | |
'Tool' => 'n==0#Tool(s)|n==1#Tool|n>1#Tools', | |
'VectorGraphic' => 'n==0#VectorGraphic(s)|n==1#VectorGraphic|n>1#VectorGraphics', | |
'VideoFile' => 'n==0#VideoFile(s)|n==1#VideoFile|n>1#VideoFiles', | |
); | |
} | |
/** | |
* @return array List of model attributes to translate using yii-i18n-attribute-messages | |
*/ | |
static public function i18nAttributeMessages() | |
{ | |
return array( | |
'attributes' => array( | |
'Chapter' => array('title', 'about', 'teachers_guide'), | |
'DataChunk' => array('title', 'about'), | |
'DataSource' => array('title', 'about'), | |
'DownloadLink' => array('title'), | |
'ExamQuestion' => array('question'), | |
'ExamQuestionAlternative' => array('markup'), | |
'Exercise' => array('title', 'question', 'description'), | |
'HtmlChunk' => array('markup'), | |
'Page' => array('title', 'about'), | |
'Section' => array('title', 'menu_label'), | |
'SlideshowFile' => array('title', 'about'), | |
'Snapshot' => array('title', 'about'), | |
'SpreadsheetFile' => array('title'), | |
'TextDoc' => array('title', 'about'), | |
'Tool' => array('title', 'about'), | |
'VectorGraphic' => array('title', 'about'), | |
'VideoFile' => array('title', 'about', 'subtitles'), | |
), | |
); | |
} | |
/** | |
* @return array List of model attributes and relations to make multilingual using yii-i18n-columns | |
*/ | |
static public function i18nColumns() | |
{ | |
return array( | |
'attributes' => array( | |
'Chapter' => array('slug', 'chapter_qa_state_id'), | |
'DataChunk' => array('slug', 'data_chunk_qa_state_id'), | |
'DataSource' => array('slug', 'data_source_qa_state_id'), | |
'ExamQuestion' => array('slug', 'exam_question_qa_state_id'), | |
'Exercise' => array('slug', 'exercise_qa_state_id'), | |
'Page' => array('slug'), | |
'PoFile' => array('processed_media_id', 'po_file_qa_state_id'), | |
'Profiles' => array('can_translate_to'), | |
'Section' => array('slug'), | |
'SlideshowFile' => array('slug', 'processed_media_id', 'slideshow_file_qa_state_id'), | |
'Snapshot' => array('slug', 'snapshot_qa_state_id'), | |
'SpreadsheetFile' => array('processed_media_id'), | |
'TextDoc' => array('slug', 'processed_media_id', 'text_doc_qa_state_id'), | |
'Tool' => array('slug'), | |
'VectorGraphic' => array('slug', 'processed_media_id', 'vector_graphic_qa_state_id'), | |
'VideoFile' => array('slug', 'processed_media_id', 'video_file_qa_state_id'), | |
), | |
'relations' => array( | |
'Chapter' => array('chapterQaState' => 'chapter_qa_state_id'), | |
'DataChunk' => array('dataChunkQaState' => 'data_chunk_qa_state_id'), | |
'DataSource' => array('dataSourceQaState' => 'data_source_qa_state_id'), | |
'ExamQuestion' => array('examQuestionQaState' => 'exam_question_qa_state_id'), | |
'Exercise' => array('exerciseQaState' => 'exercise_qa_state_id'), | |
'PoFile' => array('processedMedia' => 'processed_media_id', 'poFileQaState' => 'po_file_qa_state_id'), | |
'SlideshowFile' => array('processedMedia' => 'processed_media_id', 'slideshowFileQaState' => 'slideshow_file_qa_state_id'), | |
'Snapshot' => array('snapshotQaState' => 'snapshot_qa_state_id'), | |
'SpreadsheetFile' => array('processedMedia' => 'processed_media_id'), | |
'TextDoc' => array('processedMedia' => 'processed_media_id', 'textDocQaState' => 'text_doc_qa_state_id'), | |
'VectorGraphic' => array('processedMedia' => 'processed_media_id', 'vectorGraphicQaState' => 'vector_graphic_qa_state_id'), | |
'VideoFile' => array('processedMedia' => 'processed_media_id', 'videoFileQaState' => 'video_file_qa_state_id'), | |
), | |
); | |
} | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// GIIC CONFIG FILE | |
// ---------------- | |
$baseModels = DataModel::crudModels(); | |
$qaModels = DataModel::qaModels(); | |
$qaStateModels = DataModel::qaStateModels(); | |
$internalModels = DataModel::internalModels(); | |
// merge | |
$cruds = array_merge($baseModels, $qaStateModels); | |
// init actions | |
$actions = array(); | |
// generate hybrid CRUDs into application | |
foreach ($cruds AS $model => $table) { | |
$action = array( | |
"codeModel" => "FullCrudCode", | |
"generator" => 'vendor.phundament.gii-template-collection.fullCrud.FullCrudGenerator', | |
"templates" => array( | |
'hybrid' => dirname(__FILE__) . '/../../../../vendor/phundament/gii-template-collection/fullCrud/templates/hybrid', | |
), | |
"model" => array( | |
"model" => "application.models." . $model, | |
"controller" => lcfirst($model), | |
"template" => "hybrid", | |
"internalModels" => array_keys($internalModels), | |
) | |
); | |
if (in_array($model, array( | |
"ExamQuestion", | |
"ExamQuestionAlternative", | |
"HtmlChunk", | |
)) | |
) { | |
$action["model"]["textEditor"] = "html5Editor"; | |
} | |
$actions[] = $action; | |
} | |
return array( | |
"actions" => $actions | |
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// GIIC CONFIG FILE | |
// ---------------- | |
$baseModels = DataModel::crudModels(); | |
$qaModels = DataModel::qaModels(); | |
$qaStateModels = DataModel::qaStateModels(); | |
// merge | |
$models = array_merge($baseModels, $qaModels, $qaStateModels); | |
// init actions | |
$actions = array(); | |
// generate default models | |
foreach ($models AS $model => $table) { | |
$actions[] = array( | |
"codeModel" => "FullModelCode", | |
"generator" => 'vendor.phundament.gii-template-collection.fullModel.FullModelGenerator', | |
"templates" => array( | |
'default' => dirname(__FILE__) . '/../../../../vendor/phundament/gii-template-collection/fullModel/templates/default', | |
), | |
"model" => array( | |
"baseClass" => "ActiveRecord", | |
"tableName" => $table, | |
"modelClass" => $model, | |
"modelPath" => "application.models", | |
"template" => "default" | |
) | |
); | |
} | |
return array( | |
"actions" => $actions | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment