Example #1
0
 protected function _addModelLabel($id)
 {
     $defaults = array('label' => ucfirst(Garp_Spawn_Util::underscored2readable(Garp_Spawn_Util::camelcased2underscored($this['id']))));
     foreach ($defaults as $prop => $defaultValue) {
         if (!array_key_exists($prop, $this) || is_null($this[$prop])) {
             $this[$prop] = $defaultValue;
         }
     }
 }
Example #2
0
 /**
  * @return Garp_Spawn_Config_Model_Binding
  */
 protected function _getBindingModelConfig()
 {
     $relation = $this->getRelation();
     $habtmModelId = $this->_getBindingModelName();
     $rules = $this->_getRules();
     $config = $this->_getBindingModelParams();
     if ($relation->weighable) {
         $weightCol1 = Garp_Spawn_Util::camelcased2underscored($rules[0] . $rules[1]) . '_weight';
         $weightCol2 = Garp_Spawn_Util::camelcased2underscored($rules[1] . $rules[0]) . '_weight';
         $config['inputs'][$weightCol1] = array('type' => 'numeric');
         $config['inputs'][$weightCol2] = array('type' => 'numeric');
     }
     $bindingModelConfig = new Garp_Spawn_Config_Model_Binding($habtmModelId, new Garp_Spawn_Config_Storage_PhpArray(array($habtmModelId => $config)), new Garp_Spawn_Config_Format_PhpArray());
     return $bindingModelConfig;
 }
Example #3
0
 protected function _addWeighableRelationFields()
 {
     $weighableRels = $this->_model->relations->getRelations('weighable', true);
     $fieldConfig = array('type' => 'numeric', 'required' => false, 'default' => 0, 'editable' => false, 'visible' => false);
     foreach ($weighableRels as $relName => $rel) {
         $this->add('relation', Garp_Spawn_Util::camelcased2underscored($relName . '_weight'), $fieldConfig);
     }
 }
Example #4
0
 /**
  * @param String $modelId   Model identifier
  * @return  String  The model namespace, to be used in front of a column name, i.e. blog_post
  */
 protected function _getModelNamespace($modelId)
 {
     $modelNamespace = Garp_Spawn_Util::camelcased2underscored($modelId);
     return $modelNamespace;
 }
Example #5
0
 /**
  * Adds the weighable behavior, for user defined sorting of related objects.
  * Can only be initialized after the relations for this model are set.
  *
  * @return void
  */
 protected function _addWeighableBehavior()
 {
     $model = $this->getModel();
     $weighableRels = $model->relations->getRelations('weighable', true);
     if (!$weighableRels) {
         return;
     }
     $weighableConfig = array();
     foreach ($weighableRels as $relName => $rel) {
         $weightColumn = Garp_Spawn_Util::camelcased2underscored($relName) . '_weight';
         $weighableConfig[$relName] = array('foreignKeyColumn' => $rel->column, 'weightColumn' => $weightColumn);
     }
     $this->_add('relation', 'Weighable', $weighableConfig);
 }
Example #6
0
 /**
  * @param String $modelName Name of the model.
  * @param Int $index Optional index of this column, in case of a homosexual relation.
  * @return String Database column / field name that corresponds to this model. E.g.: 'Users' -> 'users_id'
  */
 public static function getRelationColumn($modelName, $index = null)
 {
     if (!is_string($modelName)) {
         $error = sprintf(self::ERROR_MODELNAME_IS_NO_STRING, __METHOD__);
         throw new Exception($error);
     }
     $modelNamespace = Garp_Spawn_Util::camelcased2underscored($modelName);
     $relationColumn = $modelNamespace . (is_null($index) ? '' : (string) $index) . '_id';
     return $relationColumn;
 }