Page tree

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Control Privacy

Editing file add.html.php, add following code

Code Block
actionscript3
actionscript3
{if Phpfox::isModule('privacy')}
     <div class="table form-group-flow">
            <div class="table_left">
                {_p var='privacy'}:
            </div>
            <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'}
            </div>
        </div>
{/if}

With:

  • 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

Code Block
php
php
<?php 
$iItemId  = \Phpfox::getLib('database')->insert(\Phpfox::getT('todolist_task'),[
    'user_id'=> \Phpfox::getUserId(), // get current user id
    'name'=> $vals['name'],
    'description'=>$vals['description'],
    '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

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

With:

  • 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.