/** * Sets the id of best_answer, * id of user that supplied best answer * sets 'status' to 'accptd' * and also updates the Answer object to the * set accepted property to true * * In case question was 'unanswered' we must also * update UNANSWERED_TAGS * * @param Answer $Answer object of type Answer represents * Answer being accepted as best answer * * @return \Lampcms\Question */ public function setBestAnswer(Answer $Answer) { d('about to set status to accptd'); parent::offsetSet('i_sel_ans', $Answer->getResourceId()); parent::offsetSet('i_sel_uid', $Answer->getOwnerId()); /** * Now set the Answer object's accepted status to true */ $Answer->setAccepted()->touch(); /** * If Question is still not 'answered', means * no accepted answer, * then since we are not changing its status * to answered, we must update * the count of unanswered tags, which * is done via UnansweredTags object */ if ('accptd' !== $this->offsetGet(Schema::STATUS)) { UnansweredTags::factory($this->Registry)->remove($this); } parent::offsetSet(Schema::STATUS, 'accptd'); d('setting status to accptd'); $this->touch(false); return $this; }