protected function updateObjectFromForm()
 {
     if ($this->object->getId()) {
         foreach ($this->object->getReportQuerys() as $report_query) {
             $report_query->delete();
         }
         foreach ($this->object->getReportTags() as $tag) {
             $tag->delete();
         }
     }
     $this->object->setTitle($this->getValue('title'));
     $this->object->setDescription($this->getValue('description'));
     $this->object->setMailFrequency($this->getValue('frequency'));
     if ($this->getValue('private') == 'on') {
         $this->object->setPublicRecord(false);
     } else {
         $this->object->setPublicRecord(true);
     }
     $tag_names = explode(',', $this->getValue('tags'));
     foreach ($tag_names as $tag_name) {
         if (!($tag_name = strtolower(trim($tag_name)))) {
             continue;
         }
         $tag = new ReportTag();
         $tag->setName($tag_name);
         $this->object->addReportTag($tag);
     }
     $query_texts = explode("\n", str_replace("\r", "", $this->getValue('query_texts')));
     $query_titles = explode("\n", str_replace("\r", "", $this->getValue('query_titles')));
     for ($i = 0; $i < sizeof($query_texts); $i++) {
         $query_text = $query_texts[$i];
         $query_title = $query_titles[$i];
         if ($query_text) {
             $query = QueryPeer::retrieveByQUERY($query_text);
             if (!$query) {
                 $query = new Query();
                 $query->setQuery($query_text);
             }
             $report_query = new ReportQuery();
             $report_query->setQuery($query);
             $report_query->setTitle($query_title);
             $this->object->addReportQuery($report_query);
         }
     }
     if ($this->getValue('user_id')) {
         $this->object->setUserId($this->getValue('user_id'));
     }
 }
 function saveTags($report_id, $tagArray)
 {
     $reportTagModel = new ReportTag();
     $db = $reportTagModel->getAdapter();
     $where = $db->quoteInto('report_id = ?', $report_id);
     $rows_affected = $reportTagModel->delete($where);
     if (isset($tagArray)) {
         foreach ($tagArray as $tag) {
             $reportTag = $reportTagModel->createRow();
             $reportTag->report_id = $report_id;
             $reportTag->tag_id = $tag;
             $reportTag->save();
         }
     }
 }
 private static function generateTags()
 {
     $tags = array();
     $tag_count = rand(1, 5);
     $tag_start = rand(0, sizeof(self::$TAGS) - 1);
     for ($i = 0; $i < $tag_count; $i++) {
         $tag = new ReportTag();
         $tag->setName(self::$TAGS[$tag_start]);
         $tags[] = $tag;
         $tag_start = $tag_start >= sizeof(self::$TAGS) - 1 ? 0 : $tag_start + 1;
     }
     return $tags;
 }