I am trying to link articles with one another. The scenario is define below
Take articles A, B and C.
- Admin links A to B. So, we automatically add links for B to A.
- Admin links B to C. So, we automatically add links for C to B (normal scenario) as well as C to A (because B is linked to A). ( How can i do this? I tried the below code but can't move forward )
- Admin deletes the link from B to C. So, we automatically delete links for C to B as well as C to A.
My code:
public function executeLinkarticle(sfWebRequest $request) {
$this->articleId = $request->getParameter('id');
if ($request->isMethod('POST')) {
$articles = $request->getParameter('articles');
$articleId = $request->getParameter('articleId');
foreach ($articles as $linkedArticleId) {
//Linking A To B
$linkedArticleObj = new BlogArticleLinkedArticle();
$linkedArticleObj->setArticleId($articleId);
$linkedArticleObj->setLinkedArticleId($linkedArticleId);
$linkedArticleObj->save();
//Linking B To A
$linkedArticleObj = new BlogArticleLinkedArticle();
$linkedArticleObj->setArticleId($linkedArticleId);
$linkedArticleObj->setLinkedArticleId($articleId);
$linkedArticleObj->save();
//linking C to A code
Checking the Database Table IF B is LINKED WITH A(i.e already linked) THEN how to link C to A ?
}
return $this->renderText();
}
}
Table Structure
ID | ARTICLE_ID | LINKED_ARTICLE_ID