예제 #1
0
 /**
  * Save group permissions for an item
  *
  * @param string $gperm_name   name of the permission to test
  * @param int    $gperm_itemid id of the object to check
  * @param array  $groups       group ids to grant permission to
  *
  * @return bool   true if no errors
  **/
 public function savePermissionForItem($gperm_name, $gperm_itemid, $groups)
 {
     $result = true;
     // First, delete any existing permissions for this name and id
     $this->deletePermissionForItem($gperm_name, $gperm_itemid);
     // Save the new permissions
     if (count($groups) > 0) {
         foreach ($groups as $group_id) {
             $this->permissionHandler->addRight($gperm_name, $gperm_itemid, $group_id, $this->mid);
         }
     }
     return $result;
 }
예제 #2
0
 public function updatePerms($content_id, $groups = array())
 {
     $module_id = Page::getInstance()->getModule()->getVar('mid');
     $groups_exists = parent::getGroupIds('page_view_item', $content_id, $module_id);
     $groups_exists = array_values($groups_exists);
     $groups_delete = array_diff(array_values($groups_exists), $groups);
     $groups_add = array_diff($groups, array_values($groups_exists));
     // delete
     if (count($groups_delete) != 0) {
         $criteria = $criteria = new CriteriaCompo();
         $criteria->add(new Criteria('gperm_itemid', $content_id));
         $criteria->add(new Criteria('gperm_modid', $module_id));
         $criteria->add(new Criteria('gperm_name', 'page_view_item', '='));
         $criteria->add(new Criteria('gperm_groupid', '(' . implode(', ', $groups_delete) . ')', 'IN'));
         if (parent::deleteAll($criteria)) {
         }
     }
     // Add
     if (count($groups_add) != 0) {
         foreach ($groups_add as $group_id) {
             parent::addRight('page_view_item', $content_id, $group_id, $module_id);
         }
     }
 }