Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
219 commits
Select commit Hold shift + click to select a range
9cba4c5
switch thumbnail URL sizes to 300
shirleywbi Jan 26, 2021
486bc71
Merge branch 'master' into 943-non-optimized-thumbnails-displayed
shirleywbi Feb 3, 2021
feaf4e3
Merge branch 'master' into 943-non-optimized-thumbnails-displayed
nandanmen Feb 4, 2021
24ce57e
Install avataaars and add sample code
wynnset Feb 5, 2021
c5ac477
Merge branch 'master' into avataaars
wynnset May 25, 2021
1469dd5
building Avatar customizer
eabean Jun 3, 2021
65cd648
building Avatar customizer
eabean Jun 3, 2021
f93493a
basic Avatar customizer
eabean Jun 3, 2021
34f25b8
Avatar Customizer Done
eabean Jun 3, 2021
a15ac0f
added avatar form to settings
eabean Jun 4, 2021
0063b85
beginning saving avatar
eabean Jun 4, 2021
44a633a
PUT avatar working. Starting GET avatar.
eabean Jun 7, 2021
59dfa2d
basic AvatarForm working. GET implemented. Issues with async loading.
eabean Jun 7, 2021
4416bfe
async load working
eabean Jun 8, 2021
2c51851
clean up done. starting cypress tests
eabean Jun 8, 2021
1c162e1
more clean up
eabean Jun 8, 2021
9c78a90
further cleaning up
eabean Jun 8, 2021
b8514f8
further cleaning up
eabean Jun 8, 2021
0d549a3
added environment variable for avatar popup
eabean Jun 8, 2021
9c668f1
Merge branch 'avataaars' of https://github.com/wynnset/tapestry-wp in…
eabean Jun 8, 2021
5814380
changed buttons and added cypress test
eabean Jun 8, 2021
3e7fe70
lint fixes
eabean Jun 15, 2021
759684b
migrated major CoS files
eabean Jun 15, 2021
0bc6466
migration complete
eabean Jun 15, 2021
deeb2bd
Merge branch 'master' into avataaars
EldadZZipori Jun 15, 2021
273fb98
made CoS Button
eabean Jun 15, 2021
fce9b80
change: CSS changes, lint fixes
eabean Jun 17, 2021
e801045
change: adding user setting modal
eabean Jun 18, 2021
1ee78be
user setting button set up
eabean Jun 28, 2021
cedd83b
change: all Avatar related modals only show if user is logged in and …
eabean Jun 28, 2021
ee2faf7
fix: hide avatar-related components based on .env vars
eabean Jun 28, 2021
2b36579
removed: COS button from toolbar
eabean Jun 28, 2021
f190e70
removed: COS button icon
eabean Jun 28, 2021
7a5e2ed
starting fixing cypress tests
eabean Jun 28, 2021
a78f2fc
added: cypress tests
eabean Jun 28, 2021
286dd9b
change: all users can access user settings
eabean Jun 28, 2021
ae5f07d
changed: renamed .env variable
eabean Jun 28, 2021
7762c52
fix: all Users can edit avatar
eabean Jun 28, 2021
55923e3
change: cypresss test is skipped. toolbar styling
eabean Jun 29, 2021
e7f4a17
fix: avatar enabling working
eabean Jun 29, 2021
12e806d
fix: cypress test
eabean Jun 29, 2021
de3d0fb
add toggle for tyde mode
EldadZZipori Jun 29, 2021
ad8cbed
add base node selection
EldadZZipori Jun 30, 2021
c934f47
render tapestry only if user has edit permission
EldadZZipori Jul 1, 2021
4a329fd
set default node to open in fullscreen with no exit button
EldadZZipori Jul 1, 2021
3a6de3c
preliminary navbar
EldadZZipori Jul 2, 2021
36565aa
updated navbar styling
EldadZZipori Jul 2, 2021
1ed88e1
refactor unnecessary states
EldadZZipori Jul 2, 2021
f3a3a46
Merge branch 'tyde2' into avataaars
eabean Jul 2, 2021
3e9bb4d
major migration complete, lint fixes
eabean Jul 2, 2021
dc13ab6
added: line in cypress test
eabean Jul 2, 2021
d277af1
navigation bar style and functionality update
EldadZZipori Jul 3, 2021
aa83230
fix sizeing
EldadZZipori Jul 3, 2021
0940327
fix admin view
EldadZZipori Jul 3, 2021
ebfc310
conditionals fix
EldadZZipori Jul 3, 2021
bb26771
add tyde setting validation
EldadZZipori Jul 3, 2021
1305da5
fix css and settings validation
EldadZZipori Jul 4, 2021
bc5f6bc
update style to apply only under navbar
EldadZZipori Jul 4, 2021
96cc677
update navbar css
EldadZZipori Jul 4, 2021
0ab8ad4
Merge branch 'master' into 1061-add-tyde-mode
EldadZZipori Jul 4, 2021
4ca1423
fix svgs naming
EldadZZipori Jul 4, 2021
08f0746
Merge branch '1061-add-tyde-mode' of https://github.com/wynnset/tapes…
EldadZZipori Jul 4, 2021
71416db
Merge branch 'tyde2' into 1061-add-tyde-mode
EldadZZipori Jul 5, 2021
35cec07
add tydeMode display to store
EldadZZipori Jul 5, 2021
565c024
add tooltip position to helpers.js
EldadZZipori Jul 6, 2021
cc430df
Merge branch '1061-add-tyde-mode' into 1047-migrate-circle-of-support
EldadZZipori Jul 6, 2021
bd00836
add cos route
EldadZZipori Jul 6, 2021
1a2d528
improve data flow
EldadZZipori Jul 6, 2021
5617901
remove unnecessary imports
EldadZZipori Jul 6, 2021
72ea87c
Merge branch '1061-add-tyde-mode' into 1047-migrate-circle-of-support
EldadZZipori Jul 6, 2021
c02267b
fix fullscreen
EldadZZipori Jul 6, 2021
a9861af
Merge branch '1061-add-tyde-mode' into 1047-migrate-circle-of-support
EldadZZipori Jul 6, 2021
e1df897
initial add of cos to tyde mode
EldadZZipori Jul 6, 2021
9a15d6b
remove favorite button for tyde mode
EldadZZipori Jul 6, 2021
522fc7e
move navbar to lightbox
EldadZZipori Jul 7, 2021
b3ff99d
always open in full screen
EldadZZipori Jul 7, 2021
15bd0e4
update selecting mechanism
EldadZZipori Jul 7, 2021
fc22da9
Merge branch '1061-add-tyde-mode' into 1047-migrate-circle-of-support
EldadZZipori Jul 7, 2021
15683e0
navigate to cos from navbar
EldadZZipori Jul 7, 2021
d3d15e4
fix navbar image selection
EldadZZipori Jul 7, 2021
1307ed3
code cleanup
EldadZZipori Jul 7, 2021
cd525c4
switch to canEditTapestry use
EldadZZipori Jul 7, 2021
00dfa43
naming change and small css fix
EldadZZipori Jul 7, 2021
74daf67
remove displayTydeMode use
EldadZZipori Jul 7, 2021
27443e0
move tyde assets to tyde folder
EldadZZipori Jul 7, 2021
f63f6fb
fix role selection
EldadZZipori Jul 7, 2021
7c57ee9
fix roles and add public role
EldadZZipori Jul 7, 2021
a4f6d60
Merge branch '1061-add-tyde-mode' into 1047-migrate-circle-of-support
EldadZZipori Jul 7, 2021
f584cf0
css fix
EldadZZipori Jul 7, 2021
918763f
fix normal node display
EldadZZipori Jul 7, 2021
b10ba0f
Merge branch '1061-add-tyde-mode' into 1047-migrate-circle-of-support
EldadZZipori Jul 8, 2021
d5f18d2
fix page menu not appearing
EldadZZipori Jul 8, 2021
0c5ed9f
page fix
EldadZZipori Jul 8, 2021
886ada5
exported avatar options to own file
eabean Jul 8, 2021
9b7c1bb
avatarForm refactoring
eabean Jul 8, 2021
7a55f4c
refactoring: removing unneeded code
eabean Jul 8, 2021
2e989ea
small fixes
eabean Jul 8, 2021
f24d557
toolbar refactoring
eabean Jul 9, 2021
241df6a
popup refactoring
eabean Jul 9, 2021
06b58d1
fix: toolbar only shows when an item inside it is visible
eabean Jul 9, 2021
b4c797c
css update
EldadZZipori Jul 9, 2021
c9ff8cf
change: saving userSettings instead of avatar. need to fix toolbar
eabean Jul 9, 2021
c7df108
change: saving userSettings instead of avatar. need to fix toolbar
eabean Jul 9, 2021
fa28c81
fix: toolbar displays correctly
eabean Jul 12, 2021
4251d8e
changed: getAvatar endpoint name
eabean Jul 12, 2021
d62c0cb
changed: getAvatar endpoint name 2
eabean Jul 12, 2021
0313c9e
fix: avatar retrieval
eabean Jul 12, 2021
07287aa
fixed toolbar padding
eabean Jul 12, 2021
dd177bc
added: README instructions, avatar modal CSS fixes
eabean Jul 12, 2021
b77d57d
added: README instructions, avatar modal CSS fixes
eabean Jul 12, 2021
e50f874
added: README instructions, avatar modal CSS fixes
eabean Jul 12, 2021
9e8edae
Revert "added: README instructions, avatar modal CSS fixes"
eabean Jul 12, 2021
a9b5a0c
addition: re-migrated changes
eabean Jul 13, 2021
fc6bbce
fix cypress test
eabean Jul 13, 2021
5c6aef1
I am still worthy
Frozemint Jul 14, 2021
d198d91
Revert "I am still worthy"
Frozemint Jul 14, 2021
60d7e86
Merge remote-tracking branch 'origin/master' into tyde2
wynnset Jul 15, 2021
7a80ae3
Merge branch 'tyde2' into 1061-add-tyde-mode
wynnset Jul 15, 2021
d7384a5
Merge branch '1061-add-tyde-mode' into 1047-migrate-circle-of-support
wynnset Jul 15, 2021
46fb9ee
Minor code and styling improvements
wynnset Jul 15, 2021
03bdb0d
switch to v-show
EldadZZipori Jul 15, 2021
8247d86
lightbox style fix
EldadZZipori Jul 16, 2021
0dec135
use v-if for cos
EldadZZipori Jul 16, 2021
8ea7d98
fix h5p and youtube media display
EldadZZipori Jul 16, 2021
25e915a
Merge branch '1047-migrate-circle-of-support' into 1067-migrate-commu…
EldadZZipori Jul 16, 2021
b2f5a9a
cypress test fix
EldadZZipori Jul 16, 2021
0347a22
Merge branch 'tyde2' into 1061-add-tyde-mode
wynnset Jul 19, 2021
5666895
Merge branch '1061-add-tyde-mode' into 1047-migrate-circle-of-support
wynnset Jul 19, 2021
663dd5c
change: further simplified avatarOptions, fix typo
eabean Jul 16, 2021
9769029
Merge branch 'tyde2' into 1029-avataaars-copy
eabean Jul 21, 2021
7d60843
tyde2 merging fixed
eabean Jul 21, 2021
992a776
remove comments and remove unnecessary file
EldadZZipori Jul 26, 2021
7ecf5e5
remove br and fix cos width
EldadZZipori Jul 26, 2021
d840baf
remove console log
wynnset Jul 26, 2021
d129058
Exclude admin roles in tyde mode, fix misspelling, and add more checks
wynnset Jul 28, 2021
d333274
Merge branch '1061-add-tyde-mode' into 1047-migrate-circle-of-support
wynnset Jul 28, 2021
d1ac438
pushing package-lock.json changes
eabean Aug 3, 2021
e2b9d82
copied base onboarding files
eabean Aug 3, 2021
b6a06e1
change: moved onboarding files. changed onboardingMachine.js to inclu…
eabean Aug 3, 2021
5edd57e
added: welcome-circles
eabean Aug 4, 2021
386df9f
progress
eabean Aug 4, 2021
a9fdee5
Merge remote-tracking branch 'origin/tyde2' into 1047-migrate-circle-…
wynnset Aug 4, 2021
6b6e00f
Merge branch '1047-migrate-circle-of-support' into 1029-avataaars-copy
eabean Aug 4, 2021
217960e
merge conflicts fixed
eabean Aug 4, 2021
53d4664
push package-lock.json
eabean Aug 4, 2021
fc631c0
1092 - TYDE 2 - Add ability to delete CoS connection (#1093)
EldadZZipori Aug 4, 2021
89ae912
1067 - TYDE2 - Migrate community view onboarding (#1072)
eabean Aug 4, 2021
6cb0c2d
1073 - Change emoji selector to allow skin colour selection (#1075)
Frozemint Aug 4, 2021
38ff060
chaged circle view to use avatar
eabean Aug 4, 2021
7611c3c
starting circle onboarding
eabean Aug 5, 2021
55972a5
basic onboarding layout complete
eabean Aug 5, 2021
1bad5bd
Merge branch '1047-migrate-circle-of-support' into 1094-circle-view-o…
eabean Aug 5, 2021
a3b8368
linting
eabean Aug 5, 2021
976d0e8
merged with base branch
eabean Aug 5, 2021
a123181
fix: send event when connection moved
eabean Aug 7, 2021
500c9c7
merge changes from 1047
eabean Aug 7, 2021
ab69b0c
push package.lock, lint fixes
eabean Aug 7, 2021
9067fe4
deleted old onboarding folder. basic onboarding complete
eabean Aug 9, 2021
2cfd619
minor changes
eabean Aug 9, 2021
866db15
added: circle view unlocks after selected node is complete.
eabean Aug 10, 2021
901a3df
deleted identical components
eabean Aug 13, 2021
1d37c74
removed top tooltip
eabean Aug 13, 2021
46b9a33
deleting toptooltip
eabean Aug 13, 2021
c206d57
added gifs to assets folder
eabean Aug 13, 2021
dc917a2
change: if circleViewNode not defined, circle view enabled
eabean Aug 13, 2021
48d5165
Merge branch 'tyde2' into 1047-migrate-circle-of-support
wynnset Aug 18, 2021
6e2f4fc
Code improvement
wynnset Aug 18, 2021
a58370f
fixing initialization
eabean Aug 18, 2021
e6640bc
initialization fixing 2
eabean Aug 18, 2021
423deee
cleaning up
eabean Aug 18, 2021
a964c6b
Merge remote-tracking branch 'origin/1047-migrate-circle-of-support' …
wynnset Aug 18, 2021
2400dd0
Merge remote-tracking branch 'origin/tyde2' into 1029-avataaars-copy
wynnset Aug 18, 2021
cf50973
Improve avatar customizer UI
wynnset Aug 19, 2021
47d82e8
merging in changes from tyde2
eabean Aug 20, 2021
910ee8b
lint fixes
eabean Aug 20, 2021
63c2c59
fixed toolbar conditions
eabean Aug 20, 2021
9e5f5ec
refactoring changes
eabean Aug 20, 2021
f379fe9
centered avatar in circle view
eabean Aug 20, 2021
3d3cdf6
avatar initialization works in tyde mode
eabean Aug 20, 2021
75670f0
UI & code improvements
wynnset Aug 23, 2021
ec1fb65
fix: changed button text
eabean Aug 27, 2021
2494a1b
fix initialization and tooltip positions
eabean Aug 27, 2021
1c1957e
fix tooltip
eabean Aug 27, 2021
5aab635
fix: initialization
eabean Aug 27, 2021
7771818
deleted old onboarding folder. fixing circle view enabling
eabean Aug 27, 2021
0035481
added disabled button CSS
eabean Aug 27, 2021
975bc85
try left
eabean Sep 1, 2021
b9aee80
try left 2
eabean Sep 1, 2021
c74bc0b
try left 4
eabean Sep 1, 2021
5f40216
try left 4
eabean Sep 1, 2021
a16016d
left 5
eabean Sep 1, 2021
60c5b32
try 2
eabean Sep 1, 2021
61b93dd
changed tooltip styling
eabean Sep 1, 2021
30c9f45
Merge branch 'tyde2' into 1029-avataaars-copy
wynnset Sep 13, 2021
91a58cf
Enable avatar usage without an environment variable
wynnset Sep 13, 2021
09ad762
Refactor
wynnset Sep 13, 2021
5558708
Merge branch 'tyde2' into 1094-circle-view-onboarding
wynnset Sep 17, 2021
82fa48a
Merge branch 'tyde2' into 1029-avataaars-copy
wynnset Sep 17, 2021
b765585
Refactor
wynnset Sep 17, 2021
669cb7a
Merge branch 'tyde2' into 1029-avataaars-copy
wynnset Sep 17, 2021
1d33003
Merge branch 'tyde2' into 1094-circle-view-onboarding
wynnset Sep 17, 2021
f7aef7c
bug fixes and refactoring
wynnset Sep 17, 2021
2a73584
Improve connection spacing and loading speed of COS
wynnset Sep 18, 2021
779ba56
Merge branch 'tyde2' into 1029-avataaars-copy
wynnset Sep 18, 2021
275c635
Disable avatars unless tyde mode is enabled
wynnset Sep 18, 2021
c6d725a
Merge branch 'tyde2' into 1094-circle-view-onboarding
wynnset Sep 18, 2021
a3f27eb
Wording and styling improvements
wynnset Sep 18, 2021
3b51fc3
Merge branch '1029-avataaars-copy' into 1094-circle-view-onboarding
wynnset Sep 18, 2021
08d50cb
refactor
wynnset Sep 18, 2021
3a0491c
Merge branch '1094-circle-view-onboarding' of github.com:wynnset/tape…
wynnset Sep 22, 2021
464ba5a
Merge branch 'tyde2' into 1094-circle-view-onboarding
wynnset Sep 22, 2021
3d51dca
initial refactoring for new process
EldadZZipori Sep 26, 2021
ef0c016
Merge branch 'tyde2' into 1094-circle-view-onboarding
EldadZZipori Sep 26, 2021
88c6305
Add two views for the onboarding
EldadZZipori Sep 28, 2021
7e031c0
finished circle onboarding exepect gifs
EldadZZipori Oct 1, 2021
b0fb463
refactoring and adding gif
EldadZZipori Oct 1, 2021
e677962
refactoring
EldadZZipori Oct 7, 2021
2b73c9b
Merge branch '1094-circle-view-onboarding' of github.com:wynnset/tape…
wynnset Oct 20, 2021
8b4d26a
Merge branch 'tyde2' into 1094-circle-view-onboarding
wynnset Oct 20, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions classes/activities/class.circle-of-support.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,6 @@ public function removeConnectionFromCommunity($connectionId, $communityId)

public function deleteConnection($connectionId)
{
if (!isset($this->current['connections']->$connectionId)) {
return;
}
$this->removeConnectionFromCircles($connectionId);

foreach ($this->current['communities'] as $key => $value) {
Expand All @@ -100,7 +97,9 @@ public function deleteConnection($connectionId)
$this->removeConnectionFromCommunity($connectionId, $key);
}

unset($this->current['connections']->$connectionId);
if (isset($this->current['connections']->$connectionId)) {
unset($this->current['connections']->$connectionId);
}
}

public function updateConnection($id, $connection)
Expand Down
20 changes: 4 additions & 16 deletions classes/class.tapestry-node.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ class TapestryNode implements ITapestryNode
private $license;
private $references;
private $mapCoordinates;
private $isDyad;
private $popup;

/**
Expand Down Expand Up @@ -99,7 +98,6 @@ public function __construct($tapestryPostId = 0, $nodeMetaId = 0)
'lat' => '',
'lng' => '',
];
$this->isDyad = false;
$this->popup = null;

if (TapestryHelpers::isValidTapestryNode($this->nodeMetaId)) {
Expand Down Expand Up @@ -208,9 +206,6 @@ public function set($node)
if (isset($node->hideTitle) && is_bool($node->hideTitle)) {
$this->hideTitle = $node->hideTitle;
}
if (isset($node->isDyad) && is_bool($node->isDyad)) {
$this->isDyad = $node->isDyad;
}
if (isset($node->hideProgress) && is_bool($node->hideProgress)) {
$this->hideProgress = $node->hideProgress;
}
Expand Down Expand Up @@ -304,7 +299,7 @@ public function removeConditionsById($nodeId)
}
}

public function getLockedState()
public function getLockedState($userId = 0)
{
$conditions = $this->conditions;
$userProgress = new TapestryUserProgress($this->tapestryPostId, $this->nodeMetaId);
Expand All @@ -316,8 +311,7 @@ public function getLockedState()
foreach ($conditions as $condition) {
switch ($condition->type) {
case ConditionTypes::NODE_COMPLETED:
$conditionProgress = new TapestryUserProgress($this->tapestryPostId, $condition->nodeId);
if ($conditionProgress->isCompleted()) {
if ($userId && $userProgress->isCompleted($condition->nodeId, $userId)) {
$condition->fulfilled = true;
}
break;
Expand All @@ -339,9 +333,9 @@ public function getLockedState()
return $conditions;
}

public function isLocked()
public function isLocked($userId = 0)
{
$conditions = $this->getLockedState();
$conditions = $this->getLockedState($userId);

$numFulfilled = 0;
foreach ($conditions as $condition) {
Expand Down Expand Up @@ -389,11 +383,6 @@ public function isAuthor($userId = 0)
return $nodeMeta->author->id == $userId;
}

public function isDyad()
{
return $this->isDyad;
}

public function addReview($comments)
{
if (NodeStatus::PUBLISH === $this->status) {
Expand Down Expand Up @@ -588,7 +577,6 @@ private function _formNode()
'license' => $this->license,
'references' => $this->references,
'mapCoordinates' => $this->mapCoordinates,
'isDyad' => $this->isDyad,
'popup' => $this->popup,
];
}
Expand Down
60 changes: 5 additions & 55 deletions classes/class.tapestry-user-progress.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ class TapestryUserProgress implements ITapestryUserProgress
private $_userId = null;
private $postId;
private $nodeMetaId;
private $_dyadLinkedUserId = null;
private $node;

/**
* Constructor.
Expand All @@ -26,27 +24,9 @@ class TapestryUserProgress implements ITapestryUserProgress
*/
public function __construct($postId = null, $nodeMetaId = null)
{
$this->_userId = apply_filters('determine_current_user', false);
$this->postId = $postId;
$this->nodeMetaId = $nodeMetaId;

if ($nodeMetaId) {
$this->node = new TapestryNode($postId = null, $nodeMetaId = null);
}

$this->_userId = apply_filters('determine_current_user', false);
if ($this->_userId) {
global $TYDE_DYAD_ROLES;
$isDyadUser = array_intersect(get_userdata($this->_userId)->roles, array_keys($TYDE_DYAD_ROLES));
if ($isDyadUser) {
$linkedUserId = get_user_meta($this->_userId, 'linked_dyad_user_id', true);
if ($linkedUserId) {
if ($this->node && $this->node->isDyad()) {
$this->_userId = $linkedUserId;
}
$this->_dyadLinkedUserId = $linkedUserId;
}
}
}
}

/**
Expand All @@ -62,7 +42,7 @@ public function get()
$tapestry = new Tapestry($this->postId);
$nodeIds = $tapestry->getNodeIds();

return $this->_getUserProgress($nodeIds);
return $this->_getUserProgress($nodeIds, $this->_userId);
}

/**
Expand All @@ -75,7 +55,6 @@ public function get()
public function updateUserProgress($progressValue)
{
$this->_checkPostId();
$this->_checkProgressAbility();

if (null !== $progressValue) {
$progressValue = floatval($progressValue);
Expand All @@ -97,7 +76,6 @@ public function updateUserProgress($progressValue)
public function complete()
{
$this->_checkPostId();
$this->_checkProgressAbility();
$this->_complete();
}

Expand All @@ -112,7 +90,6 @@ public function complete()
public function completeQuestion($questionId, $answerType, $answerData)
{
$this->_checkPostId();
$this->_checkProgressAbility();
$this->_completeQuestion($questionId, $answerType, $answerData);
}

Expand Down Expand Up @@ -165,19 +142,8 @@ public function getAvatar()
return $this->_getAvatar();
}

public function isCompleted($nodeId = null, $userId = null)
public function isCompleted($nodeId, $userId)
{
if (!$nodeId) {
$nodeId = $this->nodeMetaId;
}
if (!$userId) {
$userId = $this->_userId;
}

if (!$userId) {
return false;
}

$nodeMetadata = get_metadata_by_mid('post', $nodeId)->meta_value;
$completed_value = get_user_meta($userId, 'tapestry_'.$this->postId.'_node_completed_'.$nodeId, true);
if (null !== $completed_value) {
Expand Down Expand Up @@ -232,24 +198,17 @@ private function _completeQuestion($questionId, $answerType, $answerData)
update_user_meta($this->_userId, 'tapestry_'.$this->postId.'_'.$this->nodeMetaId.'_question_'.$questionId.'_answers', $userAnswer);
}

private function _getUserProgress($nodeIdArr)
private function _getUserProgress($nodeIdArr, $userId)
{
$progress = new stdClass();
$tapestry = new Tapestry($this->postId);

$nodes = $tapestry->setUnlocked($nodeIdArr, $this->_userId);
$nodes = $tapestry->setUnlocked($nodeIdArr, $userId);

// Build json object for frontend e.g. {0: 0.1, 1: 0.2} where 0 and 1 are the node IDs
foreach ($nodes as $node) {
$nodeId = $node->id;

$userId = $this->_userId;

// Use linked user's progress if the user is a dyad and this node is a dyad node
if ($node->isDyad && $this->_dyadLinkedUserId) {
$userId = $this->_dyadLinkedUserId;
}

$progress_value = get_user_meta($userId, 'tapestry_'.$this->postId.'_progress_node_'.$nodeId, true);
$progress->$nodeId = new stdClass();
if (null !== $progress_value) {
Expand All @@ -262,10 +221,6 @@ private function _getUserProgress($nodeIdArr)
$progress->$nodeId->conditions = $node->conditions;
$progress->$nodeId->unlocked = $node->unlocked;

if ($node->isDyad && $this->_dyadLinkedUserId) {
$progress->$nodeId->node = $node;
}

if ($node->accessible) {
$progress->$nodeId->content = [
'typeData' => $node->typeData,
Expand Down Expand Up @@ -401,11 +356,6 @@ private function _checkPostId()
}
}

private function _checkProgressAbility()
{
return $this->_dyadLinkedUserId && $this->node && $this->node->isDyad();
}

private function _isValidTapestryPost()
{
// post ID exists in db
Expand Down
45 changes: 11 additions & 34 deletions classes/class.tapestry.php
Original file line number Diff line number Diff line change
Expand Up @@ -342,9 +342,9 @@ public function isEmpty()
return empty($this->rootId);
}

public function setUnlocked($nodeIds)
public function setUnlocked($nodeIds, $userId = 0)
{
$nodes = $this->_setAccessibleStatus($nodeIds);
$nodes = $this->_setAccessibleStatus($nodeIds, $userId);

return array_map(
function ($nodeData) {
Expand All @@ -354,7 +354,6 @@ function ($nodeData) {
$data->accessible = $nodeData->accessible;
$data->conditions = $nodeData->conditions;
$data->unlocked = $nodeData->unlocked;
$data->isDyad = $nodeData->isDyad;

return $data;
},
Expand Down Expand Up @@ -409,17 +408,16 @@ public function export()
];
}

private function _setAccessibleStatus($nodes)
private function _setAccessibleStatus($nodes, $userId)
{
$newNodes = array_map(
function ($nodeId) {
function ($nodeId) use ($userId) {
$node = new TapestryNode($this->postId, $nodeId);
$data = new stdClass();
$data->id = $nodeId;
$data->accessible = false;
$data->unlocked = !$node->isLocked();
$data->conditions = $node->getLockedState();
$data->isDyad = $node->isDyad();
$data->unlocked = !$node->isLocked($userId);
$data->conditions = $node->getLockedState($userId);

return $data;
},
Expand All @@ -433,40 +431,20 @@ function ($nodeId) {
break;
}
}
$this->_recursivelySetAccessibleAndDyad($root, [], [], $newNodes);
$this->_recursivelySetAccessible($root, [], $newNodes);
}

return $newNodes;
}

// Note: This also sets the isDyad node recursively
private function _recursivelySetAccessibleAndDyad($node, $visited, $dyadNodes, $nodeList)
private function _recursivelySetAccessible($node, $visited, $nodeList)
{
if (!isset($node)) {
return;
}
if (!in_array($node, $visited)) {
array_push($visited, $node);
}

// If this node is in the list of dyadNodes, mark it as dyad
if (in_array($node->id, $dyadNodes)) {
$node->isDyad = true;
if (($key = array_search($node->id, $dyadNodes)) !== false) {
unset($dyadNodes[$key]);
}
}

// If this node is dyad, save its children to be marked as dyad too
if ($node->isDyad) {
$childNodes = $this->_getNeighbours($node, 'source');
foreach ($childNodes as $childNode) {
if (!in_array($childNode, $dyadNodes)) {
array_push($dyadNodes, $childNode);
}
}
}

$node->accessible = $node->unlocked;
if ($node->accessible) {
$neighbourIds = $this->_getNeighbours($node);
Expand All @@ -484,19 +462,18 @@ private function _recursivelySetAccessibleAndDyad($node, $visited, $dyadNodes, $
foreach ($neighbours as $neighbour) {
if (!in_array($neighbour, $visited)) {
array_push($visited, $neighbour);
$this->_recursivelySetAccessibleAndDyad($neighbour, $visited, $dyadNodes, $nodeList);
$this->_recursivelySetAccessible($neighbour, $visited, $nodeList);
}
}
}
}

private function _getNeighbours($node, $from = 'both')
private function _getNeighbours($node)
{
$neighbourIds = [];

foreach ($this->links as $link) {
if ((in_array($from, ['both', 'source']) && $link->source === $node->id) ||
(in_array($from, ['both', 'target']) && $link->target === $node->id)) {
if ($link->source === $node->id || $link->target === $node->id) {
array_push(
$neighbourIds,
$link->source === $node->id ? $link->target : $link->source
Expand Down
Loading