Documentation

GroupAction

bool
CAdminList::GroupAction(
)

The GroupAction method returns true if any group action have been performed on the table rows and changes are to be saved.

Example

// process single and group actions
if(($arID = $lAdmin->GroupAction()) && $POST_RIGHT=="W")
{
    // if "apply to all" is selected
    if($_REQUEST['action_target']=='selected')
    {
        $cData = new CRubric;
        $rsData = $cData->GetList(array($by=>$order), $arFilter);
        while($arRes = $rsData->Fetch())
            $arID[] = $arRes['ID'];
    }

    // walk the list of elements
    foreach($arID as $ID)
    {
        if(strlen($ID)<=0)
            continue;
           $ID = IntVal($ID);
        
        // perform the required action on each element
        switch($_REQUEST['action'])
        {
        // remove
        case "delete":
            @set_time_limit(0);
            $DB->StartTransaction();
            if(!CRubric::Delete($ID))
            {
                $DB->Rollback();
                $lAdmin->AddGroupError(GetMessage("rub_del_err"), $ID);
            }
            $DB->Commit();
            break;
        
        // activate/deactivate
        case "activate":
        case "deactivate":
            $cData = new CRubric;
            if(($rsData = $cData->GetByID($ID)) && ($arFields = $rsData->Fetch()))
            {
                $arFields["ACTIVE"]=($_REQUEST['action']=="activate"?"Y":"N");
                if(!$cData->Update($ID, $arFields))
                    $lAdmin->AddGroupError(GetMessage("rub_save_error").$cData->LAST_ERROR, $ID);
            }
            else
                $lAdmin->AddGroupError(GetMessage("rub_save_error")." ".GetMessage("rub_no_rubric"), $ID);
            break;
        }

    }
}
© «Bitrix24», 2001-2024
Up