Programmatically adding permission of adding a subpage to a group who has the permission of editing a page

Permalink
I have a huge website with advanced permissions where pages under a given path have permissions given to different group users (one per page) for editing their page content

Now, I want to add for the group the permission to add subpage but didn't find how to do that

here is some of my code:

$list = new \Concrete\Core\Page\PageList();
$list-> filterByPath('/associations');
$pages = $list->getResults();
foreach ($pages as $page) {
  $title = $page->getCollectionName();
  echo $title;
//  $pk = \Concrete\Core\Permission\Key::PagePermissionKey::getByHandle("edit_page_contents");
$permissions = new Permissions($page);
if ($permissions->canEditPageContents()) {
  echo "<pre>acces: "; print_r($permissions->canEditPageContents()); echo "</pre>"; //uggly and useless informations... I can't find there any informations about the group
  //my question here: how to find the group who can edit page contents, so that I may give that group the permission of adding page to the current page with sthing like the next line:
  //$page->assignPermissions($group,array('add_subpage'));
}


Note:
As I was unable to find an API solution, I tried to look in the db:
I've seen in the database that the only change is in the table PagePermissionAssignments where an insert is done with
1st column cID which is the pageID
2nd column "15" for pkID (which is "add_subpage")
and a strange 3rd column named paID which I don't understand how it works
Thank you

radeff
 
linuxoid replied on at Permalink Reply
linuxoid
Have a look below, it creates a folder and a group of users with certain permissions, maybe something from it may be modified to your needs:
private function install()
{
   $config_database = $this->app->make('config/database');
   $group_id = $config_database->get('classifieds.classifieds_user_group');
   if (empty($group_id)) {
      $group = Group::getByName('Classifieds User');
   }
   else {
      $group = Group::getByID($group_id);
   }
   if (!$group || $group->getGroupID() < 1) {
      $group = Group::add('Classifieds User', t('Registered Classifieds Users'));
   }
   $config_database->save('classifieds.classifieds_user_group', $group->getGroupID());
   if (is_object($group)) {
radeff replied on at Permalink Reply
radeff
Thanks Linuxoid!
But I wasn't able to fix...
so I made in a other way, searching if there was a usergroup matching an element of the page
if it may interest anybody here is my code
<?php
$nh = Loader::helper('navigation');
$list = new \Concrete\Core\Page\PageList();
$list-> filterByPath('/associations');
$pages = $list->getResults();
foreach ($pages as $page) {
  if (is_object($page) && !$page->isError()) {
    $title = $page->getCollectionName();
    $url = $nh->getLinkToCollection($page);
    echo "<a href=\"" .$url ."\" target=\"_blank\">";
    echo $title;
    echo "</a>";
    $acronyme=preg_replace("/^.*\((.*)\)/","$1",$title);
    echo " acronyme: " .$acronyme;
    $autorise=array("add_subpage");