Jump to content


Photo

Custom "ownedItemsOnly"-like attribute

customization

  • Please log in to reply
1 reply to this topic

#1 miek1123

miek1123

    Member

  • Members
  • PipPip
  • 19 posts

Posted 16 May 2014 - 02:24 PM

So i'm trying to implement my own portlet that has a configuration checkbox with functionality similar to ownedItemsOnly attribute.   But i'm getting an attribute not found error like it thinks recruiterItemsOnly is an actual database field (here's a partial stack trace).   I'm guessing i'm missing something simple to tell Zurmo that its "mapped", but i'm having a hard time finding the setting...
 
[error] [php] Undefined index: recruiterItemsOnly (C:\xampp\htdocs\zurmo\app\protected\core\models\BeanModel.php:211)
Stack trace:
#0 C:\xampp\htdocs\zurmo\app\protected\core\utils\ModelJoinBuilder.php(923): RedBeanModelAttributeToDataProviderAdapter->getAttributeTableName()
#1 C:\xampp\htdocs\zurmo\app\protected\core\utils\ModelJoinBuilder.php(190): ModelWhereAndJoinBuilder->resolveOnTableAliasNameForDerivedRelationViaCastedUpModel()
#2 C:\xampp\htdocs\zurmo\app\protected\core\utils\ModelJoinBuilder.php(147): ModelWhereAndJoinBuilder->resolveOnTableAliasName()

 
I've implemented the following logic in my custom SearchForm:
public function rules()
{
    return array_merge(parent::rules(), array(
                        array('recruiterItemsOnly', 'boolean'),
    ));
}

public function attributeLabels()
{
    return array_merge(parent::attributeLabels(), array(
                        'recruiterItemsOnly' => Zurmo::t('ZurmoModule', 'Only Recruiting Items I Own'),
    ));
}

protected static function getSearchFormAttributeMappingRulesTypes()
{
    return array_merge(parent::getSearchFormAttributeMappingRulesTypes(), array('recruiterItemsOnly' => 'RecruiterItemsOnly'));
}

public function getAttributesMappedToRealAttributesMetadata()
{
    return array_merge(parent::getAttributesMappedToRealAttributesMetadata(), array(
        'recruiterItemsOnly' => array(
            array('recruiterUser', 'id', null, 'resolveValueByRules'),
        ),
    ));
}
And i've created the mapping rule as follow:
/**
 * Rule used in search form to define when a filter should be on the current recruiters's userModel id.
 */
class RecruiterItemsOnlySearchFormAttributeMappingRules extends SearchFormAttributeMappingRules
{
    public static function resolveValueDataIntoUsableValue($value)
    {
        assert('$value == null || $value == true || $value == false');
        if ($value == true)
        {
            return Yii::app()->user->userModel->id;
        }
        return null;
    }

    /**
     * Override so that it shows up as a checkbox and not a dropdown since normally checkboxes are converted to
     * dropdowns in search views.
     */
    public static function getIgnoredSavableMetadataRules()
    {
        return array('BooleanAsDropDown');
    }
}

Any help would be appreciated!



#2 miek1123

miek1123

    Member

  • Members
  • PipPip
  • 19 posts

Posted 19 May 2014 - 06:46 PM

Well i figured out my own problem.   It seems in order to tell SearchDataProviderMetadataAdapter that the attribute is only defined in the SearchForm is you HAVE to define a class variable with the same name as the rule.

 

So in my case i had to add the following to my custom SearchForm.. and now it works like magic!

public $recruiterItemsOnly;






0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users