/** * add comments for an objects * @param array $p input params (id, msg) */ public function addComment($p) { $rez = array('success' => false); if (empty($p['id']) || !is_numeric($p['id']) || empty($p['msg'])) { $rez['msg'] = L\get('Wrong_input_data'); return $rez; } if (!Security::canRead($p['id'])) { throw new \Exception(L\get('Access_denied')); } $commentTemplates = Templates::getIdsByType('comment'); if (empty($commentTemplates)) { $rez['msg'] = 'No comment templates found'; return $rez; } $co = new Objects\Comment(); $data = array('pid' => $p['id'], 'draftId' => @$p['draftId'], 'template_id' => array_shift($commentTemplates), 'system' => 2, 'data' => array('_title' => $p['msg'])); $id = $co->create($data); Solr\Client::runCron(); return array('success' => true, 'data' => \CB\Objects\Plugins\Comments::loadComment($id)); }