コード例 #1
0
 public function replies($index = null)
 {
     global $DB;
     if (empty($this->_replies)) {
         // only all replies in an open or close state, a reply should never be automated
         // and drafts are no in the line of published conversation.
         $items = array(dialogue::STATE_OPEN, dialogue::STATE_CLOSED);
         list($insql, $inparams) = $DB->get_in_or_equal($items, SQL_PARAMS_NAMED, 'viewstate');
         $sql = "SELECT dm.*\n                      FROM {dialogue_messages} dm\n                     WHERE dm.conversationindex > 1\n                       AND dm.state {$insql}\n                       AND dm.conversationid = :conversationid\n                  ORDER BY dm.conversationindex ASC";
         $params = array('conversationid' => $this->conversationid) + $inparams;
         $records = $DB->get_records_sql($sql, $params);
         foreach ($records as $record) {
             $reply = new reply($this->_dialogue, $this);
             $reply->load($record);
             $this->_replies[$record->id] = $reply;
         }
     }
     if ($index) {
         if (!isset($this->_replies[$index])) {
             throw new \coding_exception('index not defined');
         }
         return $this->_replies[$index];
     }
     return $this->_replies;
 }