diff --git a/classes/activities/class.circle-of-support.php b/classes/activities/class.circle-of-support.php index 777539526..d359a9da8 100644 --- a/classes/activities/class.circle-of-support.php +++ b/classes/activities/class.circle-of-support.php @@ -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) { @@ -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) diff --git a/classes/class.tapestry-node.php b/classes/class.tapestry-node.php index f17b31ed5..591b844db 100644 --- a/classes/class.tapestry-node.php +++ b/classes/class.tapestry-node.php @@ -46,7 +46,6 @@ class TapestryNode implements ITapestryNode private $license; private $references; private $mapCoordinates; - private $isDyad; private $popup; /** @@ -99,7 +98,6 @@ public function __construct($tapestryPostId = 0, $nodeMetaId = 0) 'lat' => '', 'lng' => '', ]; - $this->isDyad = false; $this->popup = null; if (TapestryHelpers::isValidTapestryNode($this->nodeMetaId)) { @@ -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; } @@ -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); @@ -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; @@ -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) { @@ -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) { @@ -588,7 +577,6 @@ private function _formNode() 'license' => $this->license, 'references' => $this->references, 'mapCoordinates' => $this->mapCoordinates, - 'isDyad' => $this->isDyad, 'popup' => $this->popup, ]; } diff --git a/classes/class.tapestry-user-progress.php b/classes/class.tapestry-user-progress.php index 6320d37df..e3b8eb24a 100644 --- a/classes/class.tapestry-user-progress.php +++ b/classes/class.tapestry-user-progress.php @@ -13,8 +13,6 @@ class TapestryUserProgress implements ITapestryUserProgress private $_userId = null; private $postId; private $nodeMetaId; - private $_dyadLinkedUserId = null; - private $node; /** * Constructor. @@ -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; - } - } - } } /** @@ -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); } /** @@ -75,7 +55,6 @@ public function get() public function updateUserProgress($progressValue) { $this->_checkPostId(); - $this->_checkProgressAbility(); if (null !== $progressValue) { $progressValue = floatval($progressValue); @@ -97,7 +76,6 @@ public function updateUserProgress($progressValue) public function complete() { $this->_checkPostId(); - $this->_checkProgressAbility(); $this->_complete(); } @@ -112,7 +90,6 @@ public function complete() public function completeQuestion($questionId, $answerType, $answerData) { $this->_checkPostId(); - $this->_checkProgressAbility(); $this->_completeQuestion($questionId, $answerType, $answerData); } @@ -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) { @@ -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) { @@ -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, @@ -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 diff --git a/classes/class.tapestry.php b/classes/class.tapestry.php index 8a3dd3c08..2d35c0f89 100644 --- a/classes/class.tapestry.php +++ b/classes/class.tapestry.php @@ -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) { @@ -354,7 +354,6 @@ function ($nodeData) { $data->accessible = $nodeData->accessible; $data->conditions = $nodeData->conditions; $data->unlocked = $nodeData->unlocked; - $data->isDyad = $nodeData->isDyad; return $data; }, @@ -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; }, @@ -433,14 +431,13 @@ 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; @@ -448,25 +445,6 @@ private function _recursivelySetAccessibleAndDyad($node, $visited, $dyadNodes, $ 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); @@ -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 diff --git a/tapestry.php b/tapestry.php index a4e28974c..3af240d58 100644 --- a/tapestry.php +++ b/tapestry.php @@ -16,18 +16,6 @@ // Set this to false if you want to use the Vue build instead of npm dev $TAPESTRY_USE_DEV_MODE = true; -// TYDE settings -$TYDE_YOUTH_ROLES = [ - 'youth' => 'Youth', - 'youth_l2' => 'Youth (Level 2)', - 'youth_l3' => 'Youth (Level 3)', -]; -$TYDE_DYAD_ROLES = [ - 'dyad' => 'Dyad', - 'dyad_l2' => 'Dyad (Level 2)', - 'dyad_l3' => 'Dyad (Level 3)', -]; - /** * Register endpoints. */ @@ -144,16 +132,6 @@ function tapestry_enqueue_vue_app() global $TAPESTRY_VERSION_NUMBER; global $TAPESTRY_USE_DEV_MODE; - global $TYDE_DYAD_ROLES; - $isDyad = wp_get_current_user() && array_intersect(wp_get_current_user()->roles, array_keys($TYDE_DYAD_ROLES)); - $dyadLinkedUser = null; - if ($isDyad) { - $dyadLinkedUserId = get_the_author_meta('linked_dyad_user_id', wp_get_current_user()->ID); - if ($dyadLinkedUserId) { - $dyadLinkedUser = get_user_by('id', $dyadLinkedUserId)->data; - } - } - // register the Vue build script. $vueUrl = $TAPESTRY_USE_DEV_MODE ? 'http://localhost:8080/dist' : plugin_dir_url(__FILE__).'templates/vue/dist'; @@ -184,7 +162,6 @@ function tapestry_enqueue_vue_app() ]), 'nonce' => wp_create_nonce('wp_rest'), 'wpUserId' => apply_filters('determine_current_user', false), - 'dyadLinkedWpUser' => $dyadLinkedUser, 'adminAjaxUrl' => admin_url('admin-ajax.php'), 'file_upload_nonce' => wp_create_nonce('media-form'), 'upload_url' => admin_url('async-upload.php'), @@ -345,70 +322,20 @@ function tapestry_tool_log_event() register_activation_hook(__FILE__, 'add_tyde_roles'); function add_tyde_roles() { - global $TYDE_DYAD_ROLES; - foreach ($TYDE_DYAD_ROLES as $key => $label) { - add_role( - $key, - $label, - [ - 'read' => true, - 'edit_posts' => true, - ] - ); - } - global $TYDE_YOUTH_ROLES; - foreach ($TYDE_YOUTH_ROLES as $key => $label) { - add_role( - $key, - $label, - [ - 'read' => true, - 'edit_posts' => true, - ] - ); - } -} - -/** - * Show the youth user id input if the user is a dyad. - */ -function add_dyad_youth_user_field($user) -{ - global $TYDE_DYAD_ROLES; - $isDyadUser = array_intersect($user->roles, array_keys($TYDE_DYAD_ROLES)); - - if ($isDyadUser) : ?> -
| - |
- - - |
-
|---|