/**
 * @author Ignacio Vazquez - elpepe.uy at gmail.com
 * @param unknown_type $object
 * @param unknown_type $ignored
 */
function core_dimensions_after_update($object, &$ignored)
{
    static $objectsProcessed = array();
    if ($object instanceof Contact && !array_var($objectsProcessed, $object->getId())) {
        $person_dim = Dimensions::findOne(array("conditions" => "`code` = 'feng_persons'"));
        $person_ot = ObjectTypes::findOne(array("conditions" => "`name` = 'person'"));
        $company_ot = ObjectTypes::findOne(array("conditions" => "`name` = 'company'"));
        $members = Members::findByObjectId($object->getId(), $person_dim->getId());
        if (count($members) == 1) {
            /* @var $member Member */
            $member = $members[0];
            $member->setName($object->getObjectName());
            $parent_member_id = $member->getParentMemberId();
            $depth = $member->getDepth();
            if ($object->getCompanyId() > 0) {
                $pmember = Members::findOne(array('conditions' => '`object_id` = ' . $object->getCompanyId() . ' AND `object_type_id` = ' . $company_ot->getId() . ' AND `dimension_id` = ' . $person_dim->getId()));
                $member->setParentMemberId($pmember->getId());
                $member->setDepth($pmember->getDepth() + 1);
            } else {
                //Is first level
                $member->setDepth(1);
                $member->setParentMemberId(0);
            }
            $object->modifyMemberValidations($member);
            $member->save();
            // reload only if not disabling or enabling user
            if (!(array_var($_REQUEST, 'c') == 'account' && (array_var($_REQUEST, 'a') == 'disable' || array_var($_REQUEST, 'a') == 'restore_user'))) {
                evt_add("reload dimension tree", $member->getDimensionId());
            }
            $objectsProcessed[$object->getId()] = true;
        }
    }
}
 function modifyMemberValidations($member)
 {
     if ($member instanceof Member) {
         $member->add_skip_validation('uniqueness of parent - name');
     } else {
         if ($this->getId() > 0 && Plugins::instance()->isActivePlugin('core_dimensions')) {
             $dim = Dimensions::findByCode('feng_persons');
             if ($dim instanceof Dimension) {
                 $m = Members::findByObjectId($this->getId(), $dim->getId());
                 if ($m instanceof Member) {
                     $m->add_skip_validation('uniqueness of parent - name');
                 }
             }
         }
     }
 }