I am stuck on my project and I want your help. I have 3 tables in my database (reviews, criteria and criteriaScope), I will showcase my code below. In reviews table I have 4 fields, id, review, score and total, where score and total can be null. Score is an array, where words are saved if any word in reviews is matched with a word in the criteria table and total is the count of the positive or negative words in the score field.
In my index view I show all the reviews(without the score and total) and I have a button and when pressed I want
1) to update my database to find the matched words and set them in the score field and,
2) to update the total field respectively to the words from the score field.
Here is my code:
Reviews entity
class reviews
/**
* @var int
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* @var string
*
* @ORM\Column(name="review", type="string", length=500)
*/
private $review;
/**
* @var array
*
* @ORM\Column(name="score", type="array", nullable=true)
*/
private $score;
/**
* @var int
*
* @ORM\Column(name="total", type="integer", nullable=true)
*/
private $total;
and the getters/setters..
Criteria Entity
**
* @var int
*
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* @var string
*
* @ORM\Column(name="topic", type="string", length=30)
*/
private $topic;
/**
* @ORM\OneToMany(targetEntity="criteriaScope", mappedBy="criteria", cascade={"persist"})
*/
private $criteriaScope;
and getters/setters
CriteriaScope Entity
/**
* @var int
*
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* @var string
* @ORM\Column(name="positives", type="string", length=50)
*/
private $positives;
/**
* @var string
*
* @ORM\Column(name="negatives", type="string", length=50)
*/
private $negatives;
/**
* @ORM\ManyToOne(targetEntity="criteria", inversedBy="criteriaScope", cascade={"persist"})
* @ORM\JoinColumn(name="criteria_id", referencedColumnName="id")
*/
private $criteria;
plus the getters/setters
So what I want to do is, in my analyzedAction, to compare each review with each criteriaScope.positive and criteriaScope.negative, and update my score and total field in reviews database.
Thank you in advance :)
P.S: I am using Symfony 2.8