Open file Service/Callback.php add following function:
Code Block | ||||
---|---|---|---|---|
| ||||
public function getGlobalPrivacySettings()
{
return array(
'todo.default_privacy_setting' => array(
'phrase' => _p('todo')
)
);
}
|
Edit file add.html.php, add following code
Code Block | ||||
---|---|---|---|---|
| ||||
{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 must be added on phrase.json
- todo.default_privacy_setting is an unique var_name used in callback
Back to file Controller/AddController.php, modify it as following code
Code Block | ||||
---|---|---|---|---|
| ||||
<?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'=>$vals['privacy'], // modify this line...
'task_status'=>0, // mark task is in-complete
]);
//...and this condition statement
if ($vals['privacy'] == '4') {
\Phpfox::getService('privacy.process')->add('todo', $iItemId,
(isset($aVals['privacy_list']) ? $aVals['privacy_list'] : array()));
}
|
Now your todo list item has it own privacy. We open Controller/ViewController.php to check if user has the permission to view it.
We add following code, right after getting todo-list detail:
Code Block | ||||
---|---|---|---|---|
| ||||
<?php
$aItem = $browseService->getForBrowse($id);
if (\Phpfox::isModule('privacy')) {
\Phpfox::getService('privacy')->check('todo', $aItem['task_id'], $aItem['user_id'], $aItem['privacy'],
$aItem['is_friend']);
}
|
With:
- todo: is your app alias
- $aItem['task_id']: your todo list ID
- $aItem['user_id']: user ID of todo list owner
- $aItem['privacy']: privacy of this todo list
- $aItem['is_friend']: are viewing user and creator user friends?
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 can view
- 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.
...