public function postAddMsgType()
 {
     $type_name = Input::get('type_name');
     if ($this->checkTypeExists($type_name)) {
         return json_encode(array(false, "Notification type with the same name already exists before"));
     }
     $rows = Input::get('data');
     try {
         $msg_type = new MessageType();
         $msg_type->type_name = $type_name;
         $msg_type->save();
     } catch (Exception $e) {
         return json_encode(array(false, "Failed to add notification type"));
     }
     $type_id = $msg_type->id;
     try {
         foreach ($rows as $row) {
             $column = new MessageTypeColums();
             $column->type_id = $type_id;
             $column->key = $row['key'];
             $column->value = $row['value'];
             $column->save();
         }
         //            Session::put('msg', 'Message Type and Columns Added Successfully');
         return json_encode(array(true, "Notification type and columns added successfully"));
     } catch (Exception $e) {
         MessageType::find($type_id)->delete();
         MessageTypeColums::where('type_id', '=', $type_id)->delete();
         if ($e->getCode() == 23000) {
             $msg = " : Keys Must be Unique";
         } else {
             $msg = "";
         }
         return json_encode(array(false, "Failed to add notification type columns" . $msg));
     }
 }
示例#2
0
 /**
  * Single create Message-Type
  *
  * @param array $arrayData Data
  *
  * return int Return integer
  */
 public function singleCreate(array $arrayData)
 {
     try {
         $cnn = \Propel::getConnection("workflow");
         try {
             $messageType = new \MessageType();
             $messageType->fromArray($arrayData, \BasePeer::TYPE_FIELDNAME);
             if ($messageType->validate()) {
                 $cnn->begin();
                 $result = $messageType->save();
                 $cnn->commit();
                 //Return
                 return $result;
             } else {
                 $msg = "";
                 foreach ($messageType->getValidationFailures() as $validationFailure) {
                     $msg = $msg . ($msg != "" ? "\n" : "") . $validationFailure->getMessage();
                 }
                 throw new \Exception(\G::LoadTranslation("ID_RECORD_CANNOT_BE_CREATED") . ($msg != "" ? "\n" . $msg : ""));
             }
         } catch (\Exception $e) {
             $cnn->rollback();
             throw $e;
         }
     } catch (\Exception $e) {
         throw $e;
     }
 }