/** * save a Forum * you can pass the Site object or an array with the fields * if you pass an array the keys must be with underscore and not with CamelCase * @param Forum|array $object * @return Forum */ public function save($object) { if (is_array($object)) { $objectData = $object; if (isset($object['id']) && $object['id'] > 0) { $object = $this->find($object['id']); } else { $object = new Forum(); } if (isset($objectData['parent'])) { $parent = $this->find($objectData['parent']); if ($parent) { $object->setParent($parent); } unset($objectData['parent']); } $this->assignArrayToObject($object, $objectData); } else { if (!$object instanceof Forum) { $this->addErrorMessage(self::ERROR_WRONG_OBJECT); } } if (!$this->hasError()) { $check = $this->forumManager->update($object); if ($check === true) { $this->addSuccessMessage(self::SUCCESS_SAVED); } } return $object; }
/** * @param Forum $forum * @param $data * @param string $prefix * @return mixed */ protected function addForumToTreeArray(Forum $forum, $data, $prefix = "") { $name = $forum->getName(); if (!empty($prefix)) { $name = $prefix . " - " . $name; } $data[] = array("id" => $forum->getId(), "name" => $name, "type" => $forum->getType()); foreach ($forum->getChildren() as $subforum) { $data = $this->addForumToTreeArray($subforum, $data, $name); } return $data; }
/** * @param Forum $forum * @return Post */ public function getLastPost(Forum $forum) { $ids = array($forum->getId()); $this->getAllForumChildIds($forum, $ids); $sql = "SELECT\n p\n FROM\n SymbbCoreForumBundle:Post p\n JOIN\n p.topic t\n WHERE\n t.forum IN (?0)\n ORDER BY\n p.created DESC"; $query = $this->em->createQuery($sql); $query->setParameter(0, $ids); $query->setMaxResults(1); $post = $query->getOneOrNullResult(); return $post; }