예제 #1
0
 public function getAccessibleNotebooks($for_action, $debug_flag = 0)
 {
     if ($this->flag_is_system_admin) {
         if ($debug_flag) {
             echo "user is system admin<br/>\n";
         }
         return Notebook::getAllFromDb(['flag_delete' => FALSE], $this->dbConnection);
     }
     if (is_string($for_action)) {
         global $ACTIONS;
         $for_action = $ACTIONS[$for_action];
     }
     //util_prePrintR($this);
     $accessible_notebooks_ids = array();
     if ($for_action->name == 'view' || $for_action->name == 'list') {
         $all_notebooks = Notebook::getAllFromDb(['flag_workflow_published' => TRUE, 'flag_workflow_validated' => TRUE, 'flag_delete' => FALSE], $this->dbConnection);
         $accessible_notebooks_ids = Db_Linked::arrayOfAttrValues($all_notebooks, 'notebook_id');
     }
     $roles = $this->getRoles();
     if ($debug_flag) {
         echo "user roles are<br/>\n";
         util_prePrintR($roles);
     }
     foreach (Db_Linked::arrayOfAttrValues($roles, 'role_id') as $role_id) {
         $global_check = Role_Action_Target::getAllFromDb(['role_id' => $role_id, 'action_id' => $for_action->action_id, 'target_type' => 'global_notebook'], $this->dbConnection);
         if ($debug_flag) {
             echo "global_check is <br/>\n";
             util_prePrintR($global_check);
         }
         if (count($global_check) > 0) {
             $all_notebooks = Notebook::getAllFromDb(['flag_delete' => FALSE], $this->dbConnection);
             $accessible_notebooks_ids = Db_Linked::arrayOfAttrValues($all_notebooks, 'notebook_id');
         }
         $role_action_targets = Role_Action_Target::getAllFromDb(['role_id' => $role_id, 'action_id' => $for_action->action_id, 'target_type' => 'notebook'], $this->dbConnection);
         foreach ($role_action_targets as $rat) {
             if (!in_array($rat->target_id, $accessible_notebooks_ids)) {
                 $accessible_notebooks_ids[] = $rat->target_id;
             }
         }
     }
     //            util_prePrintR($accessible_notebooks_ids);
     $owned_notebooks = Notebook::getAllFromDb(['user_id' => $this->user_id], $this->dbConnection);
     $owned_notebook_ids = Db_Linked::arrayOfAttrValues($owned_notebooks, 'notebook_id');
     $additional_notebook_ids = array();
     foreach ($accessible_notebooks_ids as $an_id) {
         if (!in_array($an_id, $owned_notebook_ids)) {
             $additional_notebook_ids[] = $an_id;
         }
     }
     $additional_notebooks = array();
     if (count($additional_notebook_ids) > 0) {
         $additional_notebooks = Notebook::getAllFromDb(['notebook_id' => $additional_notebook_ids], $this->dbConnection);
     }
     $ret = array_merge($owned_notebooks, $additional_notebooks);
     //            util_prePrintR($accessible_notebooks_ids);
     return $ret;
 }
 public function doDelete($debug = 0)
 {
     if ($debug) {
         echo "PRE-ACTION of doDelete() on the object:\n";
         util_prePrintR($this);
     }
     $this->flag_delete = TRUE;
     $this->updateDb();
     if ($debug) {
         echo "POST-ACTION of doDelete() on the object:\n";
         util_prePrintR($this);
     }
     if ($this->matchesDb) {
         return TRUE;
     }
 }