Esempio n. 1
0
 /**
  * Saves a status entity.
  *
  * @param   JInput  $input  Holds the data to be saved.
  *
  * @return  int   ID of the inserted / saved object.
  *
  * @throws Exception
  */
 public function save($input)
 {
     $query = $this->db->getQuery(true);
     $values = array("name" => $input->getString('name'), "helptext" => $input->getString('helptext'), "open" => $input->getBool('open'), "style" => $input->getString('style'), "project_id" => $input->getInt('project_id'));
     $values = $this->validate($values);
     if (!$values) {
         return false;
     }
     $id = $input->getInt('id');
     if ($id != 0) {
         $query->update('#__monitor_status')->where('id = ' . $id);
     } else {
         $query->insert('#__monitor_status');
         $orderQuery = $this->db->getQuery(true);
         $orderQuery->select('MAX(ordering)')->from('#__monitor_status')->where('project_id = ' . $values["project_id"]);
         $this->db->setQuery($orderQuery)->execute();
         $values["ordering"] = (int) $this->db->loadResult() + 1;
     }
     $query->set(MonitorHelper::sqlValues($values, $query));
     $this->db->setQuery($query);
     return $this->db->execute();
 }