Page tree
Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 7 Next »

Control Privacy

Editing file add.html.php, add following code

{if Phpfox::isModule('privacy')}
     <div class="table form-group-flow">
            <div class="table_left">
                {_p var='privacy'}:
            <div class="table_right">
                {module name='privacy.form' privacy_name='privacy' privacy_info='control_who_can_see_this_todo' default_privacy='todo_default_privacy_setting'}


  • control_who_can_see_this_todo is a phrase that you must be added on phrase.json
  • todo_default_privacy_setting is an unique var_name use in callback

Back to file Controller/AddController.php, modify it as following code

$iItemId  = \Phpfox::getLib('database')->insert(\Phpfox::getT('todolist_task'),[
    'user_id'=> \Phpfox::getUserId(), // get current user id
    'name'=> $vals['name'],
    'time_stamp'=>time(),  // creatation time
    'time_update'=>time(), // last modification time
    'privacy'=>$aVals['privacy'], // modify this line
    'task_status'=>0, // mark task is in-complete
if ($vals['privacy'] == '4') {
    Privacy_Service_Process::instance()->add('todo', $iItemId,
 (isset($aVals['privacy_list']) ? $aVals['privacy_list'] : array()));

Now your todo list item has privacy. We move to controller view Controller/ViewController.php to check if user have permission.

We add following code, right below get todo list detail

    $aItem  = $browseService->getForBrowse($id);
    if (\Phpfox::isModule('privacy')) {
        \Privacy_Service_Privacy::instance()->check('todo', $aItem['task_id'], $aItem['user_id'], $aItem['privacy'],


  • todo: is your app alias
  • $aItem&: your todo list ID
  • $aItem&: user ID of todo list owner
  • $aItem&: privacy of this todo list
  • $aItem&:

We have following value for privacy:

  • 0: Public everyone can view
  • 1: Friends Only friend can view
  • 2: Friends of Friends Friends and Friends of Friends
  • 3: Only Me Only owner can view
  • 4: Custom Owner can define a list of users can view

We have to modify function getForBrowse to get more information if missing.

  • No labels