Example #1
0
 function canBeDeleted(&$error_message)
 {
     $childs = $this->getAllChildren();
     if (MemberPropertyMembers::isMemberAssociated($this->getId())) {
         $error_message = lang("cannot delete member is associated");
         return false;
     }
     $continue_check = false;
     if (count($childs) == 0) {
         $continue_check = true;
     } else {
         if ($this->getParentMemberId() > 0) {
             $child_ots = DimensionObjectTypeHierarchies::getAllChildrenObjectTypeIds($this->getDimensionId(), $this->getParentMember()->getObjectTypeId(), false);
         }
         foreach ($childs as $child) {
             // check if child can be put in the parent (or root)
             if ($this->getParentMemberId() == 0) {
                 $dim_ot = DimensionObjectTypes::findOne(array("conditions" => array("`dimension_id` = ? AND `object_type_id` = ?", $this->getDimensionId(), $child->getObjectTypeId())));
                 if (!$dim_ot->getIsRoot()) {
                     $error_message = lang("cannot delete member cannot be root");
                     return false;
                 }
             } else {
                 if (!in_array($child->getObjectTypeId(), $child_ots)) {
                     $error_message = lang("cannot delete member childs cannot be moved to parent");
                     return false;
                 }
             }
         }
         $continue_check = true;
     }
     if (!$continue_check) {
         return false;
     } else {
         $child_ids = $this->getAllChildrenIds();
         $child_ids[] = $this->getId();
         $child_ids_str = implode(",", $child_ids);
         $objects_in_member = ObjectMembers::instance()->findAll(array('conditions' => 'member_id = ' . $this->getId()));
         if (!$objects_in_member || count($objects_in_member) == 0) {
             return true;
         } else {
             $more_conditions = "";
             if (Plugins::instance()->isActivePlugin('core_dimensions')) {
                 $person_dim = Dimensions::findByCode('feng_persons')->getId();
                 $more_conditions = " AND member_id NOT IN (SELECT id FROM " . TABLE_PREFIX . "members WHERE dimension_id={$person_dim})";
             }
             $object_id_condition = $this->getObjectId() > 0 ? " AND o.id <> " . $this->getObjectId() : "";
             foreach ($objects_in_member as $om) {
                 $obj_members = ObjectMembers::findAll(array("conditions" => array("`object_id` = ? AND `is_optimization` = 0 AND member_id IN ({$child_ids_str}) AND EXISTS (SELECT o.id FROM " . TABLE_PREFIX . "objects o WHERE o.id = ? AND o.trashed_by_id=0 {$object_id_condition})" . $more_conditions, $om->getObjectId(), $om->getObjectId())));
                 if (count($obj_members) >= 1) {
                     $error_message = lang("cannot delete member has objects");
                     return false;
                 }
                 $db_res = DB::execute("SELECT object_type_id FROM " . TABLE_PREFIX . "objects WHERE id=" . $om->getObjectId());
                 $row = $db_res->fetchRow();
                 if ($row && array_var($row, 'object_type_id')) {
                     $req_dim_ids = DimensionObjectTypeContents::getRequiredDimensions(array_var($row, 'object_type_id'));
                     if (in_array($this->getDimensionId(), $req_dim_ids)) {
                         $error_message = lang("cannot delete member is required for objects");
                         return false;
                     }
                 }
             }
         }
     }
     return true;
 }
function workspaces_additional_dashboard_actions($ignored, &$actions)
{
    $ws_dim = Dimensions::findByCode('workspaces');
    $wot = ObjectTypes::findByName('workspace');
    $wdot = DimensionObjectTypes::findOne(array('conditions' => 'dimension_id=' . $ws_dim->getId() . ' AND object_type_id=' . $wot->getId()));
    if ($wdot instanceof DimensionObjectType && $wdot->getEnabled()) {
        if (active_context_can_contain_member_type($ws_dim->getId(), $wot->getId())) {
            $actions[] = array('id' => 'workspaces-list', 'assoc_ot' => $wot->getId(), 'assoc_dim' => $ws_dim->getId(), 'name' => lang('workspaces list'), 'class' => 'link-ico ico-workspace', 'onclick' => "og.openLink(og.getUrl('member', 'init', {dim_id:" . $ws_dim->getId() . ", type_id:" . $wot->getId() . "}), {caller:'" . $ws_dim->getCode() . "'}); return false;");
        }
    }
    $tags_dim = Dimensions::findByCode('tags');
    $tot = ObjectTypes::findByName('tag');
    $tdot = DimensionObjectTypes::findOne(array('conditions' => 'dimension_id=' . $tags_dim->getId() . ' AND object_type_id=' . $tot->getId()));
    if ($tdot instanceof DimensionObjectType && $tdot->getEnabled()) {
        if (active_context_can_contain_member_type($tags_dim->getId(), $tot->getId())) {
            $actions[] = array('id' => 'tags-list', 'assoc_ot' => $tot->getId(), 'assoc_dim' => $tags_dim->getId(), 'name' => lang('tags list'), 'class' => 'link-ico ico-tag', 'onclick' => "og.openLink(og.getUrl('member', 'init', {dim_id:" . $tags_dim->getId() . ", type_id:" . $tot->getId() . "}), {caller:'" . $tags_dim->getCode() . "'}); return false;");
        }
    }
}